Utilities
Math for the coordinate systems of ClassCAD, and timing.
Objects
MathUtils
const MathUtils: {
calcluateTransform: (originPos, xDir, yDir, offset, rotation, inverted) => Matrix4;
convertToCoordinateSystem: (matrix) => number[][];
convertToMatrix3: (coordinateSystem) => Matrix3;
convertToMatrix4: (coordinateSystem) => Matrix4;
round(value, digits): number;
};
Math for the coordinate systems of ClassCAD: to three.js matrices and back, and rounding.
ClassCAD gives a coordinate system (coordinateSystem of an object of the structure tree) as four rows: the
origin, the x axis, the y axis and the z axis.
Type Declaration
Example
import { getDrawing, MathUtils } from '@buerli.io/core'
// Place a three.js object where a work coordinate system of the tree is, in its product
const { coordinateSystem } = getDrawing(drawingId).structure.tree[workCSysId]
if (coordinateSystem) {
helper.matrix.copy(MathUtils.convertToMatrix4(coordinateSystem))
helper.matrixAutoUpdate = false
}
Timing
const Timing: {
dump: (key, message, mode) => void;
measure: (key, mode) => number;
start: (key) => string;
stop: (key) => number;
};
Measures how long things take, by name, with performance.now().
Type Declaration
| Name | Type | Description |
|---|---|---|
dump() | (key, message, mode) => void | Logs what Timing.measure returns, as <message> <ms>ms (the name stands in for a missing message). |
measure() | (key, mode) => number | Returns the milliseconds since a measurement started, or with 'fromPrevious' since it was last measured; NaN for a name that was not started. |
start() | (key) => string | Starts a time measurement. |
stop() | (key) => number | Ends a measurement, and returns the milliseconds since it started; NaN for a name that was not started. |
Example
import { createApi } from '@buerli.io/classcad'
import { Timing } from '@buerli.io/core'
const api = createApi(drawingId)
const key = Timing.start()
await api.v1.common.recalc()
Timing.dump(key, 'first recalc') // first recalc 12.34ms
await api.v1.common.recalc()
Timing.dump(key, 'second recalc', 'fromPrevious')
console.log(Timing.stop(key)) // the milliseconds since start