Skip to content

Commit 890c479

Browse files
fix: refactor private names and regexes
1 parent ac2fd09 commit 890c479

File tree

2 files changed

+21
-18
lines changed

2 files changed

+21
-18
lines changed

src/get-from-element.js

+4-6
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,10 @@ import Matrix from './matrix'
22
import { identity } from './constants'
33

44
// regexp to detect transform matrices
5-
const matrixRegEx = /^(matrix\()/g
6-
const matrix3dRegEx = /^(matrix3d\()/g
5+
const matrixRegEx = /^(matrix(3d)?\()/g
76

87
// regexp to strip matrix notation
9-
const matrixCleanRegEx = /^(matrix\()|\)/g
10-
const matrix3dCleanRegEx = /^(matrix3d\()|\)/g
8+
const matrixCleanRegEx = /^(matrix(3d)?\()|\)/g
119

1210
// regexp to split values
1311
const stripRegEx = /,\s|,/g
@@ -39,9 +37,9 @@ const getMatrixFromElement = (el) => {
3937
}
4038

4139
// handle 3d matrix
42-
if (matrix3dRegEx.test(transformMatrix)) {
40+
if (matrixRegEx.test(transformMatrix)) {
4341
const stringMatrix = transformMatrix
44-
.replace(matrix3dCleanRegEx, '')
42+
.replace(matrixCleanRegEx, '')
4543
.split(stripRegEx)
4644
const numberedMatrix = stringMatrix.map((n) => parseFloat(n))
4745

src/matrix.js

+17-12
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ function getRotateMatrix(alpha) {
4545
*/
4646
export default class Matrix {
4747
constructor(matrixRepresentation) {
48-
this.__array__ = matrixRepresentation
49-
this.__string__ = getMatrixString(matrixRepresentation)
48+
this.__a = matrixRepresentation
49+
this.__s = getMatrixString(matrixRepresentation)
5050
}
5151

5252
/**
@@ -55,7 +55,7 @@ export default class Matrix {
5555
* @returns {string} matrix as matrix3d trasnform string
5656
*/
5757
toString() {
58-
return this.__string__
58+
return this.__s
5959
}
6060

6161
/**
@@ -64,7 +64,7 @@ export default class Matrix {
6464
* @returns {Array} array of arrays of the current status of the matrix
6565
*/
6666
toArray() {
67-
return this.__array__
67+
return this.__a
6868
}
6969

7070
/**
@@ -79,8 +79,8 @@ export default class Matrix {
7979
const scaleMatrix = getScaleMatrix(x, y, z)
8080
const calculatedMatrix = multiply(this.toArray(), scaleMatrix)
8181

82-
this.__array__ = calculatedMatrix
83-
this.__string__ = getMatrixString(calculatedMatrix)
82+
this.__a = calculatedMatrix
83+
this.__s = getMatrixString(calculatedMatrix)
8484

8585
return this
8686
}
@@ -97,8 +97,13 @@ export default class Matrix {
9797
const translateMatrix = getTranslateMatrix(x, y, z)
9898
const calculatedMatrix = multiply(this.toArray(), translateMatrix)
9999

100-
this.__array__ = calculatedMatrix
101-
this.__string__ = getMatrixString(calculatedMatrix)
100+
/*
101+
* private fields minified to have less impact on bundle size
102+
* __a hoists the array representation of the matrix
103+
* __s hoists the string representation of the matrix
104+
*/
105+
this.__a = calculatedMatrix
106+
this.__s = getMatrixString(calculatedMatrix)
102107

103108
return this
104109
}
@@ -113,8 +118,8 @@ export default class Matrix {
113118
const rotateMatrix = getRotateMatrix(alpha)
114119
const calculatedMatrix = multiply(this.toArray(), rotateMatrix)
115120

116-
this.__array__ = calculatedMatrix
117-
this.__string__ = getMatrixString(calculatedMatrix)
121+
this.__a = calculatedMatrix
122+
this.__s = getMatrixString(calculatedMatrix)
118123

119124
return this
120125
}
@@ -130,8 +135,8 @@ export default class Matrix {
130135
const skewMatrix = getSkewMatrix(alpha, beta)
131136
const calculatedMatrix = multiply(this.toArray(), skewMatrix)
132137

133-
this.__array__ = calculatedMatrix
134-
this.__string__ = getMatrixString(calculatedMatrix)
138+
this.__a = calculatedMatrix
139+
this.__s = getMatrixString(calculatedMatrix)
135140

136141
return this
137142
}

0 commit comments

Comments
 (0)