// Heap of candidates
TopBoundedHeap<DoubleIntPair> candidates = new TopBoundedHeap<DoubleIntPair>(numCandidates, Collections.reverseOrder());
for(int i = 0; i < size; i++) {
// Existing object and extended rectangle:
SpatialComparable entry = getter.get(options, i);
HyperBoundingBox mbr = SpatialUtil.union(entry, obj);
// Area increase
final double inc_area = SpatialUtil.volume(mbr) - SpatialUtil.volume(entry);
candidates.add(new DoubleIntPair(inc_area, i));
}
// R*-Tree: overlap increase for leaves.
int best = -1;
double least_overlap = Double.POSITIVE_INFINITY;
double least_areainc = Double.POSITIVE_INFINITY;
double least_area = Double.POSITIVE_INFINITY;
// least overlap increase, on reduced candidate set:
while(!candidates.isEmpty()) {
DoubleIntPair pair = candidates.poll();
final double inc_area = pair.first;
// Existing object and extended rectangle:
SpatialComparable entry = getter.get(options, pair.second);
HyperBoundingBox mbr = SpatialUtil.union(entry, obj);
// Compute relative overlap increase.
double overlap_wout = 0.0;
double overlap_with = 0.0;
for(int k = 0; k < size; k++) {
if(pair.second != k) {
SpatialComparable other = getter.get(options, k);
overlap_wout += SpatialUtil.relativeOverlap(entry, other);
overlap_with += SpatialUtil.relativeOverlap(mbr, other);
}
}
double inc_overlap = overlap_with - overlap_wout;