Returns the angle in radians between a
and b
.
Returns the angle between point(s) using a radian circle system.
Applies fn
on x,y & z (if present) fields, returning all other fields as well
Uses =@ixfx/numbers#movingAverageLight to keep track of average x, y and z values.
// Create averager
const averager = Points.averager(`moving-average-light`
Returns the minimum rectangle that can enclose all provided points
Calculates the centroid of a set of points Undefined values are skipped over.
Clamps a point to be between min
and max
(0 & 1 by default)
Clamps the magnitude of a point. This is useful when using a Point as a vector, to limit forces.
Returns -2 if both x & y of a is less than b Returns -1 if either x/y of a is less than b
Compares points based on x value. Y value is ignored.
Compares points based on Y value. X value is ignored. Returns values:
Compares points based on Z value. XY values are ignored. Returns values:
Simple convex hull impementation. Returns a set of points which
enclose pts
.
Calculate distance between two points.
If both points have a z
property, the distance is 3D distance is calculated.
If only one point has a z
, it is ignored.
Returns the distance from point a
to the center of shape
.
Returns the distance from point a
to the exterior of shape
.
Returns a Point with the x,y,z values of two points divide (a/b).
Returns a function that divides a point:
Returns the 'minimum' point from an array of points, using a comparison function.
Returns a point from two or three coordinates or an array of [x,y] or [x,y,z].
Returns an array of points from an array of numbers.
Parses a point as a string, in the form 'x,y' or 'x,y,z'.
eg '10,15' will be returned as { x: 10, y: 15 }
.
Throws an error if point is invalid
Throws if parameter is not a valid point, or either x or y is 0
Returns a relative point between two points.
Inverts one or more axis of a point
Returns true if both xy (and z, if present) are 0.
Use Points.Empty
to return an empty point.
Returns true if the points have identical values
Returns true if either x, y, z isNaN.
Returns true if xy (and z, if present) are null.
Returns true if point is a placeholder, where xy (and z, if present)
are NaN
.
Returns true if p
has x & y properties.
Returns false if p
is undefined, null or does not contain properties.
Use isPoint3d to check further check for z
.
Returns true if p
has x, y, & z properties.
Returns false if p
is undefined, null or does not contain properties.
Returns the left-most of the provided points.
Returns a Point with the x,y,z values of two points multiply (a/b).
Multiplies all components by v
.
Existing properties of pt
are maintained.
Normalise point as a unit vector.
Normalises a point so it is on a 0..1 scale
Returns a pipeline function that takes a point to be transformed through a series of functions
// Create pipeline
const p = Points.pipeline(Points.normalise, Points.invert
Runs a sequential series of functions on pt
. The output from one feeding into the next.
Computes the progress between two waypoints, given position
.
Project origin
by distance
and angle
(radians).
Quantises a point.
Returns a random 2D point on a 0..1 scale.
Returns a random 3D point on a 0..1 scale.
Reduces over points, treating x and y separately.
Tracks the relation between two points.
Returns the right-most of the provided points.
Rotate a single point by a given amount in radians
Round the point's x and y to given number of digits
Returns a Point with the x,y,z values of two points subtracted (a-b).
Returns a Point with the x,y,z values of two points added.
Returns a copy of pt
with z
field omitted.
If it didn't have one to begin within, a copy is still returned.
Returns a copy of pt
with a z
field set.
Defaults to a z value of 0.
Returns point as an array in the form [x,y]. This can be useful for some libraries that expect points in array form.
Returns a point with rounded x,y coordinates. By default uses Math.round
to round.
Returns a human-friendly string representation (x, y)
.
If precision
is supplied, this will be the number of significant digits.
Returns true if two points are within a specified range on both axes.
Wraps a point to be within ptMin
and ptMax
.
Note that max values are exclusive, meaning the return value will always be one less.
A point, consisting of x, y and maybe z fields.
An empty point of { x: 0, y: 0 }
.
An empty Point of { x: 0, y: 0, z: 0}
Use isEmpty
to check if a point is empty.
Use Empty
to get an empty point without z
.
Placeholder point: { x: NaN, y: NaN }
Use isPlaceholder
to check if a point is a placeholder.
Use Placeholder3d
get a point with z
property.
Placeholder point: {x: NaN, y:NaN, z:NaN }
Use isPlaceholder
to check if a point is a placeholder.
Use Placeholder
to get a point without z
property.
Returns { x:1, y:1 }
Returns { x:1,y:1,z:1 }
Returns a point with Math.abs applied to x,y and z if present.