Skip to content

Commit d5397fd

Browse files
committed
Merge branch 'main' of github.com:https-sam/algorithm-visualizer
updated link to repo
2 parents 6d053d8 + 3c58dc7 commit d5397fd

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+2613
-1189
lines changed

package-lock.json

Lines changed: 894 additions & 23 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
"version": "0.1.0",
44
"private": true,
55
"dependencies": {
6+
"@react-spring/three": "^9.5.1",
7+
"@react-three/drei": "9.14.3",
68
"@splinetool/react-spline": "^2.2.1",
79
"@testing-library/jest-dom": "^5.16.4",
810
"@testing-library/react": "^13.3.0",
@@ -11,6 +13,7 @@
1113
"@types/node": "^18.0.6",
1214
"@types/react": "^18.0.15",
1315
"@types/react-dom": "^18.0.6",
16+
"@types/three": "0.141.0",
1417
"csstype": "^3.1.0",
1518
"postcss-cli": "^10.0.0",
1619
"react": "^18.2.0",
@@ -20,7 +23,6 @@
2023
"react-spring": "8.0.27",
2124
"react-three-fiber": "4.0.12",
2225
"three": "0.112.1",
23-
"typescript": "^4.7.4",
2426
"zustand": "^4.0.0-rc.1"
2527
},
2628
"devDependencies": {

src/App.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import './App.css';
2-
import React from 'react';
3-
import Display from './components/BoardCanvas/Display';
4-
import AppRouter from './AppRouter';
2+
import React from 'react';
3+
import MazeDisplay from './components/Algorithms/Maze/MazeDisplay';
4+
import AppRouter from './AppRouter';
55
import Navigation from './components/Page/partial/Navbar/Navigation';
66

77

src/AppRouter.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@ import {
77
import SplashScreen from './components/Page/Splash/SplashScreen';
88
import MainSortingCanvas from './components/Canvas/MainSortingCanvas';
99
import AboutScreen from './components/Page/About/AboutScreen';
10-
import ContactScreen from './components/Page/Contact/ContactScreen';
11-
import Display from './components/BoardCanvas/Display';
10+
import ContactScreen from './components/Page/Contact/ContactScreen';
11+
import MazeDisplay from './components/Algorithms/Maze/MazeDisplay';
12+
import DiceDisplay from './components/Algorithms/Propability/DiceDisplay';
1213

1314

1415

@@ -23,7 +24,9 @@ function AppRouter() {
2324
<Route exact path = "/dashboard"
2425
element = {<MainSortingCanvas/>}/>
2526
<Route exact path = "/dashboard-two"
26-
element = {<Display/>}/>
27+
element = {<MazeDisplay/>}/><
28+
Route exact path = "/dashboard-three"
29+
element = {<DiceDisplay/>}/>
2730
<Route path = "/about"
2831
element = {<AboutScreen/>}/>
2932
<Route path = "/contact"

src/Utility/Colors.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
export const TEST_COLOR = '#FF66CC';
2+
export const BURN_COLOR = '#fad6ee';
3+
export const PATH_COLOR = '#63caef';
4+
export const WALL_COLOR = '#624646';
5+
export const GOAL_COLOR = '#30fa04';
6+
export const START_COLOR = '#ff0000';
7+
export const SELECTED_COLOR = '#ffd300';
8+
export const FLOOR_COLOR = '#ffffff';
9+
export const DEFAULT_COLOR = '#8f8d8d';
10+
export const FLOOR_TYPE = '_floor_';
11+
export const DEFAULT_TYPE = '_default_';
12+
export const WALL_TYPE = '_wall_';
13+
export const PATH_TYPE = '_path_';
14+
export const GOAL_TYPE = '_goal_';
15+
export const START_TYPE = '_start_';
16+
export const TEST_TYPE = '_test_';
17+
18+
19+
export function getColor(type) {
20+
switch (type) {
21+
case FLOOR_TYPE:
22+
return FLOOR_COLOR;
23+
case WALL_TYPE:
24+
return WALL_COLOR;
25+
case PATH_TYPE:
26+
return PATH_COLOR;
27+
case GOAL_TYPE:
28+
return GOAL_COLOR;
29+
case START_TYPE:
30+
return START_COLOR;
31+
case TEST_TYPE:
32+
return TEST_COLOR;
33+
case DEFAULT_TYPE:
34+
return DEFAULT_COLOR;
35+
default:
36+
return '#ffffff';
37+
}
38+
}

src/Utility/PriorityQueue.js

Lines changed: 32 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,31 @@
11
// User defined class
22
// to store element and its priority
33
class CellPQPair {
4-
constructor(element, priority) {
4+
constructor(element) {
55
this.cell = element;
6-
this.priority = priority;
6+
this.priority = element.priority;
77
}
88
}
99

1010

1111

1212
// Cell PriorityQueue class
13-
class PriorityQueue {
13+
export class PriorityQueue {
1414
constructor() {
1515
this.cellContainer = [];
1616
}
1717

1818

19-
enqueue(pElement, priority) {
20-
const element = new CellPQPair(pElement, priority);
21-
var contain = false;
22-
23-
for (var i = 0; i < this.cellContainer.length; i++) {
24-
if (this.cellContainer[i].priority > element.priority) {
25-
this.cellContainer.splice(i, 0, element);
26-
contain = true;
27-
break;
28-
}
29-
}
19+
enqueue(pElement) {
20+
let cellPair = new CellPQPair(pElement);
21+
this.cellContainer.push(cellPair);
22+
this.sort();
23+
}
3024

31-
if (!contain) {
32-
this.cellContainer.push(qElement);
33-
}
25+
sort() {
26+
this.cellContainer.sort((a, b) => {
27+
return a.cell.priority - b.cell.priority;
28+
});
3429
}
3530

3631

@@ -39,7 +34,8 @@ class PriorityQueue {
3934
console.log('Queue Underflow');
4035
return null;
4136
}
42-
return this.cellContainer.shift();
37+
38+
return this.cellContainer.shift().cell;
4339
}
4440

4541

@@ -48,7 +44,7 @@ class PriorityQueue {
4844
console.log('Queue Underflow');
4945
return null;
5046
}
51-
return this.cellContainer[0].id;
47+
return this.cellContainer[0].cell.id;
5248
}
5349

5450

@@ -57,9 +53,17 @@ class PriorityQueue {
5753
console.log('Empty Queue');
5854
return null;
5955
}
60-
return this.cellContainer[0];
56+
return this.cellContainer[0].cell;
57+
}
58+
59+
has(cell) {
60+
return !!this.cellContainer.find(cell => cell.cell.id === cell.id);
61+
6162
}
6263

64+
equals(other) {
65+
return this.cellContainer.every(cell => other.has(cell.cell));
66+
}
6367

6468
isEmpty() {
6569
return (this.cellContainer === undefined || this.cellContainer.length === 0);
@@ -71,4 +75,12 @@ class PriorityQueue {
7175
console.log(element.cell + ' ' + element.priority);
7276
}.bind(this));
7377
}
78+
79+
length() {
80+
return this.cellContainer.length;
81+
}
82+
83+
clear() {
84+
this.cellContainer = [];
85+
}
7486
}

src/components/Algorithms/Display.js

Lines changed: 0 additions & 132 deletions
This file was deleted.

src/components/Algorithms/Greedy/Greedy.js

Whitespace-only changes.
Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
import * as React from 'react';
2-
import {Canvas, useFrame /*useFrame*/} from 'react-three-fiber';
3-
import Controls from './OrbitControls';
4-
import Cell from './Cells';
2+
// import {useFrame /*useFrame*/} from '@react-three/fiber';
3+
import {Canvas} from 'react-three-fiber';
4+
import Controls from '../OrbitControls';
55
import {useImperativeHandle, useRef, forwardRef} from 'react';
66
import {TrackballControls} from 'three/examples/jsm/controls/TrackballControls';
7-
import OrbitControls from './OrbitControls';
7+
import OrbitControls from '../OrbitControls';
8+
import Cells from './Cells';
89

910

10-
export const Board = ({board, layoutType, selectedPoint, onSelectPoint, mazeType}, ref) => {
11+
12+
13+
export const Board = ({board, solving, algorithm, layoutType, selectedPoint, onSelectPoint, mazeType}, ref) => {
14+
// Based on Peter Beshai's grid example:
1115
const controlsRef = useRef(OrbitControls);
1216

1317

@@ -19,16 +23,10 @@ export const Board = ({board, layoutType, selectedPoint, onSelectPoint, mazeType
1923

2024

2125
return (
22-
<Canvas className = "board" camera = {{position: [0, 0, 80], far: 1000}}>
26+
<Canvas>
2327
<Controls ref = {controlsRef} selectedPoint = {selectedPoint}/>
2428
<mesh> {/* BorderBox */}
25-
{(layoutType === 'standard') ?
26-
<boxBufferGeometry attach = "geometry" args = {[80, 80, -10]}/>
27-
:
28-
<boxBufferGeometry attach = "geometry" args = {[80, 80, -10]}/>
29-
30-
// <boxBufferGeometry attach = "geometry" args = {[150, 150, -10]}/>
31-
}
29+
<boxBufferGeometry attach = "geometry" args = {[80, 80, -10]}/>
3230
<meshBasicMaterial attach = "material" color = "black"/>
3331
</mesh>
3432

@@ -40,10 +38,12 @@ export const Board = ({board, layoutType, selectedPoint, onSelectPoint, mazeType
4038
groundColor = "#080820"
4139
intensity = {1.0}
4240
/>
43-
<Cell
41+
<Cells
4442
board = {board}
4543
layoutType = {layoutType}
4644
mazeType = {mazeType}
45+
solving={solving}
46+
algorithm={algorithm}
4747
selectedPoint = {selectedPoint}
4848
onSelectPoint = {onSelectPoint}
4949
/>

0 commit comments

Comments
 (0)