https://github.com/arkaung/quadtree
Quadtree implementation in Dart
https://github.com/arkaung/quadtree
Last synced: 3 months ago
JSON representation
Quadtree implementation in Dart
- Host: GitHub
- URL: https://github.com/arkaung/quadtree
- Owner: ArkAung
- License: mit
- Created: 2024-09-07T10:54:58.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2024-09-07T13:26:40.000Z (almost 2 years ago)
- Last Synced: 2026-03-18T17:07:40.090Z (4 months ago)
- Language: Dart
- Size: 12.7 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# Quadtree
[](https://pub.dev/packages/quadtree)
[](https://pub.dev/packages/quadtree)
[](https://codecov.io/gh/arkaung/quadtree)
[](https://opensource.org/licenses/MIT)
[](https://pub.dev/packages/quadtree/score)
A fast and efficient quadtree implementation in Dart for spatial partitioning and range queries.
## Features
- Efficient spatial partitioning for 2D space
- Fast point insertion and range queries
## Installation
Add `quadtree` to your `pubspec.yaml` file:
```yaml
dependencies:
quadtree: ^0.1.0
```
Then run:
```
dart pub get
```
## Usage
Here's a quick example of how to use the Quadtree package:
```dart
import 'package:quadtree/quadtree.dart';
void main() {
// Create a quadtree with a boundary of 100x100
final quadtree = Quadtree(Rectangle(0, 0, 100, 100));
// Insert some points
quadtree.insert(Point(10, 20, 'data 1'));
quadtree.insert(Point(50, 50, 'data 2'));
quadtree.insert(Point(80, 15, 'data 3'));
// Query points within a range
final pointsInRange = quadtree.query(Rectangle(0, 0, 60, 60));
print('Points in range: ${pointsInRange.length}');
// You can also associate data with points
quadtree.insert(Point(25, 35, 'Some data'));
// Retrieve points with their associated data
final pointsWithData = quadtree.query(Rectangle(20, 30, 10, 10));
for (var point in pointsWithData) {
print('Point at (${point.x}, ${point.y}) with data: ${point.data}');
}
}
```
## API Reference
### `Quadtree`
The main class for the quadtree data structure.
#### Constructor
- `Quadtree(Rectangle boundary, [int capacity = 4])` : Creates a new quadtree with the given boundary and capacity.
#### Methods
- `bool insert(Point point)` : Inserts a point into the quadtree.
- `List query(Rectangle range)` : Returns all points within the given range.
### `Point`
Represents a point in 2D space.
#### Constructor
- `Point(double x, double y, [dynamic data])` : Creates a new point with optional associated data.
### `Rectangle`
Represents a rectangular boundary.
#### Constructor
- `Rectangle(double x, double y, double width, double height)` : Creates a new rectangle.
## Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
## License
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.