- RectOps - Basic operations
- RectCompare - Comparison operations
- RectTransform - Transformation operations
- RectGeometry - Geometry operations
- RectBorder - Border operations
- RectSplit - Splitting operations
Basic rectangle operations including creation, validation, and conversion.
Rounds up size dimensions to integers.
const size = { width: 10.3, height: 20.7 };
const rounded = RectOps.ceiling(size);
// { width: 11, height: 21 }Validates and normalizes a rectangle ensuring positive dimensions.
const invalid = { x: 100, y: 100, width: -50, height: -30 };
const valid = RectOps.validate(invalid);
// Ensures width and height are positiveCreates a rectangle from two coordinate pairs.
const rect = RectOps.create(10, 20, 110, 70);
// { x: 10, y: 20, width: 100, height: 50 }Creates a rectangle from two points.
const rect = RectOps.fromPoints({ x: 10, y: 20 }, { x: 110, y: 70 });
// { x: 10, y: 20, width: 100, height: 50 }Inflates a float rectangle to integer bounds (floor left/top, ceil right/bottom).
const rect = { x: 10.3, y: 20.7, width: 100.2, height: 50.8 };
const inflated = RectOps.inflateToInteger(rect);
// Floors x/y and ceils right/bottomSnaps rectangle to pixel grid based on DPI conversion.
const rect = { x: 10.5, y: 20.5, width: 100, height: 50 };
const snapped = RectOps.snap(rect, 96, 72);
// Snaps to pixel boundaries at target DPIRectangle comparison and containment operations.
Checks if two rectangles are equal within epsilon tolerance.
const rect1 = { x: 10, y: 20, width: 100, height: 50 };
const rect2 = { x: 10.0001, y: 20, width: 100, height: 50 };
const equal = RectCompare.equals(rect1, rect2, 0.001);
// trueChecks if rectangle has zero size.
const rect = { x: 10, y: 20, width: 0, height: 0 };
const empty = RectCompare.isEmptySize(rect);
// trueChecks if rectangle is completely empty (zero position and size).
const rect = { x: 0, y: 0, width: 0, height: 0 };
const empty = RectCompare.isEmpty(rect);
// trueChecks if two rectangles intersect.
const rect1 = { x: 0, y: 0, width: 100, height: 100 };
const rect2 = { x: 50, y: 50, width: 100, height: 100 };
const intersects = RectCompare.intersects(rect1, rect2);
// trueChecks if rect1 completely contains rect2.
const outer = { x: 0, y: 0, width: 100, height: 100 };
const inner = { x: 10, y: 10, width: 50, height: 50 };
const contains = RectCompare.contains(outer, inner);
// trueChecks if rectangle contains a point.
const rect = { x: 0, y: 0, width: 100, height: 100 };
const contains = RectCompare.containsPoint(rect, { x: 50, y: 50 });
// trueChecks if rectangle contains X coordinate.
const rect = { x: 0, y: 0, width: 100, height: 100 };
const contains = RectCompare.containsX(rect, 50);
// trueChecks if rectangle contains Y coordinate.
const rect = { x: 0, y: 0, width: 100, height: 100 };
const contains = RectCompare.containsY(rect, 50);
// trueComputes intersection of two rectangles.
const rect1 = { x: 0, y: 0, width: 100, height: 100 };
const rect2 = { x: 50, y: 50, width: 100, height: 100 };
const intersection = RectCompare.intersect(rect1, rect2);
// { x: 50, y: 50, width: 50, height: 50 }Checks if rectangles intersect with non-zero area.
const rect1 = { x: 0, y: 0, width: 100, height: 100 };
const rect2 = { x: 100, y: 0, width: 100, height: 100 };
const intersects = RectCompare.intersectsExcludeBounds(rect1, rect2);
// false (only touching at boundary)Unions two rectangles, ignoring empty ones.
const rect1 = { x: 0, y: 0, width: 50, height: 50 };
const rect2 = { x: 100, y: 100, width: 50, height: 50 };
const union = RectCompare.unionNonEmpty(rect1, rect2);
// { x: 0, y: 0, width: 150, height: 150 }Checks if two rectangle arrays are equal.
const arr1 = [{ x: 0, y: 0, width: 50, height: 50 }];
const arr2 = [{ x: 0, y: 0, width: 50, height: 50 }];
const equal = RectCompare.isEqualArray(arr1, arr2);
// trueRectangle transformation operations including inflate, deflate, offset, and alignment.
Expands rectangle by specified amounts on each side.
const rect = { x: 10, y: 10, width: 80, height: 80 };
const inflated = RectTransform.inflate(rect, 5, 5, 5, 5);
// { x: 5, y: 5, width: 90, height: 90 }Expands rectangle using margins.
const rect = { x: 10, y: 10, width: 80, height: 80 };
const margins = { left: 5, top: 5, right: 5, bottom: 5 };
const inflated = RectTransform.inflateWithMargins(rect, margins);Shrinks rectangle by specified amounts on each side.
const rect = { x: 10, y: 10, width: 100, height: 100 };
const deflated = RectTransform.deflate(rect, 5, 5, 5, 5);
// { x: 15, y: 15, width: 90, height: 90 }Shrinks rectangle using margins.
const rect = { x: 10, y: 10, width: 100, height: 100 };
const margins = { left: 5, top: 5, right: 5, bottom: 5 };
const deflated = RectTransform.deflateWithMargins(rect, margins);Moves rectangle by specified offset.
const rect = { x: 10, y: 10, width: 100, height: 100 };
const moved = RectTransform.offset(rect, 20, 30);
// { x: 30, y: 40, width: 100, height: 100 }Moves rectangle by point offset.
const rect = { x: 10, y: 10, width: 100, height: 100 };
const moved = RectTransform.offsetByPoint(rect, { x: 20, y: 30 });Aligns rectangle within base rectangle according to alignment.
const rect = { x: 0, y: 0, width: 50, height: 50 };
const base = { x: 0, y: 0, width: 200, height: 200 };
const aligned = RectTransform.align(rect, base, ContentAlignment.MiddleCenter);
// { x: 75, y: 75, width: 50, height: 50 }Calculates cropping/padding needed to fit bounds within rect.
const bounds = { x: 10, y: 10, width: 80, height: 80 };
const rect = { x: 0, y: 0, width: 100, height: 100 };
const padding = RectTransform.calcCropping(bounds, rect);
// { left: 10, top: 10, right: 10, bottom: 10 }Rectangle geometry operations for calculating center and corner points.
Calculates center point of rectangle.
const rect = { x: 0, y: 0, width: 100, height: 100 };
const center = RectGeometry.center(rect);
// { x: 50, y: 50 }Gets top-left corner point.
const rect = { x: 10, y: 20, width: 100, height: 50 };
const corner = RectGeometry.topLeft(rect);
// { x: 10, y: 20 }Gets top-right corner point.
const rect = { x: 10, y: 20, width: 100, height: 50 };
const corner = RectGeometry.topRight(rect);
// { x: 110, y: 20 }Gets bottom-left corner point.
const rect = { x: 10, y: 20, width: 100, height: 50 };
const corner = RectGeometry.bottomLeft(rect);
// { x: 10, y: 70 }Gets bottom-right corner point.
const rect = { x: 10, y: 20, width: 100, height: 50 };
const corner = RectGeometry.bottomRight(rect);
// { x: 110, y: 70 }Rectangle border and side operations for extracting, cutting, and expanding.
Gets side rectangle with specified size.
const rect = { x: 0, y: 0, width: 100, height: 100 };
const top = RectBorder.getTopSide(rect, 20);
// { x: 0, y: 0, width: 100, height: 20 }Sets boundary of rectangle. Returns null if invalid.
const rect = { x: 0, y: 0, width: 100, height: 100 };
const modified = RectBorder.setLeft(rect, 10);
// { x: 10, y: 0, width: 90, height: 100 }Removes specified amount from side.
const rect = { x: 0, y: 0, width: 100, height: 100 };
const cut = RectBorder.cutFromTop(rect, 20);
// { x: 0, y: 20, width: 100, height: 80 }Expands rectangle in specified direction.
const rect = { x: 10, y: 10, width: 80, height: 80 };
const expanded = RectBorder.expandToBottom(rect, 20);
// { x: 10, y: 10, width: 80, height: 100 }Rectangle splitting and division operations.
Splits rectangle horizontally into equal cells.
const rect = { x: 0, y: 0, width: 300, height: 100 };
const cells = RectSplit.horizontal(rect, 3);
// Returns 3 rectangles of width 100 each
const rtlCells = RectSplit.horizontal(rect, 3, true);
// Splits from right to leftSplits rectangle vertically into equal cells.
const rect = { x: 0, y: 0, width: 100, height: 300 };
const cells = RectSplit.vertical(rect, 3);
// Returns 3 rectangles of height 100 each