Rect
January 7, 2026 ยท View on GitHub
Rect
Rectangle for bounds and collision areas.
Table of Contents
Instance Methods
#initialize
Create a new Rect with optional position and dimensions.
Parameters:
| Name | Type | Description |
|---|---|---|
x | Float | The x position (default: 0) |
y | Float | The y position (default: 0) |
w | Float | The width (default: 0) |
h | Float | The height (default: 0) |
Returns: Rect - The new rectangle
Example:
Rect.new(10, 20, 100, 50) # x=10, y=20, w=100, h=50
#x
Get the x position (left edge).
Returns: Float - The x position
Example:
x = rect.x
#y
Get the y position (top edge).
Returns: Float - The y position
Example:
y = rect.y
#w
Get the width.
Returns: Float - The width
Example:
width = rect.w
#h
Get the height.
Returns: Float - The height
Example:
height = rect.h
#to_s
Common math utility functions for game development. Provides lerp, clamp, smoothstep, and other interpolation helpers. Named "Mathf" to avoid conflict with Ruby's built-in Math module.
Returns: String - String in format "Rect(x, y, w, h)"
Example:
# Smooth transitions
t = elapsed / duration
alpha = Mathf.smoothstep(0, 1, t) * 255