aboutsummaryrefslogtreecommitdiffstats
path: root/src/types/Matrix.js
diff options
context:
space:
mode:
authorUlrich-Matthias Schäfer <ulima.ums@googlemail.com>2018-11-12 14:51:34 +0100
committerUlrich-Matthias Schäfer <ulima.ums@googlemail.com>2018-11-12 14:51:34 +0100
commitbf6e2aeb13f9a4bee2be1f8f7a70ca1a73215245 (patch)
tree0614edfac92e0ab9ff44144b79aa5802211ef5e0 /src/types/Matrix.js
parent334d9c73c2f74679a93b1d7b3e39b614f6444faa (diff)
downloadsvg.js-bf6e2aeb13f9a4bee2be1f8f7a70ca1a73215245.tar.gz
svg.js-bf6e2aeb13f9a4bee2be1f8f7a70ca1a73215245.zip
remove native() methods, add methods of types directly to elemenet
Diffstat (limited to 'src/types/Matrix.js')
-rw-r--r--src/types/Matrix.js58
1 files changed, 17 insertions, 41 deletions
diff --git a/src/types/Matrix.js b/src/types/Matrix.js
index ee12488..a1eb317 100644
--- a/src/types/Matrix.js
+++ b/src/types/Matrix.js
@@ -1,12 +1,7 @@
import { delimiter } from '../modules/core/regex.js'
import { radians } from '../utils/utils.js'
-import { registerMethods } from '../utils/methods.js'
import Element from '../elements/Element.js'
import Point from './Point.js'
-import parser from '../modules/core/parser.js'
-
-// Create matrix array for looping
-const abcdef = 'abcdef'.split('')
function closeEnough (a, b, threshold) {
return Math.abs(b - a) < (threshold || 1e-6)
@@ -379,19 +374,6 @@ export default class Matrix {
return this.clone().aroundO(cx, cy, matrix)
}
- // Convert to native SVGMatrix
- native () {
- // create new matrix
- var matrix = parser().svg.node.createSVGMatrix()
-
- // update with current values
- for (var i = abcdef.length - 1; i >= 0; i--) {
- matrix[abcdef[i]] = this[abcdef[i]]
- }
-
- return matrix
- }
-
// Check if two matrices are equal
equals (other) {
var comp = new Matrix(other)
@@ -499,26 +481,20 @@ export default class Matrix {
}
}
-registerMethods({
- Element: {
- // Get current matrix
- ctm () {
- return new Matrix(this.node.getCTM())
- },
-
- // Get current screen matrix
- screenCTM () {
- /* https://bugzilla.mozilla.org/show_bug.cgi?id=1344537
- This is needed because FF does not return the transformation matrix
- for the inner coordinate system when getScreenCTM() is called on nested svgs.
- However all other Browsers do that */
- if (typeof this.isRoot === 'function' && !this.isRoot()) {
- var rect = this.rect(1, 1)
- var m = rect.node.getScreenCTM()
- rect.remove()
- return new Matrix(m)
- }
- return new Matrix(this.node.getScreenCTM())
- }
- }
-})
+export function ctm () {
+ return new Matrix(this.node.getCTM())
+}
+
+export function screenCTM () {
+ /* https://bugzilla.mozilla.org/show_bug.cgi?id=1344537
+ This is needed because FF does not return the transformation matrix
+ for the inner coordinate system when getScreenCTM() is called on nested svgs.
+ However all other Browsers do that */
+ if (typeof this.isRoot === 'function' && !this.isRoot()) {
+ var rect = this.rect(1, 1)
+ var m = rect.node.getScreenCTM()
+ rect.remove()
+ return new Matrix(m)
+ }
+ return new Matrix(this.node.getScreenCTM())
+}