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.
-
#width ⇒ Object
Default implementation is max_x - min_x Subclasses can override.
Instance Method Details
#==(other) ⇒ Object
Subclasses must implement
83 84 |
# File 'lib/perfect_shape/shape.rb', line 83 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
79 80 |
# File 'lib/perfect_shape/shape.rb', line 79 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 |
#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 |