mirror of
https://github.com/zoriya/react-native-svg.git
synced 2026-05-28 13:03:12 +00:00
Optimize Matrix2d and fix skew spec conformance
This commit is contained in:
+21
-28
@@ -74,6 +74,7 @@ export default class Matrix2D {
|
||||
reset = function() {
|
||||
this.a = this.d = 1;
|
||||
this.b = this.c = this.tx = this.ty = 0;
|
||||
this.hasInitialState = true;
|
||||
return this;
|
||||
};
|
||||
|
||||
@@ -99,6 +100,16 @@ export default class Matrix2D {
|
||||
* @return {Matrix2D} This matrix. Useful for chaining method calls.
|
||||
**/
|
||||
append = function(a, b, c, d, tx, ty) {
|
||||
if (this.hasInitialState) {
|
||||
this.hasInitialState = false;
|
||||
this.a = a;
|
||||
this.b = b;
|
||||
this.c = c;
|
||||
this.d = d;
|
||||
this.tx = tx;
|
||||
this.ty = ty;
|
||||
return this;
|
||||
}
|
||||
const a1 = this.a;
|
||||
const b1 = this.b;
|
||||
const c1 = this.c;
|
||||
@@ -141,7 +152,7 @@ export default class Matrix2D {
|
||||
skewX,
|
||||
skewY,
|
||||
regX,
|
||||
regY
|
||||
regY,
|
||||
) {
|
||||
let cos, sin;
|
||||
if (rotation % 360) {
|
||||
@@ -153,35 +164,17 @@ export default class Matrix2D {
|
||||
sin = 0;
|
||||
}
|
||||
|
||||
const a = cos * scaleX;
|
||||
const b = sin * scaleX;
|
||||
const c = -sin * scaleY;
|
||||
const d = cos * scaleY;
|
||||
|
||||
if (skewX || skewY) {
|
||||
// TODO: can this be combined into a single append operation?
|
||||
skewX *= DEG_TO_RAD;
|
||||
skewY *= DEG_TO_RAD;
|
||||
this.append(
|
||||
Math.cos(skewY),
|
||||
Math.sin(skewY),
|
||||
Math.sin(skewX),
|
||||
Math.cos(skewX),
|
||||
x,
|
||||
y
|
||||
);
|
||||
this.append(
|
||||
cos * scaleX,
|
||||
sin * scaleX,
|
||||
-sin * scaleY,
|
||||
cos * scaleY,
|
||||
0,
|
||||
0
|
||||
);
|
||||
const b1 = Math.tan(skewY * DEG_TO_RAD);
|
||||
const c1 = Math.tan(skewX * DEG_TO_RAD);
|
||||
this.append(a + c1 * b, b1 * a + b, c + c1 * d, b1 * c + d, x, y);
|
||||
} else {
|
||||
this.append(
|
||||
cos * scaleX,
|
||||
sin * scaleX,
|
||||
-sin * scaleY,
|
||||
cos * scaleY,
|
||||
x,
|
||||
y
|
||||
);
|
||||
this.append(a, b, c, d, x, y);
|
||||
}
|
||||
|
||||
if (regX || regY) {
|
||||
|
||||
Reference in New Issue
Block a user