@woosh/meep-engine
Version:
Pure JavaScript game engine. Fully featured and production ready.
212 lines • 5.47 kB
TypeScript
/**
* Graph structure, consisting of nodes(vertices) and directed edges.
* @see https://en.wikipedia.org/wiki/Graph_(discrete_mathematics)
* @see https://en.wikipedia.org/wiki/Graph_(abstract_data_type)
* @template N
*/
export class Graph<N> {
/**
*
* @type {Map<N, NodeContainer<N>>}
* @readonly
* @private
*/
private readonly __nodes;
/**
*
* @type {Set<Edge<N>>}
* @readonly
* @private
*/
private readonly __edges;
/**
* @readonly
*/
readonly on: {
/**
* @type {Signal<N,this>}
*/
nodeAdded: Signal<N, this>;
/**
* @type {Signal<N,this>}
*/
nodeRemoved: Signal<N, this>;
edgeAdded: Signal<any, any, any, any, any, any, any, any>;
edgeRemoved: Signal<any, any, any, any, any, any, any, any>;
};
/**
*
* @param {N} node
* @returns {boolean}
*/
hasNode(node: N): boolean;
/**
*
* @param {N} node
* @returns {boolean} true if node was added, false if node already exists
*/
addNode(node: N): boolean;
/**
*
* @param {N} node
* @returns {boolean}
*/
removeNode(node: N): boolean;
/**
*
* @param {function(N)} visitor
* @param {*} [thisArg]
*/
traverseNodes(visitor: (arg0: N) => any, thisArg?: any): void;
/**
* Number of nodes in the graph
* @return {number}
*/
get nodeCount(): number;
/**
* @deprecated use {@link nodeCount} property instead
* @returns {number}
*/
getNodeCount(): number;
/**
*
* @param {function(N):boolean} filter
* @param {*} [thisArg]
* @returns {N|undefined} first node that is matched by the filter
*/
findNode(filter: (arg0: N) => boolean, thisArg?: any): N | undefined;
/**
* Access internal representation of a node.
* Useful for performance optimization.
* Do not modify obtained value.
* @param {N} node
* @returns {NodeContainer<N>|undefined}
*/
getNodeContainer(node: N): NodeContainer<N> | undefined;
/**
* Node degree is the number of attached edges
* @param {N} node
* @return {number}
*/
getNodeDegree(node: N): number;
/**
*
* @returns {N[]}
*/
get nodes(): N[];
/**
* Do not modify this set directly
* @return {Iterable<N>}
*/
getNodes(): Iterable<N>;
/**
* Do not modify this set directly
* @return {Set<Edge<N>>}
*/
getEdges(): Set<Edge<N>>;
/**
* Introduce a new edge into the graph. Nodes must already be a part of the graph.
* @param {N} source
* @param {N} target
* @param {EdgeDirectionType} [direction] Undirected by default
* @returns {Edge<N>}
* @throws {Error} if one or both nodes are not part of the graph
*/
createEdge(source: N, target: N, direction?: EdgeDirectionType): Edge<N>;
/**
* Both nodes that the edge is attached to must be present
* @param {Edge<N>} edge
* @returns {boolean} true if edge was added, false if edge was already present
* @throws {Error} if one or both nodes are not contained in the graph
*/
addEdge(edge: Edge<N>): boolean;
/**
*
* @param {Edge<N>} edge
* @returns {boolean} true if edge was removed, false if edge was not found
*/
removeEdge(edge: Edge<N>): boolean;
/**
*
* @param {Edge<N>} edge
* @returns {boolean}
*/
hasEdge(edge: Edge<N>): boolean;
/**
*
* @param {function(Edge<N>)} visitor
* @param {*} [thisArg]
*/
traverseEdges(visitor: (arg0: Edge<N>) => any, thisArg?: any): void;
/**
* Number of edges in the graph
* @return {number}
*/
get edgeCount(): number;
/**
* checks if there is an edge between two given nodes.
* Direction is ignored.
* @param {N} a
* @param {N} b
* @returns {boolean}
*/
edgeExistsBetween(a: N, b: N): boolean;
/**
*
* @param {N} a
* @param {N} b
* @returns {Edge<N>|undefined}
*/
getAnyEdgeBetween(a: N, b: N): Edge<N> | undefined;
/**
*
* @param {N} from
* @param {N} to
* @returns {Edge<N>|undefined}
*/
getAnyDirectedEdge(from: N, to: N): Edge<N> | undefined;
/**
*
* @param {Edge<N>[]} result found edges will be put here
* @param {N} node
* @returns {number} number of edges found
*/
getAttachedEdges(result: Edge<N>[], node: N): number;
/**
*
* @param {N} node
* @returns {N[]}
*/
getNeighbours(node: N): N[];
/**
*
* @param {N} node
* @returns {boolean}
*/
nodeHasEdges(node: N): boolean;
/**
* Find a path through the graph
* @param {N} start
* @param {N} goal
* @returns {null|N[]} null if no path exists
*/
findPath(start: N, goal: N): null | N[];
/**
* Remove all data from the graph, resetting it to empty state
*/
clear(): void;
/**
*
* @param {Graph<N>} other
*/
copy(other: Graph<N>): void;
/**
* @returns {Graph<N>}
*/
clone(): Graph<N>;
}
import Signal from "../../events/signal/Signal.js";
import { NodeContainer } from "./NodeContainer.js";
import { Edge } from "../Edge.js";
import { EdgeDirectionType } from "../Edge.js";
//# sourceMappingURL=Graph.d.ts.map