├── src ├── assets │ └── .gitkeep ├── app │ ├── app.component.css │ ├── header │ │ ├── header.component.css │ │ ├── header.component.html │ │ └── header.component.ts │ ├── app.component.html │ ├── grid │ │ ├── node.model.ts │ │ ├── grid.component.css │ │ ├── min-heap.ts │ │ ├── dijkstra.ts │ │ ├── grid.component.ts │ │ ├── grid.component.html │ │ └── maze-partation.ts │ ├── app.component.ts │ ├── app.component.spec.ts │ └── app.module.ts ├── favicon.ico ├── environments │ ├── environment.prod.ts │ └── environment.ts ├── styles.css ├── main.ts ├── index.html ├── test.ts └── polyfills.ts ├── e2e ├── tsconfig.json ├── src │ ├── app.po.ts │ └── app.e2e-spec.ts └── protractor.conf.js ├── tsconfig.app.json ├── .editorconfig ├── tsconfig.spec.json ├── browserslist ├── tsconfig.json ├── .gitignore ├── README.md ├── karma.conf.js ├── package.json ├── tslint.json └── angular.json /src/assets/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/app/app.component.css: -------------------------------------------------------------------------------- 1 | main { 2 | width: 90%; 3 | margin: 1rem auto; 4 | } 5 | -------------------------------------------------------------------------------- /src/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arjan-bal/Dijkstra-Visualiser/HEAD/src/favicon.ico -------------------------------------------------------------------------------- /src/app/header/header.component.css: -------------------------------------------------------------------------------- 1 | a { 2 | text-decoration: none; 3 | color: white; 4 | } 5 | -------------------------------------------------------------------------------- /src/environments/environment.prod.ts: -------------------------------------------------------------------------------- 1 | export const environment = { 2 | production: true 3 | }; 4 | -------------------------------------------------------------------------------- /src/app/app.component.html: -------------------------------------------------------------------------------- 1 | 2 |
3 | 4 |
5 | -------------------------------------------------------------------------------- /src/app/header/header.component.html: -------------------------------------------------------------------------------- 1 | 2 |
Dijkstra Visualiser
3 |
4 | -------------------------------------------------------------------------------- /src/styles.css: -------------------------------------------------------------------------------- 1 | /* You can add global styles to this file, and also import other style files */ 2 | 3 | html, body { height: 100%; } 4 | body { margin: 0; font-family: Roboto, "Helvetica Neue", sans-serif; } 5 | -------------------------------------------------------------------------------- /src/app/grid/node.model.ts: -------------------------------------------------------------------------------- 1 | export interface Node { 2 | isBlocked: boolean, 3 | x: number, 4 | y: number, 5 | distance: number, 6 | isColored: boolean, 7 | isOnPath: boolean, 8 | parent: Node, 9 | weight: number 10 | } 11 | -------------------------------------------------------------------------------- /src/app/header/header.component.ts: -------------------------------------------------------------------------------- 1 | import { Component } from '@angular/core'; 2 | 3 | @Component({ 4 | selector: 'app-header', 5 | templateUrl: './header.component.html', 6 | styleUrls: ['./header.component.css'] 7 | }) 8 | export class HeaderComponent { } 9 | -------------------------------------------------------------------------------- /e2e/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "../out-tsc/e2e", 5 | "module": "commonjs", 6 | "target": "es5", 7 | "types": [ 8 | "jasmine", 9 | "jasminewd2", 10 | "node" 11 | ] 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/app/app.component.ts: -------------------------------------------------------------------------------- 1 | import { Component } from '@angular/core'; 2 | 3 | @Component({ 4 | selector: 'app-root', 5 | templateUrl: './app.component.html', 6 | styleUrls: ['./app.component.css'] 7 | }) 8 | export class AppComponent { 9 | title = 'dijkstra-visualiser'; 10 | } 11 | -------------------------------------------------------------------------------- /tsconfig.app.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "./out-tsc/app", 5 | "types": [] 6 | }, 7 | "files": [ 8 | "src/main.ts", 9 | "src/polyfills.ts" 10 | ], 11 | "include": [ 12 | "src/**/*.d.ts" 13 | ] 14 | } 15 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | # Editor configuration, see https://editorconfig.org 2 | root = true 3 | 4 | [*] 5 | charset = utf-8 6 | indent_style = space 7 | indent_size = 2 8 | insert_final_newline = true 9 | trim_trailing_whitespace = true 10 | 11 | [*.ts] 12 | quote_type = single 13 | 14 | [*.md] 15 | max_line_length = off 16 | trim_trailing_whitespace = false 17 | -------------------------------------------------------------------------------- /e2e/src/app.po.ts: -------------------------------------------------------------------------------- 1 | import { browser, by, element } from 'protractor'; 2 | 3 | export class AppPage { 4 | navigateTo(): Promise { 5 | return browser.get(browser.baseUrl) as Promise; 6 | } 7 | 8 | getTitleText(): Promise { 9 | return element(by.css('app-root .content span')).getText() as Promise; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /tsconfig.spec.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "./out-tsc/spec", 5 | "types": [ 6 | "jasmine", 7 | "node" 8 | ] 9 | }, 10 | "files": [ 11 | "src/test.ts", 12 | "src/polyfills.ts" 13 | ], 14 | "include": [ 15 | "src/**/*.spec.ts", 16 | "src/**/*.d.ts" 17 | ] 18 | } 19 | -------------------------------------------------------------------------------- /src/main.ts: -------------------------------------------------------------------------------- 1 | import { enableProdMode } from '@angular/core'; 2 | import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; 3 | 4 | import { AppModule } from './app/app.module'; 5 | import { environment } from './environments/environment'; 6 | 7 | if (environment.production) { 8 | enableProdMode(); 9 | } 10 | 11 | platformBrowserDynamic().bootstrapModule(AppModule) 12 | .catch(err => console.error(err)); 13 | -------------------------------------------------------------------------------- /browserslist: -------------------------------------------------------------------------------- 1 | # This file is used by the build system to adjust CSS and JS output to support the specified browsers below. 2 | # For additional information regarding the format and rule options, please see: 3 | # https://github.com/browserslist/browserslist#queries 4 | 5 | # You can see what browsers were selected by your queries by running: 6 | # npx browserslist 7 | 8 | > 0.5% 9 | last 2 versions 10 | Firefox ESR 11 | not dead 12 | not IE 9-11 # For IE 9-11 support, remove 'not'. -------------------------------------------------------------------------------- /src/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | DijkstraVisualiser 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compileOnSave": false, 3 | "compilerOptions": { 4 | "baseUrl": "./", 5 | "outDir": "./dist/out-tsc", 6 | "sourceMap": true, 7 | "declaration": false, 8 | "downlevelIteration": true, 9 | "experimentalDecorators": true, 10 | "module": "esnext", 11 | "moduleResolution": "node", 12 | "importHelpers": true, 13 | "target": "es2015", 14 | "lib": [ 15 | "es2018", 16 | "dom" 17 | ] 18 | }, 19 | "angularCompilerOptions": { 20 | "fullTemplateTypeCheck": true, 21 | "strictInjectionParameters": true 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/environments/environment.ts: -------------------------------------------------------------------------------- 1 | // This file can be replaced during build by using the `fileReplacements` array. 2 | // `ng build --prod` replaces `environment.ts` with `environment.prod.ts`. 3 | // The list of file replacements can be found in `angular.json`. 4 | 5 | export const environment = { 6 | production: false 7 | }; 8 | 9 | /* 10 | * For easier debugging in development mode, you can import the following file 11 | * to ignore zone related error stack frames such as `zone.run`, `zoneDelegate.invokeTask`. 12 | * 13 | * This import should be commented out in production mode because it will have a negative impact 14 | * on performance if an error is thrown. 15 | */ 16 | // import 'zone.js/dist/zone-error'; // Included with Angular CLI. 17 | -------------------------------------------------------------------------------- /e2e/src/app.e2e-spec.ts: -------------------------------------------------------------------------------- 1 | import { AppPage } from './app.po'; 2 | import { browser, logging } from 'protractor'; 3 | 4 | describe('workspace-project App', () => { 5 | let page: AppPage; 6 | 7 | beforeEach(() => { 8 | page = new AppPage(); 9 | }); 10 | 11 | it('should display welcome message', () => { 12 | page.navigateTo(); 13 | expect(page.getTitleText()).toEqual('dijkstra-visualiser app is running!'); 14 | }); 15 | 16 | afterEach(async () => { 17 | // Assert that there are no errors emitted from the browser 18 | const logs = await browser.manage().logs().get(logging.Type.BROWSER); 19 | expect(logs).not.toContain(jasmine.objectContaining({ 20 | level: logging.Level.SEVERE, 21 | } as logging.Entry)); 22 | }); 23 | }); 24 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # See http://help.github.com/ignore-files/ for more about ignoring files. 2 | 3 | # compiled output 4 | /dist 5 | /tmp 6 | /out-tsc 7 | # Only exists if Bazel was run 8 | /bazel-out 9 | 10 | # dependencies 11 | /node_modules 12 | 13 | # profiling files 14 | chrome-profiler-events*.json 15 | speed-measure-plugin*.json 16 | 17 | # IDEs and editors 18 | /.idea 19 | .project 20 | .classpath 21 | .c9/ 22 | *.launch 23 | .settings/ 24 | *.sublime-workspace 25 | 26 | # IDE - VSCode 27 | .vscode/* 28 | !.vscode/settings.json 29 | !.vscode/tasks.json 30 | !.vscode/launch.json 31 | !.vscode/extensions.json 32 | .history/* 33 | 34 | # misc 35 | /.sass-cache 36 | /connect.lock 37 | /coverage 38 | /libpeerconnection.log 39 | npm-debug.log 40 | yarn-error.log 41 | testem.log 42 | /typings 43 | 44 | # System Files 45 | .DS_Store 46 | Thumbs.db 47 | -------------------------------------------------------------------------------- /src/test.ts: -------------------------------------------------------------------------------- 1 | // This file is required by karma.conf.js and loads recursively all the .spec and framework files 2 | 3 | import 'zone.js/dist/zone-testing'; 4 | import { getTestBed } from '@angular/core/testing'; 5 | import { 6 | BrowserDynamicTestingModule, 7 | platformBrowserDynamicTesting 8 | } from '@angular/platform-browser-dynamic/testing'; 9 | 10 | declare const require: { 11 | context(path: string, deep?: boolean, filter?: RegExp): { 12 | keys(): string[]; 13 | (id: string): T; 14 | }; 15 | }; 16 | 17 | // First, initialize the Angular testing environment. 18 | getTestBed().initTestEnvironment( 19 | BrowserDynamicTestingModule, 20 | platformBrowserDynamicTesting() 21 | ); 22 | // Then we find all the tests. 23 | const context = require.context('./', true, /\.spec\.ts$/); 24 | // And load the modules. 25 | context.keys().map(context); 26 | -------------------------------------------------------------------------------- /e2e/protractor.conf.js: -------------------------------------------------------------------------------- 1 | // @ts-check 2 | // Protractor configuration file, see link for more information 3 | // https://github.com/angular/protractor/blob/master/lib/config.ts 4 | 5 | const { SpecReporter } = require('jasmine-spec-reporter'); 6 | 7 | /** 8 | * @type { import("protractor").Config } 9 | */ 10 | exports.config = { 11 | allScriptsTimeout: 11000, 12 | specs: [ 13 | './src/**/*.e2e-spec.ts' 14 | ], 15 | capabilities: { 16 | browserName: 'chrome' 17 | }, 18 | directConnect: true, 19 | baseUrl: 'http://localhost:4200/', 20 | framework: 'jasmine', 21 | jasmineNodeOpts: { 22 | showColors: true, 23 | defaultTimeoutInterval: 30000, 24 | print: function() {} 25 | }, 26 | onPrepare() { 27 | require('ts-node').register({ 28 | project: require('path').join(__dirname, './tsconfig.json') 29 | }); 30 | jasmine.getEnv().addReporter(new SpecReporter({ spec: { displayStacktrace: true } })); 31 | } 32 | }; -------------------------------------------------------------------------------- /src/app/grid/grid.component.css: -------------------------------------------------------------------------------- 1 | .row { 2 | display: flex; 3 | margin: 0 auto; 4 | max-width: 100%; 5 | } 6 | 7 | .cell { 8 | min-width: 0; 9 | width: 100%; 10 | height: 100%; 11 | border-radius: 0; 12 | background-color: tomato; 13 | } 14 | 15 | .left-col { 16 | width: 3rem; 17 | } 18 | 19 | div .mat-flat-button { 20 | margin: 0 1rem; 21 | } 22 | 23 | .mat-fab { 24 | margin: 0 1rem; 25 | } 26 | 27 | .spacer { 28 | float: right; 29 | } 30 | 31 | .blocked { 32 | background-color: black; 33 | } 34 | 35 | .source { 36 | background-color: chartreuse; 37 | } 38 | 39 | .dest { 40 | background-color: crimson; 41 | } 42 | 43 | .mat-radio-button { 44 | margin: 0 1rem; 45 | } 46 | 47 | .column { 48 | display: block; 49 | margin-top: 1rem; 50 | margin-bottom: 1rem; 51 | } 52 | 53 | table { 54 | text-align: center; 55 | } 56 | 57 | .mat-grid-list { 58 | text-align: center; 59 | margin: 2rem auto; 60 | } 61 | 62 | .visited { 63 | background-color: blue; 64 | } 65 | 66 | .on-path { 67 | background-color: yellow; 68 | } 69 | -------------------------------------------------------------------------------- /src/app/app.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { TestBed, async } from '@angular/core/testing'; 2 | import { AppComponent } from './app.component'; 3 | 4 | describe('AppComponent', () => { 5 | beforeEach(async(() => { 6 | TestBed.configureTestingModule({ 7 | declarations: [ 8 | AppComponent 9 | ], 10 | }).compileComponents(); 11 | })); 12 | 13 | it('should create the app', () => { 14 | const fixture = TestBed.createComponent(AppComponent); 15 | const app = fixture.componentInstance; 16 | expect(app).toBeTruthy(); 17 | }); 18 | 19 | it(`should have as title 'dijkstra-visualiser'`, () => { 20 | const fixture = TestBed.createComponent(AppComponent); 21 | const app = fixture.componentInstance; 22 | expect(app.title).toEqual('dijkstra-visualiser'); 23 | }); 24 | 25 | it('should render title', () => { 26 | const fixture = TestBed.createComponent(AppComponent); 27 | fixture.detectChanges(); 28 | const compiled = fixture.nativeElement; 29 | expect(compiled.querySelector('.content span').textContent).toContain('dijkstra-visualiser app is running!'); 30 | }); 31 | }); 32 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # DijkstraVisualiser 2 | 3 | This project was generated with [Angular CLI](https://github.com/angular/angular-cli) version 9.1.8. 4 | 5 | ## Development server 6 | 7 | Run `ng serve` for a dev server. Navigate to `http://localhost:4200/`. The app will automatically reload if you change any of the source files. 8 | 9 | ## Code scaffolding 10 | 11 | Run `ng generate component component-name` to generate a new component. You can also use `ng generate directive|pipe|service|class|guard|interface|enum|module`. 12 | 13 | ## Build 14 | 15 | Run `ng build` to build the project. The build artifacts will be stored in the `dist/` directory. Use the `--prod` flag for a production build. 16 | 17 | ## Running unit tests 18 | 19 | Run `ng test` to execute the unit tests via [Karma](https://karma-runner.github.io). 20 | 21 | ## Running end-to-end tests 22 | 23 | Run `ng e2e` to execute the end-to-end tests via [Protractor](http://www.protractortest.org/). 24 | 25 | ## Further help 26 | 27 | To get more help on the Angular CLI use `ng help` or go check out the [Angular CLI README](https://github.com/angular/angular-cli/blob/master/README.md). 28 | -------------------------------------------------------------------------------- /karma.conf.js: -------------------------------------------------------------------------------- 1 | // Karma configuration file, see link for more information 2 | // https://karma-runner.github.io/1.0/config/configuration-file.html 3 | 4 | module.exports = function (config) { 5 | config.set({ 6 | basePath: '', 7 | frameworks: ['jasmine', '@angular-devkit/build-angular'], 8 | plugins: [ 9 | require('karma-jasmine'), 10 | require('karma-chrome-launcher'), 11 | require('karma-jasmine-html-reporter'), 12 | require('karma-coverage-istanbul-reporter'), 13 | require('@angular-devkit/build-angular/plugins/karma') 14 | ], 15 | client: { 16 | clearContext: false // leave Jasmine Spec Runner output visible in browser 17 | }, 18 | coverageIstanbulReporter: { 19 | dir: require('path').join(__dirname, './coverage/dijkstra-visualiser'), 20 | reports: ['html', 'lcovonly', 'text-summary'], 21 | fixWebpackSourcePaths: true 22 | }, 23 | reporters: ['progress', 'kjhtml'], 24 | port: 9876, 25 | colors: true, 26 | logLevel: config.LOG_INFO, 27 | autoWatch: true, 28 | browsers: ['Chrome'], 29 | singleRun: false, 30 | restartOnFileChange: true 31 | }); 32 | }; 33 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "dijkstra-visualiser", 3 | "version": "0.0.0", 4 | "scripts": { 5 | "ng": "ng", 6 | "start": "ng serve", 7 | "build": "ng build", 8 | "test": "ng test", 9 | "lint": "ng lint", 10 | "e2e": "ng e2e" 11 | }, 12 | "private": true, 13 | "dependencies": { 14 | "@angular/animations": "~9.1.11", 15 | "@angular/cdk": "^9.2.4", 16 | "@angular/common": "~9.1.11", 17 | "@angular/compiler": "~9.1.11", 18 | "@angular/core": "~9.1.11", 19 | "@angular/forms": "~9.1.11", 20 | "@angular/material": "^9.2.4", 21 | "@angular/platform-browser": "~9.1.11", 22 | "@angular/platform-browser-dynamic": "~9.1.11", 23 | "@angular/router": "~9.1.11", 24 | "rxjs": "~6.5.4", 25 | "tslib": "^1.10.0", 26 | "zone.js": "~0.10.2" 27 | }, 28 | "devDependencies": { 29 | "@angular-devkit/build-angular": "~0.901.8", 30 | "@angular/cli": "~9.1.8", 31 | "@angular/compiler-cli": "~9.1.11", 32 | "@types/jasmine": "~3.5.0", 33 | "@types/jasminewd2": "~2.0.3", 34 | "@types/node": "^12.11.1", 35 | "angular-cli-ghpages": "^0.6.2", 36 | "codelyzer": "^5.1.2", 37 | "jasmine-core": "~3.5.0", 38 | "jasmine-spec-reporter": "~4.2.1", 39 | "karma": "~6.3.16", 40 | "karma-chrome-launcher": "~3.1.0", 41 | "karma-coverage-istanbul-reporter": "~2.1.0", 42 | "karma-jasmine": "~3.0.1", 43 | "karma-jasmine-html-reporter": "^1.4.2", 44 | "protractor": "~7.0.0", 45 | "ts-node": "~8.3.0", 46 | "tslint": "~6.1.0", 47 | "typescript": "~3.8.3" 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/app/app.module.ts: -------------------------------------------------------------------------------- 1 | import { BrowserModule } from '@angular/platform-browser'; 2 | import { NgModule } from '@angular/core'; 3 | import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; 4 | 5 | import { AppComponent } from './app.component'; 6 | import { HeaderComponent } from './header/header.component'; 7 | import { GridComponent } from './grid/grid.component'; 8 | 9 | import { MatToolbarModule } from '@angular/material/toolbar'; 10 | import { MatButtonModule } from '@angular/material/button'; 11 | import { MatRadioModule } from '@angular/material/radio'; 12 | import { FormsModule } from '@angular/forms'; 13 | import { MatCardModule } from '@angular/material/card'; 14 | import { MatGridListModule } from '@angular/material/grid-list'; 15 | import { MatIconModule } from '@angular/material/icon'; 16 | import { MatDividerModule } from '@angular/material/divider'; 17 | import { MatSliderModule } from '@angular/material/slider'; 18 | import { MatExpansionModule } from '@angular/material/expansion'; 19 | 20 | 21 | @NgModule({ 22 | declarations: [ 23 | AppComponent, 24 | GridComponent, 25 | HeaderComponent 26 | ], 27 | imports: [ 28 | BrowserModule, 29 | BrowserAnimationsModule, 30 | MatToolbarModule, 31 | MatButtonModule, 32 | MatRadioModule, 33 | FormsModule, 34 | MatCardModule, 35 | MatGridListModule, 36 | MatIconModule, 37 | MatDividerModule, 38 | MatSliderModule, 39 | MatExpansionModule 40 | ], 41 | providers: [], 42 | bootstrap: [AppComponent] 43 | }) 44 | export class AppModule { } 45 | -------------------------------------------------------------------------------- /src/app/grid/min-heap.ts: -------------------------------------------------------------------------------- 1 | interface HeapNode { 2 | distance: number, 3 | x: number, 4 | y: number 5 | }; 6 | 7 | export class MinHeap { 8 | private heap: Array = []; 9 | 10 | empty() { 11 | return (this.heap.length == 0); 12 | } 13 | 14 | swap(val1: number, val2: number) { 15 | let tmp = this.heap[val1]; 16 | this.heap[val1] = this.heap[val2]; 17 | this.heap[val2] = tmp; 18 | } 19 | 20 | push(distance: number, x: number, y: number) { 21 | this.heap.push({ 22 | distance: distance, 23 | x: x, 24 | y: y 25 | }); 26 | let cur = this.heap.length - 1; 27 | 28 | while (cur > 0) { 29 | let par = Math.floor((cur - 1) / 2); 30 | // check if cur is greater than par 31 | if (this.heap[cur].distance >= this.heap[par].distance) { 32 | return ; 33 | } 34 | this.swap(cur, par); 35 | cur = par; 36 | } 37 | } 38 | 39 | 40 | pop(): HeapNode { 41 | if (this.empty()) { 42 | return null; 43 | } 44 | 45 | let ret = {...this.heap[0]}; 46 | this.swap(0, this.heap.length - 1); 47 | this.heap.pop(); 48 | const n = this.heap.length; 49 | let cur = 0; 50 | 51 | while (1) { 52 | let left = 2 * cur + 1; 53 | let right = left + 1; 54 | // if this is a leaf node, return 55 | if (left >= n) { 56 | return ret; 57 | } 58 | // if only left child is present 59 | if (right >= n) { 60 | if (this.heap[left].distance >= this.heap[cur].distance) { 61 | return ret; 62 | } 63 | this.swap(left, cur); 64 | cur = left; 65 | continue; 66 | } 67 | // both children are present 68 | // check if cur is smaller than both 69 | if (this.heap[cur].distance <= Math.min(this.heap[left].distance, this.heap[right].distance)) { 70 | return ret; 71 | } 72 | // need to swap with smaller child 73 | if (this.heap[left].distance <= this.heap[right].distance) { 74 | this.swap(cur, left); 75 | cur = left; 76 | continue; 77 | } else { 78 | this.swap(cur, right); 79 | cur = right; 80 | continue; 81 | } 82 | } 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /src/app/grid/dijkstra.ts: -------------------------------------------------------------------------------- 1 | import { Node } from './node.model'; 2 | import { MinHeap } from './min-heap'; 3 | 4 | export class Dijkstra { 5 | private grid: Node[][]; 6 | 7 | delay(ms) { 8 | return new Promise(resolve => setTimeout(resolve, ms)); 9 | } 10 | 11 | validCordinate(x: number, y: number) { 12 | return (x >= 0 && x < this.grid.length && y >= 0 && y < this.grid[0].length); 13 | } 14 | 15 | async animatePath(destNode: Node) { 16 | // animate formation of path 17 | let currentNode = destNode; 18 | 19 | while (currentNode) { 20 | // console.log(currentNode.x, currentNode.y); 21 | currentNode.isOnPath = true; 22 | currentNode = currentNode.parent; 23 | await this.delay(20); 24 | } 25 | } 26 | 27 | async findPath(grid: Node[][], sourceNode: Node, destNode: Node) { 28 | const dx = [-1, 1, 0, 0]; 29 | const dy = [0, 0, -1, 1]; 30 | 31 | console.log("In path function"); 32 | this.grid = grid; 33 | sourceNode.isBlocked = false; 34 | destNode.isBlocked = false; 35 | const queue = new MinHeap; 36 | sourceNode.distance = 0; 37 | queue.push(0, sourceNode.x, sourceNode.y); 38 | 39 | 40 | while (!queue.empty()) { 41 | let front = queue.pop(); 42 | let currentDistance = front.distance, cx = front.x, cy = front.y; 43 | const current = grid[cx][cy]; 44 | 45 | if (current.isColored) { 46 | continue; 47 | } 48 | 49 | current.isColored = true; 50 | await this.delay(15); 51 | 52 | if (current == destNode) { 53 | break; 54 | } 55 | 56 | for (var i = 0; i < 4; ++i) { 57 | let nextX = cx + dx[i]; 58 | let nextY = cy + dy[i]; 59 | if (!this.validCordinate(nextX, nextY)) { 60 | continue; 61 | } 62 | const nextNode = grid[nextX][nextY]; 63 | if (nextNode.isBlocked) { 64 | continue; 65 | } 66 | if (nextNode.distance == -1 || currentDistance + current.weight < nextNode.distance) { 67 | nextNode.distance = currentDistance + current.weight; 68 | nextNode.parent = current; 69 | queue.push(nextNode.distance, nextNode.x, nextNode.y); 70 | } 71 | } 72 | } 73 | 74 | if (destNode.isColored) { 75 | this.animatePath(destNode); 76 | } else { 77 | alert('No path to destination!'); 78 | } 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /src/polyfills.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * This file includes polyfills needed by Angular and is loaded before the app. 3 | * You can add your own extra polyfills to this file. 4 | * 5 | * This file is divided into 2 sections: 6 | * 1. Browser polyfills. These are applied before loading ZoneJS and are sorted by browsers. 7 | * 2. Application imports. Files imported after ZoneJS that should be loaded before your main 8 | * file. 9 | * 10 | * The current setup is for so-called "evergreen" browsers; the last versions of browsers that 11 | * automatically update themselves. This includes Safari >= 10, Chrome >= 55 (including Opera), 12 | * Edge >= 13 on the desktop, and iOS 10 and Chrome on mobile. 13 | * 14 | * Learn more in https://angular.io/guide/browser-support 15 | */ 16 | 17 | /*************************************************************************************************** 18 | * BROWSER POLYFILLS 19 | */ 20 | 21 | /** IE10 and IE11 requires the following for NgClass support on SVG elements */ 22 | // import 'classlist.js'; // Run `npm install --save classlist.js`. 23 | 24 | /** 25 | * Web Animations `@angular/platform-browser/animations` 26 | * Only required if AnimationBuilder is used within the application and using IE/Edge or Safari. 27 | * Standard animation support in Angular DOES NOT require any polyfills (as of Angular 6.0). 28 | */ 29 | // import 'web-animations-js'; // Run `npm install --save web-animations-js`. 30 | 31 | /** 32 | * By default, zone.js will patch all possible macroTask and DomEvents 33 | * user can disable parts of macroTask/DomEvents patch by setting following flags 34 | * because those flags need to be set before `zone.js` being loaded, and webpack 35 | * will put import in the top of bundle, so user need to create a separate file 36 | * in this directory (for example: zone-flags.ts), and put the following flags 37 | * into that file, and then add the following code before importing zone.js. 38 | * import './zone-flags'; 39 | * 40 | * The flags allowed in zone-flags.ts are listed here. 41 | * 42 | * The following flags will work for all browsers. 43 | * 44 | * (window as any).__Zone_disable_requestAnimationFrame = true; // disable patch requestAnimationFrame 45 | * (window as any).__Zone_disable_on_property = true; // disable patch onProperty such as onclick 46 | * (window as any).__zone_symbol__UNPATCHED_EVENTS = ['scroll', 'mousemove']; // disable patch specified eventNames 47 | * 48 | * in IE/Edge developer tools, the addEventListener will also be wrapped by zone.js 49 | * with the following flag, it will bypass `zone.js` patch for IE/Edge 50 | * 51 | * (window as any).__Zone_enable_cross_context_check = true; 52 | * 53 | */ 54 | 55 | /*************************************************************************************************** 56 | * Zone JS is required by default for Angular itself. 57 | */ 58 | import 'zone.js/dist/zone'; // Included with Angular CLI. 59 | 60 | 61 | /*************************************************************************************************** 62 | * APPLICATION IMPORTS 63 | */ 64 | -------------------------------------------------------------------------------- /tslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "tslint:recommended", 3 | "rules": { 4 | "align": { 5 | "options": [ 6 | "parameters", 7 | "statements" 8 | ] 9 | }, 10 | "array-type": false, 11 | "arrow-return-shorthand": true, 12 | "curly": true, 13 | "deprecation": { 14 | "severity": "warning" 15 | }, 16 | "component-class-suffix": true, 17 | "contextual-lifecycle": true, 18 | "directive-class-suffix": true, 19 | "directive-selector": [ 20 | true, 21 | "attribute", 22 | "app", 23 | "camelCase" 24 | ], 25 | "component-selector": [ 26 | true, 27 | "element", 28 | "app", 29 | "kebab-case" 30 | ], 31 | "eofline": true, 32 | "import-blacklist": [ 33 | true, 34 | "rxjs/Rx" 35 | ], 36 | "import-spacing": true, 37 | "indent": { 38 | "options": [ 39 | "spaces" 40 | ] 41 | }, 42 | "max-classes-per-file": false, 43 | "max-line-length": [ 44 | true, 45 | 140 46 | ], 47 | "member-ordering": [ 48 | true, 49 | { 50 | "order": [ 51 | "static-field", 52 | "instance-field", 53 | "static-method", 54 | "instance-method" 55 | ] 56 | } 57 | ], 58 | "no-console": [ 59 | true, 60 | "debug", 61 | "info", 62 | "time", 63 | "timeEnd", 64 | "trace" 65 | ], 66 | "no-empty": false, 67 | "no-inferrable-types": [ 68 | true, 69 | "ignore-params" 70 | ], 71 | "no-non-null-assertion": true, 72 | "no-redundant-jsdoc": true, 73 | "no-switch-case-fall-through": true, 74 | "no-var-requires": false, 75 | "object-literal-key-quotes": [ 76 | true, 77 | "as-needed" 78 | ], 79 | "quotemark": [ 80 | true, 81 | "single" 82 | ], 83 | "semicolon": { 84 | "options": [ 85 | "always" 86 | ] 87 | }, 88 | "space-before-function-paren": { 89 | "options": { 90 | "anonymous": "never", 91 | "asyncArrow": "always", 92 | "constructor": "never", 93 | "method": "never", 94 | "named": "never" 95 | } 96 | }, 97 | "typedef-whitespace": { 98 | "options": [ 99 | { 100 | "call-signature": "nospace", 101 | "index-signature": "nospace", 102 | "parameter": "nospace", 103 | "property-declaration": "nospace", 104 | "variable-declaration": "nospace" 105 | }, 106 | { 107 | "call-signature": "onespace", 108 | "index-signature": "onespace", 109 | "parameter": "onespace", 110 | "property-declaration": "onespace", 111 | "variable-declaration": "onespace" 112 | } 113 | ] 114 | }, 115 | "variable-name": { 116 | "options": [ 117 | "ban-keywords", 118 | "check-format", 119 | "allow-pascal-case" 120 | ] 121 | }, 122 | "whitespace": { 123 | "options": [ 124 | "check-branch", 125 | "check-decl", 126 | "check-operator", 127 | "check-separator", 128 | "check-type", 129 | "check-typecast" 130 | ] 131 | }, 132 | "no-conflicting-lifecycle": true, 133 | "no-host-metadata-property": true, 134 | "no-input-rename": true, 135 | "no-inputs-metadata-property": true, 136 | "no-output-native": true, 137 | "no-output-on-prefix": true, 138 | "no-output-rename": true, 139 | "no-outputs-metadata-property": true, 140 | "template-banana-in-box": true, 141 | "template-no-negated-async": true, 142 | "use-lifecycle-interface": true, 143 | "use-pipe-transform-interface": true 144 | }, 145 | "rulesDirectory": [ 146 | "codelyzer" 147 | ] 148 | } -------------------------------------------------------------------------------- /src/app/grid/grid.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit, Input } from '@angular/core'; 2 | 3 | import { Node } from './node.model'; 4 | import { Dijkstra } from './dijkstra'; 5 | import { MazePartation } from './maze-partation'; 6 | 7 | @Component({ 8 | selector: 'app-grid', 9 | templateUrl: './grid.component.html', 10 | styleUrls: ['./grid.component.css'] 11 | }) 12 | export class GridComponent implements OnInit{ 13 | height = 13; 14 | width = 45; 15 | grid: Node[][]; 16 | sourceNode: Node; 17 | destNode: Node; 18 | editMode = "AddWall"; 19 | mouseDown = false; 20 | dijkstra: Dijkstra; 21 | grid1D: Node[]; 22 | weightSlider = 20; 23 | draggingSource = false; 24 | draggingDest = false; 25 | instructionOpenState = false; 26 | maze: MazePartation; 27 | 28 | getClass(node: Node) { 29 | if (node == this.sourceNode) { 30 | return 'source'; 31 | } else if (node == this.destNode) { 32 | return 'dest'; 33 | } else if (node.isOnPath) { 34 | return 'on-path'; 35 | } else if (node.isColored) { 36 | return 'visited'; 37 | } else if (node.isBlocked) { 38 | return 'blocked'; 39 | } 40 | return ''; 41 | } 42 | 43 | getCellText(node: Node) { 44 | if (node == this.sourceNode) { 45 | return 'S'; 46 | } else if (node == this.destNode) { 47 | return 'D'; 48 | } 49 | return ''; 50 | } 51 | 52 | onMouseDown() { 53 | this.mouseDown = true; 54 | // console.log(this.mouseDown); 55 | } 56 | 57 | onMouseUp() { 58 | this.mouseDown = false; 59 | this.draggingSource = false; 60 | this.draggingDest = false; 61 | // console.log(this.mouseDown); 62 | } 63 | 64 | onMovement(node: Node, isClick: boolean = false) { 65 | if (!isClick && !this.mouseDown) { 66 | return ; 67 | } 68 | if (this.draggingSource) { 69 | this.sourceNode = node; 70 | } else if (this.draggingDest) { 71 | this.destNode = node; 72 | } else if (node == this.sourceNode) { 73 | this.draggingSource = true; 74 | } else if (node == this.destNode) { 75 | this.draggingDest = true; 76 | } else if (this.editMode === 'RemoveWall') { 77 | node.isBlocked = false; 78 | } else if (this.editMode === 'AddWeight') { 79 | node.weight = this.weightSlider ; 80 | } else if (this.editMode === 'AddWall'){ 81 | node.isBlocked = true; 82 | } 83 | } 84 | 85 | findPath() { 86 | this.dijkstra.findPath(this.grid, this.sourceNode, this.destNode); 87 | } 88 | 89 | reinit() { 90 | this.grid1D = []; 91 | this.grid = new Array(this.height); 92 | for (var i = 0; i < this.height; ++i) { 93 | this.grid[i] = new Array(this.width); 94 | 95 | for (var j = 0; j < this.width; ++j) { 96 | this.grid[i][j] = { 97 | isBlocked: false, 98 | x: i, 99 | y: j, 100 | distance: -1, 101 | isColored: false, 102 | isOnPath: false, 103 | parent: null, 104 | weight: 1 105 | }; 106 | } 107 | this.grid1D = this.grid1D.concat(this.grid[i]); 108 | } 109 | 110 | this.sourceNode = this.grid[Math.floor(this.height/2)][1]; 111 | this.destNode = this.grid[Math.floor(this.height/2)][this.width-2]; 112 | } 113 | 114 | randomWeights() { 115 | for (let i = 0; i < this.height; ++i) { 116 | for (let j = 0; j < this.width; ++j) { 117 | this.grid[i][j].weight = Math.ceil(Math.random() * 100); 118 | } 119 | } 120 | } 121 | 122 | randomWalls() { 123 | for (let i = 0; i < this.height; ++i) { 124 | for (let j = 0; j < this.width; ++j) { 125 | this.grid[i][j].isBlocked = false; 126 | } 127 | } 128 | this.maze.mazify(this.grid); 129 | } 130 | 131 | ngOnInit() { 132 | this.dijkstra = new Dijkstra; 133 | this.maze = new MazePartation; 134 | this.reinit(); 135 | } 136 | } 137 | -------------------------------------------------------------------------------- /angular.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "./node_modules/@angular/cli/lib/config/schema.json", 3 | "version": 1, 4 | "newProjectRoot": "projects", 5 | "projects": { 6 | "dijkstra-visualiser": { 7 | "projectType": "application", 8 | "schematics": {}, 9 | "root": "", 10 | "sourceRoot": "src", 11 | "prefix": "app", 12 | "architect": { 13 | "build": { 14 | "builder": "@angular-devkit/build-angular:browser", 15 | "options": { 16 | "outputPath": "dist/dijkstra-visualiser", 17 | "index": "src/index.html", 18 | "main": "src/main.ts", 19 | "polyfills": "src/polyfills.ts", 20 | "tsConfig": "tsconfig.app.json", 21 | "aot": true, 22 | "assets": [ 23 | "src/favicon.ico", 24 | "src/assets" 25 | ], 26 | "styles": [ 27 | "./node_modules/@angular/material/prebuilt-themes/deeppurple-amber.css", 28 | "src/styles.css" 29 | ], 30 | "scripts": [] 31 | }, 32 | "configurations": { 33 | "production": { 34 | "fileReplacements": [ 35 | { 36 | "replace": "src/environments/environment.ts", 37 | "with": "src/environments/environment.prod.ts" 38 | } 39 | ], 40 | "optimization": true, 41 | "outputHashing": "all", 42 | "sourceMap": false, 43 | "extractCss": true, 44 | "namedChunks": false, 45 | "extractLicenses": true, 46 | "vendorChunk": false, 47 | "buildOptimizer": true, 48 | "budgets": [ 49 | { 50 | "type": "initial", 51 | "maximumWarning": "2mb", 52 | "maximumError": "5mb" 53 | }, 54 | { 55 | "type": "anyComponentStyle", 56 | "maximumWarning": "6kb", 57 | "maximumError": "10kb" 58 | } 59 | ] 60 | } 61 | } 62 | }, 63 | "serve": { 64 | "builder": "@angular-devkit/build-angular:dev-server", 65 | "options": { 66 | "browserTarget": "dijkstra-visualiser:build" 67 | }, 68 | "configurations": { 69 | "production": { 70 | "browserTarget": "dijkstra-visualiser:build:production" 71 | } 72 | } 73 | }, 74 | "extract-i18n": { 75 | "builder": "@angular-devkit/build-angular:extract-i18n", 76 | "options": { 77 | "browserTarget": "dijkstra-visualiser:build" 78 | } 79 | }, 80 | "test": { 81 | "builder": "@angular-devkit/build-angular:karma", 82 | "options": { 83 | "main": "src/test.ts", 84 | "polyfills": "src/polyfills.ts", 85 | "tsConfig": "tsconfig.spec.json", 86 | "karmaConfig": "karma.conf.js", 87 | "assets": [ 88 | "src/favicon.ico", 89 | "src/assets" 90 | ], 91 | "styles": [ 92 | "./node_modules/@angular/material/prebuilt-themes/deeppurple-amber.css", 93 | "src/styles.css" 94 | ], 95 | "scripts": [] 96 | } 97 | }, 98 | "lint": { 99 | "builder": "@angular-devkit/build-angular:tslint", 100 | "options": { 101 | "tsConfig": [ 102 | "tsconfig.app.json", 103 | "tsconfig.spec.json", 104 | "e2e/tsconfig.json" 105 | ], 106 | "exclude": [ 107 | "**/node_modules/**" 108 | ] 109 | } 110 | }, 111 | "e2e": { 112 | "builder": "@angular-devkit/build-angular:protractor", 113 | "options": { 114 | "protractorConfig": "e2e/protractor.conf.js", 115 | "devServerTarget": "dijkstra-visualiser:serve" 116 | }, 117 | "configurations": { 118 | "production": { 119 | "devServerTarget": "dijkstra-visualiser:serve:production" 120 | } 121 | } 122 | }, 123 | "deploy": { 124 | "builder": "angular-cli-ghpages:deploy", 125 | "options": {} 126 | } 127 | } 128 | } 129 | }, 130 | "defaultProject": "dijkstra-visualiser" 131 | } -------------------------------------------------------------------------------- /src/app/grid/grid.component.html: -------------------------------------------------------------------------------- 1 | 2 | 3 |
4 | Rows: 5 | 11 | 12 | 13 | Columns: 14 | 20 | 21 | 22 | Weight: 23 | 29 | 30 | 36 | 42 |
43 | 44 | 45 | 46 |
47 | 50 | Add Walls 51 | Remove Walls 52 | Add Weights 53 | 54 | 55 | Assign Random: 56 | 57 | 60 | 61 | 64 | 65 |
66 | 67 | 68 | 69 | 73 | 76 | 82 | 83 | 84 | 85 | 86 | 87 | 88 |

