Class: PerfectShape::CompositeShape
- Defined in:
- lib/perfect_shape/composite_shape.rb
Overview
A composite of multiple shapes
Instance Attribute Summary collapse
-
#shapes ⇒ Object
Returns the value of attribute shapes.
Instance Method Summary collapse
-
#contain?(x_or_point, y = nil, outline: false, distance_tolerance: 0) ⇒ Boolean
Checks if composite shape contains point (two-number Array or x, y args) by comparing against all shapes it consists of.
-
#initialize(shapes: []) ⇒ CompositeShape
constructor
Constructs from multiple shapes.
- #intersect?(rectangle) ⇒ Boolean
- #max_x ⇒ Object
- #max_y ⇒ Object
- #min_x ⇒ Object
- #min_y ⇒ Object
Methods inherited from Shape
#==, #bounding_box, #center_point, #center_x, #center_y, #height, #width
Constructor Details
#initialize(shapes: []) ⇒ CompositeShape
Constructs from multiple shapes
37 38 39 |
# File 'lib/perfect_shape/composite_shape.rb', line 37 def initialize(shapes: []) self.shapes = shapes end |
Instance Attribute Details
#shapes ⇒ Object
Returns the value of attribute shapes.
34 35 36 |
# File 'lib/perfect_shape/composite_shape.rb', line 34 def shapes @shapes end |
Instance Method Details
#contain?(x_or_point, y = nil, outline: false, distance_tolerance: 0) ⇒ Boolean
Checks if composite shape contains point (two-number Array or x, y args) by comparing against all shapes it consists of
the composite shape or false if the point lies outside of the path’s bounds.
66 67 68 69 70 71 |
# File 'lib/perfect_shape/composite_shape.rb', line 66 def contain?(x_or_point, y = nil, outline: false, distance_tolerance: 0) x, y = Point.normalize_point(x_or_point, y) return unless x && y shapes.any? { |shape| shape.contain?(x, y, outline: outline, distance_tolerance: distance_tolerance) } end |
#intersect?(rectangle) ⇒ Boolean
73 74 75 |
# File 'lib/perfect_shape/composite_shape.rb', line 73 def intersect?(rectangle) shapes.any? { |shape| shape.intersect?(rectangle) } end |
#max_x ⇒ Object
49 50 51 |
# File 'lib/perfect_shape/composite_shape.rb', line 49 def max_x shapes.map(&:max_x).max end |
#max_y ⇒ Object
53 54 55 |
# File 'lib/perfect_shape/composite_shape.rb', line 53 def max_y shapes.map(&:max_y).max end |
#min_x ⇒ Object
41 42 43 |
# File 'lib/perfect_shape/composite_shape.rb', line 41 def min_x shapes.map(&:min_x).min end |
#min_y ⇒ Object
45 46 47 |
# File 'lib/perfect_shape/composite_shape.rb', line 45 def min_y shapes.map(&:min_y).min end |