summaryrefslogtreecommitdiffstats
path: root/src/point.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/point.js')
-rw-r--r--src/point.js28
1 files changed, 16 insertions, 12 deletions
diff --git a/src/point.js b/src/point.js
index 682092e..6c64ed6 100644
--- a/src/point.js
+++ b/src/point.js
@@ -1,19 +1,18 @@
SVG.Point = SVG.invent({
// Initialize
- create: function (x, y) {
- var base = {x: 0, y: 0}
+ create: function (x, y, base) {
var source
+ base = base || {x: 0, y: 0}
// ensure source as object
source = Array.isArray(x) ? {x: x[0], y: x[1]}
: typeof x === 'object' ? {x: x.x, y: x.y}
- : x != null ? {x: x, y: (y != null ? y : x)}
- : base // If y has no value, then x is used has its value
+ : {x: x, y: y}
// merge source
- this.x = source.x
- this.y = source.y
+ this.x = source.x == null ? base.x : source.x
+ this.y = source.y == null ? base.y : source.y
},
// Add methods
@@ -22,13 +21,14 @@ SVG.Point = SVG.invent({
clone: function () {
return new SVG.Point(this)
},
+
// Morph one point into another
morph: function (x, y) {
// store new destination
this.destination = new SVG.Point(x, y)
-
return this
},
+
// Get morphed point at a given position
at: function (pos) {
// make sure a destination is defined
@@ -39,9 +39,9 @@ SVG.Point = SVG.invent({
x: this.x + (this.destination.x - this.x) * pos,
y: this.y + (this.destination.y - this.y) * pos
})
-
return point
},
+
// Convert to native SVGPoint
native: function () {
// create new point
@@ -50,12 +50,17 @@ SVG.Point = SVG.invent({
// update with current values
point.x = this.x
point.y = this.y
-
return point
},
+
// transform point with matrix
- transform: function (matrix) {
- return new SVG.Point(this.native().matrixTransform(matrix.native()))
+ transform: function (m) {
+ // 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
+
+ // Return the required point
+ return new SVG.Point(x, y)
}
}
})
@@ -66,5 +71,4 @@ SVG.extend(SVG.Element, {
point: function (x, y) {
return new SVG.Point(x, y).transform(this.screenCTM().inverse())
}
-
})