aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/client/views/nodes/PhysicsBox/PhysicsSimulationWeight.tsx18
1 files changed, 9 insertions, 9 deletions
diff --git a/src/client/views/nodes/PhysicsBox/PhysicsSimulationWeight.tsx b/src/client/views/nodes/PhysicsBox/PhysicsSimulationWeight.tsx
index 89bdae0a0..06db9b4ce 100644
--- a/src/client/views/nodes/PhysicsBox/PhysicsSimulationWeight.tsx
+++ b/src/client/views/nodes/PhysicsBox/PhysicsSimulationWeight.tsx
@@ -90,12 +90,12 @@ export default class Weight extends React.Component<IWeightProps, IState> {
kineticFriction: false,
maxPosYConservation: 0,
timer: 0,
- updatedStartPosX: this.props.dataDoc['startPosX'],
- updatedStartPosY: this.props.dataDoc['startPosY'],
+ updatedStartPosX: this.props.dataDoc['startPosX'] ?? 0,
+ updatedStartPosY: this.props.dataDoc['startPosY'] ?? 0,
walls: [],
- xPosition: this.props.dataDoc['startPosX'],
+ xPosition: this.props.dataDoc['startPosX'] ?? 0,
xVelocity: this.props.startVelX ? this.props.startVelX: 0,
- yPosition: this.props.dataDoc['startPosY'],
+ yPosition: this.props.dataDoc['startPosY'] ?? 0,
yVelocity: this.props.startVelY ? this.props.startVelY: 0,
xAccel: 0,
yAccel: 0,
@@ -452,7 +452,7 @@ export default class Weight extends React.Component<IWeightProps, IState> {
this.props.dataDoc['positionYDisplay'] = this.state.updatedStartPosY
this.props.dataDoc['velocityXDisplay'] = this.props.startVelX ?? 0
this.props.dataDoc['velocityYDisplay'] = this.props.startVelY ?? 0
- this.setState({angleLabel: Math.round(this.props.dataDoc['pendulumAngle']* 100) / 100})
+ this.setState({angleLabel: Math.round(this.props.dataDoc['pendulumAngle'] ?? 0 * 100) / 100})
};
// Compute x acceleration from forces, F=ma
@@ -577,14 +577,14 @@ export default class Weight extends React.Component<IWeightProps, IState> {
};
// Check for collisions in x direction
- const checkForCollisionsWithWall = () => {
+ checkForCollisionsWithWall = () => {
let collision = false;
const minX = this.state.xPosition;
const maxX = this.state.xPosition + 2 * this.props.radius;
if (this.state.xVelocity != 0) {
this.state.walls.forEach((wall) => {
if (wall.angleInDegrees == 90) {
- const wallX = (wall.xPos / 100) * this.props.layoutDoc._width;
+ const wallX = (wall.xPos / 100) * this.props.layoutDoc._width ?? 500;
if (wall.xPos < 0.35) {
if (minX <= wallX) {
this.setState({xPosition: wallX+0.01});
@@ -620,7 +620,7 @@ export default class Weight extends React.Component<IWeightProps, IState> {
if (this.state.yVelocity > 0) {
this.state.walls.forEach((wall) => {
if (wall.angleInDegrees == 0 && wall.yPos > 0.4) {
- const groundY = (wall.yPos / 100) * this.props.layoutDoc._height;
+ const groundY = (wall.yPos / 100) * this.props.layoutDoc._height ?? 500;
if (maxY > groundY) {
this.setState({yPosition: groundY- 2 * this.props.radius-0.01});
if (this.props.elasticCollisions) {
@@ -666,7 +666,7 @@ export default class Weight extends React.Component<IWeightProps, IState> {
if (this.state.yVelocity < 0) {
this.state.walls.forEach((wall) => {
if (wall.angleInDegrees == 0 && wall.yPos < 0.4) {
- const groundY = (wall.yPos / 100) * this.props.layoutDoc._height;
+ const groundY = (wall.yPos / 100) * this.props.layoutDoc._height ?? 500;
if (minY < groundY) {
this.setState({yPosition: groundY + 0.01});
if (this.props.elasticCollisions) {