Skip to main content

utils

modeling/utils

Utility functions of various sorts, including conversions from different angular measures.

Example

const { areAllShapesTheSameType, degToRad, radiusToSegments, radToDeg } = require('@jscad/modeling').utils

modeling/utils.areAllShapesTheSameType(shapes)

Kind: static method of modeling/utils
Returns: Boolean - true if the given shapes are of the same type

ParamTypeDescription
shapesArraylist of shapes to compare

modeling/utils.degToRad(degrees)

Convert the given angle (degrees) to radians.

Kind: static method of modeling/utils
Returns: Number - angle in radians

ParamTypeDescription
degreesNumberangle in degrees

modeling/utils.flatten(arr)

Flatten the given list of arguments into a single flat array. The arguments can be composed of multiple depths of objects and arrays.

Kind: static method of modeling/utils
Returns: Array - a flat list of arguments

ParamTypeDescription
arrArraylist of arguments

modeling/utils.fnNumberSort()

Kind: static method of modeling/utils

modeling/utils.insertSorted()

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

Kind: static method of modeling/utils

modeling/utils.padArrayToLength(anArray, padding, targetLength)

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.

Kind: static method of modeling/utils
Returns: Array - an array of at least 'targetLength' length

ParamTypeDescription
anArrayArraythe source array to copy into the result.
padding*the value to add to the new array to reach the desired length.
targetLengthNumberThe desired length of the return array.

modeling/utils.radiusToSegments(radius, minimumLength, minimumAngle)

Calculate the number of segments from the given radius based on minimum length or angle.

Kind: static method of modeling/utils
Returns: Number - number of segments to complete the radius

ParamTypeDescription
radiusNumberradius of the requested shape
minimumLengthNumberminimum length of segments; length > 0
minimumAngleNumberminimum angle (radians) between segments; 0 > angle < TAU

modeling/utils.radToDeg(radians)

Convert the given angle (radians) to degrees.

Kind: static method of modeling/utils
Returns: Number - angle in degrees

ParamTypeDescription
radiansNumberangle in radians