diff --git a/src/geo/polygon.js b/src/geo/polygon.js index 866e3b4c..c12239cf 100644 --- a/src/geo/polygon.js +++ b/src/geo/polygon.js @@ -31,14 +31,16 @@ constructor(points) { this.id = seqid++; // polygon unique id this.open = false; - this.length = 0; // number of points this.points = []; // ordered array of points - this.area2 = 0.0; // computed as 2x area (sign = direction) this.parent = null; // enclosing parent polygon this.depth = 0; // depth nested from top parent (density for support fill) if (points) this.addPoints(points); } + get length() { + return this.points.length; + } + get bounds() { if (this._bounds) { return this._bounds; @@ -891,7 +893,6 @@ // clone any point belonging to another polygon if (p.poly) p = p.clone(); p.poly = this; - this.length++; this.points.push(p); return p; }; @@ -991,7 +992,9 @@ * @returns {Polygon} self */ PRO.reverse = function() { - this.area2 = -this.area2; + if (this.area2) { + this.area2 = -this.area2; + } this.points = this.points.reverse(); return this; }; @@ -1351,15 +1354,18 @@ * @returns {number} area */ PRO.area = function(raw) { - if (this.length < 3) return 0; - if (this.area2 === 0.0) { + if (this.length < 3) { + return 0; + } + if (this.area2 === undefined) { + this.area2 = 0.0; for (let p=this.points,pl=p.length,pi=0,p1,p2; pi