3.0.1 • Published 3 months ago

pex-geom v3.0.1

Weekly downloads
549
License
MIT
Repository
github
Last release
3 months ago

pex-geom

npm version stability-stable npm minzipped size dependencies types Conventional Commits styled with prettier linted with eslint license

Geometry intersection and bounding volume helpers for PEX.

Installation

npm install pex-geom

Usage

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

Modules

Typedefs

aabb

aabb.create() ⇒ aabb

Creates a new bounding box.

Kind: static method of aabb

aabb.empty(a) ⇒ rect

Reset a bounding box.

Kind: static method of aabb

ParamType
aaabb

aabb.copy(a) ⇒ aabb

Copies a bounding box.

Kind: static method of aabb

ParamType
aaabb

aabb.set(a, b) ⇒ aabb

Sets a bounding box to another.

Kind: static method of aabb

ParamType
aaabb
baabb

aabb.isEmpty(a) ⇒ boolean

Checks if a bounding box is empty.

Kind: static method of aabb

ParamType
aaabb

aabb.fromPoints(a, points) ⇒ aabb

Updates a bounding box from a list of points.

Kind: static method of aabb

ParamType
aaabb
pointsArray.<module:pex-math/types/types~vec3> | module:pex-math/types/types~TypedArray

aabb.getCorners(a, points) ⇒ Array.<module:pex-math/types/types~vec3>

Returns a list of 8 points from a bounding box.

Kind: static method of aabb

ParamType
aaabb
pointsArray.<module:pex-math/types/types~vec3>

aabb.center(a, out) ⇒ module:pex-math/types/types~vec3

Returns the center of a bounding box.

Kind: static method of aabb

ParamType
aaabb
outmodule:pex-math/types/types~vec3

aabb.size(a, out) ⇒ module:pex-math/types/types~vec3

Returns the size of a bounding box.

Kind: static method of aabb

ParamType
aaabb
outmodule:pex-math/types/types~vec3

aabb.containsPoint(a, p) ⇒ boolean

Checks if a point is inside a bounding box.

Kind: static method of aabb

ParamType
aaabb
pmodule:pex-math/types/types~vec3

aabb.includeAABB(a, b) ⇒ aabb

Includes a bounding box in another.

Kind: static method of aabb

ParamType
aaabb
baabb

aabb.includePoint(a, p, i) ⇒ module:pex-math/types/types~vec3

Includes a point in a bounding box.

Kind: static method of aabb

ParamTypeDefaultDescription
aaabb
pmodule:pex-math/types/types~vec3
inumber0offset in the point array

aabb.toString(a, precision) ⇒ string

Prints a bounding box to a string.

Kind: static method of aabb

ParamTypeDefault
aaabb
precisionnumber4

index

Re-export aabb, plane, ray and rect

plane

plane.Side : enum

Enum for different side values

Kind: static enum of plane Read only: true

plane.create() ⇒ plane

Creates a new plane

Kind: static method of plane

plane.side(plane, point) ⇒ number

Returns on which side a point is.

Kind: static method of plane

ParamType
planeplane
pointmodule:pex-math/types/types~vec3

plane.toString(a, precision) ⇒ string

Prints a plane to a string.

Kind: static method of plane

ParamTypeDefault
aplane
precisionnumber4

ray

ray.Intersections : enum

Enum for different intersections values

Kind: static enum of ray Read only: true

ray.create() ⇒ ray

Creates a new ray

Kind: static method of ray

ray.hitTestPlane(ray, plane, out) ⇒ number

Determines if a ray intersect a plane and set intersection point

Kind: static method of ray See: https://www.cs.princeton.edu/courses/archive/fall00/cs426/lectures/raycast/sld017.htm

ParamType
rayray
planeplane
outmodule:pex-math/types/types~vec3

ray.hitTestTriangle(ray, triangle, out) ⇒ number

Determines if a ray intersect a triangle and set intersection point

Kind: static method of ray See: http://geomalgorithms.com/a06-_intersect-2.html#intersect3D_RayTriangle()

ParamType
rayray
triangletriangle
outmodule:pex-math/types/types~vec3

ray.hitTestAABB(ray, aabb) ⇒ boolean

Determines if a ray intersect an AABB bounding box

Kind: static method of ray See: http://gamedev.stackexchange.com/questions/18436/most-efficient-aabb-vs-ray-collision-algorithms

ParamType
rayray
aabbaabb

ray.intersectsAABB()

Alias for hitTestAABB

Kind: static method of ray

ray.toString(a, precision) ⇒ string

Prints a plane to a string.

Kind: static method of ray

ParamTypeDefault
aray
precisionnumber4

rect

rect.create() ⇒ rect

Creates a new rectangle.

Kind: static method of rect

rect.empty(a) ⇒ rect

Reset a rectangle.

Kind: static method of rect

ParamType
arect

rect.copy(a) ⇒ rect

Copies a rectangle.

Kind: static method of rect

ParamType
arect

rect.set(a, b) ⇒ rect

Sets a rectangle to another.

Kind: static method of rect

ParamType
arect
brect

rect.isEmpty(a) ⇒ boolean

Checks if a rectangle is empty.

