Class: PerfectShape::Rectangle

Inherits:
Shape
  • Object
show all
Includes:
RectangularShape
Defined in:
lib/perfect_shape/rectangle.rb

Overview

Direct Known Subclasses

Square

Instance Attribute Summary

Attributes included from RectangularShape

#height, #width

Attributes included from PointLocation

#x, #y

Instance Method Summary collapse

Methods included from RectangularShape

#initialize, #max_x, #max_y

Methods included from PointLocation

#initialize, #min_x, #min_y

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.

Parameters:

  • x

    The X coordinate of the point to test.

  • y (defaults to: nil)

    The Y coordinate of the point to test.

Returns:

  • (@code true)

    if the point lies within the bound of



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