split method Null safety
Split the node into 4 subnodes (ne, nw, sw, se)
Implementation
void split() {
final nextDepth = depth + 1;
final subWidth = bounds.width / 2;
final subHeight = bounds.height / 2;
final x = bounds.x;
final y = bounds.y;
/// Top-right node
final ne = Quadtree<O>(
Rect(
x: x + subWidth,
y: y,
width: subWidth,
height: subHeight,
),
maxObjects: maxObjects,
maxDepth: maxDepth,
depth: nextDepth,
);
/// Top-left node
final nw = Quadtree<O>(
Rect(
x: x,
y: y,
width: subWidth,
height: subHeight,
),
maxObjects: maxObjects,
maxDepth: maxDepth,
depth: nextDepth,
);
/// Bottom-left node
final sw = Quadtree<O>(
Rect(
x: x,
y: y + subHeight,
width: subWidth,
height: subHeight,
),
maxObjects: maxObjects,
maxDepth: maxDepth,
depth: nextDepth,
);
/// Bottom-right node
final se = Quadtree<O>(
Rect(
x: x + subWidth,
y: y + subHeight,
width: subWidth,
height: subHeight,
),
maxObjects: maxObjects,
maxDepth: maxDepth,
depth: nextDepth,
);
nodes
..[Quadrant.ne] = ne
..[Quadrant.nw] = nw
..[Quadrant.sw] = sw
..[Quadrant.se] = se;
}