Geometry related code for the pex library
var aabb = require('pex-geom/aabb')
aabb.create()
Creates a new axis-aligned bounding box.
aabb.create()
// => [[Infinity, Infinity, Infinity], [-Infinity, -Infinity, -Infinity]]
Returns a new aabb
.
aabb.set(a, b)
Sets a bounding box to another.
a
: aabbb
: aabbReturns a
.
aabb.copy(a)
Copies a bounding box.
a
: aabbReturns a new instance of a
.
aabb.fromPoints(aa)
Creates a bounding box a list of points.
aa
: [vec3]Returns a new aabb
.
aabb.center(a, out)
Returns the center of a bounding box.
a
: aabbout
: vec3Returns out
or a new vec3
if out
isn't passed.
aabb.size(a, out)
Returns the size of a bounding box.
a
: aabbout
: vec3Returns out
or a new vec3
if out
isn't passed.
aabb.isEmpty(a)
Checks if a bounding box is empty.
a
: aabbReturns a bool
.
aabb.includeAABB(a, b)
Includes a bounding box in another.
a
: aabbb
: aabbReturns a
.
aabb.includePoint(a, v)
Includes a point in a bounding box.
a
: aabbv
: vec3Returns a
.
var rect = require('pex-geom/rect')
rect.create()
Returns a new rectangle.
var r = rect.create()
// => [[Infinity, Infinity], [-Infinity, -Infinity]]
Returns a new rect
.
rect.zero()
Returns a new rectangle with all zeros.
var r = rect.zero()
// => [[0, 0], [0, 0]]
Returns a new rect
.
rect.copy(r)
Copies a rect.
r
: rectReturns a new instance of r
.
rect.set(r, c)
Sets a rect to another.
r
: rectc
: rectReturns r
set to c
.
rect.scale(r, s)
Scales a rect.
r
: rects
: NumberReturns r
scaled.
rect.setSize(r, wh)
Sets the size of a rect using width and height.
r
: rectwh
: vec2 - [width, height]Returns r
with new size.
rect.getSize(r, out)
Returns the size of a rect.
r
: rectout
: vec2 - [width, height]Returns out
or a new vec2
if out
isn't passed.
rect.getAspectRatio(r)
Returns the aspect ratio of a rect.
r
: rectReturns a Number
.
rect.setPosition(r, v)
Sets the position of a rect.
r
: rectv
: vec2Returns a
.
rect.getCenter(r, out)
Returns the center of a rect.
r
: rectout
: vec2 - center of the rectReturns out
or a new vec
if out isn't passed.
rect.containsPoint(r, v)
Checks whether a point is inside a rect.
r
: rectv
: vec2Returns a bool
.
rect.containsRect(r, c)
Checks whether a point is inside a rect.
r
: rectc
: rectReturns a bool
.
rect.includePoint(r, v)
Includes point in a rect.
r
: rectv
: vec2Returns r
.
rect.includePoints(r, vv)
Includes an array of points in a rect.
r
: rectvv
: [vec2]Returns r
.
rect.includePoints(r, vv)
Includes an array of points in a rect.
r
: rectvv
: [vec2]Returns r
.
rect.includeRect(r, c)
Includes a rect in a rect.
r
: rectc
: rectReturns r
.
rect.includeRects(r, cc)
Includes an array of rects in a rect.
r
: rectcc
: [rect]Returns r
.
rect.mapPoint(r, v)
Maps a point into the dimensions of a rect.
r
: rectv
: vec2Returns p
.
rect.clampPoint(r, v)
Clamps a point into the dimensions of a rect.
r
: rectv
: vec2Returns p
.
rect.setEmpty(r)
Sets a rect to be empty (same as create).
r
: rectReturns r
.
rect.isEmpty(r)
Checks whether a rect is empty.
r
: rectReturns a bool
.
rect.createFromPoints(vv)
Creates a rect from an array of points.
vv
: [vec2]Returns a rect
.
var plane = require('pex-geom/plane')
plane.create()
Creates a new plane.
var p = plane.create()
// => [[0, 0, 0], [0, 1, 0]]
Returns a new plane
.
plane.getRayIntersection(p, r, out)
Returns the point of intersection betweeen a plane and a ray if it exists.
p
: planer
: rayout
: vec3Returns a vec3
or Null
.
plane.side(p, v)
Returns on which side a ray a point is.
p
: planev
: vec3Returns 1
, 0
or -1
.
var aabb = require('pex-geom/aabb')
ray.create()
Returns a new ray.
var `r = ray.create()`
// => [[0, 0, 0], [0, 0, 1]]
Returns a ray
.
ray.hitTestTriangle(r, t, out)
Tests if a ray hits a triangle.
r
: rayt
: triangleReturns a positive Number
if there is a hit and a negative Number
if test fails.
ray.hitTestPlane(r, v, n, out)
Tests if a ray hits a plane.
r
: rayv
: vec3n
: vec3 - normalout
: vec3Returns a positive Number
if there is a hit and a negative Number
if test fails.
ray.intersectAABB(r, a)
Tests if a ray intersects an axis-aligned bounding box.
r
: raya
: aabbReturns a bool
.