Skip to content

Commit

Permalink
Make copy of boundary
Browse files Browse the repository at this point in the history
  • Loading branch information
PlugFox committed Jan 11, 2025
1 parent 8845c61 commit 0a34f0c
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions lib/src/collisions/quadtree.dart
Original file line number Diff line number Diff line change
Expand Up @@ -140,18 +140,28 @@ final class QuadTree {
// Maximum depth of the QuadTree.
int depth = 12,
}) {
assert(boundary.isFinite, 'The boundary must be finite.');
assert(!boundary.isEmpty, 'The boundary must not be empty.');
// Make copy of the boundary
final rect = ui.Rect.fromLTRB(
boundary.left,
boundary.top,
boundary.right,
boundary.bottom,
);
// Validate the parameters
assert(rect.isFinite, 'The boundary must be finite.');
assert(!rect.isEmpty, 'The boundary must not be empty.');
assert(capacity >= 6, 'The capacity must be greater or equal than 6.');
assert(depth >= 1, 'The maximum depth must be greater or equal than 1.');
assert(depth <= 7000, 'The maximum depth must be less or equal than 7000.');
// Initialize the QuadTree
final nodes = List<QuadTree$Node?>.filled(_reserved, null, growable: false);
final recycledNodes = Uint32List(_reserved);
final objects = Float32List(_reserved * _objectSize);
final recycledIds = Uint32List(_reserved);
final id2node = Uint32List(_reserved);
// Create the QuadTree
return QuadTree._internal(
boundary: boundary,
boundary: rect,
capacity: capacity.clamp(6, 10000),
depth: depth.clamp(1, 7000),
nodes: nodes,
Expand Down

0 comments on commit 0a34f0c

Please sign in to comment.