Skip to content

Commit

Permalink
Drop already-consumed artifacts
Browse files Browse the repository at this point in the history
Don't re-insert already-consumed sweep events intto the queue, nor
already-consumed segments into the sweep line tree.

Fixes #68
  • Loading branch information
mfogel committed Feb 6, 2019
1 parent cdb6484 commit c4e3b85
Show file tree
Hide file tree
Showing 6 changed files with 128 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/operation.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ export class Operation {
}
const newEvents = sweepLine.process(evt)
for (let i = 0, iMax = newEvents.length; i < iMax; i++) {
queue.insert(newEvents[i])
const evt = newEvents[i]
if (evt.segment.consumedBy === undefined) queue.insert(evt)
}
prevQueueSize = queue.size
node = queue.pop()
Expand Down
3 changes: 2 additions & 1 deletion src/sweep-line.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,8 @@ export default class SweepLine {
this.queue.remove(rightSE)
const newEvents = seg.split([pt])
newEvents.push(rightSE)
this.tree.insert(seg)
// splitting can trigger consumption
if (seg.consumedBy === undefined) this.tree.insert(seg)
return newEvents
}
}
37 changes: 37 additions & 0 deletions test/end-to-end/issue-68-1/args.geojson
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"properties": null,
"geometry": {
"type": "Polygon",
"coordinates": [
[
[18.1054513, 60.4585421],
[18.10556875, 60.45856990788591],
[18.1055, 60.4587],
[18.1054513, 60.4585421]
]
]
}
},
{
"type": "Feature",
"properties": null,
"geometry": {
"type": "Polygon",
"coordinates": [
[
[18.1054513, 60.4585421],
[18.1057195, 60.4586056],
[18.10563, 60.4584],
[18.1059, 60.4584],
[18.1058, 60.4585],
[18.1054513, 60.4585421]
]
]
}
}
]
}
28 changes: 28 additions & 0 deletions test/end-to-end/issue-68-1/union.geojson
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"type": "Feature",
"properties": {},
"geometry": {
"type": "MultiPolygon",
"coordinates": [
[
[
[18.1054513, 60.4585421],
[18.105679846052258, 60.458514506685404],
[18.1057195, 60.4586056],
[18.10556875, 60.45856990788591],
[18.1055, 60.4587],
[18.1054513, 60.4585421]
]
],
[
[
[18.10563, 60.4584],
[18.1059, 60.4584],
[18.1058, 60.4585],
[18.105679846052258, 60.458514506685404],
[18.10563, 60.4584]
]
]
]
}
}
38 changes: 38 additions & 0 deletions test/end-to-end/issue-68/args.geojson
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"properties": null,
"geometry": {
"type": "MultiPolygon",
"coordinates": [
[
[
[18.1054406, 60.4686654],
[18.1052796, 60.4687447],
[18.10553, 60.4685],
[18.1054406, 60.4686654]
]
],
[
[
[18.1054406, 60.4686654],
[18.10536875, 60.46870078947205],
[18.10542, 60.4685],
[18.1054406, 60.4686654]
]
],
[
[
[18.1054406, 60.4686654],
[18.10557, 60.4687],
[18.1052796, 60.4687447],
[18.1054406, 60.4686654]
]
]
]
}
}
]
}
21 changes: 21 additions & 0 deletions test/end-to-end/issue-68/union.geojson
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"type": "Feature",
"properties": {},
"geometry": {
"type": "MultiPolygon",
"coordinates": [
[
[
[18.1052796, 60.4687447],
[18.105383444279106, 60.46864321958827],
[18.10542, 60.4685],
[18.105431935562752, 60.468595832139755],
[18.10553, 60.4685],
[18.1054406, 60.4686654],
[18.10557, 60.4687],
[18.1052796, 60.4687447]
]
]
]
}
}

0 comments on commit c4e3b85

Please sign in to comment.