@baku89/pave - v0.4.1 / Rect

Namespace: Rect

Functions for manipulating rects represented as Rect.

Properties

bottom

bottom(bbox): number

Returns the bottom coordinate of the given rect in Y-down coordinates such as SVG.

Parameters

NameTypeDescription
bboxRectThe rect to get the bottom of

Returns

number

The bottom coordinate of the rect

Defined in

Rect.ts:132open in new window


center

center(bbox): vec2

Calculates the center of the given rect.

Parameters

NameTypeDescription
bboxRectThe rect to calculate the center of

Returns

vec2

The center of the rect

Defined in

Rect.ts:91open in new window


left

left(bbox): number

Returns the left coordinate of the given rect in Y-down coordinates such as SVG.

Parameters

NameTypeDescription
bboxRectThe rect to get the left of

Returns

number

The left coordinate of the rect

Defined in

Rect.ts:102open in new window


right(bbox): number

Returns the right coordinate of the given rect in Y-down coordinates such as SVG.

Parameters

NameTypeDescription
bboxRectThe rect to get the right of

Returns

number

The right coordinate of the rect

Defined in

Rect.ts:122open in new window


size

size(bbox): vec2

Calculates the size of the given rect.

Parameters

NameTypeDescription
bboxRectThe rect to calculate the size of

Returns

vec2

The size of the rect

Defined in

Rect.ts:80open in new window


top

top(bbox): number

Returns the top coordinate of the given rect in Y-down coordinates such as SVG.

Parameters

NameTypeDescription
bboxRectThe rect to get the top of

Returns

number

The top coordinate of the rect

Defined in

Rect.ts:112open in new window

Generators

bySize

bySize(min, size): Rect

Creates a rect from the minimum point and the size.

Parameters

NameTypeDescription
minvec2Top-left point of the rect, in Y-down coordinates such as SVG
sizevec2The size of the rect.

Returns

Rect

The created rect

Defined in

Rect.ts:58open in new window


fromCenter

fromCenter(center, size): Rect

Creates a rect from the center and the size.

Parameters

NameTypeDescription
centervec2The center of the rect
sizevec2The size of the rect

Returns

Rect

The created rect

Defined in

Rect.ts:69open in new window


fromDOMRect

fromDOMRect(domRect): Rect

Creates a rect from the given DOMRect.

Parameters

NameTypeDescription
domRectDOMRectThe DOMRect to create a rect from

Returns

Rect

The created rect

Defined in

Rect.ts:19open in new window


fromPoints

fromPoints(...points): Rect

Creates a rect that contains all the given points.

Parameters

NameTypeDescription
...pointsvec2[]The points to create a rect from

Returns

Rect

The created rect

Defined in

Rect.ts:32open in new window

Other

contains

contains(source, target): boolean

Checks if the given rect contains the other rect.

Parameters

NameTypeDescription
sourceRectThe source rect
targetRectThe target rect to check if it’s contained in the source rect

Returns

boolean

True if the source rect contains the target rect, false otherwise

Defined in

Rect.ts:169open in new window


containsPoint

containsPoint(bbox, point): boolean

Checks if the given rect contains the given point.

Parameters

NameTypeDescription
bboxRectThe source rect
pointvec2The point to check if it’s contained in the source rect

Returns

boolean

True if the rect contains the point, false otherwise

Defined in

Rect.ts:186open in new window


intersect

intersect(...rects): Rect

Calculates the intersection of the given rects.

Parameters

NameTypeDescription
...rectsRect[]The rects to intersect

Returns

Rect

The intersected rect

Defined in

Rect.ts:242open in new window


intersects

intersects(a, b): boolean

Checks if the given rects intersect.

Parameters

NameTypeDescription
aRectThe first rect
bRectThe second rect

Returns

boolean

True if the rects intersect, false otherwise

Defined in

Rect.ts:202open in new window


scale

scale(bbox, scale): Rect

Scales the given rect by the given ratio.

Parameters

NameTypeDescription
bboxRectThe rect to scale
scalenumber | vec2The ratio to scale the rect by

Returns

Rect

The scaled rect

Defined in

Rect.ts:142open in new window


translate

translate(bbox, offset): Rect

Translates the given rect by the given offset.

Parameters

NameTypeDescription
bboxRectThe rect to translate
offsetvec2The offset to translate the rect by

Returns

Rect

The translated rect

Defined in

Rect.ts:158open in new window


unite

unite(...rects): Rect

Unites the given rects into a single rect.

Parameters

NameTypeDescription
...rectsRect[]The rects to unite

Returns

Rect

The united rect

Defined in

Rect.ts:218open in new window