private void split() {
double centerX = (minX + maxX) / 2;
double centerY = (minY + maxY) / 2;
this.children = new QuadTreeNode[4];
this.children[ChildPosition.CHILD_NW.ordinal()] = new QuadTreeNode(this.minX, centerY, centerX, this.maxY);
this.children[ChildPosition.CHILD_NE.ordinal()] = new QuadTreeNode(centerX, centerY, this.maxX, this.maxY);
this.children[ChildPosition.CHILD_SE.ordinal()] = new QuadTreeNode(centerX, this.minY, this.maxX, centerY);
this.children[ChildPosition.CHILD_SW.ordinal()] = new QuadTreeNode(this.minX, this.minY, centerX, centerY);
List<LinkWrapper> keep = new ArrayList<>(this.links.size() / 2);
for (LinkWrapper w : this.links) {
ChildPosition pos = getChildPosition(w);
if (pos == ChildPosition.NO_CHILD) {
keep.add(w);
} else {
this.children[pos.ordinal()].put(w);
}
}
this.links.clear();
this.links.ensureCapacity(keep.size() + 5);
this.links.addAll(keep);
}