From 7b3e1614fa645014c7de69a0f2057e389074c0ed Mon Sep 17 00:00:00 2001
From: vkalev <victor_kalev@brown.edu>
Date: Sat, 20 Nov 2021 15:38:54 -0500
Subject: updating intersections to map t-values to inks

---
 .../collectionFreeForm/CollectionFreeFormView.tsx  | 38 +++++++++++++---------
 1 file changed, 23 insertions(+), 15 deletions(-)

(limited to 'src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx')

diff --git a/src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx b/src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx
index 4447b7624..6f79c5eab 100644
--- a/src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx
+++ b/src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx
@@ -647,15 +647,18 @@ export class CollectionFreeFormView extends CollectionSubView<PanZoomDocument, P
         if (InteractionUtils.IsType(e, InteractionUtils.PENTYPE)) return;
         if (CurrentUserUtils.SelectedTool !== InkTool.None) {
             this._currPoint = { X: e.clientX, Y: e.clientY };
-            const intersections: DocumentView[] = this.getInkIntersection();
-            if (intersections.length > 0) {
-                intersections.forEach(ink => {
-                    if (!this._deleteList.includes(ink)) {
-                        this._deleteList.push(ink);
-                        // Lowering ink opacity to give the user a visual indicator of deletion.
-                        ink.Document.opacity = 0.5;
-                    }
-                });
+            const intersections: { [id: number]: DocumentView[] } = this.getEraserIntersections();
+            if (intersections) {
+                for (const t in intersections) {
+                    const inks = intersections[t];
+                    inks.forEach(ink => {
+                        if (!this._deleteList.includes(ink)) {
+                            this._deleteList.push(ink);
+                            // Lowering ink opacity to give the user a visual indicator of deletion.
+                            ink.Document.opacity = 0.5;
+                        }
+                    });
+                }
             }
         }
         if (InteractionUtils.IsType(e, InteractionUtils.TOUCHTYPE)) {
@@ -675,10 +678,10 @@ export class CollectionFreeFormView extends CollectionSubView<PanZoomDocument, P
 
     /**
      * Determines if the Eraser tool has intersected with an ink stroke in the current freeform collection.
-     * @returns The DocumentView of the intersected stroke.
+     * @returns A dictionary mapping the t-value intersection of the eraser with a list of ink DocumentViews.
      */
-    getInkIntersection = (): DocumentView[] => {
-        const inks: DocumentView[] = [];
+    getEraserIntersections = (): { [id: number]: DocumentView[] } => {
+        const intersections: { [id: number]: DocumentView[] } = {};
         this.childDocs
             .filter(doc => doc.type === DocumentType.INK)
             .forEach(doc => {
@@ -690,16 +693,21 @@ export class CollectionFreeFormView extends CollectionSubView<PanZoomDocument, P
                     const prevPointInkSpace = inkView?.ComponentView?.ptFromScreen?.(this._prevPoint);
                     const currPointInkSpace = inkView?.ComponentView?.ptFromScreen?.(this._currPoint);
                     if (prevPointInkSpace && currPointInkSpace) {
-                        const intersects = new Bezier(array.map(p => ({ x: p.X, y: p.Y }))).intersects(
+                        const curve = new Bezier(array.map(p => ({ x: p.X, y: p.Y })));
+                        const t = curve.intersects(
                             {
                                 p1: { x: prevPointInkSpace.X, y: prevPointInkSpace.Y },
                                 p2: { x: currPointInkSpace.X, y: currPointInkSpace.Y }
                             });
-                        if (inkView && intersects.length > 0) inks.push(inkView);
+                        if (inkView && t) {
+                            t.forEach(val => {
+                                intersections[+t[0]] ? intersections[+t[0]].push(inkView) : intersections[+t[0]] = [inkView];
+                            });
+                        }
                     }
                 }
             });
-        return inks;
+        return intersections;
     }
 
     handle1PointerMove = (e: TouchEvent, me: InteractionUtils.MultiTouchEvent<TouchEvent>) => {
-- 
cgit v1.2.3-70-g09d2

