From b0ad2dc3d1722d07c36c836b3839add9d8e3f6c6 Mon Sep 17 00:00:00 2001 From: Lobo Date: Sun, 1 Feb 2026 16:18:55 +0100 Subject: [PATCH] Update pathfinding.component.ts --- .../pathfinding/pathfinding.component.ts | 38 ++++--------------- 1 file changed, 8 insertions(+), 30 deletions(-) diff --git a/src/app/pages/algorithms/pathfinding/pathfinding.component.ts b/src/app/pages/algorithms/pathfinding/pathfinding.component.ts index 8ea27ae..d439e22 100644 --- a/src/app/pages/algorithms/pathfinding/pathfinding.component.ts +++ b/src/app/pages/algorithms/pathfinding/pathfinding.component.ts @@ -4,7 +4,6 @@ import { MatButtonModule } from '@angular/material/button'; import {GRID_COLS, GRID_ROWS, NODE_SIZE, Node} from './pathfinding.models'; import {MatButtonToggleModule} from '@angular/material/button-toggle'; import {FormsModule} from '@angular/forms'; -import {NgIf} from '@angular/common'; import { PathfindingService } from './service/pathfinding.service'; import { TranslateModule, TranslateService } from '@ngx-translate/core'; @@ -19,7 +18,7 @@ enum NodeType { @Component({ selector: 'app-pathfinding', standalone: true, - imports: [CommonModule, MatButtonModule, MatButtonToggleModule, FormsModule, NgIf, TranslateModule], + imports: [CommonModule, MatButtonModule, MatButtonToggleModule, FormsModule, TranslateModule], templateUrl: './pathfinding.component.html', styleUrls: ['./pathfinding.component.scss'] }) @@ -35,7 +34,7 @@ export class PathfindingComponent implements AfterViewInit { isDrawing: boolean = false; selectedNodeType: NodeType = NodeType.None; // Default to no selection - animationSpeed: number = 10; // milliseconds + animationSpeed: number = 1; // milliseconds readonly NodeType = NodeType; // Expose enum to template @@ -192,10 +191,9 @@ export class PathfindingComponent implements AfterViewInit { return; } this.clearPath(); - const gridCopy = this.getCleanGrid(); - const { visitedNodesInOrder, nodesInShortestPathOrder } = this.pathfindingService.dijkstra(gridCopy, - gridCopy[this.startNode.row][this.startNode.col], - gridCopy[this.endNode.row][this.endNode.col] + const { visitedNodesInOrder, nodesInShortestPathOrder } = this.pathfindingService.dijkstra(this.grid, + this.grid[this.startNode.row][this.startNode.col], + this.grid[this.endNode.row][this.endNode.col] ); this.animateAlgorithm(visitedNodesInOrder, nodesInShortestPathOrder); } @@ -206,10 +204,9 @@ export class PathfindingComponent implements AfterViewInit { return; } this.clearPath(); - const gridCopy = this.getCleanGrid(); - const { visitedNodesInOrder, nodesInShortestPathOrder } = this.pathfindingService.aStar(gridCopy, - gridCopy[this.startNode.row][this.startNode.col], - gridCopy[this.endNode.row][this.endNode.col] + const { visitedNodesInOrder, nodesInShortestPathOrder } = this.pathfindingService.aStar(this.grid, + this.grid[this.startNode.row][this.startNode.col], + this.grid[this.endNode.row][this.endNode.col] ); this.animateAlgorithm(visitedNodesInOrder, nodesInShortestPathOrder); } @@ -262,23 +259,4 @@ export class PathfindingComponent implements AfterViewInit { this.drawGrid(); } - // Helper to get a deep copy of the grid for algorithm execution - private getCleanGrid(): Node[][] { - const newGrid: Node[][] = []; - for (let row = 0; row < GRID_ROWS; row++) { - const currentRow: Node[] = []; - for (let col = 0; col < GRID_COLS; col++) { - const node = this.grid[row][col]; - currentRow.push({ - ...node, - isVisited: false, - isPath: false, - distance: Infinity, - previousNode: null, - }); - } - newGrid.push(currentRow); - } - return newGrid; - } }