diff options
author | brynnchernosky <56202540+brynnchernosky@users.noreply.github.com> | 2023-05-01 21:16:36 -0400 |
---|---|---|
committer | brynnchernosky <56202540+brynnchernosky@users.noreply.github.com> | 2023-05-01 21:16:36 -0400 |
commit | 1e99c215456af073a7aade297d19f4dd4a9ecf8c (patch) | |
tree | 2002433528cfd704976597eec8f8891e0a098106 | |
parent | d2e56061dd9cb7913ede040e7d16aa451e39adc0 (diff) |
debugging
-rw-r--r-- | src/client/views/nodes/PhysicsBox/PhysicsSimulationWeight.tsx | 165 |
1 files changed, 82 insertions, 83 deletions
diff --git a/src/client/views/nodes/PhysicsBox/PhysicsSimulationWeight.tsx b/src/client/views/nodes/PhysicsBox/PhysicsSimulationWeight.tsx index 192ff1d04..013b1bb5b 100644 --- a/src/client/views/nodes/PhysicsBox/PhysicsSimulationWeight.tsx +++ b/src/client/views/nodes/PhysicsBox/PhysicsSimulationWeight.tsx @@ -194,39 +194,39 @@ export default class Weight extends React.Component<IWeightProps, IState> { this.props.dataDoc['pendulumLength'] = this.props.adjustPendulumAngle.length } - // // When display values updated by user, update real values - // if (prevProps.updateDisplay != this.props.updateDisplay) { - // if (this.props.updateDisplay.xDisplay != this.state.xPosition) { - // let x = this.props.updateDisplay.xDisplay; - // x = Math.max(0, x); - // x = Math.min(x, this.props.xMax - 2 * this.props.radius); - // this.setState({updatedStartPosX: x}) - // this.setState({xPosition: x}) - // this.props.dataDoc['positionXDisplay'] = x - // } + // When display values updated by user, update real values + if (prevProps.updateDisplay != this.props.updateDisplay) { + if (this.props.updateDisplay.xDisplay != this.state.xPosition) { + let x = this.props.updateDisplay.xDisplay; + x = Math.max(0, x); + x = Math.min(x, this.props.xMax - 2 * this.props.radius); + this.setState({updatedStartPosX: x}) + this.setState({xPosition: x}) + this.props.dataDoc['positionXDisplay'] = x + } - // if (this.props.updateDisplay.yDisplay != this.getDisplayYPos(this.state.yPosition)) { - // let y = this.props.updateDisplay.yDisplay; - // y = Math.max(0, y); - // y = Math.min(y, this.props.yMax - 2 * this.props.radius); - // let coordinatePosition = this.getYPosFromDisplay(y); - // this.setState({updatedStartPosY: coordinatePosition}) - // this.setState({yPosition: coordinatePosition}) - // this.props.dataDoc['positionYDisplay'] = y - // } + if (this.props.updateDisplay.yDisplay != this.getDisplayYPos(this.state.yPosition)) { + let y = this.props.updateDisplay.yDisplay; + y = Math.max(0, y); + y = Math.min(y, this.props.yMax - 2 * this.props.radius); + let coordinatePosition = this.getYPosFromDisplay(y); + this.setState({updatedStartPosY: coordinatePosition}) + this.setState({yPosition: coordinatePosition}) + this.props.dataDoc['positionYDisplay'] = y + } - // if (this.props.displayXVelocity != this.state.xVelocity) { - // let x = this.props.displayXVelocity; - // this.setState({xVelocity: x}) - // this.props.dataDoc['velocityXDisplay'] = x - // } + if (this.props.displayXVelocity != this.state.xVelocity) { + let x = this.props.displayXVelocity; + this.setState({xVelocity: x}) + this.props.dataDoc['velocityXDisplay'] = x + } - // if (this.props.displayYVelocity != -this.state.yVelocity) { - // let y = this.props.displayYVelocity; - // this.setState({yVelocity: -y}) - // this.props.dataDoc['velocityYDisplay'] = y - // } - // } + if (this.props.displayYVelocity != -this.state.yVelocity) { + let y = this.props.displayYVelocity; + this.setState({yVelocity: -y}) + this.props.dataDoc['velocityYDisplay'] = y + } + } // Prevent bug when switching between sims if (prevProps.startForces != this.props.startForces) { @@ -235,43 +235,43 @@ export default class Weight extends React.Component<IWeightProps, IState> { this.setDisplayValues(); } - // // Make sure weight doesn't go above max height - // if (prevState.updatedStartPosY != this.state.updatedStartPosY || prevProps.startVelY != this.props.startVelY) { - // if (this.props.dataDoc['simulationType'] == "One Weight") { - // let maxYPos = this.state.updatedStartPosY; - // if (this.props.startVelY != 0) { - // maxYPos -= (this.props.startVelY * this.props.startVelY) / (2 * Math.abs(this.props.gravity)); - // } - // if (maxYPos < 0) { - // maxYPos = 0; - // } - // this.setState({maxPosYConservation: maxYPos}) - // } - // } + // Make sure weight doesn't go above max height + if (prevState.updatedStartPosY != this.state.updatedStartPosY || prevProps.startVelY != this.props.startVelY) { + if (this.props.dataDoc['simulationType'] == "One Weight") { + let maxYPos = this.state.updatedStartPosY; + if (this.props.startVelY != 0) { + maxYPos -= (this.props.startVelY * this.props.startVelY) / (2 * Math.abs(this.props.gravity)); + } + if (maxYPos < 0) { + maxYPos = 0; + } + this.setState({maxPosYConservation: maxYPos}) + } + } - // // Check for collisions and update - // if (prevState.timer != this.state.timer) { - // if (!this.props.paused && !this.props.noMovement) { - // let collisions = false; - // if ( - // this.props.dataDoc['simulationType'] == "One Weight" || - // this.props.dataDoc['simulationType'] == "Inclined Plane" - // ) { - // const collisionsWithGround = this.checkForCollisionsWithGround(); - // const collisionsWithWalls = this.checkForCollisionsWithWall(); - // collisions = collisionsWithGround || collisionsWithWalls; - // } - // if (this.props.dataDoc['simulationType'] == "Pulley") { - // if (this.state.yPosition <= this.props.yMin + 100 || this.state.yPosition >= this.props.yMax - 100) { - // collisions = true; - // } - // } - // if (!collisions) { - // this.update(); - // } - // this.setDisplayValues(); - // } - // } + // Check for collisions and update + if (prevState.timer != this.state.timer) { + if (!this.props.paused && !this.props.noMovement) { + let collisions = false; + if ( + this.props.dataDoc['simulationType'] == "One Weight" || + this.props.dataDoc['simulationType'] == "Inclined Plane" + ) { + const collisionsWithGround = this.checkForCollisionsWithGround(); + const collisionsWithWalls = this.checkForCollisionsWithWall(); + collisions = collisionsWithGround || collisionsWithWalls; + } + if (this.props.dataDoc['simulationType'] == "Pulley") { + if (this.state.yPosition <= this.props.yMin + 100 || this.state.yPosition >= this.props.yMax - 100) { + collisions = true; + } + } + if (!collisions) { + this.update(); + } + this.setDisplayValues(); + } + } // Reset everything on reset button click if (prevProps.reset != this.props.reset) { @@ -406,24 +406,23 @@ export default class Weight extends React.Component<IWeightProps, IState> { this.setState({walls: w}) } - // // Update x position when start pos x changes - // if (prevProps.startPosX != this.props.startPosX) { - // if (this.props.paused) { - // this.setState({xPosition: this.props.startPosX}) - // this.setState({updatedStartPosX: this.props.startPosX}) - // this.props.dataDoc['positionXDisplay'] = this.props.startPosX - // } - // } - + // Update x position when start pos x changes + if (prevProps.startPosX != this.props.startPosX) { + if (this.props.paused) { + this.setState({xPosition: this.props.startPosX}) + this.setState({updatedStartPosX: this.props.startPosX}) + this.props.dataDoc['positionXDisplay'] = this.props.startPosX + } + } - // // Update y position when start pos y changes - // if (prevProps.startPosY != this.props.startPosY) { - // if (this.props.paused) { - // this.setState({yPosition: this.props.startPosY}) - // this.setState({updatedStartPosY: this.props.startPosY}) - // this.props.dataDoc['positionYDisplay'] = this.props.startPosY - // } - // } + // Update y position when start pos y changes + if (prevProps.startPosY != this.props.startPosY) { + if (this.props.paused) { + // this.setState({yPosition: this.props.startPosY}) + // this.setState({updatedStartPosY: this.props.startPosY}) + this.props.dataDoc['positionYDisplay'] = this.props.startPosY + } + } // Update wedge coordinates if (prevProps.wedgeWidth != this.props.wedgeWidth || prevProps.wedgeHeight != this.props.wedgeHeight) { |