From 6a07e9995264c913632e4247d553feddc6f58671 Mon Sep 17 00:00:00 2001 From: Zachary Zhang Date: Wed, 25 Sep 2024 22:51:29 -0400 Subject: improve performance of scribble and added bounding box delete --- src/client/views/GestureOverlay.tsx | 61 +++++++++++++++++++------------------ 1 file changed, 31 insertions(+), 30 deletions(-) (limited to 'src') diff --git a/src/client/views/GestureOverlay.tsx b/src/client/views/GestureOverlay.tsx index 7e396d475..26cffb18b 100644 --- a/src/client/views/GestureOverlay.tsx +++ b/src/client/views/GestureOverlay.tsx @@ -37,6 +37,7 @@ import { SetActiveInkColor, SetActiveInkWidth, } from './nodes/DocumentView'; +import { docs } from 'googleapis/build/src/apis/docs'; export enum ToolglassTools { InkToText = 'inktotext', IgnoreGesture = 'ignoregesture', @@ -149,7 +150,7 @@ export class GestureOverlay extends ObservableReactComponent doc.type === 'ink').map(doc => DocumentView.getDocumentView(doc, DocumentView.getDocumentView(doc))); if ((ffView?.ComponentView as CollectionFreeFormView).childDocs) { //how many cusps the scribble hsa @@ -159,9 +160,7 @@ export class GestureOverlay extends ObservableReactComponent otherInk.ptToScreen(point)); if (this.isRectangleOverlap(this.getExtremeCoordinates(otherScreenPts), this.getExtremeCoordinates(inkData))) { - console.log('somethings in'); const intersects = this.doInksIntersect(inkData, otherScreenPts); - console.log(intersects); intersects.forEach(intersect => { let percentage = ''; if (intersect.includes('/')) { @@ -171,6 +170,9 @@ export class GestureOverlay extends ObservableReactComponent !docsInBoundingBox.includes(doc)); + docsToDelete.push(...docsInBoundingBox); docsToDelete.push(doc); }); } @@ -178,6 +180,8 @@ export class GestureOverlay extends ObservableReactComponent 3 && this.determineIfScribble(intersectArray)) { + const uniqueArray = Array.from(new Set(docsToDelete)); + console.log(uniqueArray.length); console.log('is a scribble'); docsToDelete.forEach(doc => { ffView?.ComponentView?.removeDocument?.(doc); @@ -188,6 +192,23 @@ export class GestureOverlay extends ObservableReactComponent + typeof doc.x === 'number' && + typeof doc.y === 'number' && + typeof doc.width === 'number' && + typeof doc.height === 'number' && + typeof mainDoc.x === 'number' && + typeof mainDoc.y === 'number' && + typeof mainDoc.width === 'number' && + typeof mainDoc.height === 'number' && + doc.x < mainDoc.x + mainDoc.width && + doc.x + doc.width > mainDoc.x && + doc.y < mainDoc.y + mainDoc.height && + doc.y + doc.height > mainDoc.y + ); + } /** * this method determines if what the user drew is a scribble based on certain criteria. * @param cuspBooleanArray will take in an array of booleans tht represent what triangles in the scribble @@ -207,7 +228,7 @@ export class GestureOverlay extends ObservableReactComponent value).length; const percentageTrues = trueCount / cuspBooleanArray.length; - return percentageTrues > 0.5 || hasObjectInFirstAndLast25; + return percentageTrues >= 0.5 || hasObjectInFirstAndLast25; } /** * determines if two rectangles are overlapping each other @@ -231,6 +252,7 @@ export class GestureOverlay extends ObservableReactComponent view.ComponentView instanceof CollectionFreeFormView); if (ffView && ffView.ComponentView instanceof CollectionFreeFormView) { for (let i = 0; i < scribble.length - 3; i += 4) { @@ -238,7 +260,11 @@ export class GestureOverlay extends ObservableReactComponent ({ + X: point.x, + Y: point.y, + })); + if (ffView && ffView.ComponentView instanceof CollectionFreeFormView && this.isRectangleOverlap(extremeScribble, this.getExtremeCoordinates(points))) { const result = (ffView.ComponentView as CollectionFreeFormView).bintersects(intersectCurve, eraserCurve)[0]; if (result !== undefined) { intersectArray.push(result.toString()); @@ -249,31 +275,6 @@ export class GestureOverlay extends ObservableReactComponent view.ComponentView instanceof CollectionFreeFormView); - if (ffView && ffView.ComponentView instanceof CollectionFreeFormView) { - for (let i = 0; i < points.length - 3; i += 4) { - // iterate over each segment of bezier curve - for (let j = 0; j < line.length - 3; j += 4) { - const intersectCurve: Bezier = InkField.Segment(points, i); // other curve - const eraserCurve: Bezier = InkField.Segment(line, j); // eraser curve - if (ffView && ffView.ComponentView instanceof CollectionFreeFormView) { - //(ffView.ComponentView as CollectionFreeFormView).bintersects(); - } - } - } - } - return false; - } - dryInk = () => { const newPoints = this._points.reduce((p, pts) => { p.push([pts.X, pts.Y]); -- cgit v1.2.3-70-g09d2