From 623336c24870320732bca09469a3a26acd1b56da Mon Sep 17 00:00:00 2001 From: wvffle Date: Thu, 28 Dec 2017 16:09:41 +0100 Subject: [PATCH] Added #36 --- rhill-voronoi-core.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/rhill-voronoi-core.js b/rhill-voronoi-core.js index 83336bd..e3ea885 100644 --- a/rhill-voronoi-core.js +++ b/rhill-voronoi-core.js @@ -1413,7 +1413,8 @@ Voronoi.prototype.clipEdge = function(edge, bbox) { Voronoi.prototype.clipEdges = function(bbox) { // connect all dangling edges to bounding box // or get rid of them if it can't be done - var edges = this.edges, + var newEdges = [], + edges = this.edges, iEdge = edges.length, edge, abs_fn = Math.abs; @@ -1427,10 +1428,13 @@ Voronoi.prototype.clipEdges = function(bbox) { if (!this.connectEdge(edge, bbox) || !this.clipEdge(edge, bbox) || (abs_fn(edge.va.x-edge.vb.x)<1e-9 && abs_fn(edge.va.y-edge.vb.y)<1e-9)) { - edge.va = edge.vb = null; - edges.splice(iEdge,1); + edge.va = edge.vb = null; + } else { + newEdges.unshift(edge); } } + + this.edges = newEdges; }; // Close the cells.