Utility functions of various sorts.
- Source:
Example
const { flatten, insertSorted } = require('@jscad/modeling').utils
Methods
(static) areAllShapesTheSameType(shapes) → {Boolean}
Parameters:
Name | Type | Description |
---|---|---|
shapes |
Array | list of shapes to compare |
Returns:
true if the given shapes are of the same type
- Type
- Boolean
(static) cos(radians) → {Number}
Return Math.cos but accurate for TAU / 4 rotations. Fixes rounding errors when cos should be 0.
Example
cos(TAU * 0.25) == 0
cos(TAU * 0.75) == 0
Parameters:
Name | Type | Description |
---|---|---|
radians |
Number | angle in radians |
Returns:
cosine of the given angle
- Type
- Number
(static) degToRad(degrees) → {Number}
- Source:
Convert the given angle (degrees) to radians.
Parameters:
Name | Type | Description |
---|---|---|
degrees |
Number | angle in degrees |
Returns:
angle in radians
- Type
- Number
(static) flatten(arr) → {Array}
- Source:
Flatten the given list of arguments into a single flat array. The arguments can be composed of multiple depths of objects and arrays.
Parameters:
Name | Type | Description |
---|---|---|
arr |
Array | list of arguments |
Returns:
a flat list of arguments
- Type
- Array
(static) fnNumberSort()
- Source:
(static) insertSorted()
- Source:
Insert the given element into the given array using the compareFunction.
(static) padArrayToLength(anArray, padding, targetLength) → {Array}
Build an array of at minimum a specified length from an existing array and a padding value. IF the array is already larger than the target length, it will not be shortened.
Parameters:
Name | Type | Description |
---|---|---|
anArray |
Array | the source array to copy into the result. |
padding |
* | the value to add to the new array to reach the desired length. |
targetLength |
Number | The desired length of the return array. |
Returns:
an array of at least 'targetLength' length
- Type
- Array
(static) radiusToSegments(radius, minimumLength, minimumAngle) → {Number}
Calculate the number of segments from the given radius based on minimum length or angle.
Parameters:
Name | Type | Description |
---|---|---|
radius |
Number | radius of the requested shape |
minimumLength |
Number | minimum length of segments; length > 0 |
minimumAngle |
Number | minimum angle (radians) between segments; 0 > angle < TAU |
Returns:
number of segments to complete the radius
- Type
- Number
(static) radToDeg(radians) → {Number}
- Source:
Convert the given angle (radians) to degrees.
Parameters:
Name | Type | Description |
---|---|---|
radians |
Number | angle in radians |
Returns:
angle in degrees
- Type
- Number
(static) sin(radians) → {Number}
Return Math.sin but accurate for TAU / 4 rotations. Fixes rounding errors when sin should be 0.
Example
sin(TAU / 2) == 0
sin(TAU) == 0
Parameters:
Name | Type | Description |
---|---|---|
radians |
Number | angle in radians |
Returns:
sine of the given angle
- Type
- Number