summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorUlrich-Matthias Schäfer <ulima.ums@googlemail.com>2020-04-29 14:43:13 +1000
committerUlrich-Matthias Schäfer <ulima.ums@googlemail.com>2020-04-29 14:43:13 +1000
commit12f87d58bf7401af11c9d67789f2ffeda52f0372 (patch)
tree2440acdd9ffb3975727eb2f63f818fbd30800481 /src
parent7f614c73d96f3d982804c6a0473f9aa0236cc44b (diff)
downloadsvg.js-12f87d58bf7401af11c9d67789f2ffeda52f0372.tar.gz
svg.js-12f87d58bf7401af11c9d67789f2ffeda52f0372.zip
finish tests for Matrix.js
Diffstat (limited to 'src')
-rw-r--r--src/types/Matrix.js45
1 files changed, 6 insertions, 39 deletions
diff --git a/src/types/Matrix.js b/src/types/Matrix.js
index c42adf7..9b783da 100644
--- a/src/types/Matrix.js
+++ b/src/types/Matrix.js
@@ -70,8 +70,9 @@ export default class Matrix {
if (isFinite(t.px) || isFinite(t.py)) {
const origin = new 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
+ // Doesnt work because t.px is also 0 if it wasnt passed
+ const dx = isFinite(t.px) ? t.px - origin.x : 0
+ const dy = isFinite(t.py) ? t.py - origin.y : 0
transformer.translateO(dx, dy)
}
@@ -80,34 +81,6 @@ export default class Matrix {
return transformer
}
- // Applies a matrix defined by its affine parameters
- compose (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
- var theta = o.rotate || 0
- var tx = o.translateX || 0
- var ty = o.translateY || 0
-
- // Apply the standard matrix
- var result = new Matrix()
- .translateO(-ox, -oy)
- .scaleO(sx, sy)
- .shearO(lam)
- .rotateO(theta)
- .translateO(tx, ty)
- .lmultiplyO(this)
- .translateO(ox, oy)
- return result
- }
-
// Decomposes this matrix into its affine parameters
decompose (cx = 0, cy = 0) {
// Get the parameters from the matrix
@@ -351,19 +324,11 @@ export default class Matrix {
return this.skew(x, 0, cx, cy)
}
- skewXO (x, cx, cy) {
- return this.skewO(x, 0, cx, cy)
- }
-
// SkewY
skewY (y, cx, cy) {
return this.skew(0, y, cx, cy)
}
- skewYO (y, cx, cy) {
- return this.skewO(0, y, cx, cy)
- }
-
// Transform around a center point
aroundO (cx, cy, matrix) {
var dx = cx || 0
@@ -377,6 +342,7 @@ export default class Matrix {
// Check if two matrices are equal
equals (other) {
+ if (other === this) return true
var comp = new Matrix(other)
return closeEnough(this.a, comp.a) && closeEnough(this.b, comp.b)
&& closeEnough(this.c, comp.c) && closeEnough(this.d, comp.d)
@@ -444,7 +410,8 @@ export default class Matrix {
var origin = new Point(o.origin || o.around || o.ox || o.originX, o.oy || o.originY)
var ox = origin.x
var oy = origin.y
- var position = new Point(o.position || o.px || o.positionX, o.py || o.positionY)
+ // We need Point to be invalid if nothing was passed because we cannot default to 0 here. Thats why NaN
+ var position = new Point(o.position || o.px || o.positionX || NaN, o.py || o.positionY || NaN)
var px = position.x
var py = position.y
var translate = new Point(o.translate || o.tx || o.translateX, o.ty || o.translateY)