UNPKG

transformation-matrix

Version:

2d transformation matrix functions written in ES6 syntax. Tree shaking ready!

17 lines (16 loc) 723 B
/** * 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 */ export 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 } }