diff --git a/src/path.js b/src/path.js index 6fca293..e8c336c 100644 --- a/src/path.js +++ b/src/path.js @@ -6,7 +6,7 @@ var pi = Math.PI, function Path() { this._x0 = this._y0 = // start of current subpath this._x1 = this._y1 = null; // end of current subpath - this.str = ""; + this._ = ""; } function path() { @@ -16,22 +16,22 @@ function path() { Path.prototype = path.prototype = { constructor: Path, moveTo: function(x, y) { - this.str += "M" + (this._x0 = this._x1 = +x) + "," + (this._y0 = this._y1 = +y); + this._ += "M" + (this._x0 = this._x1 = +x) + "," + (this._y0 = this._y1 = +y); }, closePath: function() { if (this._x1 !== null) { this._x1 = this._x0, this._y1 = this._y0; - this.str += "Z"; + this._ += "Z"; } }, lineTo: function(x, y) { - this.str += "L" + (this._x1 = +x) + "," + (this._y1 = +y); + this._ += "L" + (this._x1 = +x) + "," + (this._y1 = +y); }, quadraticCurveTo: function(x1, y1, x, y) { - this.str += "Q" + (+x1) + "," + (+y1) + "," + (this._x1 = +x) + "," + (this._y1 = +y); + this._ += "Q" + (+x1) + "," + (+y1) + "," + (this._x1 = +x) + "," + (this._y1 = +y); }, bezierCurveTo: function(x1, y1, x2, y2, x, y) { - this.str += "C" + (+x1) + "," + (+y1) + "," + (+x2) + "," + (+y2) + "," + (this._x1 = +x) + "," + (this._y1 = +y); + this._ += "C" + (+x1) + "," + (+y1) + "," + (+x2) + "," + (+y2) + "," + (this._x1 = +x) + "," + (this._y1 = +y); }, arcTo: function(x1, y1, x2, y2, r) { x1 = +x1, y1 = +y1, x2 = +x2, y2 = +y2, r = +r; @@ -48,7 +48,7 @@ Path.prototype = path.prototype = { // Is this path empty? Move to (x1,y1). if (this._x1 === null) { - this.str += "M" + (this._x1 = x1) + "," + (this._y1 = y1); + this._ += "M" + (this._x1 = x1) + "," + (this._y1 = y1); } // Or, is (x1,y1) coincident with (x0,y0)? Do nothing. @@ -58,7 +58,7 @@ Path.prototype = path.prototype = { // Equivalently, is (x1,y1) coincident with (x2,y2)? // Or, is the radius zero? Line to (x1,y1). else if (!(Math.abs(y01 * x21 - y21 * x01) > epsilon) || !r) { - this.str += "L" + (this._x1 = x1) + "," + (this._y1 = y1); + this._ += "L" + (this._x1 = x1) + "," + (this._y1 = y1); } // Otherwise, draw an arc! @@ -75,11 +75,10 @@ Path.prototype = path.prototype = { // If the start tangent is not coincident with (x0,y0), line to. if (Math.abs(t01 - 1) > epsilon) { - this.str += "L" + (x1 + t01 * x01) + "," + (y1 + t01 * y01); + this._ += "L" + (x1 + t01 * x01) + "," + (y1 + t01 * y01); } - this.str += - "A" + r + "," + r + ",0,0," + (+(y01 * x20 > x01 * y20)) + "," + (this._x1 = x1 + t21 * x21) + "," + (this._y1 = y1 + t21 * y21); + this._ += "A" + r + "," + r + ",0,0," + (+(y01 * x20 > x01 * y20)) + "," + (this._x1 = x1 + t21 * x21) + "," + (this._y1 = y1 + t21 * y21); } }, arc: function(x, y, r, a0, a1, ccw) { @@ -96,12 +95,12 @@ Path.prototype = path.prototype = { // Is this path empty? Move to (x0,y0). if (this._x1 === null) { - this.str += "M" + x0 + "," + y0; + this._ += "M" + x0 + "," + y0; } // Or, is (x0,y0) not coincident with the previous point? Line to (x0,y0). else if (Math.abs(this._x1 - x0) > epsilon || Math.abs(this._y1 - y0) > epsilon) { - this.str += "L" + x0 + "," + y0; + this._ += "L" + x0 + "," + y0; } // Is this arc empty? We’re done. @@ -109,25 +108,20 @@ Path.prototype = path.prototype = { // Is this a complete circle? Draw two arcs to complete the circle. if (da > tauEpsilon) { - this.str += - "A" + r + "," + r + ",0,1," + cw + "," + (x - dx) + "," + (y - dy) + - "A" + r + "," + r + ",0,1," + cw + "," + (this._x1 = x0) + "," + (this._y1 = y0); + this._ += "A" + r + "," + r + ",0,1," + cw + "," + (x - dx) + "," + (y - dy) + "A" + r + "," + r + ",0,1," + cw + "," + (this._x1 = x0) + "," + (this._y1 = y0); } // Otherwise, draw an arc! else { if (da < 0) da = da % tau + tau; - this.str += - "A" + r + "," + r + ",0," + (+(da >= pi)) + "," + cw + "," + - (this._x1 = x + r * Math.cos(a1)) + "," + (this._y1 = y + r * Math.sin(a1)); + this._ += "A" + r + "," + r + ",0," + (+(da >= pi)) + "," + cw + "," + (this._x1 = x + r * Math.cos(a1)) + "," + (this._y1 = y + r * Math.sin(a1)); } }, rect: function(x, y, w, h) { - this.str += "M" + (this._x0 = this._x1 = +x) + "," + (this._y0 = this._y1 = +y) + - "h" + (+w) + "v" + (+h) + "h" + (-w) + "Z"; + this._ += "M" + (this._x0 = this._x1 = +x) + "," + (this._y0 = this._y1 = +y) + "h" + (+w) + "v" + (+h) + "h" + (-w) + "Z"; }, toString: function() { - return this.str; + return this._; } };