GeomeGeome
Home
API
GitHub
Home
API
GitHub
  • Rect

geome v0.2.0


geome / Rect

Rect

Functions for manipulating rects represented as Rect.

Generators

bySize()

bySize(min, size): Rect

Defined in: Rect.ts:69

Creates a rect from the minimum point and the size.

Parameters

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

Returns

Rect

The created rect


fromCenter()

fromCenter(center, size): Rect

Defined in: Rect.ts:80

Creates a rect from the center and the size.

Parameters

ParameterTypeDescription
centervec2The center of the rect
sizevec2The size of the rect

Returns

Rect

The created rect


fromDOM()

fromDOM(dom): Rect

Defined in: Rect.ts:32

Creates a rect from the given DOM element using getBoundingClientRect.

Parameters

ParameterTypeDescription
domHTMLElementThe DOM element to create a rect from

Returns

Rect

The created rect


fromDOMRect()

fromDOMRect(domRect): Rect

Defined in: Rect.ts:20

Creates a rect from the given DOMRect.

Parameters

ParameterTypeDescription
domRectDOMRectThe DOMRect to create a rect from

Returns

Rect

The created rect


fromPoints()

fromPoints(…points): Rect

Defined in: Rect.ts:43

Creates a rect that contains all the given points.

Parameters

ParameterTypeDescription
…pointsvec2[]The points to create a rect from

Returns

Rect

The created rect

Properties

bottom()

bottom(bbox): number

Defined in: Rect.ts:192

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

Parameters

ParameterTypeDescription
bboxRectThe rect to get the bottom of

Returns

number

The bottom coordinate of the rect


center()

center(bbox): vec2

Defined in: Rect.ts:151

Calculates the center of the given rect.

Parameters

ParameterTypeDescription
bboxRectThe rect to calculate the center of

Returns

vec2

The center of the rect


left()

left(bbox): number

Defined in: Rect.ts:162

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

Parameters

ParameterTypeDescription
bboxRectThe rect to get the left of

Returns

number

The left coordinate of the rect


lerp()

lerp(a, b, t): Rect

Defined in: Rect.ts:353

Linearly interpolates between two rects.

Parameters

ParameterTypeDescription
aRectThe first rect
bRectThe second rect
tnumberThe interpolation factor

Returns

Rect

The interpolated rect


max()

max(bbox): vec2

Defined in: Rect.ts:101

Returns a max point of the given rect.

Parameters

ParameterTypeDescription
bboxRectThe rect to get the max point of

Returns

vec2

The max point of the rect


min()

min(bbox): vec2

Defined in: Rect.ts:91

Returns a min point of the given rect.

Parameters

ParameterTypeDescription
bboxRectThe rect to get the min point of

Returns

vec2

The min point of the rect


right()

right(bbox): number

Defined in: Rect.ts:182

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

Parameters

ParameterTypeDescription
bboxRectThe rect to get the right of

Returns

number

The right coordinate of the rect


size()

size(bbox): vec2

Defined in: Rect.ts:111

Calculates the size of the given rect.

Parameters

ParameterTypeDescription
bboxRectThe rect to calculate the size of

Returns

vec2

The size of the rect


top()

top(bbox): number

Defined in: Rect.ts:172

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

Parameters

ParameterTypeDescription
bboxRectThe rect to get the top of

Returns

number

The top coordinate of the rect

Functions

contains()

contains(source, target): boolean

Defined in: Rect.ts:249

Checks if the given rect contains the other rect.

Parameters

ParameterTypeDescription
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


containsPoint()

containsPoint(bbox, point): boolean

Defined in: Rect.ts:267

Checks if the given rect contains the given point.

Parameters

ParameterTypeDescription
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


intersect()

intersect(…rects): Rect

Defined in: Rect.ts:326

Calculates the intersection of the given rects.

Parameters

ParameterTypeDescription
…rectsRect[]The rects to intersect

Returns

Rect

The intersected rect


intersects()

intersects(a, b): boolean

Defined in: Rect.ts:284

Checks if the given rects intersect.

Parameters

ParameterTypeDescription
aRectThe first rect
bRectThe second rect

Returns

boolean

True if the rects intersect, false otherwise


objectFit()

objectFit(frame, object, mode): mat2d

Defined in: Rect.ts:365

Calculates the transform matrix from given frame and object rects, like CSS’s object-fit property.

Parameters

ParameterTypeDefault valueDescription
frameRectundefinedThe frame rect
objectRectundefinedThe object rect
mode"fit" | "contain" | "fill"'fit'The mode to fit the object in the frame

Returns

mat2d

The transform matrix


offset()

offset(rect, offset): Rect

Defined in: Rect.ts:232

Offsets the given rect by the given offset.

Parameters

ParameterTypeDescription
rectRectThe rect to offset
offsetnumber | vec2The offset to offset the rect by

Returns

Rect

The offsetted rect


scale()

scale(bbox, scale): Rect

Defined in: Rect.ts:203

Scales the given rect by the given ratio.

Parameters

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

Returns

Rect

The scaled rect


translate()

translate(bbox, offset): Rect

Defined in: Rect.ts:220

Translates the given rect by the given offset.

Parameters

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

Returns

Rect

The translated rect


unite()

unite(…rects): Rect

Defined in: Rect.ts:301

Unites the given rects into a single rect.

Parameters

ParameterTypeDescription
…rectsRect[]The rects to unite

Returns

Rect

The united rect

Edit this page