From b904681b9b417220e5e350f935b70a98f15ba41c Mon Sep 17 00:00:00 2001
From: brynnchernosky <56202540+brynnchernosky@users.noreply.github.com>
Date: Thu, 4 May 2023 00:13:05 -0400
Subject: debug issue with projectile forces

---
 .../nodes/PhysicsBox/PhysicsSimulationBox.tsx      | 43 ++++++++++++----------
 1 file changed, 23 insertions(+), 20 deletions(-)

(limited to 'src/client/views/nodes/PhysicsBox/PhysicsSimulationBox.tsx')

diff --git a/src/client/views/nodes/PhysicsBox/PhysicsSimulationBox.tsx b/src/client/views/nodes/PhysicsBox/PhysicsSimulationBox.tsx
index b24591a0d..7efb8b73a 100644
--- a/src/client/views/nodes/PhysicsBox/PhysicsSimulationBox.tsx
+++ b/src/client/views/nodes/PhysicsBox/PhysicsSimulationBox.tsx
@@ -111,7 +111,7 @@ export default class PhysicsSimulationBox extends ViewBoxAnnotatableComponent<Fi
     this.layoutDoc._height = 800;
     this.xMax = this.layoutDoc._width*0.6;
     this.yMax = this.layoutDoc._height*0.9;
-    this.radius = 75;
+    this.radius = 60;
     this.dataDoc.reviewCoefficient = this.dataDoc.reviewCoefficient ?? 0;
     this.dataDoc.questionVariables = this.dataDoc.questionVariables ?? [];
     this.dataDoc.accelerationXDisplay = this.dataDoc.accelerationXDisplay ?? 0;
