diff --git a/html/images/space.svg b/html/images/space.svg
index c76c9d7..e0ba281 100644
--- a/html/images/space.svg
+++ b/html/images/space.svg
@@ -446,16 +446,12 @@ const Move = (() => {
const denom = x21*y43-x43*y21;
const denomr = Math.round(x21r*100*y43r-x43r*y21r*100) / 100;
-
const x31 = x3-x1;
const x31r = subR(x3, x1);
const y31 = y3-y1;
const y31r = subR(y3, y1);
-
-
-
// if (denom) {
if (denomr) {
// const s = ((x3-x1)*(y4-y3)-(x4-x3)*(y3-y1))/denom;
@@ -474,8 +470,6 @@ const Move = (() => {
// const tr = (-(x21r*y31r*100*100-x31r*y21r*100*100) / denomr)/10000;
const tr = -Math.round((x21r*y31r-x31r*y21r) / denomr * 100) / 100;
-
-
// console.log("s", s, "t", t);
// console.log("sr", sr, "tr", tr);
const x1r = Math.round(x1 * 100);
@@ -487,60 +481,26 @@ const Move = (() => {
const y3r = Math.round(y3 * 100);
const y4r = Math.round(y4 * 100);
-
// 2.03 * 10
// 20.299999999999997
- // offset position slightly (by adding 1 to sr), so contact point is
- // not inside the wall
- const xsrOff = Math.round(x1r + (sr + 1) * (x2r - x1r)) / 100;
- const ysrOff = Math.round(y1r + (sr + 1) * (y2r - y1r)) / 100;
-
- // if (roundedS >= 0 && roundedS <= 1 && roundedT >= 0 && roundedT <= 1) {
- // if (s >= 0 && s < 1 && t >= 0 && t <= 1) { // this falls through
- // if (s >= 0 && s <= 1 && t >= 0 && t <= 1) { // this sometimes falls through
- if (sr >= 0 && sr <= 1 && tr >= 0 && tr <= 1) { // this sometimes falls through
- // const xs = x1 + s * (x2 - x1);
- // const ys = y1 + s * (y2 - y1);
+ if (sr >= 0 && sr <= 1 && tr >= 0 && tr <= 1) {
const xs = x1 + s * (x2 - x1);
const ys = y1 + s * (y2 - y1);
- // console.log("xs", xs, "ys", ys);
-
- // Math.round(Math.round(-2.03 * 100) + 0.45000000000000445 * (Math.round(-1.95 * 100) - Math.round(-2.03 * 100))) / 100
- // console.log("x1", x1, "x2", x2);
- // console.log("y1", y1, "y2", y2);
const xsr = Math.round(x1r + sr * (x2r - x1r)) / 100;
const ysr = Math.round(y1r + sr * (y2r - y1r)) / 100;
-
const xtr = Math.round(x3r + tr * (x4r - x3r)) / 100;
const ytr = Math.round(y3r + tr * (y4r - y3r)) / 100;
- // console.log("xsr", xsr, "ysr", ysr, " ::: xtr", xtr, "ytr", ytr);
+ // offset position slightly (by adding 1 to sr), so contact point is
+ // not inside the wall
+ const xsrOff = Math.round(x1r + (sr + 1) * (x2r - x1r)) / 100;
+ const ysrOff = Math.round(y1r + (sr + 1) * (y2r - y1r)) / 100;
- const lnD = distance(xtr, ytr, edge.xa, edge.ya);
-
- const ln = document.createElementNS(namespaceURIsvg, 'line');
- ln.setAttribute('x1', edge.xa);
- ln.setAttribute('y1', edge.ya);
- ln.setAttribute('x2', edge.xb);
- ln.setAttribute('y2', edge.yb);
-
- const lnP = ln.getPointAtLength(lnD);
-
- // collision.position = { x: xs, y: ys };
- // collision.position = { x: xsr, y: ysr };
collision.position = { x: xsrOff, y: ysrOff };
- // collision.position = { x: xtr, y: ytr };
- // collision.position = lnP;
-
- // collision.position = { x: xs, y: ys };
- // collision.position = { x: +xs.toFixed(15), y: +ys.toFixed(15) };
-
-
- // collision.position = { x: xc, y: yc };
return true;
}
@@ -618,6 +578,24 @@ const Move = (() => {
};
}
+ function cornerContactPosition(xc, yc, x, y, corner, cLength) {
+ const positionSeg = { xa: xc, ya: yc, xb: x, yb: y };
+ const posNormIntxn = perpIntxn(slope(positionSeg), x, y, corner.x, corner.y);
+
+ // shortest distance between corner and path
+ const aLength = distance(corner.x, corner.y, posNormIntxn.x, posNormIntxn.y);
+ // distance from position/normal intersection
+ const bLength = Math.sqrt(Math.abs(cLength ** 2 - aLength ** 2));
+
+ const intxnSeg = document.createElementNS(namespaceURIsvg, 'line');
+ intxnSeg.setAttribute('x1', posNormIntxn.x);
+ intxnSeg.setAttribute('y1', posNormIntxn.y);
+ intxnSeg.setAttribute('x2', x);
+ intxnSeg.setAttribute('y2', y);
+
+ return intxnSeg.getPointAtLength(bLength);
+ }
+
function withinCollisionDistance({ x: x1, y: y1 }, { x: x2, y: y2 }, distance) {
const diffx = x2;
const diffy = y2;
@@ -1166,24 +1144,6 @@ function isLandable(edge) {
// return Object.is(slope(edge), +0);
}
-function cornerContactPosition(xc, yc, x, y, corner, cLength) {
- const positionSeg = { xa: xc, ya: yc, xb: x, yb: y };
- const posNormIntxn = perpIntxn(slope(positionSeg), x, y, corner.x, corner.y);
-
- // shortest distance between corner and path
- const aLength = distance(corner.x, corner.y, posNormIntxn.x, posNormIntxn.y);
- // distance from position/normal intersection
- const bLength = Math.sqrt(Math.abs(cLength ** 2 - aLength ** 2));
-
- const intxnSeg = document.createElementNS(namespaceURIsvg, 'line');
- intxnSeg.setAttribute('x1', posNormIntxn.x);
- intxnSeg.setAttribute('y1', posNormIntxn.y);
- intxnSeg.setAttribute('x2', x);
- intxnSeg.setAttribute('y2', y);
-
- return intxnSeg.getPointAtLength(bLength);
-}
-
function edgeContactPosition(xc, yc, x, y, edge, radius) {
const baseSlope = slope(edge);
// if (Object.is(baseSlope, 0)) s.isLanded = true;
@@ -1297,7 +1257,7 @@ function updateShip(s, elapsed) {
if (s.collision) {
let posP;
if (s.collision.corner) {
- posP = cornerContactPosition(p.x, p.y, px, py, s.collision.corner, s.radius);
+ // posP = cornerContactPosition(p.x, p.y, px, py, s.collision.corner, s.radius);
} else if (s.collision.edge) {
if (isLandable(s.collision.edge) && s.gearDown) s.isLanded = true;