-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvoronoi.cc
executable file
·109 lines (100 loc) · 3.58 KB
/
voronoi.cc
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
/*
$Date: 1999/10/15 12:40:27 $
$Revision: 1.1.1.1 $
$Author: kise $
voronoi.c
*/
#include <stdio.h>
#include "const.h"
#include "defs.h"
#include "extern.h"
#include "function.h"
/* implicit parameters: nsites, sqrt_nsites, xmin, xmax, ymin, ymax,
deltax, deltay (can all be estimates).
Performance suffers if they are wrong; better to make nsites,
deltax, and deltay too big than too small. (?) */
namespace voronoi{
void voronoi( Coordinate imax, Coordinate jmax)
{
struct Site *newsite, *bot, *top, *temp, *p;
struct Site *v = 0;
struct Point newintstar = {0.0,0.0};
int pm;
struct Halfedge *lbnd, *rbnd, *llbnd, *rrbnd, *bisector;
struct Edge *e;
freeinit(&sfl, sizeof *sites);
siteidx = 0;
geominit();
PQinitialize();
bottomsite = (*nextsite)();
ELinitialize();
newsite = (*nextsite)();
while(1) {
if(!PQempty()) newintstar = PQ_min();
if (newsite != (struct Site *)NULL
&& (PQempty()
|| newsite -> coord.y < newintstar.y
|| (newsite->coord.y == newintstar.y
&& newsite->coord.x < newintstar.x))) {
/* new site is smallest */
lbnd = ELleftbnd(&(newsite->coord));
rbnd = ELright(lbnd);
bot = rightreg(lbnd);
e = bisect(bot, newsite);
bisector = HEcreate(e, LE);
ELinsert(lbnd, bisector);
if ((p = intersect(lbnd, bisector)) != (struct Site *) NULL) {
PQdelete(lbnd);
PQinsert(lbnd, p, dist(p,newsite));
}
lbnd = bisector;
bisector = HEcreate(e, RE);
ELinsert(lbnd, bisector);
if ((p = intersect(bisector, rbnd)) != (struct Site *) NULL) {
PQinsert(bisector, p, dist(p,newsite));
}
newsite = (*nextsite)();
}
else if (!PQempty()) {
/* intersection is smallest */
lbnd = PQextractmin();
llbnd = ELleft(lbnd);
rbnd = ELright(lbnd);
rrbnd = ELright(rbnd);
bot = leftreg(lbnd);
top = rightreg(rbnd);
v = lbnd->vertex;
makevertex(v);
endpoint(lbnd->ELedge,lbnd->ELpm,v,imax,jmax);
endpoint(rbnd->ELedge,rbnd->ELpm,v,imax,jmax);
ELdelete(lbnd);
PQdelete(rbnd);
ELdelete(rbnd);
pm = LE;
if (bot->coord.y > top->coord.y) {
temp = bot;
bot = top;
top = temp;
pm = RE;
}
e = bisect(bot, top);
bisector = HEcreate(e, pm);
ELinsert(llbnd, bisector);
endpoint(e, RE-pm, v, imax, jmax);
deref(v);
if((p = intersect(llbnd, bisector)) != (struct Site *) NULL){
PQdelete(llbnd);
PQinsert(llbnd, p, dist(p,bot));
}
if ((p = intersect(bisector, rrbnd)) != (struct Site *) NULL){
PQinsert(bisector, p, dist(p,bot));
}
}
else break;
}
for(lbnd=ELright(ELleftend); lbnd != ELrightend; lbnd=ELright(lbnd)) {
e = lbnd -> ELedge;
out_ep2(e,v,imax,jmax); /* Voronoi ÊÕ¤òÀ¸À® */
}
}
}