sector
Fast and intuitive 2D data structures: grids, graphs, pathfinding & more.
✅ Health | 🚀 Release | 📝 Docs | ♻️ Maintenance |
---|---|---|---|
Getting Started
Add a dependency in your pubspec.yaml
or run the following command:
dart pub add sector
Features
- Platform independent, works on the Web, Flutter, and Dart VM.
- Idiomatically Dart, with a familiar and fully documented API.
- Extensible, with a focus on performance and ergonomics.
- Well-tested, with 100% code coverage and property-based tests.
- Lightweight, with zero dependencies, minimal overhead, and benchmarked.
Usage
Sector offers a powerful toolkit for graphs, grids, pathfinding, and more.
Graphs
Create a graph and add edges:
final graph = Graph<String>();
graph.addEdge(Edge('a', 'b'));
graph.addEdge(Edge('b', 'c'));
print(graph.roots); // ['a']
print(graph.successors('b')); // ['c']
Grids
Create a grid and update cells:
enum Tile {
wall,
floor,
}
// Create a 5x8 grid filled with `Tile.wall`.
//
// When resizing a grid, the `empty` value is used to fill the new cells.
final grid = Grid.filled(5, 8, empty: Tile.wall);
// Itereate over the grid.
for (final row in grid.rows) {
for (final cell in row) {
print(cell);
}
}
Pathfinding
Use built-in pathfinding algorithms or write your own:
final graph = Walkable.linear(['a', 'b', 'c']);
final path = breadthFirstSearch(graph, 'a', Goal.node('c'));
print(path); // Path(['a', 'b', 'c'])
Contributing
We welcome contributions to this package!
Please file an issue before contributing larger changes.
This package uses repository specific tooling to enforce formatting, static analysis, and testing. Please run the following commands locally before submitting a pull request:
./dev.sh --packages packages/sector check
./dev.sh --packages packages/sector test