Rect

ceramic.Rect (Class)

Represents a rectangular area defined by position and dimensions.

Rect is a simple data structure for storing rectangular bounds, commonly used for collision detection, viewport definitions, texture regions, and UI layout calculations. The rectangle is defined by its top-left corner (x, y) and its dimensions (width, height).

The @:structInit metadata allows convenient struct-style initialization:

// Different ways to create rectangles
var rect1 = new Rect(10, 20, 100, 50);
var rect2:Rect = {x: 10, y: 20, width: 100, height: 50};
var rect3 = new Rect(); // Defaults to (0, 0, 0, 0)

// Common usage patterns
var bounds = new Rect(visual.x, visual.y, visual.width, visual.height);
var viewport:Rect = {x: 0, y: 0, width: screen.width, height: screen.height};

// Accessing properties
var right = rect.x + rect.width;
var bottom = rect.y + rect.height;
var area = rect.width * rect.height;

Note: This class does not include utility methods for intersection, containment, or other geometric operations. Use GeometryUtils for such calculations.

See: ceramic.GeometryUtils For rectangle intersection and containment tests, ceramic.Visual For visual bounds, ceramic.Screen For screen viewport

Instance Members

The X coordinate of the rectangle's top-left corner. In screen coordinates, this represents the horizontal position.


The Y coordinate of the rectangle's top-left corner. In screen coordinates, this represents the vertical position.


width: Float

The width of the rectangle. Should typically be positive for a valid rectangle.


height: Float

The height of the rectangle. Should typically be positive for a valid rectangle.


new(?x: Float = 0, ?y: Float = 0, ?width: Float = 0, ?height: Float = 0): Void

Creates a new Rect instance with the specified position and dimensions.

Name Type Default Description
x Float 0 The X coordinate of the top-left corner (default: 0)
y Float 0 The Y coordinate of the top-left corner (default: 0)
width Float 0 The width of the rectangle (default: 0)
height Float 0 The height of the rectangle (default: 0)

Private Members

toString(): String

Returns a string representation of this rectangle. Format: "Rect(x, y, width, height)" with the actual numeric values.

Returns Description
String String representation of the rectangle

Metadata

Name Parameters
:structInit -