This repository was archived by the owner on Apr 11, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadvancing_front.d
More file actions
126 lines (113 loc) · 1.84 KB
/
advancing_front.d
File metadata and controls
126 lines (113 loc) · 1.84 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
module poly2trid.advancing_front;
import poly2trid;
class Node
{
Point point;
Triangle triangle;
Node next;
Node prev;
double value;
this(Point p)
{
point = p;
value = p.x;
}
this(Point p, Triangle t)
{
point = p;
triangle = t;
value = p.x;
}
}
class AdvancingFront
{
this(Node head, Node tail)
{
head_ = head;
tail_ = tail;
search_node_ = head;
}
Node head()
{
return head_;
}
void set_head(Node node)
{
head_ = node;
}
Node tail()
{
return tail_;
}
void set_tail(Node node)
{
tail_ = node;
}
Node search()
{
return search_node_;
}
void set_search(Node node)
{
search_node_ = node;
}
/// Locate insertion point along advancing front
Node LocateNode(const double x)
{
Node node = search_node_;
if (x < node.value) {
while ((node = node.prev) !is null) {
if (x >= node.value) {
search_node_ = node;
return node;
}
}
} else {
while ((node = node.next) !is null) {
if (x < node.value) {
search_node_ = node.prev;
return node.prev;
}
}
}
return null;
}
Node LocatePoint(const Point point)
{
const double px = point.x;
Node node = FindSearchNode(px);
const double nx = node.point.x;
if (px == nx) {
if (point != node.point) {
// We might have two nodes with same x value for a short time
if (point == node.prev.point) {
node = node.prev;
} else if (point == node.next.point) {
node = node.next;
} else {
assert(0);
}
}
} else if (px < nx) {
while ((node = node.prev) !is null) {
if (point == node.point) {
break;
}
}
} else {
while ((node = node.next) !is null) {
if (point == node.point)
break;
}
}
if(node)
search_node_ = node;
return node;
}
private:
Node head_, tail_, search_node_;
Node FindSearchNode(const double x)
{
return search_node_;
}
}