mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-04-01 12:42:58 +08:00
Add javascript-astar definitions
This commit is contained in:
26
javascript-astar/javascript-astar-test.ts
Normal file
26
javascript-astar/javascript-astar-test.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
/// <reference path="javascript-astar.d.ts" />
|
||||
|
||||
function test_create() {
|
||||
let graph: Graph = new Graph([]);
|
||||
}
|
||||
|
||||
function test_create_with_diagonals() {
|
||||
let graph: Graph = new Graph([], {diagonal: true});
|
||||
}
|
||||
|
||||
function test_get_node() {
|
||||
let graph: Graph = new Graph([[5, 1, 0, 9], [0, 8, 7, 1]]);
|
||||
let node: GridNode = graph.grid[0][1];
|
||||
}
|
||||
|
||||
function test_search_returns_nodes() {
|
||||
let nodes: Array<GridNode> = astar.search(new Graph([]), {x: 1, y: 1}, {x: 2, y: 2});
|
||||
}
|
||||
|
||||
function test_search_alternative_heuristic() {
|
||||
let nodes: Array<GridNode> = astar.search(new Graph([]), {x: 1, y: 1}, {x: 2, y: 2}, {heuristic: astar.heuristics.manhatten});
|
||||
}
|
||||
|
||||
function test_search_or_closest() {
|
||||
let nodes: Array<GridNode> = astar.search(new Graph([], {diagonal: true}), {x: 1, y: 1}, {x: 2, y: 2}, {closest: true});
|
||||
}
|
||||
37
javascript-astar/javascript-astar.d.ts
vendored
Normal file
37
javascript-astar/javascript-astar.d.ts
vendored
Normal file
@@ -0,0 +1,37 @@
|
||||
// Type definitions for javascript-astar
|
||||
// Project: https://github.com/bgrins/javascript-astar
|
||||
// Definitions by: brian ridley <https://github.com/ptlis/>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
declare class Graph {
|
||||
grid: Array<Array<GridNode>>;
|
||||
constructor(grid: Array<Array<number>>, options?: {diagonal?: boolean});
|
||||
}
|
||||
|
||||
declare class GridNode {
|
||||
x: number;
|
||||
y: number;
|
||||
}
|
||||
|
||||
interface Heuristic {
|
||||
(pos0: {x: number, y: number}, pos1: {x: number, y: number}): number;
|
||||
}
|
||||
|
||||
interface Heuristics {
|
||||
manhatten: Heuristic;
|
||||
diagonal: Heuristic;
|
||||
}
|
||||
|
||||
declare module astar {
|
||||
function search(
|
||||
graph: Graph,
|
||||
start: {x: number, y: number},
|
||||
end: {x: number, y: number},
|
||||
options?: {
|
||||
closest?: boolean,
|
||||
heuristic?: Heuristic
|
||||
}
|
||||
): Array<GridNode>;
|
||||
var heuristics: Heuristics;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user