@baku89/pave / Rect
Rect
Functions for manipulating rects represented as Rect.
Properties
bottom()
bottom(
bbox
):number
Defined in: Rect.ts:133
Returns the bottom coordinate of the given rect in Y-down coordinates such as SVG.
Parameters
Parameter | Type | Description |
---|---|---|
bbox | Rect | The rect to get the bottom of |
Returns
number
The bottom coordinate of the rect
center()
center(
bbox
):vec2
Defined in: Rect.ts:92
Calculates the center of the given rect.
Parameters
Parameter | Type | Description |
---|---|---|
bbox | Rect | The rect to calculate the center of |
Returns
vec2
The center of the rect
left()
left(
bbox
):number
Defined in: Rect.ts:103
Returns the left coordinate of the given rect in Y-down coordinates such as SVG.
Parameters
Parameter | Type | Description |
---|---|---|
bbox | Rect | The rect to get the left of |
Returns
number
The left coordinate of the rect
right()
right(
bbox
):number
Defined in: Rect.ts:123
Returns the right coordinate of the given rect in Y-down coordinates such as SVG.
Parameters
Parameter | Type | Description |
---|---|---|
bbox | Rect | The rect to get the right of |
Returns
number
The right coordinate of the rect
size()
size(
bbox
):vec2
Defined in: Rect.ts:81
Calculates the size of the given rect.
Parameters
Parameter | Type | Description |
---|---|---|
bbox | Rect | The rect to calculate the size of |
Returns
vec2
The size of the rect
top()
top(
bbox
):number
Defined in: Rect.ts:113
Returns the top coordinate of the given rect in Y-down coordinates such as SVG.
Parameters
Parameter | Type | Description |
---|---|---|
bbox | Rect | The rect to get the top of |
Returns
number
The top coordinate of the rect
Generators
bySize()
bySize(
min
,size
):Rect
Defined in: Rect.ts:59
Creates a rect from the minimum point and the size.
Parameters
Parameter | Type | Description |
---|---|---|
min | vec2 | Top-left point of the rect, in Y-down coordinates such as SVG |
size | vec2 | The size of the rect. |
Returns
The created rect
fromCenter()
fromCenter(
center
,size
):Rect
Defined in: Rect.ts:70
Creates a rect from the center and the size.
Parameters
Parameter | Type | Description |
---|---|---|
center | vec2 | The center of the rect |
size | vec2 | The size of the rect |
Returns
The created rect
fromDOMRect()
fromDOMRect(
domRect
):Rect
Defined in: Rect.ts:20
Creates a rect from the given DOMRect.
Parameters
Parameter | Type | Description |
---|---|---|
domRect | DOMRect | The DOMRect to create a rect from |
Returns
The created rect
fromPoints()
fromPoints(…
points
):Rect
Defined in: Rect.ts:33
Creates a rect that contains all the given points.
Parameters
Parameter | Type | Description |
---|---|---|
…points | vec2 [] | The points to create a rect from |
Returns
The created rect
Other
contains()
contains(
source
,target
):boolean
Defined in: Rect.ts:170
Checks if the given rect contains the other rect.
Parameters
Parameter | Type | Description |
---|---|---|
source | Rect | The source rect |
target | Rect | The 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:187
Checks if the given rect contains the given point.
Parameters
Parameter | Type | Description |
---|---|---|
bbox | Rect | The source rect |
point | vec2 | The 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:243
Calculates the intersection of the given rects.
Parameters
Parameter | Type | Description |
---|---|---|
…rects | Rect [] | The rects to intersect |
Returns
The intersected rect
intersects()
intersects(
a
,b
):boolean
Defined in: Rect.ts:203
Checks if the given rects intersect.
Parameters
Parameter | Type | Description |
---|---|---|
a | Rect | The first rect |
b | Rect | The second rect |
Returns
boolean
True if the rects intersect, false otherwise
scale()
scale(
bbox
,scale
):Rect
Defined in: Rect.ts:143
Scales the given rect by the given ratio.
Parameters
Parameter | Type | Description |
---|---|---|
bbox | Rect | The rect to scale |
scale | number | vec2 | The ratio to scale the rect by |
Returns
The scaled rect
translate()
translate(
bbox
,offset
):Rect
Defined in: Rect.ts:159
Translates the given rect by the given offset.
Parameters
Parameter | Type | Description |
---|---|---|
bbox | Rect | The rect to translate |
offset | vec2 | The offset to translate the rect by |
Returns
The translated rect
unite()
unite(…
rects
):Rect
Defined in: Rect.ts:219
Unites the given rects into a single rect.
Parameters
Parameter | Type | Description |
---|---|---|
…rects | Rect [] | The rects to unite |
Returns
The united rect