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) ⇒ @code true
Checks if rectangle contains point (two-number Array or x, y args).
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
Instance Method Details
#contain?(x_or_point, y = nil) ⇒ @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.
39 40 41 42 43 |
# File 'lib/perfect_shape/rectangle.rb', line 39 def contain?(x_or_point, y = nil) x, y = normalize_point(x_or_point, y) return unless x && y x.between?(self.x, self.x + self.width) && y.between?(self.y, self.y + self.height) end |