@@ -217,9 +217,12 @@ export default class PhysicsSimulationBox extends ViewBoxAnnotatableComponent<Fi
   }
 
   componentDidUpdate() {
-    this.xMax = this.layoutDoc._width*0.6;
-    this.yMax = this.layoutDoc._height*0.9;
-    this.radius = 0.9*this.layoutDoc._height ?? 75;
+    if (this.xMax != this.layoutDoc._width*0.6 || this.yMax != this.layoutDoc._height*0.9) {
+      this.xMax = this.layoutDoc._width*0.6;
+      this.yMax = this.layoutDoc._height*0.9;
+      this.radius = 0.08*this.layoutDoc._height ?? 60;
+      this.dataDoc.simulationReset = (!this.dataDoc.simulationReset);
+    }
   }
 
   setupSimulation = (simulationType: string, mode: string) => {
@@ -237,7 +240,7 @@ export default class PhysicsSimulationBox extends ViewBoxAnnotatableComponent<Fi
         this.dataDoc.startPosY = (this.yMin + this.radius);
         this.dataDoc.startPosX = ((this.xMax + this.xMin) / 2 - this.radius);
         this.dataDoc.positionYDisplay = (this.getDisplayYPos(this.yMin + this.radius));
-        this.dataDoc.positionXDisplay((this.xMax + this.xMin) / 2 - this.radius);
+        this.dataDoc.positionXDisplay = ((this.xMax + this.xMin) / 2 - this.radius);
         this.dataDoc.updatedForces = ([
           {
             description: "Gravity",
@@ -1001,7 +1004,7 @@ export default class PhysicsSimulationBox extends ViewBoxAnnotatableComponent<Fi
               step={1}
               unit={"°"}
               upperBound={49}
-              value={this.dataDoc.wedgeAngle}
+              value={this.dataDoc.wedgeAngle ?? 26}
               effect={(val: number) => {
                 this.changeWedgeBasedOnNewAngle(val);
                 this.updateReviewForcesBasedOnAngle(val);
@@ -1785,7 +1788,7 @@ export default class PhysicsSimulationBox extends ViewBoxAnnotatableComponent<Fi
                   step={1}
                   unit={"x"}
                   upperBound={10}
-                  value={this.dataDoc.simulationSpeed}
+                  value={this.dataDoc.simulationSpeed ?? 2}
                   labelWidth={"5em"}
                 />
                 {this.dataDoc.simulationPaused && this.dataDoc.simulationType != "Circular Motion" && (
@@ -1797,7 +1800,7 @@ export default class PhysicsSimulationBox extends ViewBoxAnnotatableComponent<Fi
                     step={0.01}
                     unit={"m/s2"}
                     upperBound={0}
-                    value={this.dataDoc.gravity}
+                    value={this.dataDoc.gravity ?? -9.81}
                     effect={(val: number) => {
                       this.dataDoc.resetAll = (!this.dataDoc.resetAll);
                     }}
@@ -1813,7 +1816,7 @@ export default class PhysicsSimulationBox extends ViewBoxAnnotatableComponent<Fi
                     step={0.1}
                     unit={"kg"}
                     upperBound={5}
-                    value={this.dataDoc.mass}
+                    value={this.dataDoc.mass ?? 1}
                     effect={(val: number) => {
                       this.dataDoc.resetAll = (!this.dataDoc.resetAll);
                     }}
@@ -1829,7 +1832,7 @@ export default class PhysicsSimulationBox extends ViewBoxAnnotatableComponent<Fi
                     step={0.1}
                     unit={"kg"}
                     upperBound={5}
-                    value={this.dataDoc.mass}
+                    value={this.dataDoc.mass ?? 1}
                     effect={(val: number) => {
                       this.dataDoc.resetAll = (!this.dataDoc.resetAll);
                     }}
@@ -1845,7 +1848,7 @@ export default class PhysicsSimulationBox extends ViewBoxAnnotatableComponent<Fi
                     step={0.1}
                     unit={"kg"}
                     upperBound={5}
-                    value={this.dataDoc.mass2}
+                    value={this.dataDoc.mass2 ?? 1}
                     effect={(val: number) => {
                       this.dataDoc.resetAll = (!this.dataDoc.resetAll);
                     }}
@@ -1859,9 +1862,9 @@ export default class PhysicsSimulationBox extends ViewBoxAnnotatableComponent<Fi
                     dataDoc={this.dataDoc}
                     prop={'circularMotionRadius'}
                     step={5}
-                    unit={"kg"}
+                    unit={"m"}
                     upperBound={250}
-                    value={this.dataDoc.circularMotionRadius}
+                    value={this.dataDoc.circularMotionRadius ?? 100}
                     effect={(val: number) => {
                       this.dataDoc.resetAll = (!this.dataDoc.resetAll);
                     }}
@@ -1882,7 +1885,7 @@ export default class PhysicsSimulationBox extends ViewBoxAnnotatableComponent<Fi
                   step={1}
                   unit={"N/m"}
                   upperBound={500}
-                  value={this.dataDoc.springConstant}
+                  value={this.dataDoc.springConstant ?? 0.5}
                   effect={(val: number) => {
                     this.dataDoc.simulationReset(!this.dataDoc.simulationReset);
                   }}
@@ -1898,7 +1901,7 @@ export default class PhysicsSimulationBox extends ViewBoxAnnotatableComponent<Fi
                   step={100}
                   unit={""}
                   upperBound={500}
-                  value={this.dataDoc.springRestLength}
+                  value={this.dataDoc.springRestLength ?? 200}
                   effect={(val: number) => {
                     this.dataDoc.simulationReset = (!this.dataDoc.simulationReset);
                   }}
@@ -1918,7 +1921,7 @@ export default class PhysicsSimulationBox extends ViewBoxAnnotatableComponent<Fi
                   step={10}
                   unit={""}
                   upperBound={this.dataDoc.springRestLength}
-                  value={this.dataDoc.springStartLength - this.dataDoc.springRestLength}
+                  value={this.dataDoc.springStartLength - this.dataDoc.springRestLength ?? 0}
                   effect={(val: number) => {
                     this.dataDoc.startPosY = (this.dataDoc.springRestLength + val);
                     this.dataDoc.springStartLength = (this.dataDoc.springRestLength + val);
@@ -1940,7 +1943,7 @@ export default class PhysicsSimulationBox extends ViewBoxAnnotatableComponent<Fi
                   step={1}
                   unit={"°"}
                   upperBound={49}
-                  value={this.dataDoc.wedgeAngle}
+                  value={this.dataDoc.wedgeAngle ?? 26}
                   effect={(val: number) => {
                     this.changeWedgeBasedOnNewAngle(val);
                     this.dataDoc.simulationReset = (!this.dataDoc.simulationReset);
@@ -1961,7 +1964,7 @@ export default class PhysicsSimulationBox extends ViewBoxAnnotatableComponent<Fi
                   step={0.1}
                   unit={""}
                   upperBound={1}
-                  value={this.dataDoc.coefficientOfStaticFriction}
+                  value={this.dataDoc.coefficientOfStaticFriction ?? 0}
                   effect={(val: number) => {
                     this.updateForcesWithFriction(val);
                     if (val < Number(this.dataDoc.coefficientOfKineticFriction)) {
@@ -1984,7 +1987,7 @@ export default class PhysicsSimulationBox extends ViewBoxAnnotatableComponent<Fi
                   step={0.1}
                   unit={""}
                   upperBound={Number(this.dataDoc.coefficientOfStaticFriction)}
-                  value={this.dataDoc.coefficientOfKineticFriction}
+                  value={this.dataDoc.coefficientOfKineticFriction ?? 0}
                   effect={(val: number) => {
                     this.dataDoc.simulationReset = (!this.dataDoc.simulationReset);
                   }}
@@ -2022,7 +2025,7 @@ export default class PhysicsSimulationBox extends ViewBoxAnnotatableComponent<Fi
                   step={1}
                   unit={"°"}
                   upperBound={59}
-                  value={this.dataDoc.pendulumAngle}
+                  value={this.dataDoc.pendulumAngle ?? 30}
                   effect={(value) => {
                     this.dataDoc.startPendulumAngle = (value);
                     if (this.dataDoc.simulationType == "Pendulum") {
-- 
cgit v1.2.3-70-g09d2

