Skip to content

Commit a7d072f

Browse files
committed
merge sort
2 parents 874d7c1 + 7a0a8ac commit a7d072f

13 files changed

Lines changed: 208 additions & 141 deletions

File tree

‎package-lock.json‎

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

‎package.json‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@
33
"version": "0.1.0",
44
"private": true,
55
"dependencies": {
6+
"@react-three/fiber": "^8.0.27",
67
"@testing-library/jest-dom": "^5.16.4",
78
"@testing-library/react": "^13.3.0",
89
"@testing-library/user-event": "^13.5.0",
10+
"csstype": "^3.1.0",
911
"react": "^18.2.0",
1012
"react-dom": "^18.2.0",
1113
"react-router": "^6.3.0",
1214
"react-router-dom": "^6.3.0",
13-
"react-three-fiber": "^6.0.13",
1415
"rsuite": "^5.16.0",
1516
"web-vitals": "^2.1.4"
1617
},

‎src/App.js‎

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import './App.css';
22
import React, {Component} from 'react';
3-
import {Canvas} from 'react-three-fiber';
3+
import {Canvas, useFrame} from '@react-three/fiber';
44

55
import {Strategy /*changeRed*/} from './components/Strategy/Strategy';
66
import {InputField} from './components/Canvas/InputField.js';
@@ -13,6 +13,7 @@ import Footer from './components/Page/partial/Footer';
1313
import SplashScreen from './components/Page/Splash/SplashScreen';
1414
import Box from './modals/cube/Box';
1515
import AppRouter from './AppRouter';
16+
import Cell from './components/Board/Cell';
1617

1718

1819

@@ -30,15 +31,21 @@ class App extends Component {
3031
render() {
3132

3233
return (
33-
<>
34-
<div className = "App">
35-
<AppRouter/>
34+
/*<div className = "App">
3635
37-
</div>
36+
<AppRouter/>
3837
39-
</>
40-
);
38+
</div>*/
4139

40+
// TESTING PURPOSES: CELL COMPONENT
41+
<Canvas>
42+
<Cell id = {1}
43+
value = {1}
44+
size = {1}
45+
position = {[0, 0, 0]}
46+
/>
47+
</Canvas>
48+
);
4249
}
4350
}
4451

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import {Component} from 'react';
2+
import {Canvas, useFrame} from '@react-three/fiber';
3+
4+
5+
6+
export class Display extends Component {
7+
constructor(fArgs) {
8+
super(fArgs);
9+
this.state = {
10+
displayType: fArgs.displayType,
11+
algorithm : fArgs.algorithm,
12+
dataString : fArgs.dataString,
13+
width : fArgs.innerWidth,
14+
height : fArgs.innerHeight,
15+
aspect : fArgs.aspect,
16+
perspective: fArgs.perspective,
17+
};
18+
}
19+
20+
21+
componentDidMount() {
22+
window.addEventListener('resize', this.handleWindowSizeChange);
23+
}
24+
25+
26+
componentWillUnmount() {
27+
window.removeEventListener('resize', this.handleWindowSizeChange);
28+
}
29+
30+
31+
handleWindowSizeChange = () => {
32+
this.setState({width: window.innerWidth, height: window.innerHeight});
33+
};
34+
35+
36+
render() {
37+
const {width, height} = this.state;
38+
const aspect = width / height;
39+
return (
40+
<Canvas children = {}>
41+
42+
</Canvas>
43+
);
44+
};
45+
}
File renamed without changes.

‎src/components/Algorithms/MinMax/MiniMax.js‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ class MiniMax {
5050
return 0;
5151
}
5252

53-
var board = new Board(grid);
54-
var leaves = new Move[10];
53+
var board = new Board(grid);
54+
let leaves: Move[] = new Move[10];
5555

5656
//
5757
for (var iter = 0; iter < leaves.length; iter++) {
@@ -60,7 +60,7 @@ class MiniMax {
6060
}
6161
}
6262

63-
var bestMove = null;
63+
let bestMove: Move = null;
6464
for (var i = 0; i < leaves.length; i++) {
6565
if (bestMove == null) {
6666
// bestMove = moves[i];

‎src/components/Algorithms/Search/BreadthFirst.js‎

Whitespace-only changes.

‎src/components/Algorithms/Search/DepthFirst.js‎

Whitespace-only changes.

‎src/components/Animation/Animation.js‎

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,53 @@
1-
import { Document } from "postcss";
1+
import {Document} from 'postcss';
2+
3+
24

35
class Animation {
46

5-
constructor() {
7+
constructor() {
68
Animation.threads = [];
79
// SG 07/09/2022 15:11 Singleton pattern
8-
if(Animation._instance) {
10+
if (Animation._instance) {
911
return Animation._instance;
1012
}
1113
Animation._instance = this;
12-
Animation.stop = false;
14+
Animation.stop = false;
1315
}
1416

1517

1618
// SG 07/07/2022 22:00 define differnet animaitons here and call it in sorting algorithms
1719

1820
static async clearTimeout() {
1921
Animation.stop = true;
20-
for(const timeout of Animation.threads) {
22+
for (const timeout of Animation.threads) {
2123
await this.clearTimeout(timeout);
2224
}
2325
}
2426

27+
2528
/**
2629
* takes indecies to be swapped
27-
* @param {Integer} i
30+
* @param {Integer} i
2831
* @param {Integer} minBarIndex
2932
*/
3033
swap(i, minBarIndex) {
31-
let unSortedBars = document.querySelectorAll('.array-bars');
32-
var temp1 = unSortedBars[minBarIndex].style.height;
34+
let unSortedBars = document.querySelectorAll('.array-bars');
35+
var temp1 = unSortedBars[minBarIndex].style.height;
3336
unSortedBars[minBarIndex].style.height = unSortedBars[i].style.height;
34-
unSortedBars[i].style.height = temp1;
37+
unSortedBars[i].style.height = temp1;
3538

36-
var temp2 = unSortedBars[minBarIndex].id;
39+
var temp2 = unSortedBars[minBarIndex].id;
3740
unSortedBars[minBarIndex].id = unSortedBars[i].id;
38-
unSortedBars[i].id = temp1;
41+
unSortedBars[i].id = temp1;
3942
}
4043

4144

4245
static async getAnimation(delay) {
43-
if(!Animation.stop) {
46+
if (!Animation.stop) {
4447
await new Promise((resolve) =>
45-
Animation.threads.push(setTimeout(() => {
46-
resolve();
47-
}, delay)));
48+
Animation.threads.push(setTimeout(() => {
49+
resolve();
50+
}, delay)));
4851
}
4952
}
5053

@@ -76,4 +79,5 @@ class Animation {
7679
}
7780

7881

79-
export { Animation }
82+
83+
export {Animation};

‎src/components/Board/Cell.js‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import {Component} from 'react';
2+
import Box from '../../modals/cube/Box';
3+
4+
5+
6+
const Cell = (fArgs) => {
7+
const id = fArgs.id;
8+
const value = fArgs.value;
9+
const onClick = fArgs.onClick;
10+
return (
11+
<Box size = {fArgs.size}/>
12+
);
13+
14+
};
15+
16+
export default Cell;

0 commit comments

Comments
 (0)