-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #35 from peterchenadded/master
added changes for #29
- Loading branch information
Showing
7 changed files
with
130 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// Please note below heuristics are experimental and only for pretty lines. | ||
// They may not take the shortest path and require additional cpu cycles. | ||
|
||
#include <cmath> | ||
#include <cstddef> | ||
#include <experimental_heuristics.h> | ||
|
||
|
||
heuristic_ptr select_heuristic(int h) { | ||
switch (h) { | ||
case ORTHOGONAL_X: | ||
return orthogonal_x; | ||
case ORTHOGONAL_Y: | ||
return orthogonal_y; | ||
default: | ||
return NULL; | ||
} | ||
} | ||
|
||
// Orthogonal x (moves by x first, then half way by y) | ||
float orthogonal_x(int i0, int j0, int i1, int j1, int i2, int j2) { | ||
int di = std::abs(i0 - i1); | ||
int dim = std::abs(i1 - i2); | ||
int djm = std::abs(j1 - j2); | ||
if (di > (dim * 0.5)) { | ||
return di + djm; | ||
} else { | ||
return std::abs(j0 - j1); | ||
} | ||
} | ||
|
||
// Orthogonal y (moves by y first, then half way by x) | ||
float orthogonal_y(int i0, int j0, int i1, int j1, int i2, int j2) { | ||
int dj = std::abs(j0 - j1); | ||
int djm = std::abs(j1 - j2); | ||
int dim = std::abs(i1 - i2); | ||
if (dj > (djm * 0.5)) { | ||
return dj + dim; | ||
} else { | ||
return std::abs(i0 - i1); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// Please note below heuristics are experimental and only for pretty lines. | ||
// They may not take the shortest path and require additional cpu cycles. | ||
|
||
#ifndef EXPERIMENTAL_HEURISTICS_H_ | ||
#define EXPERIMENTAL_HEURISTICS_H_ | ||
|
||
|
||
enum Heuristic { DEFAULT, ORTHOGONAL_X, ORTHOGONAL_Y }; | ||
|
||
typedef float (*heuristic_ptr)(int, int, int, int, int, int); | ||
|
||
heuristic_ptr select_heuristic(int); | ||
|
||
// Orthogonal x (moves by x first, then half way by y) | ||
float orthogonal_x(int, int, int, int, int, int); | ||
|
||
// Orthogonal y (moves by y first, then half way by x) | ||
float orthogonal_y(int, int, int, int, int, int); | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
from pyastar2d.astar_wrapper import astar_path | ||
__all__ = ["astar_path"] | ||
from pyastar2d.astar_wrapper import astar_path, Heuristic | ||
__all__ = ["astar_path", "Heuristic"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters