sector 0.4.0-alpha+3 sector: ^0.4.0-alpha+3 copied to clipboard
Fast and intuitive 2D data structures: grids, graphs, pathfinding & more.
Sector #
Fast and intuitive 2D data structures: grids, graphs, pathfinding & more.
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 #
To run the tests, run:
dart test
To check code coverage locally, run:
dart pub global activate -sgit https://github.com/matanlurey/chore.dart.git --git-ref=8b252e7
To preview dartdoc
output locally, run:
chore dartdoc