Skip to content

Commit f3805ea

Browse files
committed
Merge pull request qiao#19 from tapio/dont-cross-corners
Finalizing dontCrossCorners
2 parents d5fbbbb + 1278f3b commit f3805ea

File tree

3 files changed

+43
-4
lines changed

3 files changed

+43
-4
lines changed

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,19 @@ var finder = new PF.AStarFinder({
126126
});
127127
```
128128

129+
When diagonal movement is enabled, you might want to prevent the path from touching the corners of the occupied grid blocks. This is usually desirable if the objects using the path have physical width and can also move between the grid cells.
130+
131+
To enable the corner crossing prevention:
132+
133+
```javascript
134+
var finder = new PF.AStarFinder({
135+
allowDiagonal: true,
136+
dontCrossCorners: true
137+
});
138+
```
139+
140+
Note that `dontCrossCorners` only makes sense when `allowDiagonal` is also used. Currently all algorithms except `JumpPointFinder` support this feature.
141+
129142
For `AStarFinder`, `BestFirstFinder` and all their `Bi` relatives, you may indicate which heuristic function to use.
130143

131144
The predefined heuristics are `PF.Heuristic.manhattan`(defalut), `PF.Heuristic.chebyshev` and `PF.Heuristic.euclidean`.

visual/index.html

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ <h3>Options</h3>
8484
<label class="option_label">Allow Diagonal</label> <br>
8585
<input type="checkbox" class="bi-directional">
8686
<label class="option_label">Bi-directional</label> <br>
87+
<input type="checkbox" class="dont_cross_corners">
88+
<label class="option_label">Don't Cross Corners</label> <br>
8789
</div>
8890
</div>
8991

@@ -109,6 +111,8 @@ <h3>Options</h3>
109111
<label class="option_label">Allow Diagonal</label> <br>
110112
<input type="checkbox" class="bi-directional">
111113
<label class="option_label">Bi-directional</label> <br>
114+
<input type="checkbox" class="dont_cross_corners">
115+
<label class="option_label">Don't Cross Corners</label> <br>
112116
</div>
113117
</div>
114118

@@ -122,6 +126,8 @@ <h3>Options</h3>
122126
<label class="option_label">Allow Diagonal</label> <br>
123127
<input type="checkbox" class="bi-directional">
124128
<label class="option_label">Bi-directional</label> <br>
129+
<input type="checkbox" class="dont_cross_corners">
130+
<label class="option_label">Don't Cross Corners</label> <br>
125131
</div>
126132
</div>
127133

visual/js/panel.js

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,18 @@ var Panel = {
6262
'.allow_diagonal:checked').val() !== 'undefined';
6363
biDirectional = typeof $('#breadthfirst_section ' +
6464
'.bi-directional:checked').val() !== 'undefined';
65+
dontCrossCorners = typeof $('#breadthfirst_section ' +
66+
'.dont_cross_corners:checked').val() !=='undefined';
6567
if (biDirectional) {
66-
finder = new PF.BiBreadthFirstFinder({allowDiagonal: allowDiagonal});
68+
finder = new PF.BiBreadthFirstFinder({
69+
allowDiagonal: allowDiagonal,
70+
dontCrossCorners: dontCrossCorners
71+
});
6772
} else {
68-
finder = new PF.BreadthFirstFinder({allowDiagonal: allowDiagonal});
73+
finder = new PF.BreadthFirstFinder({
74+
allowDiagonal: allowDiagonal,
75+
dontCrossCorners: dontCrossCorners
76+
});
6977
}
7078
break;
7179

@@ -74,15 +82,19 @@ var Panel = {
7482
'.allow_diagonal:checked').val() !== 'undefined';
7583
biDirectional = typeof $('#bestfirst_section ' +
7684
'.bi-directional:checked').val() !== 'undefined';
85+
dontCrossCorners = typeof $('#bestfirst_section ' +
86+
'.dont_cross_corners:checked').val() !=='undefined';
7787
heuristic = $('input[name=bestfirst_heuristic]:checked').val();
7888
if (biDirectional) {
7989
finder = new PF.BiBestFirstFinder({
8090
allowDiagonal: allowDiagonal,
91+
dontCrossCorners: dontCrossCorners,
8192
heuristic: PF.Heuristic[heuristic]
8293
});
8394
} else {
8495
finder = new PF.BestFirstFinder({
8596
allowDiagonal: allowDiagonal,
97+
dontCrossCorners: dontCrossCorners,
8698
heuristic: PF.Heuristic[heuristic]
8799
});
88100
}
@@ -93,10 +105,18 @@ var Panel = {
93105
'.allow_diagonal:checked').val() !== 'undefined';
94106
biDirectional = typeof $('#dijkstra_section ' +
95107
'.bi-directional:checked').val() !=='undefined';
108+
dontCrossCorners = typeof $('#dijkstra_section ' +
109+
'.dont_cross_corners:checked').val() !=='undefined';
96110
if (biDirectional) {
97-
finder = new PF.BiDijkstraFinder({allowDiagonal: allowDiagonal});
111+
finder = new PF.BiDijkstraFinder({
112+
allowDiagonal: allowDiagonal,
113+
dontCrossCorners: dontCrossCorners
114+
});
98115
} else {
99-
finder = new PF.DijkstraFinder({allowDiagonal: allowDiagonal});
116+
finder = new PF.DijkstraFinder({
117+
allowDiagonal: allowDiagonal,
118+
dontCrossCorners: dontCrossCorners
119+
});
100120
}
101121
break;
102122

0 commit comments

Comments
 (0)