-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: separate SingleRoot and MultipleRoots Quadtrees in their ow…
…n files
- Loading branch information
1 parent
968147a
commit 7bfece6
Showing
5 changed files
with
281 additions
and
265 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
import 'dart:math'; | ||
import 'dart:ui'; | ||
|
||
import 'package:equatable/equatable.dart'; | ||
import 'package:fast_quadtree/src/quadrant.dart'; | ||
import 'package:fast_quadtree/src/quadtree.dart'; | ||
|
||
abstract class MultipleRootsQuadtree<T> | ||
with EquatableMixin | ||
implements Quadtree<T> { | ||
MultipleRootsQuadtree( | ||
Quadrant quadrant, { | ||
this.maxItems = 5, | ||
this.maxDepth = 4, | ||
required this.getBounds, | ||
}) { | ||
quadtreeNodes[0] = QuadtreeNode<T>( | ||
quadrant, | ||
tree: this, | ||
); | ||
} | ||
|
||
@override | ||
final int maxItems; | ||
|
||
@override | ||
final int maxDepth; | ||
|
||
@override | ||
double get left => firstNode.quadrant.left; | ||
|
||
@override | ||
double get top => firstNode.quadrant.top; | ||
|
||
@override | ||
double get width => firstNode.quadrant.width; | ||
|
||
@override | ||
double get height => firstNode.quadrant.height; | ||
|
||
@override | ||
final Rect Function(T) getBounds; | ||
|
||
int _depth = 0; | ||
|
||
@override | ||
int get depth => _depth; | ||
|
||
@override | ||
set depth(int newDepth) => _depth = newDepth; | ||
|
||
int _negativeDepth = 0; | ||
|
||
@override | ||
int get negativeDepth => _negativeDepth; | ||
|
||
@override | ||
set negativeDepth(int newNegativeDepth) => _negativeDepth = newNegativeDepth; | ||
|
||
@override | ||
void communicateNewNodeDepth(int newDepth) => depth = max(depth, newDepth); | ||
|
||
final Map<int, QuadtreeNode<T>> quadtreeNodes = {}; | ||
|
||
QuadtreeNode<T> get firstNode => quadtreeNodes[0]!; | ||
|
||
@override | ||
bool insertAll(List<T> items) { | ||
bool valid = true; | ||
|
||
for (final item in items) { | ||
valid = insert(item); | ||
} | ||
|
||
return valid; | ||
} | ||
|
||
@override | ||
void removeAll(List<T> items) { | ||
for (final item in items) { | ||
remove(item); | ||
} | ||
} | ||
|
||
@override | ||
void localizedRemoveAll(List<T> items) { | ||
for (final item in items) { | ||
localizedRemove(item); | ||
} | ||
} | ||
|
||
@override | ||
List<Quadrant> getAllQuadrants() { | ||
List<Quadrant> results = []; | ||
|
||
for (final node in quadtreeNodes.values) { | ||
results.addAll(node.getAllQuadrants()); | ||
} | ||
|
||
return results; | ||
} | ||
|
||
@override | ||
List<T> getAllItems({bool removeDuplicates = true}) { | ||
List<T> results = []; | ||
|
||
for (final node in quadtreeNodes.values) { | ||
results.addAll(node.getAllItems(removeDuplicates: removeDuplicates)); | ||
} | ||
|
||
return results; | ||
} | ||
|
||
@override | ||
void clear() { | ||
for (final node in quadtreeNodes.values) { | ||
node.clear(); | ||
} | ||
} | ||
} |
Oops, something went wrong.