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
|
/* All points start out in separate regions. */
/* R is the set of all such regions. */
/* S starts as the null set,
* and will grow to contain all resulting regions.
*/
/* r is the distance between points sufficient
* to put them in the same region
*/
int k = 0; /* index to our result set S */
for (int i = 0; i < n; ++i)
{
if (R[i] == NULL) continue; /* Skip, R[i] is empty! */
S[k] := R[i]; /* Initialize result region k */
for (int j = i+1; j < n; ++j)
{
forall( Point a , R[i] )
{
forall( Point b , R[j] )
{
if (dist(a,b) <= r)
{
S[k] := union (S[k], R[j]); /* Union the regions */
R[j] := NULL; /* Set R[j] to empty set
* so it is skipped later
*/
}
}
}
}
++ k;
}
/* S is your resulting set of regions! */
|