Remove unnecessary conditional branches

This commit is contained in:
2026-01-23 14:58:38 -08:00
parent e1cfff39f0
commit 176fd98cb5

View File

@@ -126,6 +126,7 @@
<!-- <polygon class="wall" points="20,-50 10,-50 10,-60 20,-60" /> --> <!-- <polygon class="wall" points="20,-50 10,-50 10,-60 20,-60" /> -->
<!-- <polygon class="wall" points="-10,10 10,10 10,40 -10,40" /> --> <!-- <polygon class="wall" points="-10,10 10,10 10,40 -10,40" /> -->
<polygon class="wall" points="-10,-40 10,-40 10,-20 -10,-20" />
<!-- <polygon class="wall" points="-10,10 10,30 -10,40 -20,20" /> --> <!-- <polygon class="wall" points="-10,10 10,30 -10,40 -20,20" /> -->
<!-- <polygon class="wall" points="-20,-10 0,10 -20,20 -30,0" /> --> <!-- <polygon class="wall" points="-20,-10 0,10 -20,20 -30,0" /> -->
@@ -510,44 +511,6 @@ const Move = (() => {
console.log("INTENDED POSITION", p.x, p.y); console.log("INTENDED POSITION", p.x, p.y);
console.log("CONTACT POSITION", contact.position); console.log("CONTACT POSITION", contact.position);
if (isHorizontal) {
if (contact.edge.xa < contact.edge.xb) {
if (v.y <= 0) {
Velocity[entity_id] = { x: v.x, y: v.y };
Position[entity_id] = { x: p.x, y: p.y };
} else if (v.y > 0) {
Velocity[entity_id] = { x: v.x, y: 0 };
Position[entity_id] = { x: p.x, y: contact.position.y };
}
} else if (contact.edge.xa > contact.edge.xb) {
if (v.y <= 0) {
Velocity[entity_id] = { x: v.x, y: 0 };
Position[entity_id] = { x: p.x, y: contact.position.y };
} else if (v.y > 0) {
Velocity[entity_id] = { x: v.x, y: v.y };
Position[entity_id] = { x: p.x, y: p.y };
}
}
} else if (isVertical) {
if (contact.edge.ya > contact.edge.yb) {
if (v.x <= 0) {
Velocity[entity_id] = { x: v.x, y: v.y };
Position[entity_id] = { x: p.x, y: p.y };
} else if (v.x > 0) {
Velocity[entity_id] = { x: 0, y: v.y };
Position[entity_id] = { x: contact.position.x, y: p.y };
}
} else if (contact.edge.ya < contact.edge.yb) {
if (v.x <= 0) {
Velocity[entity_id] = { x: 0, y: v.y };
Position[entity_id] = { x: contact.position.x, y: p.y };
} else if (v.x > 0) {
Velocity[entity_id] = { x: v.x, y: v.y };
Position[entity_id] = { x: p.x, y: p.y };
}
}
} else {
if (contact.edge.xa < contact.edge.xb && contact.edge.ya < contact.edge.yb) {
// const m1 = slope({ xa: vx, ya: vy, xb: v.x, yb: v.y }); // const m1 = slope({ xa: vx, ya: vy, xb: v.x, yb: v.y });
// const m2 = slope(contact.edge); // const m2 = slope(contact.edge);
// const theta = Math.atan(Math.abs((m1-m2)/(1+m1*m2))); // const theta = Math.atan(Math.abs((m1-m2)/(1+m1*m2)));
@@ -683,10 +646,6 @@ const Move = (() => {
// Position[entity_id] = { x: p.x, y: p.y }; // Position[entity_id] = { x: p.x, y: p.y };
// console.log("contact", contact.edge); // console.log("contact", contact.edge);
// Position[entity_id] = contact.position; // Position[entity_id] = contact.position;
} else {
}
}
} }
} else { } else {
Velocity[entity_id] = { x: v.x, y: v.y }; Velocity[entity_id] = { x: v.x, y: v.y };

Before

Width:  |  Height:  |  Size: 57 KiB

After

Width:  |  Height:  |  Size: 54 KiB