})
-let obj = { rotate: 180, origin: [600, 600] }
+let obj = { shear: 2, rotate: 50, origin: [600, 600] }
a.clone() // startPosition
a.clone().transform(obj) // endPosition
* @copyright Wout Fierens <wout@mick-wout.com>
* @license MIT
*
-* BUILT: Thu Jun 28 2018 22:44:34 GMT+1000 (AEST)
+* BUILT: Thu Jun 28 2018 23:40:30 GMT+1000 (AEST)
*/;
(function(root, factory) {
},
// Applies a matrix defined by its affine parameters
- compose: function (o, ox, oy) {
+ compose: function (o) {
+ if (o.origin) {
+ o.originX = o.origin[0]
+ o.originY = o.origin[1]
+ }
// Get the parameters
+ var ox = o.originX || 0
+ var oy = o.originY || 0
var sx = o.scaleX || 1
var sy = o.scaleY || 1
var lam = o.shear || 0
// Apply the standard matrix
var result = new SVG.Matrix()
+ .translate(-ox, -oy)
.scale(sx, sy)
.shear(lam)
.rotate(theta)
.translate(tx, ty)
.lmultiply(this)
+ .translate(ox, oy)
return result
},
// Decomposes this matrix into its affine parameters
- decompose: function () {
+ decompose: function (ox=0, oy=0) {
// Get the parameters from the matrix
var a = this.a
var b = this.b
var c = this.c
var d = this.d
- var e = this.e
- var f = this.f
+ var e = this.e - ox
+ var f = this.f - oy
// Figure out if the winding direction is clockwise or counterclockwise
var determinant = a * d - b * c
scaleY: sy,
shear: lam,
rotate: theta,
- translateX: e,
- translateY: f,
+ translateX: e + ox,
+ translateY: f + oy,
+ originX: ox,
+ originY: oy,
// Return the matrix parameters
a: this.a,
b: this.b,
c: this.c,
d: this.d,
- e: this.e,
- f: this.f
+ e: this.e + ox,
+ f: this.f + oy
}
},
},
// Applies a matrix defined by its affine parameters
- compose: function (o, ox, oy) {
+ compose: function (o) {
+ if (o.origin) {
+ o.originX = o.origin[0]
+ o.originY = o.origin[1]
+ }
// Get the parameters
+ var ox = o.originX || 0
+ var oy = o.originY || 0
var sx = o.scaleX || 1
var sy = o.scaleY || 1
var lam = o.shear || 0
// Apply the standard matrix
var result = new SVG.Matrix()
+ .translate(-ox, -oy)
.scale(sx, sy)
.shear(lam)
.rotate(theta)
.translate(tx, ty)
.lmultiply(this)
+ .translate(ox, oy)
return result
},
// Decomposes this matrix into its affine parameters
- decompose: function () {
+ decompose: function (ox=0, oy=0) {
// Get the parameters from the matrix
var a = this.a
var b = this.b
var c = this.c
var d = this.d
- var e = this.e
- var f = this.f
+ var e = this.e - ox
+ var f = this.f - oy
// Figure out if the winding direction is clockwise or counterclockwise
var determinant = a * d - b * c
scaleY: sy,
shear: lam,
rotate: theta,
- translateX: e,
- translateY: f,
+ translateX: e + ox,
+ translateY: f + oy,
+ originX: ox,
+ originY: oy,
// Return the matrix parameters
a: this.a,
b: this.b,
c: this.c,
d: this.d,
- e: this.e,
- f: this.f
+ e: this.e + ox,
+ f: this.f + oy
}
},
shear: obj[2],
rotate: obj[3],
translateX: obj[4],
- translateY: obj[5]
+ translateY: obj[5],
+ originX: obj[6],
+ originY: obj[7]
}
}
SVG.Matrix.call(this, obj)
- if (obj && obj.origin){
- this.translateO(-obj.origin[0], -obj.origin[1])
+ if (obj && obj.origin) {
+ obj.originX = origin[0]
+ obj.originY = origin[1]
}
+
+ this.originX = obj && obj.originX || 0
+ this.originY = obj && obj.originY || 0
+
+ /*if (obj && obj.origin){
+ this.translateO(-obj.origin[0], -obj.origin[1])
+ }*/
//this.value = new SVG.Matrix(obj)
},
extend: {
toArray: function (){
- var v = this.decompose()
+ var v = this.decompose(this.originX, this.originY)
return [
v.scaleX,
v.shear,
v.rotate,
v.translateX,
- v.translateY
+ v.translateY,
+ v.originX,
+ v.originY,
]
}
}
// make sure to add an origin if we morph affine
//if (affine) {
- startMatrix = startMatrix.translate(-origin[0], -origin[1])
+ /*startMatrix = startMatrix.decompose(origin[0], origin[1])
+
+ startMatrix = new SVG.Matrix().compose(startMatrix)*/
+
+ startMatrix.origin = origin
//}
// FIXME: correct the rotation so that it takes the shortest path