From a928d4894ddf0c1d960574f38d8c30f5bdfee5ef Mon Sep 17 00:00:00 2001 From: Bryan Housel Date: Thu, 10 Apr 2014 01:41:07 -0400 Subject: [PATCH] Add isConvex() to iD.Way.. --- js/id/core/way.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/js/id/core/way.js b/js/id/core/way.js index 4d254de40..19a3237bb 100644 --- a/js/id/core/way.js +++ b/js/id/core/way.js @@ -55,6 +55,25 @@ _.extend(iD.Way.prototype, { return this.nodes.length > 0 && this.first() === this.last(); }, + isConvex: function(resolver) { + if (!this.isClosed() || this.isDegenerate()) return null; + + var coords = _.pluck(resolver.childNodes(this), 'loc'), + curr = 0, prev = 0; + + for (var i = 1; i < coords.length - 1; i++) { + curr = iD.geo.cross(coords[i-1], coords[i], coords[i+1]); + curr = (curr > 0) ? 1 : (curr < 0) ? -1 : 0; + if (curr === 0) { + continue; + } else if ((prev) && (curr !== prev)) { + return false; + } + prev = curr; + } + return true; + }, + isArea: function() { if (this.tags.area === 'yes') return true;