diff options
Diffstat (limited to 'src/point.js')
-rw-r--r-- | src/point.js | 48 |
1 files changed, 23 insertions, 25 deletions
diff --git a/src/point.js b/src/point.js index 2ae2271..682092e 100644 --- a/src/point.js +++ b/src/point.js @@ -1,49 +1,49 @@ + SVG.Point = SVG.invent({ // Initialize - create: function(x,y) { - var i, source, base = {x:0, y:0} + create: function (x, y) { + var base = {x: 0, y: 0} + var source // 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 + 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 // merge source this.x = source.x this.y = source.y - } + }, // Add methods -, extend: { + extend: { // Clone point - clone: function() { + clone: function () { return new SVG.Point(this) - } + }, // Morph one point into another - , morph: function(x, y) { + 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) { + at: function (pos) { // make sure a destination is defined if (!this.destination) return this // calculate morphed matrix at a given position var point = new SVG.Point({ - x: this.x + (this.destination.x - this.x) * pos - , y: this.y + (this.destination.y - this.y) * pos + 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() { + native: function () { // create new point var point = SVG.parser.nodes.svg.node.createSVGPoint() @@ -52,21 +52,19 @@ SVG.Point = SVG.invent({ point.y = this.y return point - } + }, // transform point with matrix - , transform: function(matrix) { + transform: function (matrix) { return new SVG.Point(this.native().matrixTransform(matrix.native())) } - } - }) SVG.extend(SVG.Element, { // Get point - point: function(x, y) { - return new SVG.Point(x,y).transform(this.screenCTM().inverse()); + point: function (x, y) { + return new SVG.Point(x, y).transform(this.screenCTM().inverse()) } }) |