From 993210bb011e326edb93b4654a1f97850e7c9ee8 Mon Sep 17 00:00:00 2001 From: brynnchernosky <56202540+brynnchernosky@users.noreply.github.com> Date: Mon, 1 May 2023 17:36:33 -0400 Subject: refactorweight --- .../nodes/PhysicsBox/PhysicsSimulationBox.tsx | 2 + .../nodes/PhysicsBox/PhysicsSimulationWeight.tsx | 99 +++++++++++----------- 2 files changed, 52 insertions(+), 49 deletions(-) (limited to 'src') diff --git a/src/client/views/nodes/PhysicsBox/PhysicsSimulationBox.tsx b/src/client/views/nodes/PhysicsBox/PhysicsSimulationBox.tsx index bdc76048c..35a7ee346 100644 --- a/src/client/views/nodes/PhysicsBox/PhysicsSimulationBox.tsx +++ b/src/client/views/nodes/PhysicsBox/PhysicsSimulationBox.tsx @@ -1281,6 +1281,7 @@ export default class PhysicsSimulationBox extends ViewBoxAnnotatableComponent { if (this.state.xVelocity != 0) { this.state.walls.forEach((wall) => { if (wall.angleInDegrees == 90) { - const wallX = (wall.xPos / 100) * window.innerWidth; + const wallX = (wall.xPos / 100) * this.props.layoutDoc._width; if (wall.xPos < 0.35) { if (minX <= wallX) { this.setState({xPosition: wallX+0.01}); @@ -613,14 +614,14 @@ export default class Weight extends React.Component { }; // Check for collisions in y direction - const checkForCollisionsWithGround = () => { + checkForCollisionsWithGround = () => { let collision = false; const minY = this.state.yPosition; const maxY = this.state.yPosition + 2 * this.props.radius; if (this.state.yVelocity > 0) { this.state.walls.forEach((wall) => { if (wall.angleInDegrees == 0 && wall.yPos > 0.4) { - const groundY = (wall.yPos / 100) * window.innerHeight; + const groundY = (wall.yPos / 100) * this.props.layoutDoc._height; if (maxY > groundY) { this.setState({yPosition: groundY- 2 * this.props.radius-0.01}); if (this.props.elasticCollisions) { @@ -666,7 +667,7 @@ export default class Weight extends React.Component { if (this.state.yVelocity < 0) { this.state.walls.forEach((wall) => { if (wall.angleInDegrees == 0 && wall.yPos < 0.4) { - const groundY = (wall.yPos / 100) * window.innerHeight; + const groundY = (wall.yPos / 100) * this.props.layoutDoc._height; if (minY < groundY) { this.setState({yPosition: groundY + 0.01}); if (this.props.elasticCollisions) { @@ -730,7 +731,7 @@ export default class Weight extends React.Component { let yPos = this.state.yPosition; let xVel = this.state.xVelocity; let yVel = this.state.yVelocity; - let forces = this.props.dataDoc['updatedForces']; + let forces: IForce[] = this.props.dataDoc['updatedForces']; if (this.props.dataDoc['simulationType'] == "Pendulum") { forces = this.getNewPendulumForces(xPos, yPos, xVel, yVel); } else if (this.props.dataDoc['simulationType'] == "Spring") { @@ -1025,7 +1026,7 @@ export default class Weight extends React.Component { zIndex: -2, }} > - + {[0, 1, 2, 3, 4, 5, 6, 7, 8, 9].map((val) => { const count = 10; let xPos1; @@ -1067,7 +1068,7 @@ export default class Weight extends React.Component { zIndex: -1, }} > - + { zIndex: -2, }} > - + { zIndex: -2, }} > - + { zIndex: -2, }} > - + { zIndex: -2, }} > - + { zIndex: -2, }} > - + { position: "absolute", zIndex: 500, left: Math.round(this.props.xMax * 0.5 - 200 + this.props.wedgeWidth - 80) + "px", - top: Math.round(window.innerHeight * 0.8 - 40) + "px", + top: Math.round(this.props.layoutDoc._height * 0.8 - 40) + "px", }} > {Math.round( @@ -1301,7 +1302,7 @@ export default class Weight extends React.Component { top: 0, }} > - + { top: 0, }} > - + { {Math.round( 100 * Math.sqrt( - this.props.displayXVelocity * this.props.displayXVelocity + - this.props.displayYVelocity * this.props.displayYVelocity + this.props.displayXVelocity * this.props.displayXVelocity + + this.props.displayYVelocity * this.props.displayYVelocity ) ) / 100}{" "} m/s @@ -1405,14 +1406,14 @@ export default class Weight extends React.Component { )} - {!dragging && - showComponentForces && - componentForces.map((force, index) => { - if (force.magnitude < epsilon) { + {!this.state.dragging && + this.props.showComponentForces && + this.props.componentForces.map((force, index) => { + if (force.magnitude < this.epsilon) { return; } - let arrowStartY: number = yPosition + radius; - const arrowStartX: number = xPosition + radius; + let arrowStartY: number = this.state.yPosition + this.props.radius; + const arrowStartX: number = this.state.xPosition + this.props.radius; let arrowEndY: number = arrowStartY - Math.abs(force.magnitude) * @@ -1438,10 +1439,10 @@ export default class Weight extends React.Component { } else { labelTop -= 40; } - labelTop = Math.min(labelTop, yMax + 50); - labelTop = Math.max(labelTop, yMin); - labelLeft = Math.min(labelLeft, xMax - 60); - labelLeft = Math.max(labelLeft, xMin); + labelTop = Math.min(labelTop, this.props.yMax + 50); + labelTop = Math.max(labelTop, this.props.yMin); + labelLeft = Math.min(labelLeft, this.props.xMax - 60); + labelLeft = Math.max(labelLeft, this.props.xMin); return (
@@ -1450,13 +1451,13 @@ export default class Weight extends React.Component { pointerEvents: "none", position: "absolute", zIndex: -1, - left: xMin, - top: yMin, + left: this.props.xMin, + top: this.props.yMin, }} > { top: labelTop + "px", // zIndex: -1, lineHeight: 0.5, - backgroundColor: labelBackgroundColor, + backgroundColor: this.labelBackgroundColor, }} > {force.description &&

{force.description}

} {!force.description &&

Force

} - {showForceMagnitudes && ( + {this.props.showForceMagnitudes && (

{Math.round(100 * force.magnitude) / 100} N

)}
); })} - {!dragging && - showForces && - updatedForces.map((force, index) => { - if (force.magnitude < epsilon) { + {!this.state.dragging && + this.props.showForces && + this.props.updatedForces.map((force, index) => { + if (force.magnitude < this.epsilon) { return; } - let arrowStartY: number = yPosition + radius; - const arrowStartX: number = xPosition + radius; + let arrowStartY: number = this.state.yPosition + this.props.radius; + const arrowStartX: number = this.state.xPosition + this.props.radius; let arrowEndY: number = arrowStartY - Math.abs(force.magnitude) * @@ -1549,10 +1550,10 @@ export default class Weight extends React.Component { } else { labelTop -= 40; } - labelTop = Math.min(labelTop, yMax + 50); - labelTop = Math.max(labelTop, yMin); - labelLeft = Math.min(labelLeft, xMax - 60); - labelLeft = Math.max(labelLeft, xMin); + labelTop = Math.min(labelTop, this.props.yMax + 50); + labelTop = Math.max(labelTop, this.props.yMin); + labelLeft = Math.min(labelLeft, this.props.xMax - 60); + labelLeft = Math.max(labelLeft, this.props.xMin); return (
@@ -1561,13 +1562,13 @@ export default class Weight extends React.Component { pointerEvents: "none", position: "absolute", zIndex: -1, - left: xMin, - top: yMin, + left: this.props.xMin, + top: this.props.yMin, }} > { left: labelLeft + "px", top: labelTop + "px", lineHeight: 0.5, - backgroundColor: labelBackgroundColor, + backgroundColor: this.labelBackgroundColor, }} > {force.description &&

{force.description}

} {!force.description &&

Force

} - {showForceMagnitudes && ( + {this.props.showForceMagnitudes && (

{Math.round(100 * force.magnitude) / 100} N

)}
-- cgit v1.2.3-70-g09d2