kdbush 0.0.1 copy "kdbush: ^0.0.1" to clipboard
kdbush: ^0.0.1 copied to clipboard

outdated

A very fast static spatial index for 2D points based on a flat KD-tree. A port of javascript kdbush.

A very fast static spatial index for 2D points based on a flat KD-tree. Ported from the javascript kdbush package. Only points are supported (no rectangles) and points may not be added/removed.

Usage #

import 'dart:math';
import 'package:kdbush/kdbush.dart';

void main() {
  final points = <Point<int>>[
    Point(2, 2),
    Point(2, 4),
    Point(4, 2),
    Point(4, 4),
  ];

  final kdbush = KDBush<Point<int>, int>(
    points: points,
    getX: (p) => p.x,
    getY: (p) => p.y,
    nodeSize: 10,
  );

  final withinRadiusPoints = <Point<int>>[];
  for (final index in kdbush.withinRadius(4, 3, 2)) {
    withinRadiusPoints.add(points[index]);
  }
  print('Within radius: ${withinRadiusPoints.join(',')}'); // Within radius: Point(4, 2),Point(4, 4)

  final withinBoundsPoints = <Point<int>>[];
  for (final index in kdbush.withinBounds(0, 0, 2, 4)) {
    withinBoundsPoints.add(points[index]);
  }
  print('Within bounds: ${withinBoundsPoints.join(',')}'); // Within bounds: Point(2, 2),Point(2, 4)
}
1
likes
0
pub points
26%
popularity

Publisher

verified publisherbalanci.ng

A very fast static spatial index for 2D points based on a flat KD-tree. A port of javascript kdbush.

Homepage

License

unknown (license)

More

Packages that depend on kdbush