class MiniGL::Rectangle
This class represents a rectangle by its x and y coordinates and width and height.
Attributes
h[RW]
The height of the rectangle.
w[RW]
The width of the rectangle.
x[RW]
The x-coordinate of the rectangle.
y[RW]
The y-coordinate of the rectangle.
Public Class Methods
new(x, y, w, h)
click to toggle source
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.
# File lib/minigl/global.rb, line 110 def initialize(x, y, w, h) @x = x; @y = y; @w = w; @h = h end
Public Instance Methods
intersect?(r)
click to toggle source
Returns whether this rectangle intersects another.
Parameters:
- r
-
The rectangle to check intersection with.
# 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