Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test added (to ensure that the nodes are square shaped) #2

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion lib/src/rbush.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
// Copyright (c) 2021 Ilya Zverev, (c) 2020 Vladimir Agafonkin.
// Port of https://github.com/mourner/rbush and https://github.com/mourner/rbush-knn.
// Use of this code is governed by an ISC license, see the LICENSE file.
import 'dart:math' show min, max, log, pow, sqrt;
import 'dart:math' show min, max, log, pow, sqrt, Random;
import 'package:collection/collection.dart';

import 'quickselect.dart';
import 'tinyqueue.dart';
Expand Down Expand Up @@ -313,6 +314,31 @@ class RBushBase<T> {
return node;
}

void test() {
var ri = Random();
int n = 100000;
for (var i = 0; i < n; i++) {
double lat = ri.nextDouble() * 180 - 90;
double lng = ri.nextDouble() * 360 - 180;
insert(RBushElement.fromList([lat, lng, lat, lng], null) as T);
}
_RBushNode node = data;
final List<_RBushNode> nodesToSearch = [];
final observations = <num>[];
while (true) {
observations.add(log((node.maxX - node.minX) / (node.maxY - node.minY)));
// print(
// "stats: ${node.height} ${node.leaf ? node.leafChildren.length : node.children.length} ${node.minX} ${node.minY} ${node.maxX} ${node.maxY}");
if (node.leaf) {
} else {
nodesToSearch.addAll(node.children);
}
if (nodesToSearch.isEmpty) break;
node = nodesToSearch.removeLast();
}
assert(observations.average.abs() < 0.1);
}

_RBushNode<T> _chooseSubtree(
RBushBox bbox, _RBushNode<T> node, int level, List<_RBushNode<T>> path) {
while (true) {
Expand Down