Class: Waxy::Geometry::Point
- Inherits:
-
Object
- Object
- Waxy::Geometry::Point
- Defined in:
- lib/waxy/geometry/point.rb
Instance Attribute Summary collapse
-
#x ⇒ Object
Returns the value of attribute x.
-
#y ⇒ Object
Returns the value of attribute y.
Instance Method Summary collapse
- #hex_corner_offset(layout, corner) ⇒ Object
- #hex_to_pixel(layout, h) ⇒ Object
-
#initialize(_x, _y) ⇒ Point
constructor
A new instance of Point.
Constructor Details
#initialize(_x, _y) ⇒ Point
Returns a new instance of Point.
7 8 9 10 |
# File 'lib/waxy/geometry/point.rb', line 7 def initialize(_x, _y) @x = _x @y = _y end |
Instance Attribute Details
#x ⇒ Object
Returns the value of attribute x.
5 6 7 |
# File 'lib/waxy/geometry/point.rb', line 5 def x @x end |
#y ⇒ Object
Returns the value of attribute y.
5 6 7 |
# File 'lib/waxy/geometry/point.rb', line 5 def y @y end |
Instance Method Details
#hex_corner_offset(layout, corner) ⇒ Object
19 20 21 22 23 |
# File 'lib/waxy/geometry/point.rb', line 19 def hex_corner_offset(layout, corner) size = Point.new(layout.size) angle = 2.0 * M_PI * (layout.orientation.start_angle + corner ) / 6 Point.new(size.x * cos(angle), size.y * sin(angle)) end |
#hex_to_pixel(layout, h) ⇒ Object
12 13 14 15 16 17 |
# File 'lib/waxy/geometry/point.rb', line 12 def hex_to_pixel(layout, h) m = layout.orientation x = (m.f0 * h.q + m.f1 * h.r) * layout.size.x y = (m.f2 * h.q + m.f3 * h.r) * layout.size.y return Point.new(x + layout.origin.x, y + layout.origin.y) end |