pex-geom
Version:
Geometry intersection and bounding volume helpers for PEX.
798 lines (519 loc) • 25.8 kB
Markdown
# pex-geom
[](https://www.npmjs.com/package/pex-geom)
[](https://www.npmjs.com/package/pex-geom)
[](https://bundlephobia.com/package/pex-geom)
[](https://github.com/pex-gl/pex-geom/blob/main/package.json)
[](https://github.com/microsoft/TypeScript)
[](https://conventionalcommits.org)
[](https://github.com/prettier/prettier)
[](https://github.com/eslint/eslint)
[](https://github.com/pex-gl/pex-geom/blob/main/LICENSE.md)
Geometry intersection and bounding volume helpers for [PEX](https://pex.gl).
## Installation
```bash
npm install pex-geom
```
## Usage
```js
import { ray, aabb } from "pex-geom";
const box = aabb.fromPoints([
[-1, -1, -1],
[1, 1, 1],
]);
const intersect = ray.hitTestAABB(
[
[0, 0, 0],
[0, 1, 0],
],
box
);
console.log(intersect);
// => true
```
## API
<!-- api-start -->
## Modules
<dl>
<dt><a href="#module_aabb">aabb</a></dt>
<dd></dd>
<dt><a href="#module_pex-geom">pex-geom</a></dt>
<dd></dd>
<dt><a href="#module_plane">plane</a></dt>
<dd></dd>
<dt><a href="#module_ray">ray</a></dt>
<dd></dd>
<dt><a href="#module_rect">rect</a></dt>
<dd></dd>
</dl>
## Typedefs
<dl>
<dt><a href="#aabb">aabb</a> : <code>Array.<Array.<number>></code></dt>
<dd><p>An axis-aligned bounding box defined by two min and max 3D points (eg. [[minX, minY, minZ], [maxX, maxY, maxZ]]).</p>
</dd>
<dt><a href="#plane">plane</a> : <code>Array.<Array.<number>></code></dt>
<dd><p>A plane defined by a 3D point and a normal vector perpendicular to the plane’s surface (eg. [[pointX, pointY, pointZ], [normalX, normalY, normalZ]]).</p>
</dd>
<dt><a href="#ray">ray</a> : <code>Array.<Array.<number>></code></dt>
<dd><p>A ray defined by a starting 3D point origin and a 3D direction vector (eg. [[originX, originY, originZ], [directionX, directionY, directionZ]).</p>
</dd>
<dt><a href="#rect">rect</a> : <code>Array.<Array.<number>></code></dt>
<dd><p>A rectangle defined by two diagonally opposite 2D points (eg. [[minX, minY], [maxX, maxY]]).</p>
</dd>
<dt><a href="#triangle">triangle</a> : <code>Array.<Array.<number>></code></dt>
<dd><p>A triangle defined by three 3D points.</p>
</dd>
<dt><a href="#vec2">vec2</a> : <code>module:pex-math~vec2</code></dt>
<dd></dd>
<dt><a href="#vec3">vec3</a> : <code>module:pex-math~vec3</code></dt>
<dd></dd>
<dt><a href="#TypedArray">TypedArray</a> : <code>module:pex-math~TypedArray</code></dt>
<dd></dd>
</dl>
<a name="module_aabb"></a>
## aabb
- [aabb](#module_aabb)
- [.create()](#module_aabb.create) ⇒ [<code>aabb</code>](#aabb)
- [.empty(a)](#module_aabb.empty) ⇒ [<code>rect</code>](#rect)
- [.copy(a)](#module_aabb.copy) ⇒ [<code>aabb</code>](#aabb)
- [.set(a, b)](#module_aabb.set) ⇒ [<code>aabb</code>](#aabb)
- [.isEmpty(a)](#module_aabb.isEmpty) ⇒ <code>boolean</code>
- [.fromPoints(a, points)](#module_aabb.fromPoints) ⇒ [<code>aabb</code>](#aabb)
- [.getCorners(a, [points])](#module_aabb.getCorners) ⇒ [<code>Array.<vec3></code>](#vec3)
- [.center(a, out)](#module_aabb.center) ⇒ [<code>vec3</code>](#vec3)
- [.size(a, out)](#module_aabb.size) ⇒ [<code>vec3</code>](#vec3)
- [.containsPoint(a, p)](#module_aabb.containsPoint) ⇒ <code>boolean</code>
- [.includeAABB(a, b)](#module_aabb.includeAABB) ⇒ [<code>aabb</code>](#aabb)
- [.includePoint(a, p, [i])](#module_aabb.includePoint) ⇒ [<code>vec3</code>](#vec3)
- [.toString(a, [precision])](#module_aabb.toString) ⇒ <code>string</code>
<a name="module_aabb.create"></a>
### aabb.create() ⇒ [<code>aabb</code>](#aabb)
Creates a new bounding box.
**Kind**: static method of [<code>aabb</code>](#module_aabb)
<a name="module_aabb.empty"></a>
### aabb.empty(a) ⇒ [<code>rect</code>](#rect)
Reset a bounding box.
**Kind**: static method of [<code>aabb</code>](#module_aabb)
| Param | Type |
| ----- | -------------------------- |
| a | [<code>aabb</code>](#aabb) |
<a name="module_aabb.copy"></a>
### aabb.copy(a) ⇒ [<code>aabb</code>](#aabb)
Copies a bounding box.
**Kind**: static method of [<code>aabb</code>](#module_aabb)
| Param | Type |
| ----- | -------------------------- |
| a | [<code>aabb</code>](#aabb) |
<a name="module_aabb.set"></a>
### aabb.set(a, b) ⇒ [<code>aabb</code>](#aabb)
Sets a bounding box to another.
**Kind**: static method of [<code>aabb</code>](#module_aabb)
| Param | Type |
| ----- | -------------------------- |
| a | [<code>aabb</code>](#aabb) |
| b | [<code>aabb</code>](#aabb) |
<a name="module_aabb.isEmpty"></a>
### aabb.isEmpty(a) ⇒ <code>boolean</code>
Checks if a bounding box is empty.
**Kind**: static method of [<code>aabb</code>](#module_aabb)
| Param | Type |
| ----- | -------------------------- |
| a | [<code>aabb</code>](#aabb) |
<a name="module_aabb.fromPoints"></a>
### aabb.fromPoints(a, points) ⇒ [<code>aabb</code>](#aabb)
Updates a bounding box from a list of points.
**Kind**: static method of [<code>aabb</code>](#module_aabb)
| Param | Type |
| ------ | ---------------------------------------------------------------------------------- |
| a | [<code>aabb</code>](#aabb) |
| points | [<code>Array.<vec3></code>](#vec3) \| [<code>TypedArray</code>](#TypedArray) |
<a name="module_aabb.getCorners"></a>
### aabb.getCorners(a, [points]) ⇒ [<code>Array.<vec3></code>](#vec3)
Returns a list of 8 points from a bounding box.
**Kind**: static method of [<code>aabb</code>](#module_aabb)
| Param | Type |
| -------- | ---------------------------------------- |
| a | [<code>aabb</code>](#aabb) |
| [points] | [<code>Array.<vec3></code>](#vec3) |
<a name="module_aabb.center"></a>
### aabb.center(a, out) ⇒ [<code>vec3</code>](#vec3)
Returns the center of a bounding box.
**Kind**: static method of [<code>aabb</code>](#module_aabb)
| Param | Type |
| ----- | -------------------------- |
| a | [<code>aabb</code>](#aabb) |
| out | [<code>vec3</code>](#vec3) |
<a name="module_aabb.size"></a>
### aabb.size(a, out) ⇒ [<code>vec3</code>](#vec3)
Returns the size of a bounding box.
**Kind**: static method of [<code>aabb</code>](#module_aabb)
| Param | Type |
| ----- | -------------------------- |
| a | [<code>aabb</code>](#aabb) |
| out | [<code>vec3</code>](#vec3) |
<a name="module_aabb.containsPoint"></a>
### aabb.containsPoint(a, p) ⇒ <code>boolean</code>
Checks if a point is inside a bounding box.
**Kind**: static method of [<code>aabb</code>](#module_aabb)
| Param | Type |
| ----- | -------------------------- |
| a | [<code>aabb</code>](#aabb) |
| p | [<code>vec3</code>](#vec3) |
<a name="module_aabb.includeAABB"></a>
### aabb.includeAABB(a, b) ⇒ [<code>aabb</code>](#aabb)
Includes a bounding box in another.
**Kind**: static method of [<code>aabb</code>](#module_aabb)
| Param | Type |
| ----- | -------------------------- |
| a | [<code>aabb</code>](#aabb) |
| b | [<code>aabb</code>](#aabb) |
<a name="module_aabb.includePoint"></a>
### aabb.includePoint(a, p, [i]) ⇒ [<code>vec3</code>](#vec3)
Includes a point in a bounding box.
**Kind**: static method of [<code>aabb</code>](#module_aabb)
| Param | Type | Default | Description |
| ----- | -------------------------- | -------------- | ------------------------- |
| a | [<code>aabb</code>](#aabb) | | |
| p | [<code>vec3</code>](#vec3) | | |
| [i] | <code>number</code> | <code>0</code> | offset in the point array |
<a name="module_aabb.toString"></a>
### aabb.toString(a, [precision]) ⇒ <code>string</code>
Prints a bounding box to a string.
**Kind**: static method of [<code>aabb</code>](#module_aabb)
| Param | Type | Default |
| ----------- | -------------------------- | -------------- |
| a | [<code>aabb</code>](#aabb) | |
| [precision] | <code>number</code> | <code>4</code> |
<a name="module_pex-geom"></a>
## pex-geom
- [pex-geom](#module_pex-geom)
- [.aabb](#module_pex-geom.aabb) : [<code>aabb</code>](#module_aabb)
- [.plane](#module_pex-geom.plane) : [<code>plane</code>](#module_plane)
- [.ray](#module_pex-geom.ray) : [<code>ray</code>](#module_ray)
- [.rect](#module_pex-geom.rect) : [<code>rect</code>](#module_rect)
<a name="module_pex-geom.aabb"></a>
### pex-geom.aabb : [<code>aabb</code>](#module_aabb)
**Kind**: static property of [<code>pex-geom</code>](#module_pex-geom)
<a name="module_pex-geom.plane"></a>
### pex-geom.plane : [<code>plane</code>](#module_plane)
**Kind**: static property of [<code>pex-geom</code>](#module_pex-geom)
<a name="module_pex-geom.ray"></a>
### pex-geom.ray : [<code>ray</code>](#module_ray)
**Kind**: static property of [<code>pex-geom</code>](#module_pex-geom)
<a name="module_pex-geom.rect"></a>
### pex-geom.rect : [<code>rect</code>](#module_rect)
**Kind**: static property of [<code>pex-geom</code>](#module_pex-geom)
<a name="module_plane"></a>
## plane
- [plane](#module_plane)
- [.Side](#module_plane.Side) : <code>enum</code>
- [.create()](#module_plane.create) ⇒ [<code>plane</code>](#plane)
- [.side(plane, point)](#module_plane.side) ⇒ <code>number</code>
- [.toString(a, [precision])](#module_plane.toString) ⇒ <code>string</code>
<a name="module_plane.Side"></a>
### plane.Side : <code>enum</code>
Enum for different side values
**Kind**: static enum of [<code>plane</code>](#module_plane)
**Read only**: true
<a name="module_plane.create"></a>
### plane.create() ⇒ [<code>plane</code>](#plane)
Creates a new plane
**Kind**: static method of [<code>plane</code>](#module_plane)
<a name="module_plane.side"></a>
### plane.side(plane, point) ⇒ <code>number</code>
Returns on which side a point is.
**Kind**: static method of [<code>plane</code>](#module_plane)
| Param | Type |
| ----- | ---------------------------- |
| plane | [<code>plane</code>](#plane) |
| point | [<code>vec3</code>](#vec3) |
<a name="module_plane.toString"></a>
### plane.toString(a, [precision]) ⇒ <code>string</code>
Prints a plane to a string.
**Kind**: static method of [<code>plane</code>](#module_plane)
| Param | Type | Default |
| ----------- | ---------------------------- | -------------- |
| a | [<code>plane</code>](#plane) | |
| [precision] | <code>number</code> | <code>4</code> |
<a name="module_ray"></a>
## ray
- [ray](#module_ray)
- [.Intersections](#module_ray.Intersections) : <code>enum</code>
- [.create()](#module_ray.create) ⇒ [<code>ray</code>](#ray)
- [.hitTestPlane(ray, plane, out)](#module_ray.hitTestPlane) ⇒ <code>number</code>
- [.hitTestTriangle(ray, triangle, out)](#module_ray.hitTestTriangle) ⇒ <code>number</code>
- [.hitTestAABB(ray, aabb)](#module_ray.hitTestAABB) ⇒ <code>boolean</code>
- [.intersectsAABB()](#module_ray.intersectsAABB)
- [.toString(a, [precision])](#module_ray.toString) ⇒ <code>string</code>
<a name="module_ray.Intersections"></a>
### ray.Intersections : <code>enum</code>
Enum for different intersections values
**Kind**: static enum of [<code>ray</code>](#module_ray)
**Read only**: true
<a name="module_ray.create"></a>
### ray.create() ⇒ [<code>ray</code>](#ray)
Creates a new ray
**Kind**: static method of [<code>ray</code>](#module_ray)
<a name="module_ray.hitTestPlane"></a>
### ray.hitTestPlane(ray, plane, out) ⇒ <code>number</code>
Determines if a ray intersect a plane and set intersection point
**Kind**: static method of [<code>ray</code>](#module_ray)
**See**: [https://www.cs.princeton.edu/courses/archive/fall00/cs426/lectures/raycast/sld017.htm](https://www.cs.princeton.edu/courses/archive/fall00/cs426/lectures/raycast/sld017.htm)
| Param | Type |
| ----- | ---------------------------- |
| ray | [<code>ray</code>](#ray) |
| plane | [<code>plane</code>](#plane) |
| out | [<code>vec3</code>](#vec3) |
<a name="module_ray.hitTestTriangle"></a>
### ray.hitTestTriangle(ray, triangle, out) ⇒ <code>number</code>
Determines if a ray intersect a triangle and set intersection point
**Kind**: static method of [<code>ray</code>](#module_ray)
**See**: [http://geomalgorithms.com/a06-\_intersect-2.html#intersect3D_RayTriangle()](<http://geomalgorithms.com/a06-_intersect-2.html#intersect3D_RayTriangle()>)
| Param | Type |
| -------- | ---------------------------------- |
| ray | [<code>ray</code>](#ray) |
| triangle | [<code>triangle</code>](#triangle) |
| out | [<code>vec3</code>](#vec3) |
<a name="module_ray.hitTestAABB"></a>
### ray.hitTestAABB(ray, aabb) ⇒ <code>boolean</code>
Determines if a ray intersect an AABB bounding box
**Kind**: static method of [<code>ray</code>](#module_ray)
**See**: [http://gamedev.stackexchange.com/questions/18436/most-efficient-aabb-vs-ray-collision-algorithms](http://gamedev.stackexchange.com/questions/18436/most-efficient-aabb-vs-ray-collision-algorithms)
| Param | Type |
| ----- | -------------------------- |
| ray | [<code>ray</code>](#ray) |
| aabb | [<code>aabb</code>](#aabb) |
<a name="module_ray.intersectsAABB"></a>
### ray.intersectsAABB()
Alias for [hitTestAABB](hitTestAABB)
**Kind**: static method of [<code>ray</code>](#module_ray)
<a name="module_ray.toString"></a>
### ray.toString(a, [precision]) ⇒ <code>string</code>
Prints a plane to a string.
**Kind**: static method of [<code>ray</code>](#module_ray)
| Param | Type | Default |
| ----------- | ------------------------ | -------------- |
| a | [<code>ray</code>](#ray) | |
| [precision] | <code>number</code> | <code>4</code> |
<a name="module_rect"></a>
## rect
- [rect](#module_rect)
- [.create()](#module_rect.create) ⇒ [<code>rect</code>](#rect)
- [.empty(a)](#module_rect.empty) ⇒ [<code>rect</code>](#rect)
- [.copy(a)](#module_rect.copy) ⇒ [<code>rect</code>](#rect)
- [.set(a, b)](#module_rect.set) ⇒ [<code>rect</code>](#rect)
- [.isEmpty(a)](#module_rect.isEmpty) ⇒ <code>boolean</code>
- [.fromPoints(a, points)](#module_rect.fromPoints) ⇒ [<code>rect</code>](#rect)
- [.getCorners(a, points)](#module_rect.getCorners) ⇒ [<code>Array.<vec2></code>](#vec2)
- [.scale(a, n)](#module_rect.scale) ⇒ [<code>rect</code>](#rect)
- [.setSize(a, size)](#module_rect.setSize) ⇒ [<code>rect</code>](#rect)
- [.size(a, out)](#module_rect.size) ⇒ [<code>vec2</code>](#vec2)
- [.width(a)](#module_rect.width) ⇒ <code>number</code>
- [.height(a)](#module_rect.height) ⇒ <code>number</code>
- [.aspectRatio(a)](#module_rect.aspectRatio) ⇒ <code>number</code>
- [.setPosition(a, p)](#module_rect.setPosition) ⇒ [<code>rect</code>](#rect)
- [.center(a, out)](#module_rect.center) ⇒ [<code>rect</code>](#rect)
- [.containsPoint(a, p)](#module_rect.containsPoint) ⇒ <code>boolean</code>
- [.containsRect(a, b)](#module_rect.containsRect) ⇒ <code>boolean</code>
- [.includePoint(a, p)](#module_rect.includePoint) ⇒ [<code>rect</code>](#rect)
- [.includeRect(a, b)](#module_rect.includeRect) ⇒ [<code>rect</code>](#rect)
- [.mapPoint(a, p)](#module_rect.mapPoint) ⇒ [<code>vec2</code>](#vec2)
- [.clampPoint(a, p)](#module_rect.clampPoint) ⇒ [<code>vec2</code>](#vec2)
- [.toString(a, [precision])](#module_rect.toString) ⇒ <code>string</code>
<a name="module_rect.create"></a>
### rect.create() ⇒ [<code>rect</code>](#rect)
Creates a new rectangle.
**Kind**: static method of [<code>rect</code>](#module_rect)
<a name="module_rect.empty"></a>
### rect.empty(a) ⇒ [<code>rect</code>](#rect)
Reset a rectangle.
**Kind**: static method of [<code>rect</code>](#module_rect)
| Param | Type |
| ----- | -------------------------- |
| a | [<code>rect</code>](#rect) |
<a name="module_rect.copy"></a>
### rect.copy(a) ⇒ [<code>rect</code>](#rect)
Copies a rectangle.
**Kind**: static method of [<code>rect</code>](#module_rect)
| Param | Type |
| ----- | -------------------------- |
| a | [<code>rect</code>](#rect) |
<a name="module_rect.set"></a>
### rect.set(a, b) ⇒ [<code>rect</code>](#rect)
Sets a rectangle to another.
**Kind**: static method of [<code>rect</code>](#module_rect)
| Param | Type |
| ----- | -------------------------- |
| a | [<code>rect</code>](#rect) |
| b | [<code>rect</code>](#rect) |
<a name="module_rect.isEmpty"></a>
### rect.isEmpty(a) ⇒ <code>boolean</code>
Checks if a rectangle is empty.
**Kind**: static method of [<code>rect</code>](#module_rect)
| Param | Type |
| ----- | -------------------------- |
| a | [<code>rect</code>](#rect) |
<a name="module_rect.fromPoints"></a>
### rect.fromPoints(a, points) ⇒ [<code>rect</code>](#rect)
Updates a rectangle from a list of points.
**Kind**: static method of [<code>rect</code>](#module_rect)
| Param | Type |
| ------ | ---------------------------------------------------------------------------------- |
| a | [<code>rect</code>](#rect) |
| points | [<code>Array.<vec2></code>](#vec2) \| [<code>TypedArray</code>](#TypedArray) |
<a name="module_rect.getCorners"></a>
### rect.getCorners(a, points) ⇒ [<code>Array.<vec2></code>](#vec2)
Returns a list of 4 points from a rectangle.
**Kind**: static method of [<code>rect</code>](#module_rect)
| Param | Type |
| ------ | ---------------------------------------- |
| a | [<code>rect</code>](#rect) |
| points | [<code>Array.<vec2></code>](#vec2) |
<a name="module_rect.scale"></a>
### rect.scale(a, n) ⇒ [<code>rect</code>](#rect)
Scales a rectangle.
**Kind**: static method of [<code>rect</code>](#module_rect)
| Param | Type |
| ----- | -------------------------- |
| a | [<code>rect</code>](#rect) |
| n | <code>number</code> |
<a name="module_rect.setSize"></a>
### rect.setSize(a, size) ⇒ [<code>rect</code>](#rect)
Sets the size of a rectangle using width and height.
**Kind**: static method of [<code>rect</code>](#module_rect)
| Param | Type |
| ----- | -------------------------- |
| a | [<code>rect</code>](#rect) |
| size | [<code>vec2</code>](#vec2) |
<a name="module_rect.size"></a>
### rect.size(a, out) ⇒ [<code>vec2</code>](#vec2)
Returns the size of a rectangle.
**Kind**: static method of [<code>rect</code>](#module_rect)
| Param | Type |
| ----- | -------------------------- |
| a | [<code>rect</code>](#rect) |
| out | [<code>vec2</code>](#vec2) |
<a name="module_rect.width"></a>
### rect.width(a) ⇒ <code>number</code>
Returns the width of a rectangle.
**Kind**: static method of [<code>rect</code>](#module_rect)
| Param | Type |
| ----- | -------------------------- |
| a | [<code>rect</code>](#rect) |
<a name="module_rect.height"></a>
### rect.height(a) ⇒ <code>number</code>
Returns the height of a rectangle.
**Kind**: static method of [<code>rect</code>](#module_rect)
| Param | Type |
| ----- | -------------------------- |
| a | [<code>rect</code>](#rect) |
<a name="module_rect.aspectRatio"></a>
### rect.aspectRatio(a) ⇒ <code>number</code>
Returns the aspect ratio of a rectangle.
**Kind**: static method of [<code>rect</code>](#module_rect)
| Param | Type |
| ----- | -------------------------- |
| a | [<code>rect</code>](#rect) |
<a name="module_rect.setPosition"></a>
### rect.setPosition(a, p) ⇒ [<code>rect</code>](#rect)
Sets the position of a rectangle.
**Kind**: static method of [<code>rect</code>](#module_rect)
| Param | Type |
| ----- | -------------------------- |
| a | [<code>rect</code>](#rect) |
| p | [<code>vec2</code>](#vec2) |
<a name="module_rect.center"></a>
### rect.center(a, out) ⇒ [<code>rect</code>](#rect)
Returns the center of a rectangle.
**Kind**: static method of [<code>rect</code>](#module_rect)
| Param | Type |
| ----- | -------------------------- |
| a | [<code>rect</code>](#rect) |
| out | [<code>vec2</code>](#vec2) |
<a name="module_rect.containsPoint"></a>
### rect.containsPoint(a, p) ⇒ <code>boolean</code>
Checks if a point is inside a rectangle.
**Kind**: static method of [<code>rect</code>](#module_rect)
| Param | Type |
| ----- | -------------------------- |
| a | [<code>rect</code>](#rect) |
| p | [<code>vec2</code>](#vec2) |
<a name="module_rect.containsRect"></a>
### rect.containsRect(a, b) ⇒ <code>boolean</code>
Checks if a rectangle is inside another rectangle.
**Kind**: static method of [<code>rect</code>](#module_rect)
| Param | Type |
| ----- | -------------------------- |
| a | [<code>rect</code>](#rect) |
| b | [<code>rect</code>](#rect) |
<a name="module_rect.includePoint"></a>
### rect.includePoint(a, p) ⇒ [<code>rect</code>](#rect)
Includes a point in a rectangle.
**Kind**: static method of [<code>rect</code>](#module_rect)
| Param | Type |
| ----- | -------------------------- |
| a | [<code>rect</code>](#rect) |
| p | [<code>vec2</code>](#vec2) |
<a name="module_rect.includeRect"></a>
### rect.includeRect(a, b) ⇒ [<code>rect</code>](#rect)
Includes a rectangle in another rectangle.
**Kind**: static method of [<code>rect</code>](#module_rect)
| Param | Type |
| ----- | -------------------------- |
| a | [<code>rect</code>](#rect) |
| b | [<code>rect</code>](#rect) |
<a name="module_rect.mapPoint"></a>
### rect.mapPoint(a, p) ⇒ [<code>vec2</code>](#vec2)
Maps a point into the dimensions of a rectangle.
**Kind**: static method of [<code>rect</code>](#module_rect)
| Param | Type |
| ----- | -------------------------- |
| a | [<code>rect</code>](#rect) |
| p | [<code>vec2</code>](#vec2) |
<a name="module_rect.clampPoint"></a>
### rect.clampPoint(a, p) ⇒ [<code>vec2</code>](#vec2)
Clamps a point into the dimensions of a rectangle.
**Kind**: static method of [<code>rect</code>](#module_rect)
| Param | Type |
| ----- | -------------------------- |
| a | [<code>rect</code>](#rect) |
| p | [<code>vec2</code>](#vec2) |
<a name="module_rect.toString"></a>
### rect.toString(a, [precision]) ⇒ <code>string</code>
Prints a rect to a string.
**Kind**: static method of [<code>rect</code>](#module_rect)
| Param | Type | Default |
| ----------- | -------------------------- | -------------- |
| a | [<code>rect</code>](#rect) | |
| [precision] | <code>number</code> | <code>4</code> |
<a name="aabb"></a>
## aabb : <code>Array.<Array.<number>></code>
An axis-aligned bounding box defined by two min and max 3D points (eg. [[minX, minY, minZ], [maxX, maxY, maxZ]]).
**Kind**: global typedef
<a name="plane"></a>
## plane : <code>Array.<Array.<number>></code>
A plane defined by a 3D point and a normal vector perpendicular to the plane’s surface (eg. [[pointX, pointY, pointZ], [normalX, normalY, normalZ]]).
**Kind**: global typedef
<a name="ray"></a>
## ray : <code>Array.<Array.<number>></code>
A ray defined by a starting 3D point origin and a 3D direction vector (eg. [[originX, originY, originZ], [directionX, directionY, directionZ]).
**Kind**: global typedef
<a name="rect"></a>
## rect : <code>Array.<Array.<number>></code>
A rectangle defined by two diagonally opposite 2D points (eg. [[minX, minY], [maxX, maxY]]).
**Kind**: global typedef
<a name="triangle"></a>
## triangle : <code>Array.<Array.<number>></code>
A triangle defined by three 3D points.
**Kind**: global typedef
<a name="vec2"></a>
## vec2 : <code>module:pex-math~vec2</code>
**Kind**: global typedef
<a name="vec3"></a>
## vec3 : <code>module:pex-math~vec3</code>
**Kind**: global typedef
<a name="TypedArray"></a>
## TypedArray : <code>module:pex-math~TypedArray</code>
**Kind**: global typedef
<!-- api-end -->
## License
MIT. See [license file](https://github.com/pex-gl/pex-geom/blob/main/LICENSE.md).