-
-
Notifications
You must be signed in to change notification settings - Fork 76
/
divide_segment.js
39 lines (31 loc) · 1.04 KB
/
divide_segment.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
35
36
37
38
39
import SweepEvent from './sweep_event';
import equals from './equals';
import compareEvents from './compare_events';
/**
* @param {SweepEvent} se
* @param {Array.<Number>} p
* @param {Queue} queue
* @return {Queue}
*/
export default function divideSegment(se, p, queue) {
const r = new SweepEvent(p, false, se, se.isSubject);
const l = new SweepEvent(p, true, se.otherEvent, se.isSubject);
/* eslint-disable no-console */
if (equals(se.point, se.otherEvent.point)) {
console.warn('what is that, a collapsed segment?', se);
}
/* eslint-enable no-console */
r.contourId = l.contourId = se.contourId;
// avoid a rounding error. The left event would be processed after the right event
if (compareEvents(l, se.otherEvent) > 0) {
se.otherEvent.left = true;
l.left = false;
}
// avoid a rounding error. The left event would be processed after the right event
// if (compareEvents(se, r) > 0) {}
se.otherEvent.otherEvent = l;
se.otherEvent = r;
queue.push(l);
queue.push(r);
return queue;
}