Kind: static method of rect

ParamType
arect

rect.fromPoints(a, points) ⇒ rect

Updates a rectangle from a list of points.

Kind: static method of rect

ParamType
arect
pointsArray.<module:pex-math/types/types~vec2> | module:pex-math/types/types~TypedArray

rect.getCorners(a, points) ⇒ Array.<module:pex-math/types/types~vec2>

Returns a list of 4 points from a rectangle.

Kind: static method of rect

ParamType
arect
pointsArray.<module:pex-math/types/types~vec2>

rect.scale(a, n) ⇒ rect

Scales a rectangle.

Kind: static method of rect

ParamType
arect
nnumber

rect.setSize(a, size) ⇒ rect

Sets the size of a rectangle using width and height.

Kind: static method of rect

ParamType
arect
sizemodule:pex-math/types/types~vec2

rect.size(a, out) ⇒ module:pex-math/types/types~vec2

Returns the size of a rectangle.

Kind: static method of rect

ParamType
arect
outmodule:pex-math/types/types~vec2

rect.width(a) ⇒ number

Returns the width of a rectangle.

Kind: static method of rect

ParamType
arect

rect.height(a) ⇒ number

Returns the height of a rectangle.

Kind: static method of rect

ParamType
arect

rect.aspectRatio(a) ⇒ number

Returns the aspect ratio of a rectangle.

Kind: static method of rect

ParamType
arect

rect.setPosition(a, p) ⇒ rect

Sets the position of a rectangle.

Kind: static method of rect

ParamType
arect
pmodule:pex-math/types/types~vec2

rect.center(a, out) ⇒ rect

Returns the center of a rectangle.

Kind: static method of rect

ParamType
arect
outmodule:pex-math/types/types~vec2

rect.containsPoint(a, p) ⇒ boolean

Checks if a point is inside a rectangle.

Kind: static method of rect

ParamType
arect
pmodule:pex-math/types/types~vec2

rect.containsRect(a, b) ⇒ boolean

Checks if a rectangle is inside another rectangle.

Kind: static method of rect

ParamType
arect
brect

rect.includePoint(a, p) ⇒ rect

Includes a point in a rectangle.

Kind: static method of rect

ParamType
arect
pmodule:pex-math/types/types~vec2

rect.includeRect(a, b) ⇒ rect

Includes a rectangle in another rectangle.

Kind: static method of rect

ParamType
arect
brect

rect.mapPoint(a, p) ⇒ module:pex-math/types/types~vec2

Maps a point into the dimensions of a rectangle.

Kind: static method of rect

ParamType
arect
pmodule:pex-math/types/types~vec2

rect.clampPoint(a, p) ⇒ module:pex-math/types/types~vec2

Clamps a point into the dimensions of a rectangle.

Kind: static method of rect

ParamType
arect
pmodule:pex-math/types/types~vec2

rect.toString(a, precision) ⇒ string

Prints a rect to a string.

Kind: static method of rect

ParamTypeDefault
arect
precisionnumber4

aabb : Array.<Array.<number>>

An axis-aligned bounding box defined by two min and max 3D points (eg. [minX, minY, minZ, maxX, maxY, maxZ]).

Kind: global typedef

plane : Array.<Array.<number>>

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

ray : Array.<Array.<number>>

A ray defined by a starting 3D point origin and a 3D direction vector (eg. [originX, originY, originZ, directionX, directionY, directionZ).

Kind: global typedef

rect : Array.<Array.<number>>

A rectangle defined by two diagonally opposite 2D points (eg. [minX, minY, maxX, maxY]).

Kind: global typedef

triangle : Array.<Array.<number>>

A triangle defined by three 3D points.

Kind: global typedef

License

MIT. See license file.

3.0.1

3 months ago

3.0.0

3 months ago

3.0.0-alpha.4

11 months ago

3.0.0-alpha.3

2 years ago

3.0.0-alpha.1

2 years ago

3.0.0-alpha.0

2 years ago

3.0.0-alpha.2

2 years ago

2.0.2

6 years ago

2.0.1

6 years ago

2.0.0

6 years ago

1.0.0

7 years ago

1.0.0-beta.2

8 years ago

1.0.0-beta.1

8 years ago

0.14.0

9 years ago

0.13.0

9 years ago

0.12.1

9 years ago

0.12.0

9 years ago

0.11.1

9 years ago

0.11.0

9 years ago

0.10.7

9 years ago

0.10.6

9 years ago

0.10.5

9 years ago

0.10.4

9 years ago

0.10.3

9 years ago

0.10.2

9 years ago

0.10.1

9 years ago

0.10.0

9 years ago

0.9.3

9 years ago

0.9.2

9 years ago

0.9.0

9 years ago

0.8.0

9 years ago

0.7.1

10 years ago

0.7.0

10 years ago

0.6.0

10 years ago

0.5.0

10 years ago

0.3.1

10 years ago

0.2.0

10 years ago

0.1.0

10 years ago

0.0.10

10 years ago

0.0.8

10 years ago

0.0.8-alpha

10 years ago

0.0.7

10 years ago

0.0.6

10 years ago

0.0.5

10 years ago

0.0.4

10 years ago