Class: PerfectShape::Shape

Inherits:
Object
  • Object
show all
Defined in:
lib/perfect_shape/shape.rb

Overview

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

Instance Method Summary collapse

Instance Method Details

#==(other) ⇒ Object

Subclasses must implement



83
84
# File 'lib/perfect_shape/shape.rb', line 83

def ==(other)
end

#bounding_boxObject

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



73
74
75
76
# 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_pointObject

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



56
57
58
# File 'lib/perfect_shape/shape.rb', line 56

def center_point
  [center_x, center_y] unless center_x.nil? || center_y.nil?
end

#center_xObject

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



62
63
64
# File 'lib/perfect_shape/shape.rb', line 62

def center_x
  min_x + width / BigDecimal('2.0') if min_x && width
end

#center_yObject

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



68
69
70
# 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) ⇒ Boolean

Subclasses must implement

Returns:

  • (Boolean)


79
80
# File 'lib/perfect_shape/shape.rb', line 79

def contain?(x_or_point, y = nil, outline: false, distance_tolerance: 0)
end

#heightObject

Default implementation is max_y - min_y Subclasses can override



50
51
52
# File 'lib/perfect_shape/shape.rb', line 50

def height
  max_y - min_y if max_y && min_y
end

#max_xObject

Subclasses must implement



35
36
# File 'lib/perfect_shape/shape.rb', line 35

def max_x
end

#max_yObject

Subclasses must implement



39
40
# File 'lib/perfect_shape/shape.rb', line 39

def max_y
end

#min_xObject

Subclasses must implement



27
28
# File 'lib/perfect_shape/shape.rb', line 27

def min_x
end

#min_yObject

Subclasses must implement



31
32
# File 'lib/perfect_shape/shape.rb', line 31

def min_y
end

#widthObject

Default implementation is max_x - min_x Subclasses can override



44
45
46
# File 'lib/perfect_shape/shape.rb', line 44

def width
  max_x - min_x if max_x && min_x
end