Class: PerfectShape::Shape
- Inherits:
-
Object
- Object
- PerfectShape::Shape
- 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.
Direct Known Subclasses
Arc, CompositeShape, CubicBezierCurve, Line, Path, Point, Polygon, QuadraticBezierCurve, Rectangle
Instance Method Summary collapse
-
#==(other) ⇒ Object
Subclasses must implement.
-
#bounding_box ⇒ Object
Rectangle with x = self.min_x, y = self.min_y, width = self.width, height = self.height.
-
#center_point ⇒ Object
Center point is ‘[center_x, center_y]` Returns `nil` if either center_x or center_y are `nil`.
-
#center_x ⇒ Object
center_x is min_x + width/2.0 by default Returns nil if min_x or width are nil.
-
#center_y ⇒ Object
center_y is min_y + height/2.0 by default Returns nil if min_y or height are nil.
-
#contain?(x_or_point, y = nil, outline: false, distance_tolerance: 0) ⇒ Boolean
Subclasses must implement.
-
#height ⇒ Object
Default implementation is max_y - min_y Subclasses can override.
-
#max_x ⇒ Object
Subclasses must implement.
-
#max_y ⇒ Object
Subclasses must implement.
-
#min_x ⇒ Object
Subclasses must implement.
-
#min_y ⇒ Object
Subclasses must implement.
-
#normalize_point(x_or_point, y = nil) ⇒ Object
Normalizes point args whether two-number Array or x, y args returning normalized point array of two BigDecimal’s.
-
#width ⇒ Object
Default implementation is max_x - min_x Subclasses can override.
Instance Method Details
#==(other) ⇒ Object
Subclasses must implement
98 99 |
# File 'lib/perfect_shape/shape.rb', line 98 def ==(other) end |
#bounding_box ⇒ Object
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_point ⇒ Object
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_x ⇒ Object
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_y ⇒ Object
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
94 95 |
# File 'lib/perfect_shape/shape.rb', line 94 def contain?(x_or_point, y = nil, outline: false, distance_tolerance: 0) end |
#height ⇒ Object
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_x ⇒ Object
Subclasses must implement
35 36 |
# File 'lib/perfect_shape/shape.rb', line 35 def max_x end |
#max_y ⇒ Object
Subclasses must implement
39 40 |
# File 'lib/perfect_shape/shape.rb', line 39 def max_y end |
#min_x ⇒ Object
Subclasses must implement
27 28 |
# File 'lib/perfect_shape/shape.rb', line 27 def min_x end |
#min_y ⇒ Object
Subclasses must implement
31 32 |
# File 'lib/perfect_shape/shape.rb', line 31 def min_y end |
#normalize_point(x_or_point, y = nil) ⇒ Object
Normalizes point args whether two-number Array or x, y args returning normalized point array of two BigDecimal’s
85 86 87 88 89 90 91 |
# File 'lib/perfect_shape/shape.rb', line 85 def normalize_point(x_or_point, y = nil) x = x_or_point x, y = x if y.nil? && x_or_point.is_a?(Array) && x_or_point.size == 2 x = x.is_a?(BigDecimal) ? x : BigDecimal(x.to_s) y = y.is_a?(BigDecimal) ? y : BigDecimal(y.to_s) [x, y] end |
#width ⇒ Object
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 |