export default {

	identity () {
		const matrix = [];
		for (let i = 0; i < 16; i++) {
			i % 5 == 0 ? matrix.push(1) : matrix.push(0);
		}
		return matrix;
	},


	multiply (m, x) {
		const result = [];
		for (let i = 0; i < 4; i++) {
			const r = [m[i], m[i + 4], m[i + 8], m[i + 12]];
			for (let j = 0; j < 4; j++) {
				const k = j * 4;
				const c = [x[k], x[k + 1], x[k + 2], x[k + 3]];
				result[i + k] = r[0] * c[0] + r[1] * c[1] + r[2] * c[2] + r[3] * c[3];
			}
		}
		return result;
	},


	rotateX (theta) {
		const angle = Math.PI / 180 * theta;
		const matrix = this.identity();
		matrix[5] = matrix[10] = parseFloat(Math.cos(angle).toFixed(6));
		matrix[6] = parseFloat(Math.sin(angle).toFixed(6));
		matrix[9] = parseFloat(Math.sin(angle).toFixed(6)) * -1;
		return matrix;
	},


	rotateY (theta) {
		const angle = Math.PI / 180 * theta;
		const matrix = this.identity();
		matrix[0] = matrix[10] = parseFloat(Math.cos(angle).toFixed(6));
		matrix[8] = parseFloat(Math.sin(angle).toFixed(6));
		matrix[2] = parseFloat(Math.sin(angle).toFixed(6)) * -1;
		return matrix;
	},


	rotateZ (theta) {
		const angle = Math.PI / 180 * theta;
		const matrix = this.identity();
		matrix[0] = matrix[5] = parseFloat(Math.cos(angle).toFixed(6));
		matrix[1] = parseFloat(Math.sin(angle).toFixed(6));
		matrix[4] = parseFloat(Math.sin(angle).toFixed(6)) * -1;
		return matrix;
	},


	scale (scalar) {
		const matrix = this.identity();
		matrix[0] = matrix[5] = scalar;
		return matrix;
	},


	translateX (distance) {
		const matrix = this.identity();
		matrix[12] = distance;
		return matrix;
	},


	translateY (distance) {
		const matrix = this.identity();
		matrix[13] = distance;
		return matrix;
	},
};

@@ -183,22 +183,19 @@
 %09%09const 
-result
+sum
  = %5B%5D;%0A%09
@@ -391,21 +391,18 @@
 %09%09%09%09
+let 
 result
-%5Bi + k%5D
  = r
@@ -455,16 +455,68 @@
 * c%5B3%5D;%0A
+%09%09%09%09sum%5Bi + k%5D = parseFloat(result.toPrecision(6));%0A
 %09%09%09%7D%0A%09%09%7D
@@ -525,22 +525,19 @@
 %09return 
-result
+sum
 ;%0A%09%7D,%0A%0A%0A
@@ -676,37 +676,41 @@
 th.cos(angle).to
-Fixed
+Precision
 (6));%0A%09%09matrix%5B6
@@ -734,37 +734,41 @@
 th.sin(angle).to
-Fixed
+Precision
 (6));%0A%09%09matrix%5B9
@@ -792,37 +792,41 @@
 th.sin(angle).to
-Fixed
+Precision
 (6)) * -1;%0A%09%09ret
@@ -983,37 +983,41 @@
 th.cos(angle).to
-Fixed
+Precision
 (6));%0A%09%09matrix%5B8
@@ -1041,37 +1041,41 @@
 th.sin(angle).to
-Fixed
+Precision
 (6));%0A%09%09matrix%5B2
@@ -1099,37 +1099,41 @@
 th.sin(angle).to
-Fixed
+Precision
 (6)) * -1;%0A%09%09ret
@@ -1289,37 +1289,41 @@
 th.cos(angle).to
-Fixed
+Precision
 (6));%0A%09%09matrix%5B1
@@ -1351,29 +1351,33 @@
 in(angle).to
-Fixed
+Precision
 (6));%0A%09%09matr
@@ -1417,13 +1417,17 @@
 ).to
-Fixed
+Precision
 (6))

update precision of matrix utilities