A Group is a subclass of standard javascript Array
. It should only contain Pt instances. You can think of it as an array of Float32Arrays.
See Group guide for details.
Create a Group by passing an array of Pt
. You may also create a Group using Group.fromArray
or Group.fromPtArray
.
an array of Pts
Apply this group as a matrix and calculate matrix addition.
a scalar number, an array of numeric arrays, or a group of Pt
a new Group
Apply this group as a matrix and calculate matrix multiplication.
a scalar number, an array of numeric arrays, or a Group of K Pts, each with N dimensions (K-rows, N-columns) -- or if transposed is true, then N Pts with K dimensions
(Only applicable if it's not elementwise multiplication) If true, then a and b's columns should match (ie, each Pt should have the same dimensions). Default is false
.
if true, then the multiplication is done element-wise. Default is false
.
If not elementwise, this will return a new Group with M Pt, each with N dimensions (M-rows, N-columns).
Zip a group of Pt. eg, [[1,2],[3,4],[5,6]] => [[1,3,5],[2,4,6]].
a default value to fill if index out of bound. If not provided, it will throw an error instead.
If true, find the longest list of values in a Pt and use its length for zipping. Default is false, which uses the first item's length for zipping.
Add scalar or vector values to this group's Pts.
can be either a list of numbers, an array, a Pt, or an object with {x,y,z,w} properties
Anchor all the Pts in this Group by its absolute position from a target Pt. (ie, add all Pt with the target anchor to get an absolute position). All the Pts' values will be updated.
a Pt, or a numeric index to target a specific Pt in this Group
Anchor all the Pts in this Group using a target Pt as origin. (ie, subtract all Pt with the target anchor to get a relative position). All the Pts' values will be updated.
a Pt, or a numeric index to target a specific Pt in this Group
Find the rectangular bounding box of this group's Pts.
a Group of 2 Pts representing the top-left and bottom-right of the rectangle
Find the centroid of this group's Pts, which is the average middle point.
Divide this group's Pts over scalar or vector values (as element-wise).
can be either a list of numbers, an array, a Pt, or an object with {x,y,z,w} properties
Update each Pt in this Group with an existing Pt function.
string name of an existing Pt function. Note that the function must return Pt.
arguments for the function specified in ptFn
Convert an array of numeric arrays into a Group.
an Iterable
Group.fromArray( [[1,2], [3,4], [5,6]] )
Convert an Array/Iterable of Pt into a Group.
an Iterable
Insert more Pt into this group.
a Group or an Iterable
the index position to insert into
Get an interpolated point on the line segments defined by this Group.
a value between 0 to 1 usually
Move the first Pt in this group to a specific position, and move all the other Pts correspondingly.
can be either a list of numbers, an array, a Pt, or an object with {x,y,z,w} properties
Multiply scalar or vector values (as element-wise) with this group's Pts.
can be either a list of numbers, an array, a Pt, or an object with {x,y,z,w} properties
Create an operation using this Group, passing this Group into a custom function's first parameter. See the Op guide for details.
any function that takes a Group as its first parameter
a resulting function that takes other parameters required in fn
let myOp = group.op( fn ); let result = myOp( [1,2,3] );
This combines a series of operations into an array. See the Op guide for details.
an array of functions for op
an array of resulting functions
let myOps = pt.ops([fn1, fn2, fn3]); let results = myOps.map( (op) => op([1,2,3]) );
Reflect this group's Pts along a 2D line. Default anchor point is the first Pt in this group.
a Group or an Iterable
optional axis such as "yz" to define a 2D plane of reflection
Like Array's splice function, with support for negative index and a friendlier name.
start index, which can be negative (where -1 is at index 0, -2 at index 1, etc)
number of items to remove
The items that are removed.
Rotate this group's Pt from an anchor point in 2D. Default anchor point is the first Pt in this group.
rotate angle
optional anchor point to scale from
optional string such as "yz" to specify a 2D plane
Scale this group's Pts from an anchor point. Default anchor point is the first Pt in this group.
scale ratio
optional anchor point to scale from
Split this group into an array of sub-group segments.
number of Pts in each segment
forward-step to take
if true
, always go through the array till the end and loop back to the beginning to complete the segments if needed
Shear this group's Pt from an anchor point in 2D. Default anchor point is the first Pt in this group.
optional anchor point to scale from
optional string such as "yz" to specify a 2D plane
Sort this group's Pts by values in a specific dimension.
dimensional index
if true, sort descending. Default is false (ascending)
Split this Group into an array of sub-groups.
number of items per sub-group
forward-steps after each sub-group
if true
, always go through the array till the end and loop back to the beginning to complete the segments if needed
Subtract scalar or vector values from this group's Pts.
can be either a list of numbers, an array, a Pt, or an object with {x,y,z,w} properties
Get a string representation of this group.
Array.toString
in src/Pt.tsZip one slice of an array of Pt. Imagine the Pts are organized in rows, then this function will take the values in a specific column.
a default value to fill if index out of bound. If not provided, it will throw an error instead.
Iterator
Array.[Symbol.iterator]
Returns an object whose properties have the value 'true' when they will be absent when used in a 'with' statement.
Array.[Symbol.unscopables]
Combines two or more arrays. This method returns a new array without modifying any existing arrays.
Additional arrays and/or items to add to the end of the array.
Array.concat
Returns the this object after copying a section of the array identified by start and end to the same array starting at position target
If target is negative, it is treated as length+target where length is the length of the array.
If start is negative, it is treated as length+start. If end is negative, it is treated as length+end.
If not specified, length of the this object is used as its default value.
Array.copyWithin
Returns an iterable of key, value pairs for every entry in the array
Array.entries
Determines whether all the members of an array satisfy the specified test.
A function that accepts up to three arguments. The every method calls the predicate function for each element in the array until the predicate returns a value which is coercible to the Boolean value false, or until the end of the array.
An object to which the this keyword can refer in the predicate function. If thisArg is omitted, undefined is used as the this value.
Array.every
Changes all array elements from start
to end
index to a static value
and returns the modified array
value to fill array section with
index to start filling the array at. If start is negative, it is treated as length+start where length is the length of the array.
index to stop filling the array at. If end is negative, it is treated as length+end.
Array.fill
Returns the elements of an array that meet the condition specified in a callback function.
A function that accepts up to three arguments. The filter method calls the predicate function one time for each element in the array.
An object to which the this keyword can refer in the predicate function. If thisArg is omitted, undefined is used as the this value.
Array.filter
Returns the value of the first element in the array where predicate is true, and undefined otherwise.
find calls predicate once for each element of the array, in ascending order, until it finds one where predicate returns true. If such an element is found, find immediately returns that element value. Otherwise, find returns undefined.
If provided, it will be used as the this value for each invocation of predicate. If it is not provided, undefined is used instead.
Array.find
Returns the index of the first element in the array where predicate is true, and -1 otherwise.
find calls predicate once for each element of the array, in ascending order, until it finds one where predicate returns true. If such an element is found, findIndex immediately returns that element index. Otherwise, findIndex returns -1.
If provided, it will be used as the this value for each invocation of predicate. If it is not provided, undefined is used instead.
Array.findIndex
Performs the specified action for each element in an array.
A function that accepts up to three arguments. forEach calls the callbackfn function one time for each element in the array.
An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value.
Array.forEach
Determines whether an array includes a certain element, returning true or false as appropriate.
The element to search for.
The position in this array at which to begin searching for searchElement.
Array.includes
Returns the index of the first occurrence of a value in an array, or -1 if it is not present.
The value to locate in the array.
The array index at which to begin the search. If fromIndex is omitted, the search starts at index 0.
Array.indexOf
Adds all the elements of an array into a string, separated by the specified separator string.
A string used to separate one element of the array from the next in the resulting string. If omitted, the array elements are separated with a comma.
Array.join
Returns an iterable of keys in the array
Array.keys
Returns the index of the last occurrence of a specified value in an array, or -1 if it is not present.
The value to locate in the array.
The array index at which to begin searching backward. If fromIndex is omitted, the search starts at the last index in the array.
Array.lastIndexOf
Calls a defined callback function on each element of an array, and returns an array that contains the results.
A function that accepts up to three arguments. The map method calls the callbackfn function one time for each element in the array.
An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value.
Array.map
Removes the last element from an array and returns it. If the array is empty, undefined is returned and the array is not modified.
Array.pop
Appends new elements to the end of an array, and returns the new length of the array.
New elements to add to the array.
Array.push
Calls the specified callback function for all the elements in an array. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function.
A function that accepts up to four arguments. The reduce method calls the callbackfn function one time for each element in the array.
Array.reduce
Calls the specified callback function for all the elements in an array, in descending order. The return value of the callback function is the accumulated result, and is provided as an argument in the next call to the callback function.
A function that accepts up to four arguments. The reduceRight method calls the callbackfn function one time for each element in the array.
Array.reduceRight
Reverses the elements in an array in place. This method mutates the array and returns a reference to the same array.
Array.reverse
Removes the first element from an array and returns it. If the array is empty, undefined is returned and the array is not modified.
Array.shift
Returns a copy of a section of an array. For both start and end, a negative index can be used to indicate an offset from the end of the array. For example, -2 refers to the second to last element of the array.
The beginning index of the specified portion of the array. If start is undefined, then the slice begins at index 0.
The end index of the specified portion of the array. This is exclusive of the element at the index 'end'. If end is undefined, then the slice extends to the end of the array.
Array.slice
Determines whether the specified callback function returns true for any element of an array.
A function that accepts up to three arguments. The some method calls the predicate function for each element in the array until the predicate returns a value which is coercible to the Boolean value true, or until the end of the array.
An object to which the this keyword can refer in the predicate function. If thisArg is omitted, undefined is used as the this value.
Array.some
Sorts an array in place. This method mutates the array and returns a reference to the same array.
Function used to determine the order of the elements. It is expected to return a negative value if the first argument is less than the second argument, zero if they're equal, and a positive value otherwise. If omitted, the elements are sorted in ascending, ASCII character order.
[11,2,22,1].sort((a, b) => a - b)
Array.sort
Removes elements from an array and, if necessary, inserts new elements in their place, returning the deleted elements.
The zero-based location in the array from which to start removing elements.
The number of elements to remove.
An array containing the elements that were deleted.
Array.splice
Returns a string representation of an array. The elements are converted to string using their toLocaleString methods.
Array.toLocaleString
Inserts new elements at the start of an array, and returns the new length of the array.
Elements to insert at the start of the array.
Array.unshift
Returns an iterable of values in the array
Array.values