Util
Enumerations
Type Aliases
Functions
Type Aliases
Action
ActionLike
ActionResult
LazyLike
StateReducer
Functions
TypeAssert
- Util.TypeAssert(_x)
- Arguments
_x (
T()
) – None
This purpose of this function is guarantee a value is of a given type.
This is essentially a compile time
console.assert(x instanceof T)
.This function is useful when terminating a type-narrowing if-else chain in that this function makes the code more robust to future type changes.
—
Warning:
T=never
doesn’t appear to work properly, hence the existence ofTypeAssertNever
.—
Example:
declare const x: Foo | Bar; if (x instanceof Foo) { console.log("foo"); } else { // This becomes a compiler error if, for example, `x`'s type gets changed to add `Baz`: // x: Foo | Bar | Baz TypeAssert<Bar>(x); console.log("bar"); }
- Return type
void
TypeAssertNever
- Util.TypeAssertNever(_x)
- Arguments
_x (
never()
) – None
See
TypeAssert
for details.This is useful for making the compiler enforce fully-covered switch statements.
This function unconditionally throws
InternalLogicError
.—
Example:
switch (x) { case Enum.A: break; case Enum.B: break; default: TypeAssertNever(x); // compiler complains if missing other enum cases }
- Return type
never
_timerStressTest
- Util._timerStressTest()
- Return type
void
copyMap
- Util.copyMap(input)
- Arguments
input (
Map
) – The Map to be copied
Performs a shallow copy of a Map.
- Return type
Map <K, V>
copySet
- Util.copySet(input)
- Arguments
input (
Set
) – The Map to be copied
Performs a shallow copy of a Set.
- Return type
Set <T>
createCylinderMeshDataFromArc
- Util.createCylinderMeshDataFromArc(arc, axisDirection, numSegments, scale)
- Arguments
arc (
[number]()
) – an array of numbers describing points on an arc that will be used to deform the cylinderaxisDirection (
Point3()
) – cylinder axis.numSegments (
number()
) – the number of segments to use when constructing the cylinder. A higher number will give a smoother appearance but consume more memory.scale (
number()
) – a scaling factor to apply to the geometry.
Creates a cylinder that is deformed by an arc. An example of the resulting geometry can be observed in the Handles implementation.
- Return type
MeshData
createOpenPromise
- Util.createOpenPromise()
Creates a new
OpenPromise
that does not have its state resolved or rejected.- Return type
OpenPromise <T>
createTrackedOpenPromise
- Util.createTrackedOpenPromise()
Creates a new
TrackedOpenPromise
that does not have its state resolved or rejected.- Return type
TrackedOpenPromise <T>
createUnsafePromise
- Util.createUnsafePromise(promisedValue, readyPromise)
- Arguments
promisedValue (
T()
) – The value this promise resolves to. (Seethis.unsafeValue
.)readyPromise (
Promise
) – The promise used forthis.readyPromise
. (See alsothis.isReady
.)
Creates a new
UnsafePromise
.- Returns
A new
UnsafePromise
.- Return type
UnsafePromise <T>
delayCall
- Util.delayCall(cb, args)
- Arguments
cb (
function()
) – the callback to call the promise to call on the next frame.args (
[unknown]()
) – the arguments of the callback.
This function is an helper function that delay the call to a callback to the computation of the next ‘frame’ of the browser’s js engine. The point is to let the js engine deal with pending promises before running the given code.
- Returns
a timeout id in order to cancel it if necessary.
- Return type
ReturnType <unknown>
- Util.cb(cbArgs)
- Arguments
cbArgs (
[unknown]()
) – None
- Return type
unknown
exchangeIdEqual
- Util.exchangeIdEqual(exchangeIdA, exchangeIdB)
- Arguments
exchangeIdA (
string()
) – the first exchange id to compare.exchangeIdB (
string()
) – the second exchange id to compare.
Check if two exchange ids are equal.
- Returns
true or false if exchange ids are equal.
- Return type
boolean
filterInPlace
- Util.filterInPlace(xs, pred)
- Arguments
xs (
[T]()
) – Array to filter.pred (
function()
) – If this function returns true when testing an item, the item will be kept in the array, otherwise the item will be removed.
This function takes an array of type <T>, and a predicate function to test each element of the array. This function does not create a new array.
- Return type
void
- Util.pred(x)
- Arguments
x (
T()
) – None
- Return type
boolean
generateConeCylinderMeshData
- Util.generateConeCylinderMeshData(cylinderRadius, numSegments, stemHeight, coneBaseRadius, capHeight, taperHeight)
- Arguments
cylinderRadius (
number()
) – the radius of the cylinder portion of the geometry.numSegments (
number()
) – the number of segments used to create the cylinder and cone portions. Increasing this number will result in a smoother appearance but consume more memory.stemHeight (
number()
) – the height of the cone portion.coneBaseRadius (
number()
) – the radius of the cone portioncapHeight (
number()
) – the height of the cylinder captaperHeight (
number()
) – the height of the taper.
Creates a cylinder with an attached cone. An example of the resulting geometry can be observed in the default Axis Triad or Handles implementation.
- Return type
MeshData
generateSphereMeshData
- Util.generateSphereMeshData()
Creates a basic sphere with normals.
- Return type
MeshData
isCircleElement
- Util.isCircleElement(prop)
- Arguments
prop (
object()
) – the Subentity to check.
Check whether or not a Subentity is a CircleElement.
- Returns
true if the prop passed is a CircleElement, false otherwise.
- Return type
boolean
isFace
- Util.isFace(prop)
- Arguments
prop (
object()
) – the Subentity to check.
Check whether or not a Subentity is a Face.
- Returns
true if the prop passed is a Face, false otherwise.
- Return type
boolean
isLineElement
- Util.isLineElement(prop)
- Arguments
prop (
object()
) – the Subentity to check.
Check whether or not a Subentity is a LineElement.
- Returns
true if the prop passed is a LineElement, false otherwise.
- Return type
boolean
isOtherEdgeElement
- Util.isOtherEdgeElement(prop)
- Arguments
prop (
object()
) – the Subentity to check.
Check whether or not a Subentity is a OtherEdgeElement.
- Returns
true if the prop passed is a OtherEdgeElement, false otherwise.
- Return type
boolean
isPlaneElement
- Util.isPlaneElement(prop)
- Arguments
prop (
object()
) – the Subentity to check.
Check whether or not a Subentity is a PlaneElement.
- Returns
true if the prop passed is a PlaneElement, false otherwise.
- Return type
boolean
setSubtraction
- Util.setSubtraction(setA, setB)
- Arguments
setA (
Set
) – The starting set to start subtracting from.setB (
Set
) – The set used to reject values fromsetA
.
Returns a new set consisting of all elements in
setA
not found insetB
.- Returns
The resulting set.
- Return type
Set <T>
setToArray
- Util.setToArray(set)
- Arguments
set (
Set
) – The set to convert.
Turns a Set<T> into an Array<T>.
- Returns
The resulting array.
- Return type
[T]
sleep
- Util.sleep(duration)
- Arguments
duration (
number()
) – number of milliseconds until the returned promise can resolve
Returns a promise that resolves after the provided number of milliseconds
- Return type
Promise <void>
toSet
- Util.toSet(xs)
- Arguments
xs (
[T]()
) – Array to create a Set from
Creates a Set from the provided array.
- Return type
Set <T>
waitForAll
- Util.waitForAll(promises)
- Arguments
promises (
[Promise <void>]()
) – array of promises.
This function behaves like writing [[Promise.all(promises).then(no_op)]] but does not incur the overhead of creating a [[.then]] promise. Using this function can provide a performance boost when doing large amounts of batch processing with groups of promises.
- Return type
Promise <void>