update
parent
e141a2db96
commit
18bd4d1df2
|
@ -25,41 +25,28 @@ export class Matrix {
|
||||||
f = 0
|
f = 0
|
||||||
|
|
||||||
constructor(a, b, c, d, e, f) {
|
constructor(a, b, c, d, e, f) {
|
||||||
if (b === void 0 && is(a, 'SVGMatrix')) {
|
this.a = +a
|
||||||
this.a = a.a
|
this.b = +b
|
||||||
this.b = a.b
|
this.c = +c
|
||||||
this.c = a.c
|
this.d = +d
|
||||||
this.d = a.d
|
this.e = +e
|
||||||
this.e = a.e
|
this.f = +f
|
||||||
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
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds the given matrix to existing one
|
* Adds the given matrix to existing one
|
||||||
*/
|
*/
|
||||||
add(a, b, c, d, e, f) {
|
add(a, b, c, d, e, f) {
|
||||||
if (a && a instanceof Matrix) {
|
let _a = a * this.a + b * this.c
|
||||||
return this.add(a.a, a.b, a.c, a.d, a.e, a.f)
|
let _b = a * this.b + b * this.d
|
||||||
}
|
|
||||||
let aNew = a * this.a + b * this.c,
|
|
||||||
bNew = a * this.b + b * this.d
|
|
||||||
this.e += e * this.a + f * this.c
|
this.e += e * this.a + f * this.c
|
||||||
this.f += e * this.b + f * this.d
|
this.f += e * this.b + f * this.d
|
||||||
this.c = c * this.a + d * this.c
|
this.c = c * this.a + d * this.c
|
||||||
this.d = c * this.b + d * this.d
|
this.d = c * this.b + d * this.d
|
||||||
|
|
||||||
this.a = aNew
|
this.a = _a
|
||||||
this.b = bNew
|
this.b = _b
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -70,16 +57,17 @@ export class Matrix {
|
||||||
if (a && a instanceof Matrix) {
|
if (a && a instanceof Matrix) {
|
||||||
return this.multLeft(a.a, a.b, a.c, a.d, a.e, a.f)
|
return this.multLeft(a.a, a.b, a.c, a.d, a.e, a.f)
|
||||||
}
|
}
|
||||||
let aNew = a * this.a + c * this.b,
|
let _a = a * this.a + c * this.b
|
||||||
cNew = a * this.c + c * this.d,
|
let _c = a * this.c + c * this.d
|
||||||
eNew = a * this.e + c * this.f + e
|
let _e = a * this.e + c * this.f + e
|
||||||
|
|
||||||
this.b = b * this.a + d * this.b
|
this.b = b * this.a + d * this.b
|
||||||
this.d = b * this.c + d * this.d
|
this.d = b * this.c + d * this.d
|
||||||
this.f = b * this.e + d * this.f + f
|
this.f = b * this.e + d * this.f + f
|
||||||
|
|
||||||
this.a = aNew
|
this.a = _a
|
||||||
this.c = cNew
|
this.c = _c
|
||||||
this.e = eNew
|
this.e = _e
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -87,15 +75,15 @@ export class Matrix {
|
||||||
* Returns an inverted version of the matrix
|
* Returns an inverted version of the matrix
|
||||||
*/
|
*/
|
||||||
invert() {
|
invert() {
|
||||||
let me = this
|
let { a, b, c, d, e, f } = this
|
||||||
let x = me.a * me.d - me.b * me.c
|
let x = a * d - b * c
|
||||||
return new Matrix(
|
return new Matrix(
|
||||||
me.d / x,
|
d / x,
|
||||||
-me.b / x,
|
-b / x,
|
||||||
-me.c / x,
|
-c / x,
|
||||||
me.a / x,
|
a / x,
|
||||||
(me.c * me.f - me.d * me.e) / x,
|
(c * f - d * e) / x,
|
||||||
(me.b * me.e - me.a * me.f) / x
|
(b * e - a * f) / x
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
|
@ -195,18 +183,18 @@ export class Matrix {
|
||||||
return x * this.b + y * this.d + this.f
|
return x * this.b + y * this.d + this.f
|
||||||
}
|
}
|
||||||
get(i) {
|
get(i) {
|
||||||
return +this[String.fromCharCode(97 + i)].toFixed(4)
|
return +this[i].toFixed(4)
|
||||||
}
|
}
|
||||||
toString() {
|
toString() {
|
||||||
return (
|
return (
|
||||||
'matrix(' +
|
'matrix(' +
|
||||||
[
|
[
|
||||||
this.get(0),
|
this.get('a'),
|
||||||
this.get(1),
|
this.get('b'),
|
||||||
this.get(2),
|
this.get('c'),
|
||||||
this.get(3),
|
this.get('d'),
|
||||||
this.get(4),
|
this.get('e'),
|
||||||
this.get(5)
|
this.get('f')
|
||||||
].join() +
|
].join() +
|
||||||
')'
|
')'
|
||||||
)
|
)
|
||||||
|
@ -301,12 +289,12 @@ export class Matrix {
|
||||||
return (
|
return (
|
||||||
'm' +
|
'm' +
|
||||||
[
|
[
|
||||||
this.get(0),
|
this.get('a'),
|
||||||
this.get(1),
|
this.get('b'),
|
||||||
this.get(2),
|
this.get('c'),
|
||||||
this.get(3),
|
this.get('d'),
|
||||||
this.get(4),
|
this.get('e'),
|
||||||
this.get(5)
|
this.get('f')
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
11
src/paper.js
11
src/paper.js
|
@ -131,19 +131,12 @@ let proto = Paper.prototype
|
||||||
return el
|
return el
|
||||||
}
|
}
|
||||||
function gradientLinear(defs, x1, y1, x2, y2) {
|
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.stops = Gstops
|
||||||
el.addStop = GaddStop
|
el.addStop = GaddStop
|
||||||
el.getBBox = GgetBBox
|
el.getBBox = GgetBBox
|
||||||
el.setStops = GsetStops
|
el.setStops = GsetStops
|
||||||
if (x1 != null) {
|
|
||||||
$(el.node, {
|
|
||||||
x1: x1,
|
|
||||||
y1: y1,
|
|
||||||
x2: x2,
|
|
||||||
y2: y2
|
|
||||||
})
|
|
||||||
}
|
|
||||||
return el
|
return el
|
||||||
}
|
}
|
||||||
function gradientRadial(defs, cx, cy, r, fx, fy) {
|
function gradientRadial(defs, cx, cy, r, fx, fy) {
|
||||||
|
|
|
@ -104,8 +104,8 @@ export function h(el, props = null, children) {
|
||||||
if (children) {
|
if (children) {
|
||||||
if (Array.isArray(children)) {
|
if (Array.isArray(children)) {
|
||||||
let f = doc.createDocumentFragment()
|
let f = doc.createDocumentFragment()
|
||||||
for (let it of children) {
|
for (let i = -1, it; (it = children[++i]); ) {
|
||||||
f.appendChild(h('tspan', null, it))
|
f.appendChild(h('tspan', { dy: i * 16 }, it))
|
||||||
}
|
}
|
||||||
el.appendChild(f)
|
el.appendChild(f)
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in New Issue