seed = iter.next();
for(int i = 0; iter.hasNext(); i++) {
assert (i < len);
Vector p = iter.next();
// Pair with distance, list-position
sort[i] = new DoubleIntPair(quadraticEuclidean(seed, p), i + 1);
}
assert (sort[len - 1] != null);
Arrays.sort(sort);
}
assert (sort[0].first > 0);
// final Vector seed2 = points.get(sort[0].second);
final int seed2id = sort[0].second;
int start = 1;
// Find minimal triangle for these two points:
Triangle besttri = new Triangle(seedid, seed2id, -1);
{
besttri.r2 = Double.MAX_VALUE;
Triangle testtri = new Triangle(seedid, seed2id, -1);
int besti = -1;
for(int i = start; i < len; i++) {
// Update test triad
testtri.c = sort[i].second;
if(testtri.updateCircumcircle(points) && testtri.r2 < besttri.r2) {
besttri.copyFrom(testtri);
besti = i;
}
else if(besttri.r2 * 4 < sort[i].first) {
// Stop early, points are too far away from seed.
break;
}
}
assert (besti != -1);
// Rearrange - remove third seed point.
if(besti > 1) {
DoubleIntPair tmp = sort[besti];
System.arraycopy(sort, 1, sort, 2, besti - 1);
sort[1] = tmp;
}
}
start = 2; // First two points have already been processed.