From f1a922ae36eaae2262aa5dcc9df5b1d8bd6a38ca Mon Sep 17 00:00:00 2001 From: Justin Young Date: Wed, 2 Apr 2025 15:08:59 -0400 Subject: [PATCH] cleaned up jsdocs --- src/engine/Math/Graph.ts | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/src/engine/Math/Graph.ts b/src/engine/Math/Graph.ts index 99723854..ca65f788 100644 --- a/src/engine/Math/Graph.ts +++ b/src/engine/Math/Graph.ts @@ -72,15 +72,6 @@ export class Graph { return this._nodes; } - /** - * Deletes a node from the graph along with all its associated edges. - * This method removes the specified node and any edges connected to it - * from the graph. It updates the internal structures to reflect these - * changes. - * @param node - The node to be deleted from the graph. - * @returns A map of all remaining nodes in the graph. - */ - /** * Deletes a node from the graph along with all its associated edges. * This method removes the specified node and any edges connected to it @@ -106,7 +97,7 @@ export class Graph { } /** - * Adds a new node to the graph with the given data and returns the newly + * Adds a new vertex to the graph with the given data and returns the newly * created node. This method is just an alias for {@link addNode}. * @param data - The data to be stored in the new node. * @returns The newly created node. @@ -509,16 +500,30 @@ export class Graph { return resultArray; } - shortestPathDijkstra(startingnode: Node, endnode: Node): { path: Node[]; distance: number } { - const dAnalysis = this.dijkstra(startingnode); + /** + * Finds the shortest path between two nodes in the graph using the Dijkstra method + * + * This method calculates the shortest path from the specified start node to the + * specified end node in the graph. It returns an object containing the path and + * the total distance of the path. + * @param startingNode - The node from which the search for the shortest path begins. + * @param endNode - The node where the search for the shortest path ends. + * @returns An object containing: + * - `path`: An array of nodes representing the shortest path from startNode to endNode. + * If no path is found, this will be `null`. + * - `distance`: The total distance of the shortest path. If no path is found, this will + * be `Infinity`. + */ + shortestPathDijkstra(startingNode: Node, endNode: Node): { path: Node[]; distance: number } { + const dAnalysis = this.dijkstra(startingNode); if (dAnalysis.length === 0) { return { path: [], distance: Infinity }; } //iterate through dAnalysis to plot shortest path to endnode const path: Node[] = []; - let current: Node | null | undefined = endnode; - const distance = dAnalysis.find((node) => node.node === endnode)?.distance as number; + let current: Node | null | undefined = endNode; + const distance = dAnalysis.find((node) => node.node === endNode)?.distance as number; while (current != null) { path.push(current); -- 2.51.2