From b6f2451920328a3b7c01388bee8d60cac868d183 Mon Sep 17 00:00:00 2001
From: Daniel Perelman <perelman@cs.washington.edu>
Date: Fri, 29 Sep 2023 12:05:48 -0700
Subject: [PATCH] [WIP] Pass by still not quite right.

---
 www/js/animation.ts | 17 +++++------------
 1 file changed, 5 insertions(+), 12 deletions(-)

diff --git a/www/js/animation.ts b/www/js/animation.ts
index f0fd0c3..2783126 100644
--- a/www/js/animation.ts
+++ b/www/js/animation.ts
@@ -421,9 +421,8 @@ MIN[(x_0**2+y_0**2 + (2x_0*x_m+2y_0*y_m)*t + (x_m**2+y_m**2)*t**2)]
 
 a = x_m**2+y_m**2 = (xa_m-xb_m)**2 + (ya_m-yb_m)**2
 b = (2x_0*x_m+2y_0*y_m) = 2*((xa_0-xb_0)*(xa_m-xb_m) + (ya_0-yb_0)*(ya_m-yb_m))
-c = x_0**2+y_0**2 = (xa_0-xb_0)**2 + (ya_0-yb_0)**2
 
-t = (-b +/- sqrt(b**2 - 4ac)) / 2a
+t = -b/2a
        */
       const otherVector = OffsetMinus(otherPath.end, otherPath.start);
       const m = OffsetMinus(otherVector, vector);
@@ -431,23 +430,17 @@ t = (-b +/- sqrt(b**2 - 4ac)) / 2a
 
       const a = m.x*m.x + m.y*m.y;
       const b = 2*(i.x*m.x + i.y*m.y);
-      const c = i.x*i.x + i.y*i.y;
 
-      /*
-      const tPlus = (-b + Math.sqrt(b**b - 4*a*c))/(2*a);
-      const tMinus = (-b - Math.sqrt(b**b - 4*a*c))/(2*a);
-
-      const t = tPlus >= 0 && tPlus <= 1 ? tPlus
-              : tMinus >= 0 && tMinus <= 1 ? tMinus
-              : undefined;
-      */
       const tMin = -b/(2*a);
       const t = tMin >= 0 && tMin <= 1 ? tMin : undefined;
 
       if (t !== undefined) {
         this.progressCenter = t;
         this.actualCenter = interpolateLinearOffset(t, this.startPosition.position, this.endPosition.position);
-        const distanceAdjustment = OffsetDistance(this.actualCenter, interpolateLinearOffset(t, otherPath.start, otherPath.end));
+        const otherCenter = interpolateLinearOffset(t, otherPath.start, otherPath.end);
+        const otherSideways = OffsetMinus(this.actualCenter, otherCenter);
+        const sidewaysLinedUp = Math.sign(otherSideways.x) === Math.sign(sideways.x) && Math.sign(otherSideways.y) === Math.sign(sideways.y);
+        const distanceAdjustment = OffsetDistance(this.actualCenter, otherCenter) * (sidewaysLinedUp ? +1 : -1);
         if (this.distanceAtMidpoint > 0) {
           this.distanceAtMidpoint = Math.max(0, this.distanceAtMidpoint - distanceAdjustment);
         } else {