class PerfectShape::Shape

Superclass of all shapes. Not meant to be used directly. Subclasses must implement/override methods as needed.

Public Instance Methods

==(other) click to toggle source

Subclasses must implement

# File lib/perfect_shape/shape.rb, line 83
def ==(other)
end
bounding_box() click to toggle source

Rectangle with x = self.min_x, y = self.min_y, width = self.width, height = self.height

# File lib/perfect_shape/shape.rb, line 73
def bounding_box
  require 'perfect_shape/rectangle'
  Rectangle.new(x: min_x, y: min_y, width: width, height: height)
end
center_point() click to toggle source

Center point is ‘[center_x, center_y]` Returns `nil` if either center_x or center_y are `nil`

# File lib/perfect_shape/shape.rb, line 56
def center_point
  [center_x, center_y] unless center_x.nil? || center_y.nil?
end
center_x() click to toggle source

center_x is min_x + width/2.0 by default Returns nil if min_x or width are nil

# File lib/perfect_shape/shape.rb, line 62
def center_x
  min_x + width / BigDecimal('2.0') if min_x && width
end
center_y() click to toggle source

center_y is min_y + height/2.0 by default Returns nil if min_y or height are nil

# File lib/perfect_shape/shape.rb, line 68
def center_y
  min_y + height / BigDecimal('2.0') if min_y && height
end
contain?(x_or_point, y = nil, outline: false, distance_tolerance: 0) click to toggle source

Subclasses must implement

# File lib/perfect_shape/shape.rb, line 79
def contain?(x_or_point, y = nil, outline: false, distance_tolerance: 0)
end
height() click to toggle source

Default implementation is max_y - min_y Subclasses can override

# File lib/perfect_shape/shape.rb, line 50
def height
  max_y - min_y if max_y && min_y
end
max_x() click to toggle source

Subclasses must implement

# File lib/perfect_shape/shape.rb, line 35
def max_x
end
max_y() click to toggle source

Subclasses must implement

# File lib/perfect_shape/shape.rb, line 39
def max_y
end
min_x() click to toggle source

Subclasses must implement

# File lib/perfect_shape/shape.rb, line 27
def min_x
end
min_y() click to toggle source

Subclasses must implement

# File lib/perfect_shape/shape.rb, line 31
def min_y
end
width() click to toggle source

Default implementation is max_x - min_x Subclasses can override

# File lib/perfect_shape/shape.rb, line 44
def width
  max_x - min_x if max_x && min_x
end