Skip to content

Commit

Permalink
Make internal state private again.
Browse files Browse the repository at this point in the history
  • Loading branch information
mbostock committed Nov 18, 2016
1 parent 496ae39 commit b2295e5
Showing 1 changed file with 16 additions and 22 deletions.
38 changes: 16 additions & 22 deletions src/path.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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;
Expand All @@ -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.
Expand All @@ -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!
Expand All @@ -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) {
Expand All @@ -96,38 +95,33 @@ 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.
if (!r) return;

// 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._;
}
};

Expand Down

0 comments on commit b2295e5

Please sign in to comment.