-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
main.js
35 lines (28 loc) · 1.25 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import TinyQueue from 'tinyqueue'
import Segment from './Segment'
import {checkWhichEventIsLeft, checkWhichSegmentHasRightEndpointFirst} from './compareEvents'
import {fillEventQueue} from './fillQueue'
import {testSegmentIntersect} from './utils'
// import {debugEventAndSegments, debugRemovingSegment} from './debug'
export default function bentleyOttmann (geojson) {
const intersectionPoints = []
const eventQueue = new TinyQueue([], checkWhichEventIsLeft);
fillEventQueue(geojson, eventQueue)
const outQueue = new TinyQueue([], checkWhichSegmentHasRightEndpointFirst);
while (eventQueue.length) {
const event = eventQueue.pop();
if (event.isLeftEndpoint) {
// debugEventAndSegments(event.p, outQueue.data)
const segment = new Segment(event)
for (let i = 0; i < outQueue.data.length; i++) {
const intersection = testSegmentIntersect(segment, outQueue.data[i])
if (intersection !== false) intersectionPoints.push(intersection)
}
outQueue.push(segment)
} else if (event.isLeftEndpoint === false) {
const seg = outQueue.pop()
// debugRemovingSegment(event.p, seg)
}
}
return intersectionPoints
}