class PerfectShape::CompositeShape

A composite of multiple shapes

Attributes

shapes[RW]

Public Class Methods

new(shapes: []) click to toggle source

Constructs from multiple shapes

# File lib/perfect_shape/composite_shape.rb, line 37
def initialize(shapes: [])
  self.shapes = shapes
end

Public Instance Methods

contain?(x_or_point, y = nil, outline: false, distance_tolerance: 0) click to toggle source

Checks if composite shape contains point (two-number Array or x, y args) by comparing against all shapes it consists of

@param x The X coordinate of the point to test. @param y The Y coordinate of the point to test.

@return true if the point lies within the bound of the composite shape or false if the point lies outside of the path’s bounds.

# 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) click to toggle source
# File lib/perfect_shape/composite_shape.rb, line 73
def intersect?(rectangle)
  shapes.any? { |shape| shape.intersect?(rectangle) }
end
max_x() click to toggle source
# File lib/perfect_shape/composite_shape.rb, line 49
def max_x
  shapes.map(&:max_x).max
end
max_y() click to toggle source
# File lib/perfect_shape/composite_shape.rb, line 53
def max_y
  shapes.map(&:max_y).max
end
min_x() click to toggle source
# File lib/perfect_shape/composite_shape.rb, line 41
def min_x
  shapes.map(&:min_x).min
end
min_y() click to toggle source
# File lib/perfect_shape/composite_shape.rb, line 45
def min_y
  shapes.map(&:min_y).min
end