class Geometry · Computations

Rectangles

Creates rectangles (along a segment, anchored at or centered on a pin) and computes their corners, sides, size and diagonal.

Static methods

alongPaddedSegmentstatic

static alongPaddedSegment(p1: Point | VectorLike, p2: Point | VectorLike, height: Real | NumberLike, leftSide: Bool | BoolLike, distance: Real | NumberLike, paddingStart: Real | NumberLike, paddingEnd: Real | NumberLike, result?: Rectangle | null): Rectangle

Creates a rectangle along a segment defined by two points, with a specified height, side, distance, and optional start and end paddings.

If the sum of paddingStart and paddingEnd exceeds the length of the segment, the rectangle is positioned according to the weighted ratio having width 0.

p1
The first point defining the segment.
p2
The second point defining the segment.
height
The height of the rectangle extending from the segment.
leftSide
Determines the direction the rectangle extends from the segment.
distance
The offset distance from the segment start at which the rectangle is positioned, after applying paddings.
paddingStart
The padding applied at the start of the segment.
paddingEnd
The padding applied at the end of the segment.
result optional
Optional rectangle to store the result; if null, a new rectangle is created.

Returns A rectangle constructed along the segment with the specified parameters.

alongSegmentstatic

static alongSegment(bottomLeft: Point | VectorLike, bottomRight: Point | VectorLike, height: Real | NumberLike, left: Bool | BoolLike, result?: Rectangle | null): Rectangle

Creates a rectangle from a baseline defined by two points and a specified height.

bottomLeft
The bottom-left point of the baseline.
bottomRight
The bottom-right point of the baseline.
height
The height of the rectangle extending from the baseline.
left
Determines the direction the rectangle extends from the baseline.
result optional
Optional rectangle to store the result; if null, a new rectangle is created.

Returns A rectangle constructed from the baseline and height.

anchoredRectanglestatic

static anchoredRectangle(anchor: Pin | PinLike, xRatio: Real | NumberLike, yRatio: Real | NumberLike, width: Real | NumberLike, height: Real | NumberLike, result?: Rectangle | null): Rectangle

Creates a rectangle anchored at a specific point using x and y ratios to position the anchor within the rectangle bounds.

anchor
The pin point where the rectangle is anchored.
xRatio
The ratio (0 to 1) defining the anchor position along the rectangle's width.
yRatio
The ratio (0 to 1) defining the anchor position along the rectangle's height.
width
The width of the rectangle.
height
The height of the rectangle.
result optional
Optional rectangle to store the result; if null, a new rectangle is created.

Returns A rectangle anchored at the specified point with the given dimensions and ratios.

areastatic

static area(rectangle: Rectangle | ShapeLike, result?: Real | null): Real

Calculates the area of a rectangle.

rectangle
The rectangle whose area is to be calculated.
result optional
Optional area object to store the result; if null, a new area is created.

Returns The area of the rectangle.

bottomLeftstatic

static bottomLeft(rectangle: Rectangle | ShapeLike, result?: Point | null): Point

Gets the bottom-left corner point of a rectangle.

rectangle
The rectangle whose bottom-left corner is to be retrieved.
result optional
Optional point object to store the result; if null, a new point is created.

Returns The bottom-left corner point of the rectangle.

bottomRightstatic

static bottomRight(rectangle: Rectangle | ShapeLike, result?: Point | null): Point

Gets the bottom-right corner point of a rectangle.

rectangle
The rectangle whose bottom-right corner is to be retrieved.
result optional
Optional point object to store the result; if null, a new point is created.

Returns The bottom-right corner point of the rectangle.

bottomSidestatic

static bottomSide(rectangle: Rectangle | ShapeLike, result?: Segment | null): Segment

Gets the bottom side of a rectangle as a line segment going from left to right.

rectangle
The rectangle whose bottom side is to be retrieved.
result optional
Optional line segment object to store the result; if null, a new line segment is created.

Returns A line segment representing the bottom side of the rectangle, oriented from left to right.

boundingBoxstatic

static boundingBox(rectangle: Rectangle | ShapeLike, result?: Box | null): Box

Computes the axis-aligned bounding box of the specified rectangle.

rectangle
The rectangle whose bounding box is computed.
result optional
Optional box to store the result; if null, a new box is created.

Returns A box representing the bounds of the rectangle.

centeredRectanglestatic

static centeredRectangle(center: Pin | PinLike, width: Real | NumberLike, height: Real | NumberLike, result?: Rectangle | null): Rectangle

Creates a rectangle centered at a specific point.

center
The pin point at the center of the rectangle.
width
The width of the rectangle.
height
The height of the rectangle.
result optional
Optional rectangle to store the result; if null, a new rectangle is created.

Returns A rectangle centered at the specified point.

copystatic

static copy(rectangle: Rectangle | ShapeLike, result?: Rectangle | null): Rectangle

Creates a copy of the specified rectangle.

rectangle
The rectangle to copy.
result optional
Optional rectangle to store the result; if null, a new rectangle is created.

Returns A copy of the specified rectangle.

diagonalstatic

static diagonal(rectangle: Rectangle | ShapeLike, result?: Real | null): Real

Calculates the diagonal length of a rectangle.

rectangle
The rectangle whose diagonal is to be calculated.
result optional
Optional length object to store the result; if null, a new length is created.

Returns The diagonal length of the rectangle.

heightstatic

static height(rectangle: Rectangle | ShapeLike, result?: Real | null): Real

Calculates the height of a rectangle.

rectangle
The rectangle whose height is to be calculated.
result optional
Optional length object to store the result; if null, a new length is created.

Returns The height of the rectangle.

leftSidestatic

static leftSide(rectangle: Rectangle | ShapeLike, result?: Segment | null): Segment

Gets the left side of a rectangle as a line segment going from bottom to top.

rectangle
The rectangle whose left side is to be retrieved.
result optional
Optional line segment object to store the result; if null, a new line segment is created.

Returns A line segment representing the left side of the rectangle, oriented from bottom to top.

rightSidestatic

static rightSide(rectangle: Rectangle | ShapeLike, result?: Segment | null): Segment

Gets the right side of a rectangle as a line segment going from bottom to top.

rectangle
The rectangle whose right side is to be retrieved.
result optional
Optional line segment object to store the result; if null, a new line segment is created.

Returns A line segment representing the right side of the rectangle, oriented from bottom to top.

topLeftstatic

static topLeft(rectangle: Rectangle | ShapeLike, result?: Point | null): Point

Gets the top-left corner point of a rectangle.

rectangle
The rectangle whose top-left corner is to be retrieved.
result optional
Optional point object to store the result; if null, a new point is created.

Returns The top-left corner point of the rectangle.

topRightstatic

static topRight(rectangle: Rectangle | ShapeLike, result?: Point | null): Point

Gets the top-right corner point of a rectangle.

rectangle
The rectangle whose top-right corner is to be retrieved.
result optional
Optional point object to store the result; if null, a new point is created.

Returns The top-right corner point of the rectangle.

topSidestatic

static topSide(rectangle: Rectangle | ShapeLike, result?: Segment | null): Segment

Gets the top side of a rectangle as a line segment going from left to right.

rectangle
The rectangle whose top side is to be retrieved.
result optional
Optional line segment object to store the result; if null, a new line segment is created.

Returns A line segment representing the top side of the rectangle, oriented from left to right.

widthstatic

static width(rectangle: Rectangle | ShapeLike, result?: Real | null): Real

Calculates the width of a rectangle.

rectangle
The rectangle whose width is to be calculated.
result optional
Optional length object to store the result; if null, a new length is created.

Returns The width of the rectangle.