 |
 |
 |
 |
 |
 |
 |
 |
 |
 |
 |
 |
 |
 |
ClosestPair
(pointSet):
|
|
|
Split pointSet
in half with a vertical line so that half are on left and
|
|
|
|
half are on right;
|
|
|
Recursively
determine closest pair in each half and let d be
|
|
|
|
smallest of these
two distances;
|
|
|
Let L (on the
left) and R (on the right) be the sets of points that are
|
|
|
within distance d
of the dividing line;
|
|
|
Sort L and R by
y-coordinate;
|
|
|
For each point p
of L, inspect the points of R with y-coordinate
|
|
|
|
within distance
d of p’s y-coordinate to determine if there is a
|
|
|
|
point within
distance d of p;
|
|
|
|
/* The
L pointer always advances */
|
|
|
|
/* The
R pointer may oscillate, but never by more than 6 */
|
|
|
return the
shortest distance found;
|
|