Class: MiniGL::Rectangle

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#hObject

The height of the rectangle.



101
102
103
# File 'lib/minigl/global.rb', line 101

def h
  @h
end

#wObject

The width of the rectangle.



98
99
100
# File 'lib/minigl/global.rb', line 98

def w
  @w
end

#xObject

The x-coordinate of the rectangle.



92
93
94
# File 'lib/minigl/global.rb', line 92

def x
  @x
end

#yObject

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.

Returns:

  • (Boolean)


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