aboutsummaryrefslogtreecommitdiff
path: root/src/client/views/nodes/PhysicsSimulationWeight.tsx
diff options
context:
space:
mode:
authorbrynnchernosky <56202540+brynnchernosky@users.noreply.github.com>2023-02-07 12:58:32 -0500
committerbrynnchernosky <56202540+brynnchernosky@users.noreply.github.com>2023-02-07 12:58:32 -0500
commit2387225f18bd63f70569df7039af445064738836 (patch)
tree69439252d3967dd74d98985b826cd3fa25399a10 /src/client/views/nodes/PhysicsSimulationWeight.tsx
parent983ffa5e10abd89448e8b3f9be65894c7b775d84 (diff)
free weight and wedge work
Diffstat (limited to 'src/client/views/nodes/PhysicsSimulationWeight.tsx')
-rw-r--r--src/client/views/nodes/PhysicsSimulationWeight.tsx66
1 files changed, 33 insertions, 33 deletions
diff --git a/src/client/views/nodes/PhysicsSimulationWeight.tsx b/src/client/views/nodes/PhysicsSimulationWeight.tsx
index 92d65cf3d..63f8c965f 100644
--- a/src/client/views/nodes/PhysicsSimulationWeight.tsx
+++ b/src/client/views/nodes/PhysicsSimulationWeight.tsx
@@ -52,6 +52,10 @@ export interface IWeightProps {
coefficientOfKineticFriction: number;
wedgeWidth: number;
wedgeHeight: number;
+ xMax: number;
+ yMax: number;
+ xMin: number;
+ yMin: number;
}
interface IState {
@@ -92,10 +96,6 @@ export default class Weight extends React.Component<IWeightProps, IState> {
magnitude: this.props.mass * 9.81,
directionInDegrees: 270,
};
- xMax = 300;
- yMax = 300;
- xMin = 0;
- yMin = 0;
// Var
weightStyle = {
@@ -116,10 +116,10 @@ export default class Weight extends React.Component<IWeightProps, IState> {
// Helper function to go between display and real values
getDisplayYPos = (yPos: number) => {
- return this.yMax - yPos - 2 * this.props.radius + 5;
+ return this.props.yMax - yPos - 2 * this.props.radius + 5;
};
getYPosFromDisplay = (yDisplay: number) => {
- return this.yMax - yDisplay - 2 * this.props.radius + 5;
+ return this.props.yMax - yDisplay - 2 * this.props.radius + 5;
};
// Set display values based on real values
@@ -161,7 +161,7 @@ export default class Weight extends React.Component<IWeightProps, IState> {
if (this.props.updateDisplay.xDisplay != this.state.xPosition) {
let x = this.props.updateDisplay.xDisplay;
x = Math.max(0, x);
- x = Math.min(x, this.xMax - 2 * this.props.radius);
+ x = Math.min(x, this.props.xMax - 2 * this.props.radius);
this.setState({updatedStartPosX: x})
this.setState({xPosition: x})
this.props.setDisplayXPosition(x);
@@ -170,7 +170,7 @@ export default class Weight extends React.Component<IWeightProps, IState> {
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.yMax - 2 * this.props.radius);
+ y = Math.min(y, this.props.yMax - 2 * this.props.radius);
this.props.setDisplayYPosition(y);
let coordinatePosition = this.getYPosFromDisplay(y);
this.setState({updatedStartPosY: coordinatePosition})
@@ -235,7 +235,7 @@ export default class Weight extends React.Component<IWeightProps, IState> {
length * Math.cos(((90 - this.props.adjustPendulumAngle.angle) * Math.PI) / 180);
const y =
length * Math.sin(((90 - this.props.adjustPendulumAngle.angle) * Math.PI) / 180);
- const xPos = this.xMax / 2 - x - this.props.radius;
+ const xPos = this.props.xMax / 2 - x - this.props.radius;
const yPos = y - this.props.radius - 5;
this.setState({xPosition: xPos})
this.setState({yPosition: yPos})
@@ -343,7 +343,7 @@ export default class Weight extends React.Component<IWeightProps, IState> {
if (!this.props.pendulum) {
return this.props.updatedForces;
}
- const x = this.xMax / 2 - xPos - this.props.radius;
+ const x = this.props.xMax / 2 - xPos - this.props.radius;
const y = yPos + this.props.radius + 5;
let angle = (Math.atan(y / x) * 180) / Math.PI;
if (angle < 0) {
@@ -423,7 +423,7 @@ export default class Weight extends React.Component<IWeightProps, IState> {
if (this.state.yVelocity > 0) {
this.props.walls.forEach((wall) => {
if (wall.angleInDegrees == 0) {
- const groundY = (wall.yPos / 100) * this.yMax;
+ const groundY = (wall.yPos / 100) * this.props.yMax;
if (maxY >= groundY) {
console.log('collision with ground ', wall, maxY)
if (this.props.elasticCollisions) {
@@ -537,13 +537,13 @@ export default class Weight extends React.Component<IWeightProps, IState> {
e.preventDefault();
if (this.state.dragging) {
let newY = this.state.yPosition + e.clientY - this.state.clickPositionY;
- if (newY > this.yMax - 2 * this.props.radius) {
- newY = this.yMax - 2 * this.props.radius;
+ if (newY > this.props.yMax - 2 * this.props.radius) {
+ newY = this.props.yMax - 2 * this.props.radius;
}
let newX = this.state.xPosition + e.clientX - this.state.clickPositionX;
- if (newX > this.xMax - 2 * this.props.radius) {
- newX = this.xMax - 2 * this.props.radius;
+ if (newX > this.props.xMax - 2 * this.props.radius) {
+ newX = this.props.xMax - 2 * this.props.radius;
} else if (newX < 0) {
newX = 0;
}
@@ -551,7 +551,7 @@ export default class Weight extends React.Component<IWeightProps, IState> {
this.setState({yPosition: newY})
this.setState({updatedStartPosX: newX})
this.setState({updatedStartPosY: newY})
- this.props.setDisplayYPosition(Math.round((this.yMax - 2 * this.props.radius - newY + 5) * 100) / 100)
+ this.props.setDisplayYPosition(Math.round((this.props.yMax - 2 * this.props.radius - newY + 5) * 100) / 100)
this.setState({clickPositionX: e.clientX})
this.setState({clickPositionY: e.clientY})
this.setDisplayValues();
@@ -565,18 +565,18 @@ export default class Weight extends React.Component<IWeightProps, IState> {
}
this.setState({dragging: false});
let newY = this.state.yPosition + e.clientY - this.state.clickPositionY;
- if (newY > this.yMax - 2 * this.props.radius) {
- newY = this.yMax - 2 * this.props.radius;
+ if (newY > this.props.yMax - 2 * this.props.radius) {
+ newY = this.props.yMax - 2 * this.props.radius;
}
let newX = this.state.xPosition + e.clientX - this.state.clickPositionX;
- if (newX > this.xMax - 2 * this.props.radius) {
- newX = this.xMax - 2 * this.props.radius;
+ if (newX > this.props.xMax - 2 * this.props.radius) {
+ newX = this.props.xMax - 2 * this.props.radius;
} else if (newX < 0) {
newX = 0;
}
if (this.props.pendulum) {
- const x = this.xMax / 2 - newX - this.props.radius;
+ const x = this.props.xMax / 2 - newX - this.props.radius;
const y = newY + this.props.radius + 5;
let angle = (Math.atan(y / x) * 180) / Math.PI;
if (angle < 0) {
@@ -620,11 +620,11 @@ export default class Weight extends React.Component<IWeightProps, IState> {
zIndex: -2,
}}
>
- <svg width={this.xMax + "px"} height={300 + "px"}>
+ <svg width={this.props.xMax + "px"} height={300 + "px"}>
<line
x1={this.state.xPosition + this.props.radius}
y1={this.state.yPosition + this.props.radius}
- x2={this.xMax / 2}
+ x2={this.props.xMax / 2}
y2={-5}
stroke={"#deb887"}
strokeWidth="10"
@@ -647,7 +647,7 @@ export default class Weight extends React.Component<IWeightProps, IState> {
style={{
position: "absolute",
zIndex: -1,
- left: this.xMax / 2 + "px",
+ left: this.props.xMax / 2 + "px",
top: 30 + "px",
backgroundColor: this.labelBackgroundColor,
}}
@@ -669,7 +669,7 @@ export default class Weight extends React.Component<IWeightProps, IState> {
top: 0,
}}
>
- <svg width={this.xMax + "px"} height={300 + "px"}>
+ <svg width={this.props.xMax + "px"} height={300 + "px"}>
<defs>
<marker
id="accArrow"
@@ -738,7 +738,7 @@ export default class Weight extends React.Component<IWeightProps, IState> {
top: 0,
}}
>
- <svg width={this.xMax + "px"} height={300 + "px"}>
+ <svg width={this.props.xMax + "px"} height={300 + "px"}>
<defs>
<marker
id="velArrow"
@@ -815,10 +815,10 @@ export default class Weight extends React.Component<IWeightProps, IState> {
} else {
labelTop -= 40;
}
- labelTop = Math.min(labelTop, this.yMax + 50);
- labelTop = Math.max(labelTop, this.yMin);
- labelLeft = Math.min(labelLeft, this.xMax - 60);
- labelLeft = Math.max(labelLeft, this.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 (
<div key={index}>
@@ -827,12 +827,12 @@ export default class Weight extends React.Component<IWeightProps, IState> {
pointerEvents: "none",
position: "absolute",
zIndex: -1,
- left: this.xMin,
- top: this.yMin,
+ left: this.props.xMin,
+ top: this.props.yMin,
}}
>
<svg
- width={this.xMax - this.xMin + "px"}
+ width={this.props.xMax - this.props.xMin + "px"}
height={300 + "px"}
>
<defs>