Class: MiniGL::Rectangle
- Inherits:
-
Object
- Object
- MiniGL::Rectangle
- Defined in:
- lib/minigl/global.rb
Overview
This class represents a rectangle by its x and y coordinates and width and height.
Instance Attribute Summary collapse
-
#h ⇒ Object
The height of the rectangle.
-
#w ⇒ Object
The width of the rectangle.
-
#x ⇒ Object
The x-coordinate of the rectangle.
-
#y ⇒ Object
The y-coordinate of the rectangle.
Instance Method Summary collapse
-
#initialize(x, y, w, h) ⇒ Rectangle
constructor
Creates a new rectangle.
-
#intersect?(r) ⇒ Boolean
Returns whether this rectangle intersects another.
Constructor Details
#initialize(x, y, w, h) ⇒ Rectangle
Creates a new rectangle.
Parameters:
- x
-
The x-coordinate of the rectangle.
- y
-
The y-coordinate of the rectangle.
- w
-
The width of the rectangle.
- h
-
The height of the rectangle.
110 111 112 |
# File 'lib/minigl/global.rb', line 110 def initialize(x, y, w, h) @x = x; @y = y; @w = w; @h = h end |
Instance Attribute Details
#h ⇒ Object
The height of the rectangle.
101 102 103 |
# File 'lib/minigl/global.rb', line 101 def h @h end |
#w ⇒ Object
The width of the rectangle.
98 99 100 |
# File 'lib/minigl/global.rb', line 98 def w @w end |
#x ⇒ Object
The x-coordinate of the rectangle.
92 93 94 |
# File 'lib/minigl/global.rb', line 92 def x @x end |
#y ⇒ Object
The y-coordinate of the rectangle.
95 96 97 |
# File 'lib/minigl/global.rb', line 95 def y @y end |
Instance Method Details
#intersect?(r) ⇒ Boolean
Returns whether this rectangle intersects another.
Parameters:
- r
-
The rectangle to check intersection with.
118 119 120 |
# File 'lib/minigl/global.rb', line 118 def intersect?(r) @x < r.x + r.w && @x + @w > r.x && @y < r.y + r.h && @y + @h > r.y end |