Class: PerfectShape::Rectangle
- Includes:
- RectangularShape
- Defined in:
- lib/perfect_shape/rectangle.rb
Overview
Mostly ported from java.awt.geom: docs.oracle.com/javase/8/docs/api/java/awt/geom/Rectangle2D.html
Direct Known Subclasses
Instance Attribute Summary
Attributes included from RectangularShape
Attributes included from PointLocation
Instance Method Summary collapse
-
#contain?(x_or_point, y = nil, outline: false, distance_tolerance: 0) ⇒ @code true
Checks if rectangle contains point (two-number Array or x, y args).
- #edges ⇒ Object
Methods included from RectangularShape
Methods included from PointLocation
Methods inherited from Shape
#==, #bounding_box, #center_point, #center_x, #center_y, #height, #max_x, #max_y, #min_x, #min_y, #normalize_point, #width
Instance Method Details
#contain?(x_or_point, y = nil, outline: false, distance_tolerance: 0) ⇒ @code true
Checks if rectangle contains point (two-number Array or x, y args)
the rectangle, false if the point lies outside of the rectangle’s bounds.
40 41 42 43 44 45 46 47 48 |
# File 'lib/perfect_shape/rectangle.rb', line 40 def contain?(x_or_point, y = nil, outline: false, distance_tolerance: 0) x, y = normalize_point(x_or_point, y) return unless x && y if outline edges.any? { |edge| edge.contain?(x, y, distance_tolerance: distance_tolerance) } else x.between?(self.x, self.x + width) && y.between?(self.y, self.y + height) end end |
#edges ⇒ Object
50 51 52 53 54 55 56 57 |
# File 'lib/perfect_shape/rectangle.rb', line 50 def edges [ Line.new(points: [[self.x, self.y], [self.x + width, self.y]]), Line.new(points: [[self.x + width, self.y], [self.x + width, self.y + height]]), Line.new(points: [[self.x + width, self.y + height], [self.x, self.y + height]]), Line.new(points: [[self.x, self.y + height], [self.x, self.y]]) ] end |