diff options
author | vkalev <victor_kalev@brown.edu> | 2021-11-20 15:38:54 -0500 |
---|---|---|
committer | vkalev <victor_kalev@brown.edu> | 2021-11-20 15:38:54 -0500 |
commit | 7b3e1614fa645014c7de69a0f2057e389074c0ed (patch) | |
tree | 72c5438d3c21c1201f1d66c5b6be387f90d6a0a3 | |
parent | 9b5c863f7b88db579fba3ea8f85c43c2562f4289 (diff) |
updating intersections to map t-values to inks
-rw-r--r-- | src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx | 38 |
1 files changed, 23 insertions, 15 deletions
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>) => { |