master
yutent 2024-03-19 18:24:25 +08:00
parent e141a2db96
commit 18bd4d1df2
3 changed files with 43 additions and 62 deletions

View File

@ -25,16 +25,6 @@ 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
@ -42,24 +32,21 @@ export class Matrix {
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')
]
)
}

View File

@ -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) {

View File

@ -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 {