Class: PerfectShape::Ellipse
- Defined in:
- lib/perfect_shape/ellipse.rb
Overview
Mostly ported from java.awt.geom: docs.oracle.com/javase/8/docs/api/java/awt/geom/Ellipse2D.html
Direct Known Subclasses
Constant Summary collapse
- MESSAGE_CANNOT_UPDATE_ATTRIUBTE =
"Ellipse %s cannot be updated. If you want to update type, use Arc instead!"
Constants inherited from Arc
Instance Attribute Summary
Attributes inherited from Arc
Attributes included from RectangularShape
Attributes included from PointLocation
Instance Method Summary collapse
-
#contain?(x_or_point, y = nil) ⇒ @code true
Checks if ellipse contains point (two-number Array or x, y args).
- #extent=(value) ⇒ Object
-
#initialize(x: 0, y: 0, width: 1, height: 1, center_x: nil, center_y: nil, radius_x: nil, radius_y: nil) ⇒ Ellipse
constructor
A new instance of Ellipse.
- #start=(value) ⇒ Object
- #type=(value) ⇒ Object
Methods inherited from Arc
#center_x, #center_x=, #center_y, #center_y=, #contain_angle?, #height, #height=, #radius_x, #radius_x=, #radius_y, #radius_y=, #width, #width=, #x, #x=, #y, #y=
Methods included from RectangularShape
Methods included from PointLocation
Methods inherited from Shape
#==, #bounding_box, #center_x, #center_y, #height, #max_x, #max_y, #min_x, #min_y, #normalize_point, #width
Constructor Details
#initialize(x: 0, y: 0, width: 1, height: 1, center_x: nil, center_y: nil, radius_x: nil, radius_y: nil) ⇒ Ellipse
Returns a new instance of Ellipse.
29 30 31 32 |
# File 'lib/perfect_shape/ellipse.rb', line 29 def initialize(x: 0, y: 0, width: 1, height: 1, center_x: nil, center_y: nil, radius_x: nil, radius_y: nil) super @initialized = true end |
Instance Method Details
#contain?(x_or_point, y = nil) ⇒ @code true
Checks if ellipse contains point (two-number Array or x, y args)
the ellipse, false if the point lies outside of the ellipseās bounds.
66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/perfect_shape/ellipse.rb', line 66 def contain?(x_or_point, y = nil) # This is implemented again even though super would have just worked to have an optimized algorithm for Ellipse. x, y = normalize_point(x_or_point, y) return unless x && y ellw = self.width return false if ellw <= 0.0 normx = (x - self.x) / ellw - 0.5 ellh = self.height return false if ellh <= 0.0 normy = (y - self.y) / ellh - 0.5 (normx * normx + normy * normy) < 0.25 end |
#extent=(value) ⇒ Object
50 51 52 53 54 55 56 |
# File 'lib/perfect_shape/ellipse.rb', line 50 def extent=(value) if @initialized raise MESSAGE_CANNOT_UPDATE_ATTRIUBTE % 'extent' else super end end |
#start=(value) ⇒ Object
42 43 44 45 46 47 48 |
# File 'lib/perfect_shape/ellipse.rb', line 42 def start=(value) if @initialized raise MESSAGE_CANNOT_UPDATE_ATTRIUBTE % 'start' else super end end |
#type=(value) ⇒ Object
34 35 36 37 38 39 40 |
# File 'lib/perfect_shape/ellipse.rb', line 34 def type=(value) if @initialized raise MESSAGE_CANNOT_UPDATE_ATTRIUBTE % 'type' else super end end |