insert method Null safety
- O object
Insert the object into the node. If the node exceeds the capacity, it will split and add all objects to their corresponding subnodes.
Takes bounds to be inserted.
Implementation
void insert(O object) {
/// If we have subnodes, call [insert] on the matching subnodes.
if (nodes.isNotEmpty) {
final quadrants = getQuadrants(object);
for (int i = 0; i < quadrants.length; i++) {
nodes[quadrants[i]]!.insert(object);
}
return;
}
objects.add(object);
/// Max objects reached; only split if maxDepth hasn't been reached.
if (objects.length > maxObjects && depth < maxDepth) {
if (nodes.isEmpty) split();
/// Add objects to their corresponding subnodes
for (final obj in objects) {
getQuadrants(obj).forEach((q) {
nodes[q]!.insert(obj);
});
}
/// Node should be cleaned up as the objects are now contained within
/// subnodes.
objects.clear();
}
}