Instructions

89 |
90 |
91 | Drag source and destination to change them 92 |

93 | Select the current edit mode using the radio buttons provided 94 | To edit the grid simply click or drag over the cells you want to add/remove a wall or add a weight to 95 |

96 |

Symbols and their meanings:

97 |

98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 |
SymbolMeaning
Source Cell
Destination Cell
Explored Cell
Unvisited Cell
On the shortest path from source to destination
Blocked Cell
fitness_centerWeight of cell, larger size indicates higher weight
navigationStart simulation
refreshReset simulation
141 |
142 |
143 |
144 | -------------------------------------------------------------------------------- /src/app/grid/maze-partation.ts: -------------------------------------------------------------------------------- 1 | import { Node } from './node.model'; 2 | import { partition } from 'rxjs'; 3 | 4 | interface Hole { 5 | x: number; 6 | y: number; 7 | }; 8 | 9 | const timeDelay = 40; 10 | 11 | export class MazePartation { 12 | private grid: Node[][]; 13 | 14 | delay(ms) { 15 | return new Promise(resolve => setTimeout(resolve, ms)); 16 | } 17 | 18 | // generates a random value in the range [minVal, maxVal] 19 | random(minVal: number, maxVal: number) { 20 | return minVal + Math.floor(Math.random() * (maxVal - minVal)); 21 | } 22 | 23 | validCordinate(x: number, y: number) { 24 | return (x >= 0 && x < this.grid.length && y >= 0 && y < this.grid[0].length); 25 | } 26 | 27 | async partition(startX: number, endX: number, startY: number, endY: number) { 28 | const vRange = endX - startX - 1; 29 | let hCut: number; 30 | if (vRange >= 1) { 31 | hCut = this.random(startX + 1, endX - 1); 32 | // make the horizontal cut 33 | // check if first cell doesn't block a gap in a vertical wall 34 | // only then build a wall 35 | if (!this.validCordinate(hCut, startY - 1) || this.grid[hCut][startY - 1].isBlocked) { 36 | this.grid[hCut][startY].isBlocked = true; 37 | await this.delay(timeDelay); 38 | } 39 | 40 | for (let j = startY + 1; j <= endY - 1; ++j) { 41 | this.grid[hCut][j].isBlocked = true; 42 | await this.delay(timeDelay); 43 | } 44 | 45 | // check if last cell doesn't block a gap in a vertical wall 46 | // only then build a wall 47 | if (!this.validCordinate(hCut, endY + 1) || this.grid[hCut][endY + 1].isBlocked) { 48 | this.grid[hCut][endY].isBlocked = true; 49 | await this.delay(timeDelay); 50 | } 51 | } 52 | 53 | let vCut: number; 54 | const hRange = endY - startY - 1; 55 | if (hRange >= 1) { 56 | vCut = this.random(startY + 1, endY - 1); 57 | // make the vertical cut 58 | // check if first cell doesn't block a gap in a horizontal wall 59 | // only then build a wall 60 | if (!this.validCordinate(startX - 1, vCut) || this.grid[startX - 1][vCut].isBlocked) { 61 | this.grid[startX][vCut].isBlocked = true; 62 | await this.delay(timeDelay); 63 | } 64 | 65 | for (let i = startX + 1; i < endX; ++i) { 66 | this.grid[i][vCut].isBlocked = true; 67 | await this.delay(timeDelay); 68 | } 69 | 70 | // check if last cell doesn't block a gap in a horizontal wall 71 | // only then build a wall 72 | if (!this.validCordinate(endX + 1, vCut) || this.grid[endX + 1][vCut].isBlocked) { 73 | this.grid[endX][vCut].isBlocked = true; 74 | await this.delay(timeDelay); 75 | } 76 | } 77 | 78 | // Base condition 79 | // if you made 0 cuts, return 80 | if (vRange < 1 && hRange < 1) { 81 | return ; 82 | } 83 | 84 | // if you made 1 cut, need to unblock one cell and recurse 85 | if (vRange < 1) { 86 | // this means hRange >=1 and we only made a vertical cut 87 | // generate a number to make a hole in the vertical wall 88 | const hole = this.random(startX, endX); 89 | this.grid[hole][vCut].isBlocked = false; 90 | this.partition(startX, endX, startY, vCut - 1); 91 | this.partition(startX, endX, vCut + 1, endY); 92 | return ; 93 | } 94 | 95 | if (hRange < 1) { 96 | // this means vRange >=1 and we only made a horizontal cut 97 | // generate a number to make a hole in the horizontal wall 98 | const hole = this.random(startY, endY); 99 | this.grid[hCut][hole].isBlocked = false; 100 | this.partition(startX, hCut -1, startY, endY); 101 | this.partition(hCut + 1, endX, startY, endY); 102 | return ; 103 | } 104 | 105 | // we made a horizontal and vertical cut 106 | // need to generate 3 holes 107 | // to do that, we make holes in all four segments of walls 108 | // and choose one to fill back 109 | 110 | let holes: Hole[] = []; 111 | // make 2 holes in vertical wall 112 | holes.push({ 113 | x: this.random(startX, hCut - 1), 114 | y: vCut 115 | }); 116 | 117 | holes.push({ 118 | x: this.random(hCut + 1, endX), 119 | y: vCut 120 | }); 121 | 122 | // make 2 holes in horizontal wall 123 | holes.push({ 124 | x: hCut, 125 | y: this.random(startY, vCut - 1) 126 | }); 127 | holes.push({ 128 | x: hCut, 129 | y: this.random(vCut + 1, endY) 130 | }); 131 | 132 | // choose an index to leave 133 | const leaveIndex = this.random(0, 3); 134 | 135 | for (let i = 0; i < 4; ++i) { 136 | if (i != leaveIndex) { 137 | await this.delay(timeDelay); 138 | this.grid[holes[i].x][holes[i].y].isBlocked = false; 139 | } 140 | } 141 | 142 | // recurse on 4 smaller parts 143 | this.partition(startX, hCut - 1, startY, vCut - 1); 144 | this.partition(startX, hCut - 1, vCut + 1, endY); 145 | this.partition(hCut + 1, endX, startY, vCut - 1); 146 | this.partition(hCut + 1, endX, vCut + 1, endY); 147 | } 148 | 149 | mazify(grid: Node[][]) { 150 | this.grid = grid; 151 | const height = grid.length; 152 | const width = grid[0].length; 153 | 154 | this.partition(0, height - 1, 0, width - 1); 155 | } 156 | } 157 | --------------------------------------------------------------------------------