transformation-matrix
Version:
2d transformation matrix functions written in ES6 syntax. Tree shaking ready!
22 lines (21 loc) • 832 B
JavaScript
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.smoothMatrix = smoothMatrix;
/**
* Rounds all elements of the given matrix using the given precision
* @param matrix {Matrix} An affine matrix to round
* @param [precision] {number} A precision to use for Math.round. Defaults to 10000000000 (meaning which rounds to the 10th digit after the comma).
* @returns {Matrix} The rounded Affine Matrix
*/
function smoothMatrix(matrix, precision = 10000000000) {
return {
a: Math.round(matrix.a * precision) / precision,
b: Math.round(matrix.b * precision) / precision,
c: Math.round(matrix.c * precision) / precision,
d: Math.round(matrix.d * precision) / precision,
e: Math.round(matrix.e * precision) / precision,
f: Math.round(matrix.f * precision) / precision
};
}
;