Canvas Toolkit
← Class index

CRect

Geometry

Represents an axis-aligned rectangle defined by its position and size. The right and bottom edges are exclusive for point containment tests.

import { CRect } from "canvas-toolkit-lib";

Declared members

constructor(x?: number, y?: number, width?: number, height?: number);

Creates a rectangle with the specified position and dimensions. @param x Horizontal coordinate of the left edge. @param y Vertical coordinate of the top edge. @param width Rectangle width. @param height Rectangle height.

x(): number;

@returns The horizontal coordinate of the left edge.

y(): number;

@returns The vertical coordinate of the top edge.

width(): number;

@returns The rectangle width.

height(): number;

@returns The rectangle height.

right(): number;

@returns The horizontal coordinate immediately after the right edge.

bottom(): number;

@returns The vertical coordinate immediately after the bottom edge.

equals(rect: CRect): boolean;

Tests whether this rectangle has the same position and size as another rectangle. @param rect Rectangle to compare with. @returns `true` if both rectangles have identical geometry; otherwise `false`.

setGeometry(x: number, y: number, width: number, height: number): void;

Sets the rectangle position and dimensions. @param x Horizontal coordinate of the left edge. @param y Vertical coordinate of the top edge. @param width New rectangle width. @param height New rectangle height.

contains(point: CPoint): boolean;

Tests whether a point lies inside the rectangle. The left and top edges are included, while the right and bottom edges are excluded. @param point Point to test. @returns `true` if the point is inside the rectangle; otherwise `false`.

center(): CPoint;
intersects(other: CRect): boolean;

Tests whether this rectangle overlaps another rectangle. Rectangles that only touch at an edge or corner are not considered intersecting. @param other Rectangle to test against. @returns `true` if the rectangles overlap; otherwise `false`.

intersection(other: CRect): CRect;

Returns the overlapping area of this rectangle and another rectangle. @param other Rectangle to intersect with. @returns The intersection rectangle, or an empty rectangle if there is no overlap.