pathfinding_dart 0.0.1

pBuild Status

pathfinding-dart - BSD LICENSE #

A pathfinding library written in dart, meant to be used for games. It is generic enough to be used in different kind of graphs (though, right now it only has implementation for grid graphs).

It is a port of my java library [https://github.com/xaguzman/pathfinding]. The java version was used in my old #1GAM january entry.


Intro #

The library works on a bunch of interfaces:

  • NavigationNode: this basically just represents a node of a graph. contains some getters and setters meant for navigation. Right now, only implementation is GridCell
  • NavigationGrap: a group of navigation nodes. Right now, only implementation is NavigationGrid
  • PathFinder: the implementation for the pathfinding algorithm, current options are:
    • AStarFinder
    • AStarGridFinder
    • JumpPointFinder (Currently broken)
    • ThetaStarFinder
    • ThetaStarGridFinder

Finders are fed with so called PathFinderOptions, which determine how the pathfinding will work (allowing diagonal movement, for example).

How to use #

You need to create a graph. Be aware that the NavigationGrid class, expects a bidimensional array of GridCell stored as [x][y]

//these should be stored as [x][y]
NavigationGridNode[][] nodes = new NavigationGridNode[5][5];
	
//create your cells with whatever data you need
nodes = createNodes();
	
//create a navigation grid with the cells you just created
NavigationGrid<NavigationGridNode> navGrid = new NavigationGrid(nodes);

Now, you need a finder which can work on your graph.

//create a finder either using the default options
AStarGridFinder<NavigationGridNode> finder = new AStarGridFinder();
	
//or create your own pathfinder options:
GridFinderOptions opt = new GridFinderOptions();
opt.allowDiagonal = false;
	
AStarGridFinder<GridCell> finder = new AStarGridFinder.withOptions(opt);

Once you have both, a graph and a finder, you can find paths within your graph at any time.

List<NavigationGridNode> pathToEnd = finder.findPath(0, 0, 4, 3, navGrid);

That's pretty much all there is to using the library.

0.0.1 #

  • Initial version, astar and thetastar finders are working

example/pathfinding_dart_example.dart

// import 'package:pathfinding_dart/pathfinding_dart.dart';

// main() {
//   var awesome = Awesome();
//   print('awesome: ${awesome.isAwesome}');
// }

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  pathfinding_dart: ^0.0.1

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:pathfinding_dart/pathfinding.dart';
import 'package:pathfinding_dart/pathfinding_grid.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
51
Health:
Code health derived from static analysis. [more]
83
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
82
Overall:
Weighted score of the above. [more]
67
Learn more about scoring.

We analyzed this package on Aug 22, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.4.0
  • pana: 0.12.19

Platforms

Detected platforms: Flutter, web, other

No platform restriction found in libraries.

Health suggestions

Fix lib/src/grid/grid_finders.dart. (-9.08 points)

Analysis of lib/src/grid/grid_finders.dart reported 19 hints, including:

line 53 col 11: DO use curly braces for all flow control structures.

line 55 col 11: DO use curly braces for all flow control structures.

line 57 col 11: DO use curly braces for all flow control structures.

line 70 col 4: DO use curly braces for all flow control structures.

line 117 col 9: DO use curly braces for all flow control structures.

Fix lib/src/finders/thetastar_finder.dart. (-2.48 points)

Analysis of lib/src/finders/thetastar_finder.dart reported 5 hints:

line 3 col 1: Prefer using /// for doc comments.

line 24 col 13: DO use curly braces for all flow control structures.

line 26 col 13: DO use curly braces for all flow control structures.

line 28 col 13: DO use curly braces for all flow control structures.

line 41 col 4: DO use curly braces for all flow control structures.

Fix lib/src/bheap.dart. (-1.99 points)

Analysis of lib/src/bheap.dart reported 4 hints:

line 50 col 4: DO use curly braces for all flow control structures.

line 57 col 4: DO use curly braces for all flow control structures.

line 59 col 4: DO use curly braces for all flow control structures.

line 75 col 5: DO use curly braces for all flow control structures.

Fix additional 8 files with analysis or formatting issues. (-4.48 points)

Additional issues in the following files:

  • lib/src/finders/astar_finder.dart (4 hints)
  • lib/src/grid/grid_graph.dart (4 hints)
  • lib/src/interfaces.dart (1 hint)
  • lib/pathfinding.dart (Run dartfmt to format lib/pathfinding.dart.)
  • lib/pathfinding_grid.dart (Run dartfmt to format lib/pathfinding_grid.dart.)
  • lib/src/grid/grid_node.dart (Run dartfmt to format lib/src/grid/grid_node.dart.)
  • lib/src/grid/heuristics.dart (Run dartfmt to format lib/src/grid/heuristics.dart.)
  • lib/src/util.dart (Run dartfmt to format lib/src/util.dart.)

Maintenance suggestions

Package is pre-v0.1 release. (-10 points)

While nothing is inherently wrong with versions of 0.0.*, it might mean that the author is still experimenting with the general direction of the API.

The package description is too short. (-8 points)

Add more detail to the description field of pubspec.yaml. Use 60 to 180 characters to describe the package, what it does, and its target use case.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
Dev dependencies
build_runner ^1.0.0
build_test ^0.10.2
build_web_compilers ^0.4.0
pedantic ^1.0.0
test ^1.0.0
tweenengine ^0.12.1