diff options
author | Saivan <savian@me.com> | 2018-07-05 21:40:08 +1000 |
---|---|---|
committer | Saivan <savian@me.com> | 2018-07-05 21:40:08 +1000 |
commit | b96c88212ea943a0d8950d6d71d9a3bc3ee40705 (patch) | |
tree | 6a53b2aaa8eb2ab105592464507e8b0064ad3489 /src/matrix.js | |
parent | ee25f92f87f2fc5bb6ab65023c4515a285535ff4 (diff) | |
download | svg.js-b96c88212ea943a0d8950d6d71d9a3bc3ee40705.tar.gz svg.js-b96c88212ea943a0d8950d6d71d9a3bc3ee40705.zip |
Fixed the transformation code to use the bbox properly
This commit fixes the transformations and allows single animated
transformations to properly work.
Diffstat (limited to 'src/matrix.js')
-rw-r--r-- | src/matrix.js | 24 |
1 files changed, 12 insertions, 12 deletions
diff --git a/src/matrix.js b/src/matrix.js index 07dc82b..2a9f2a9 100644 --- a/src/matrix.js +++ b/src/matrix.js @@ -45,30 +45,30 @@ SVG.Matrix = SVG.invent({ // Get the proposed transformations and the current transformations var t = formatTransforms(o) - var currentTransform = new SVG.Matrix(this) + var current = new SVG.Matrix(this) + let { x: ox, y: oy } = new SVG.Point(t.ox, t.oy).transform(current) // Construct the resulting matrix - var transformer = new SVG.Matrix(currentTransform) - .translate(-t.ox, -t.oy) + var transformer = new SVG.Matrix() + .translate(t.rx, t.ry) + .lmultiply(current) + .translate(-ox, -oy) .scale(t.scaleX, t.scaleY) .skew(t.skewX, t.skewY) .shear(t.shear) .rotate(t.theta) - .translate(t.ox, t.oy) - .translate(t.rx, t.ry) + .translate(ox, oy) // If we want the origin at a particular place, we force it there if (isFinite(t.px) || isFinite(t.py)) { - // Figure out where the origin went and the delta to get there - var current = new SVG.Point(t.ox - t.rx, t.oy - t.ry).transform(transformer) - var dx = t.px ? t.px - current.x : 0 - var dy = t.py ? t.py - current.y : 0 - - // Apply another translation + const origin = new SVG.Point(ox, oy).transform(transformer) + // TODO: Replace t.px with isFinite(t.px) + const dx = t.px ? t.px - origin.x : 0 + const dy = t.py ? t.py - origin.y : 0 transformer = transformer.translate(dx, dy) } - // We can apply translations after everything else + // Translate now after positioning transformer = transformer.translate(t.tx, t.ty) return transformer }, |