summaryrefslogtreecommitdiffstats
path: root/src/types
diff options
context:
space:
mode:
authorUlrich-Matthias Schäfer <ulima.ums@googlemail.com>2019-01-12 20:32:39 +0100
committerUlrich-Matthias Schäfer <ulima.ums@googlemail.com>2019-01-12 20:32:39 +0100
commit60792807eee29f1b748c9b12d308c477f7c1227d (patch)
tree27f5c46c02ea0acbec71668935ef72cf2749698e /src/types
parentf5eff8745af43fcfcc2e837d89d549cb66220d99 (diff)
downloadsvg.js-60792807eee29f1b748c9b12d308c477f7c1227d.tar.gz
svg.js-60792807eee29f1b748c9b12d308c477f7c1227d.zip
Fix move and size of groups, removed setting of a default font so we dont act against user intention, fixed bug in `font()`
Diffstat (limited to 'src/types')
-rw-r--r--src/types/Box.js6
-rw-r--r--src/types/Point.js21
-rw-r--r--src/types/PointArray.js2
3 files changed, 22 insertions, 7 deletions
diff --git a/src/types/Box.js b/src/types/Box.js
index eb43d07..8cbda30 100644
--- a/src/types/Box.js
+++ b/src/types/Box.js
@@ -59,6 +59,10 @@ export default class Box {
}
transform (m) {
+ if (!(m instanceof Matrix)) {
+ m = new Matrix(m)
+ }
+
let xMin = Infinity
let xMax = -Infinity
let yMin = Infinity
@@ -130,7 +134,7 @@ export function bbox () {
clone.remove()
return box
} catch (e) {
- throw new Error('Getting bbox of element "' + el.node.nodeName + '" is not possible')
+ throw new Error('Getting bbox of element "' + el.node.nodeName + '" is not possible. ' + e.toString())
}
}))
}
diff --git a/src/types/Point.js b/src/types/Point.js
index f1c85a1..329b37d 100644
--- a/src/types/Point.js
+++ b/src/types/Point.js
@@ -1,3 +1,5 @@
+import Matrix from './Matrix.js'
+
export default class Point {
// Initialize
constructor (...args) {
@@ -25,14 +27,23 @@ export default class Point {
return new Point(this)
}
- // transform point with matrix
transform (m) {
+ return this.clone().transformO(m)
+ }
+
+ // Transform point with matrix
+ transformO (m) {
+ if (!Matrix.isMatrixLike(m)) {
+ m = new Matrix(m)
+ }
+
+ let { x, y } = this
+
// Perform the matrix multiplication
- var x = m.a * this.x + m.c * this.y + m.e
- var y = m.b * this.x + m.d * this.y + m.f
+ this.x = m.a * x + m.c * y + m.e
+ this.y = m.b * x + m.d * y + m.f
- // Return the required point
- return new Point(x, y)
+ return this
}
toArray () {
diff --git a/src/types/PointArray.js b/src/types/PointArray.js
index 2246bbd..6a869d7 100644
--- a/src/types/PointArray.js
+++ b/src/types/PointArray.js
@@ -63,7 +63,7 @@ extend(PointArray, {
// Odd number of coordinates is an error. In such cases, drop the last odd coordinate.
if (array.length % 2 !== 0) array.pop()
- // wrap points in two-tuples and parse points as floats
+ // wrap points in two-tuples
for (var i = 0, len = array.length; i < len; i = i + 2) {
points.push([ array[i], array[i + 1] ])
}