Skip to content

Commit a688c1d

Browse files
committed
refactor solver class to improve variable visibility and correct bounds parameter naming
1 parent 92eac46 commit a688c1d

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

src/solver.ts

+15-15
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as THREE from 'three';
22

33
export default class Solver {
4-
static instance: Solver;
4+
private static instance: Solver;
55
private readonly G: number = 1;
66
private readonly softening: number = 0.1;
77
private deltaT: number = 0.1;
@@ -14,7 +14,7 @@ export default class Solver {
1414
return Solver.instance;
1515
}
1616

17-
public solve(spheres: THREE.Mesh[], bouns: number, e: number): void {
17+
public solve(spheres: THREE.Mesh[], bounds: number, e: number): void {
1818
spheres.forEach((sphere) => {
1919
let objectAcceleration = new THREE.Vector3(0, 0, 0);
2020
spheres.forEach((other) => {
@@ -36,28 +36,28 @@ export default class Solver {
3636

3737
sphere.position.add(sphere.userData.velocity.clone().multiplyScalar(this.deltaT));
3838

39-
let wallBounceE : number = 0.8;
40-
if (sphere.position.x + sphere.userData.radius > bouns) {
41-
sphere.position.x = bouns - sphere.userData.radius;
39+
let wallBounceE : number = 1.2;
40+
if (sphere.position.x + sphere.userData.radius > bounds) {
41+
sphere.position.x = bounds - sphere.userData.radius;
4242
sphere.userData.velocity.x *= wallBounceE;
43-
} else if (sphere.position.x - sphere.userData.radius < -bouns) {
44-
sphere.position.x = -bouns + sphere.userData.radius;
43+
} else if (sphere.position.x - sphere.userData.radius < -bounds) {
44+
sphere.position.x = -bounds + sphere.userData.radius;
4545
sphere.userData.velocity.x *= wallBounceE;
4646
}
4747

48-
if (sphere.position.y + sphere.userData.radius > bouns) {
49-
sphere.position.y = bouns - sphere.userData.radius;
48+
if (sphere.position.y + sphere.userData.radius > bounds) {
49+
sphere.position.y = bounds - sphere.userData.radius;
5050
sphere.userData.velocity.y *= wallBounceE;
51-
} else if (sphere.position.y - sphere.userData.radius < -bouns) {
52-
sphere.position.y = -bouns + sphere.userData.radius;
51+
} else if (sphere.position.y - sphere.userData.radius < -bounds) {
52+
sphere.position.y = -bounds + sphere.userData.radius;
5353
sphere.userData.velocity.y *= wallBounceE;
5454
}
5555

56-
if (sphere.position.z + sphere.userData.radius > bouns) {
57-
sphere.position.z = bouns - sphere.userData.radius;
56+
if (sphere.position.z + sphere.userData.radius > bounds) {
57+
sphere.position.z = bounds - sphere.userData.radius;
5858
sphere.userData.velocity.z *= wallBounceE;
59-
} else if (sphere.position.z - sphere.userData.radius < -bouns) {
60-
sphere.position.z = -bouns + sphere.userData.radius;
59+
} else if (sphere.position.z - sphere.userData.radius < -bounds) {
60+
sphere.position.z = -bounds + sphere.userData.radius;
6161
sphere.userData.velocity.z *= wallBounceE;
6262
}
6363

0 commit comments

Comments
 (0)