From 18bd4d1df2d2d840a226fe0ffe1be269785caab5 Mon Sep 17 00:00:00 2001 From: yutent Date: Tue, 19 Mar 2024 18:24:25 +0800 Subject: [PATCH] update --- src/matrix.js | 90 ++++++++++++++++++++++----------------------------- src/paper.js | 11 ++----- src/utils.js | 4 +-- 3 files changed, 43 insertions(+), 62 deletions(-) diff --git a/src/matrix.js b/src/matrix.js index d19697c..c8d7205 100644 --- a/src/matrix.js +++ b/src/matrix.js @@ -25,41 +25,28 @@ export class Matrix { f = 0 constructor(a, b, c, d, e, f) { - if (b === void 0 && is(a, 'SVGMatrix')) { - this.a = a.a - this.b = a.b - this.c = a.c - this.d = a.d - this.e = a.e - this.f = a.f - return - } - if (a !== void 0) { - this.a = +a - this.b = +b - this.c = +c - this.d = +d - this.e = +e - this.f = +f - } + this.a = +a + this.b = +b + this.c = +c + this.d = +d + this.e = +e + this.f = +f } /** * Adds the given matrix to existing one */ add(a, b, c, d, e, f) { - if (a && a instanceof Matrix) { - return this.add(a.a, a.b, a.c, a.d, a.e, a.f) - } - let aNew = a * this.a + b * this.c, - bNew = a * this.b + b * this.d + let _a = a * this.a + b * this.c + let _b = a * this.b + b * this.d + this.e += e * this.a + f * this.c this.f += e * this.b + f * this.d this.c = c * this.a + d * this.c this.d = c * this.b + d * this.d - this.a = aNew - this.b = bNew + this.a = _a + this.b = _b return this } @@ -70,16 +57,17 @@ export class Matrix { if (a && a instanceof Matrix) { return this.multLeft(a.a, a.b, a.c, a.d, a.e, a.f) } - let aNew = a * this.a + c * this.b, - cNew = a * this.c + c * this.d, - eNew = a * this.e + c * this.f + e + let _a = a * this.a + c * this.b + let _c = a * this.c + c * this.d + let _e = a * this.e + c * this.f + e + this.b = b * this.a + d * this.b this.d = b * this.c + d * this.d this.f = b * this.e + d * this.f + f - this.a = aNew - this.c = cNew - this.e = eNew + this.a = _a + this.c = _c + this.e = _e return this } @@ -87,15 +75,15 @@ export class Matrix { * Returns an inverted version of the matrix */ invert() { - let me = this - let x = me.a * me.d - me.b * me.c + let { a, b, c, d, e, f } = this + let x = a * d - b * c return new Matrix( - me.d / x, - -me.b / x, - -me.c / x, - me.a / x, - (me.c * me.f - me.d * me.e) / x, - (me.b * me.e - me.a * me.f) / x + d / x, + -b / x, + -c / x, + a / x, + (c * f - d * e) / x, + (b * e - a * f) / x ) } /** @@ -195,18 +183,18 @@ export class Matrix { return x * this.b + y * this.d + this.f } get(i) { - return +this[String.fromCharCode(97 + i)].toFixed(4) + return +this[i].toFixed(4) } toString() { return ( 'matrix(' + [ - this.get(0), - this.get(1), - this.get(2), - this.get(3), - this.get(4), - this.get(5) + this.get('a'), + this.get('b'), + this.get('c'), + this.get('d'), + this.get('e'), + this.get('f') ].join() + ')' ) @@ -301,12 +289,12 @@ export class Matrix { return ( 'm' + [ - this.get(0), - this.get(1), - this.get(2), - this.get(3), - this.get(4), - this.get(5) + this.get('a'), + this.get('b'), + this.get('c'), + this.get('d'), + this.get('e'), + this.get('f') ] ) } diff --git a/src/paper.js b/src/paper.js index 3344a77..f512842 100644 --- a/src/paper.js +++ b/src/paper.js @@ -131,19 +131,12 @@ let proto = Paper.prototype return el } function gradientLinear(defs, x1, y1, x2, y2) { - let el = make('linearGradient', defs) + let el = make('linearGradient', defs, { x1, y1, x2, y2 }) el.stops = Gstops el.addStop = GaddStop el.getBBox = GgetBBox el.setStops = GsetStops - if (x1 != null) { - $(el.node, { - x1: x1, - y1: y1, - x2: x2, - y2: y2 - }) - } + return el } function gradientRadial(defs, cx, cy, r, fx, fy) { diff --git a/src/utils.js b/src/utils.js index 3067a03..27d96ee 100644 --- a/src/utils.js +++ b/src/utils.js @@ -104,8 +104,8 @@ export function h(el, props = null, children) { if (children) { if (Array.isArray(children)) { let f = doc.createDocumentFragment() - for (let it of children) { - f.appendChild(h('tspan', null, it)) + for (let i = -1, it; (it = children[++i]); ) { + f.appendChild(h('tspan', { dy: i * 16 }, it)) } el.appendChild(f) } else {