Skip to content

Commit

Permalink
Handle doughtnuts of islands of dough...
Browse files Browse the repository at this point in the history
The logic to determine which, if any, ring encloses another given ring
depends on starting with the vertex that comes earliest in the
sweep-line pass. This commit fixes the situation so that this bit of
logic starts from the correct vertex.

Fixes #38
Closes #39
  • Loading branch information
mfogel committed Oct 17, 2018
1 parent 2cbfbd2 commit db3acf9
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 7 deletions.
12 changes: 10 additions & 2 deletions src/geom-out.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { compareVectorAngles } from './vector'
import SweepEvent from './sweep-event'

export class RingOut {
/* Given the segments from the sweep line pass, compute & return a series
Expand Down Expand Up @@ -147,8 +148,15 @@ export class RingOut {

/* Returns the ring that encloses this one, if any */
_enclosingRing () {
let prevSeg = this.events[0].segment.prevInResult
while (prevSeg && prevSeg.ringOut === this) prevSeg = prevSeg.prevInResult
// start with the ealier sweep line event so that the prevSeg
// chain doesn't lead us inside of a loop of ours
let leftMostEvt = this.events[0]
for (let i = 1, iMax = this.events.length; i < iMax; i++) {
const evt = this.events[i]
if (SweepEvent.compare(leftMostEvt, evt) > 0) leftMostEvt = evt
}

let prevSeg = leftMostEvt.segment.prevInResult
let prevPrevSeg = prevSeg ? prevSeg.prevInResult : null

while (true) {
Expand Down
10 changes: 5 additions & 5 deletions test/end-to-end/issue-38/args.geojson
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
"coordinates": [
[
[-76.377, 38.782],
[-76.385, 38.765],
[-76.393, 38.758],
[-76.343, 38.714],
[-76.509, 38.751],
[-76.343, 38.714],
[-76.393, 38.758],
[-76.385, 38.765],
[-76.377, 38.782]
]
]
Expand All @@ -26,8 +26,8 @@
"coordinates": [
[
[-76.377, 38.749],
[-76.388, 38.755],
[-76.383, 38.756],
[-76.388, 38.755],
[-76.377, 38.749]
]
]
Expand All @@ -41,8 +41,8 @@
"coordinates": [
[
[-76.377, 38.782],
[-76.339, 38.721],
[-76.376, 38.742],
[-76.339, 38.721],
[-76.377, 38.782]
]
]
Expand Down
25 changes: 25 additions & 0 deletions test/end-to-end/issue-38/union.geojson
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,31 @@
"geometry": {
"type": "MultiPolygon",
"coordinates": [
[
[
[-76.509, 38.751],
[-76.343, 38.714],
[-76.37267128027682, 38.74011072664359],
[-76.339, 38.721],
[-76.377, 38.782],
[-76.509, 38.751]
],
[
[-76.377, 38.782],
[-76.37602658486709, 38.743063394683034],
[-76.393, 38.758],
[-76.385, 38.765],
[-76.377, 38.782]
]
],
[
[
[-76.388, 38.755],
[-76.377, 38.749],
[-76.383, 38.756],
[-76.388, 38.755]
]
]
]
}
}

0 comments on commit db3acf9

Please sign in to comment.