mirror of
https://github.com/zoriya/react-native-svg.git
synced 2026-06-07 00:42:31 +00:00
refactor Matrix2D, return early when appending identity
This commit is contained in:
+10
-3
@@ -63,6 +63,11 @@ export function toArray() {
|
|||||||
* @param {Number} ty2
|
* @param {Number} ty2
|
||||||
**/
|
**/
|
||||||
export function append(a2, b2, c2, d2, tx2, ty2) {
|
export function append(a2, b2, c2, d2, tx2, ty2) {
|
||||||
|
const change = a2 !== 1 || b2 !== 0 || c2 !== 0 || d2 !== 1;
|
||||||
|
const translate = tx2 !== 0 || ty2 !== 0;
|
||||||
|
if (!change && !translate) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (hasInitialState) {
|
if (hasInitialState) {
|
||||||
hasInitialState = false;
|
hasInitialState = false;
|
||||||
a = a2;
|
a = a2;
|
||||||
@@ -77,14 +82,16 @@ export function append(a2, b2, c2, d2, tx2, ty2) {
|
|||||||
const b1 = b;
|
const b1 = b;
|
||||||
const c1 = c;
|
const c1 = c;
|
||||||
const d1 = d;
|
const d1 = d;
|
||||||
if (a2 !== 1 || b2 !== 0 || c2 !== 0 || d2 !== 1) {
|
if (change) {
|
||||||
a = a1 * a2 + c1 * b2;
|
a = a1 * a2 + c1 * b2;
|
||||||
b = b1 * a2 + d1 * b2;
|
b = b1 * a2 + d1 * b2;
|
||||||
c = a1 * c2 + c1 * d2;
|
c = a1 * c2 + c1 * d2;
|
||||||
d = b1 * c2 + d1 * d2;
|
d = b1 * c2 + d1 * d2;
|
||||||
}
|
}
|
||||||
tx = a1 * tx2 + c1 * ty2 + tx;
|
if (translate) {
|
||||||
ty = b1 * tx2 + d1 * ty2 + ty;
|
tx = a1 * tx2 + c1 * ty2 + tx;
|
||||||
|
ty = b1 * tx2 + d1 * ty2 + ty;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user