diff options
Diffstat (limited to 'src/client/views/nodes/PhysicsBox/PhysicsSimulationWeight.tsx')
-rw-r--r-- | src/client/views/nodes/PhysicsBox/PhysicsSimulationWeight.tsx | 65 |
1 files changed, 32 insertions, 33 deletions
diff --git a/src/client/views/nodes/PhysicsBox/PhysicsSimulationWeight.tsx b/src/client/views/nodes/PhysicsBox/PhysicsSimulationWeight.tsx index 8369a994a..b973d30c8 100644 --- a/src/client/views/nodes/PhysicsBox/PhysicsSimulationWeight.tsx +++ b/src/client/views/nodes/PhysicsBox/PhysicsSimulationWeight.tsx @@ -1,6 +1,5 @@ import { Doc } from '../../../../fields/Doc'; import React = require('react'); -import { IWallProps } from "./PhysicsSimulationWall"; import "./PhysicsSimulationBox.scss"; interface IWallProps { @@ -242,45 +241,45 @@ 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) && !isNaN(this.state.updatedStartPosY) && !isNaN(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 (!this.props.paused) { - if (prevState.timer != this.state.timer) { - if (!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 (prevState.timer != this.state.timer) { + if (!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(); } - if (!collisions) { - this.update(); - } - this.setDisplayValues(); } } - } // Reset everything on reset button click if (prevProps.reset != this.props.reset) { |