modeling/utils

Utility functions of various sorts.

Source:
Example
const { flatten, insertSorted } = require('@jscad/modeling').utils

Methods

(static) areAllShapesTheSameType(shapes) → {Boolean}

Source:
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) 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(array, element, compareFunction)

Source:

Insert the given element into the give array using the compareFunction.

Example
const numbers = [1, 5]
const result = insertSorted(numbers, 3, fnNumberSort)
Parameters:
Name Type Description
array Array

array in which to insert

element *

element to insert into the array

compareFunction function

a function that defines the sort order of elements

(static) insertSorted()

Source:

(static) padArrayToLength(anArray, padding, targetLength) → {Array}

Source:

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}

Source:

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; 0 > length

minimumAngle Number

minimum angle (radians) between segments; 0 > angle < Math.PI * 2

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