Modules
Enumerations
Classes
Type aliases
Functions
- Type
Assert - Type
Assert Never - closest
Point From Point ToSegment - closest
Point Scalar From Point ToSegment - compute
Angle Between Vector - compute
Offaxis Rotation - compute
Point ToLine Distance - copy
Map - copy
Set - create
Cylinder Mesh Data From Arc - degrees
ToRadians - distance
Line Line - filter
InPlace - format
With Unit - generate
Arc Points - generate
Cone Cylinder Mesh Data - generate
Points OnCircle - generate
Sphere Mesh Data - get
Long Unit String - intersect3d2
Planes - intersection
Plane Line - intersection
Plane Line2 - is
Point InRect2d - is
Point OnLine Segment - is
Point OnLine Segment2d - line
Line Intersect - one
Vector Cross - radians
ToDegrees - set
Subtraction - set
ToArray - sleep
- to
Set - wait
For All
Type aliases
Action
ActionLike
ActionResult
LazyLike
Functions
TypeAssert
-
Type parameters
-
T
Parameters
-
_x: T
Returns void
-
TypeAssertNever
-
See
TypeAssert
for details.This is useful for making the compiler enforce fully-covered switch statements.
This function unconditionally throws
InternalLogicError
.
Example:
switch (x) { case Enum.A: break; case Enum.B: break; default: TypeAssertNever(x); // compiler complains if missing other enum cases }
Parameters
-
_x: never
Returns never
-
closestPointFromPointToSegment
-
Finds the closest point on line segment p0-p1 to the given point. The closest point will always lie on or between the line segment endpoints.
Parameters
-
p0: Point3
First point of the line segment
-
p1: Point3
Second point of the line segment
-
point: Point3
Point at which to find closest line segment point.
Returns Point3
-
closestPointScalarFromPointToSegment
-
Finds the scalar for the closest point on line segment p0-p1 to the given point. The returned scalar will always be in the range [0, 1], where 0 indicates p0 is closest, and 1 indicates p1 is closest.
Parameters
-
p0: Point3
First point of the line segment
-
p1: Point3
Second point of the line segment
-
point: Point3
Point at which to find closest line segment scalar
Returns number
-
computeAngleBetweenVector
computeOffaxisRotation
computePointToLineDistance
-
Computes the shortest distance between a point and a line segment.
Parameters
-
point: Point3
-
lineBegin: Point3
The start point of the line segment to compute against.
-
lineEnd: Point3
The end point of the line segment to compute against.
-
out_closestPointOnLine: Point3
The out parameter for a closest point on the line segment to the point.
Returns number
The distance from the point and the closest point on the line.
-
copyMap
-
Performs a shallow copy of a Map.
Type parameters
-
K
-
V
Parameters
-
input: Map<K, V>
The Map to be copied
Returns Map<K, V>
-
copySet
-
Performs a shallow copy of a Set.
Type parameters
-
T
Parameters
-
input: Set<T>
The Map to be copied
Returns Set<T>
-
createCylinderMeshDataFromArc
-
Creates a cylinder that is deformed by an arc. An example of the resulting geometry can be observed in the Handles implementation.
Parameters
-
arc: number[]
an array of numbers describing points on an arc that will be used to deform the cylinder
-
axisDirection: Point3
cylinder axis.
-
numSegments: number
the number of segments to use when constructing the cylinder. A higher number will give a smoother appearance but consume more memory.
-
scale: number
a scaling factor to apply to the geometry.
Returns MeshData
-
degreesToRadians
distanceLineLine
-
Returns the distance between two line segments.
Parameters
-
line1Begin: Point3
The start of the first line segment.
-
line1End: Point3
The end of the first line segment.
-
line2Begin: Point3
The start of the second line segment.
-
line2End: Point3
The end of the second line segment.
-
out_closestPointLine1: Point3
Out parameter for the closest point of line1 to line2.
-
out_closestPointLine2: Point3
Out parameter for the closest point of line2 to line1.
Returns number
The distance between the two input line segments.
-
filterInPlace
-
This function takes an array of type
, and a predicate function to test each element of the array. This function does not create a new array. Type parameters
-
T
Parameters
-
xs: T[]
Array to filter.
-
pred: function
If this function returns true when testing an item, the item will be kept in the array, otherwise the item will be removed.
-
-
Parameters
-
x: T
Returns boolean
-
-
-
Returns void
-
formatWithUnit
-
Returns the formatted string of a value and its units. Unit scaling is based on
unit === 1
being for millimeters.Parameters
-
value: number
The value to format (without units).
-
unit: number
The unit scale to be applied to
value
.
Returns string
-
generateArcPoints
-
Returns an array of evenly-distributed points that lie on an arc.
Parameters
-
axis: Point3
The normal of the plane containing the arc (in other words, the axis of rotation).
-
angle: number
The angle swept by the arc (may be negative).
-
center: Point3
The center point of the arc.
-
startOffset: Point3
The starting point of the arc, expressed as an offset relative to the center.
-
segmentCount: number
The number of line segments to be generated.
Returns Point3[]
An array containing
segmentCount + 1
points. -
generateConeCylinderMeshData
-
Creates a cylinder with an attached cone. An example of the resulting geometry can be observed in the default Axis Triad or Handles implementation.
Parameters
-
cylinderRadius: number
the radius of the cylinder portion of the geometry.
-
numSegments: number
the number of segments used to create the cylinder and cone portions. Increasing this number will result in a smoother appearance but consume more memory.
-
stemHeight: number
the height of the cone portion.
-
coneBaseRadius: number
the radius of the cone portion
-
capHeight: number
the height of the cylinder cap
-
taperHeight: number
the height of the taper.
Returns MeshData
-
generatePointsOnCircle
-
Generates tessellated points suitable for mesh creation for a given circle.
Parameters
-
out_points: Point3[]
The out parameter for the generated points.
-
center: Point3
The center of the circle.
-
radius: number
The radius of the circle.
-
numPoints: number
The number of points to use for the tesesselated circle.
-
axisVector: Point3
The axis to orient the circle against.
Returns void
-
generateSphereMeshData
-
Creates a basic sphere with normals.
Returns MeshData
getLongUnitString
-
Parameters
-
unit: UnitElement[]
Returns string
-
intersect3d2Planes
-
Computes the intersection of two planes.
Parameters
-
plane1: Plane
The first plane.
-
pointOnPlane1: Point3
A point on the first plane.
-
plane2: Plane
The second plane.
-
pointOnPlane2: Point3
A point on the second plane.
-
out_lineBegin: Point3
Out parameter for resulting intersection line (if any).
-
out_lineEnd: Point3
Out parameter for resulting intersection line (if any).
Returns 0 | 1 | 2
0
if the planes are disjoint.1
if the planes coincide.2
if the planes intersect in a line. -
intersectionPlaneLine
-
Computes the intersection of a line segment and a plane.
Parameters
-
lineBegin: Point3
The start point of the line segment to intersect.
-
lineEnd: Point3
The end point of the line segment to intersect.
-
planePoint1: Point3
A point on the plane to intersect.
-
planePoint2: Point3
A point on the plane to intersect.
-
planePoint3: Point3
A point on the plane to intersect.
-
out_intersectionPoint: Point3
The out parameter for the point of intersection if one exists.
Returns boolean
True if the line segment and plane intersect. False otherwise.
See also: intersectionPlaneLine2.
-
intersectionPlaneLine2
-
Computes the intersection of a line segment and a plane.
Parameters
-
lineBegin: Point3
The start point of the line segment to intersect.
-
lineEnd: Point3
The end point of the line segment to intersect.
-
plane: Plane
The plane to intersect.
-
out_intersectionPoint: Point3
The out parameter for the point of intersection if one exists.
Returns boolean
True if the line segment and plane intersect. False otherwise.
-
isPointInRect2d
-
Returns whether the 2-dimensional point
point
lies within the given rectangle.Parameters
-
point: Point2
The point to test
-
rectPos: Point2
The lower-left corner of the rectangle
-
rectSize: Point2
The width and height of the rectangle
-
Optional tolerance: number
The maximum distance along the x- or y-axis that
point
is allowed to be outside the rectangle
Returns boolean
-
isPointOnLineSegment
-
Determine if the point is both on the line formed by p0-p1, and within the p0-p1 line-segment endpoints
Parameters
-
p0: Point3
First point of the line segment
-
p1: Point3
Second point of the line segment
-
point: Point3
Point that possibly lies on the line segment.
-
epsilon: number
Epsilon value used with point-on-line distance calculation.
Returns boolean
-
isPointOnLineSegment2d
-
Returns whether the 2-dimensional point
point
lies on the line segmentp1p2
.Parameters
-
point: Point2
The point to test
-
p1: Point2
The first endpoint of the line segment
-
p2: Point2
The second endpoint of the line segment
-
tolerance: number
If the perpendicular distance of
point
from the line segment is less than or equal totolerance
, the function will returntrue
.
Returns boolean
-
lineLineIntersect
oneVectorCross
radiansToDegrees
setSubtraction
-
Returns a new set consisting of all elements in
setA
not found insetB
.Type parameters
-
T
Parameters
-
setA: Set<T>
The starting set to start subtracting from.
-
setB: Set<T>
The set used to reject values from
setA
.
Returns Set<T>
The resulting set.
-
setToArray
-
Turns a Set
into an Array . Type parameters
-
T
Parameters
-
set: Set<T>
The set to convert.
Returns T[]
The resulting array.
-
sleep
-
Returns a promise that resolves after the provided number of milliseconds
Parameters
-
duration: Milliseconds
number of milliseconds until the returned promise can resolve
Returns Promise<void>
-
toSet
-
Creates a Set from the provided array.
Type parameters
-
T
Parameters
-
xs: T[]
Array to create a Set from
Returns Set<T>
-
waitForAll
-
This function behaves like writing [[Promise.all(promises).then(no_op)]] but does not incur the overhead of creating a .then promise. Using this function can provide a performance boost when doing large amounts of batch processing with groups of promises.
Parameters
-
promises: Promise<void>[]
array of promises.
Returns Promise<void>
-
This purpose of this function is guarantee a value is of a given type.
This is essentially a compile time
console.assert(x instanceof T)
.This function is useful when terminating a type-narrowing if-else chain in that this function makes the code more robust to future type changes.
Warning:
T=never
doesn't appear to work properly, hence the existence ofTypeAssertNever
.Example:
declare const x: Foo | Bar; if (x instanceof Foo) { console.log("foo"); } else { // This becomes a compiler error if, for example, `x`'s type gets changed to add `Baz`: // x: Foo | Bar | Baz TypeAssert<Bar>(x); console.log("bar"); }