Module: PerfectShape::MultiPoint
- Included in:
- CubicBezierCurve, Line, Path, Polygon, QuadraticBezierCurve
- Defined in:
- lib/perfect_shape/multi_point.rb
Overview
Represents multi-point shapes like Line, Polygon, and Polyline
Instance Attribute Summary collapse
-
#points ⇒ Object
Returns the value of attribute points.
Class Method Summary collapse
Instance Method Summary collapse
- #first_point ⇒ Object
- #initialize(points: []) ⇒ Object
- #max_x ⇒ Object
- #max_y ⇒ Object
- #min_x ⇒ Object
- #min_y ⇒ Object
Instance Attribute Details
#points ⇒ Object
Returns the value of attribute points.
40 41 42 |
# File 'lib/perfect_shape/multi_point.rb', line 40 def points @points end |
Class Method Details
.normalize_point_array(the_points) ⇒ Object
28 29 30 31 32 33 34 35 36 37 |
# File 'lib/perfect_shape/multi_point.rb', line 28 def normalize_point_array(the_points) if the_points.all? {|the_point| the_point.is_a?(Array)} the_points else the_points = the_points.flatten xs = the_points.each_with_index.select {|n, i| i.even?}.map(&:first) ys = the_points.each_with_index.select {|n, i| i.odd?}.map(&:first) xs.zip(ys) end end |
Instance Method Details
#first_point ⇒ Object
58 59 60 |
# File 'lib/perfect_shape/multi_point.rb', line 58 def first_point points.first.to_a end |
#initialize(points: []) ⇒ Object
42 43 44 |
# File 'lib/perfect_shape/multi_point.rb', line 42 def initialize(points: []) self.points = points end |
#max_x ⇒ Object
70 71 72 |
# File 'lib/perfect_shape/multi_point.rb', line 70 def max_x points.map(&:first).max end |
#max_y ⇒ Object
74 75 76 |
# File 'lib/perfect_shape/multi_point.rb', line 74 def max_y points.map(&:last).max end |
#min_x ⇒ Object
62 63 64 |
# File 'lib/perfect_shape/multi_point.rb', line 62 def min_x points.map(&:first).min end |
#min_y ⇒ Object
66 67 68 |
# File 'lib/perfect_shape/multi_point.rb', line 66 def min_y points.map(&:last).min end |