node.clear();
node.addChild(seeds[0]);
node.addToInvertedIndex(seeds[0]);
Node group1 = new Node(
Arrays.copyOf(seeds[1].getMinCoordinates(), seeds[1].getMinCoordinates().length),
Arrays.copyOf(seeds[1].getMaxCoordinates(), seeds[1].getMaxCoordinates().length),
Lists.newArrayList(seeds[1]),
node.isLeaf(),
node.getParent(),
bf.getEmptyBitmap()
);
group1.addToInvertedIndex(seeds[1]);
if (node.getParent() != null) {
node.getParent().addChild(group1);
}
Node[] groups = new Node[]{
node, group1
};
RTreeUtils.enclose(groups);
while (!children.isEmpty()) {
for (Node group : groups) {
if (group.getChildren().size() + children.size() <= minNumChildren) {
for (Node child : group.getChildren()) {
group.addToInvertedIndex(child);
group.addChild(child);
}
RTreeUtils.enclose(groups);
return groups;
}
}
Node nextToAssign = pickNext(children, groups);
double group0ExpandedArea = RTreeUtils.getEnclosingArea(groups[0], nextToAssign);
double group1ExpandedArea = RTreeUtils.getEnclosingArea(groups[1], nextToAssign);
Node optimal;
if (group0ExpandedArea < group1ExpandedArea) {
optimal = groups[0];
} else if (group0ExpandedArea == group1ExpandedArea) {
if (groups[0].getArea() < groups[1].getArea()) {
optimal = groups[0];
} else {
optimal = groups[1];
}
} else {
optimal = groups[1];
}
optimal.addToInvertedIndex(nextToAssign);
optimal.addChild(nextToAssign);
optimal.enclose();
}
return groups;
}