Last active
June 17, 2016 19:56
-
-
Save cmargroff/f7000aa09249e95aaacde2ca2ff3214f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Object.defineProperty(SVGPolygonElement.prototype, 'pathLength', { | |
| get: function(){ | |
| var numPoints = this.points.length || this.points.numberOfItems; | |
| var l = 0; | |
| for (var i = 1; i < numPoints; i++) { | |
| var point2 = this.points[i] || this.points.getItem(i); | |
| var point1 = this.points[i-1] || this.points.getItem(i-1); | |
| l += Math.sqrt(Math.pow(Math.abs(point2.x-point1.x),2)+Math.pow(Math.abs(point2.y-point1.y),2)); | |
| } | |
| return l; | |
| }, | |
| set: function(val){ return undefined; } | |
| }); | |
| Object.defineProperty(SVGCircleElement.prototype, 'pathLength', { | |
| get: function(){ | |
| return 2*Math.PI*this.getAttribute("r"); | |
| }, | |
| set: function(val){ return undefined; } | |
| }); | |
| Object.defineProperty(SVGRectElement.prototype, 'pathLength', { | |
| get: function(){ | |
| return 2*this.getAttribute("width")+2*this.getAttribute("height"); | |
| }, | |
| set: function(val){ return undefined; } | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment