From 1b4665378cd93aa49388d92831ce5785b4423bbf Mon Sep 17 00:00:00 2001 From: bobzel Date: Sun, 14 Apr 2024 16:19:55 -0400 Subject: fixed coordinate system transform for ink --- .../collectionFreeForm/CollectionFreeFormView.tsx | 60 +++++++++++----------- 1 file changed, 29 insertions(+), 31 deletions(-) (limited to 'src') diff --git a/src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx b/src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx index 2bf4f3c1e..57868825e 100644 --- a/src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx +++ b/src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx @@ -755,13 +755,12 @@ export class CollectionFreeFormView extends CollectionSubView @@ -842,15 +841,15 @@ export class CollectionFreeFormView extends CollectionSubView { + radiusErase = (ink: DocumentView, eraseT: number, inkCoords: { X: number; Y: number }): Segment[] => { const segments: Segment[] = []; var segment1: Segment = []; var segment2: Segment = []; const eraseRadius = ActiveInkWidth() / 2; const inkStroke = ink?.ComponentView as InkingStroke; - const { inkData } = (inkStroke).inkScaledData(); + const { inkData } = inkStroke.inkScaledData(); - const eraserInkData = inkStroke.splitByEraser(inkCoords, eraseRadius); + const eraserInkData = inkStroke.splitByEraser(inkCoords, eraseRadius).inkData; const tVals: number[] = []; // should be the tvals of the intersections @@ -858,16 +857,16 @@ export class CollectionFreeFormView extends CollectionSubView { - // // Converting the Bezier.js Split type to a t-value number. - // const t = +val.toString().split('/')[0]; - // if (i % 2 === 0 && !tVals.includes(t)) tVals.push(t); // bcz: Hack! don't know why but intersection points are doubled from bezier.js (but not identical). - // }); + const inkSegment: Bezier = InkField.Segment(inkData, i); + // this.bintersects(inkSegment, eraserBezier).forEach((val: string | number, i: number) => { + // // Converting the Bezier.js Split type to a t-value number. + // const t = +val.toString().split('/')[0]; + // if (i % 2 === 0 && !tVals.includes(t)) tVals.push(t); // bcz: Hack! don't know why but intersection points are doubled from bezier.js (but not identical). + // }); } } // segment1.push(eraserBezier); - + // for (var i = 0; i < inkData.length - 3; i += 4) { // const currCurveT = Math.floor(i/4); // const inkSegment: Bezier = InkField.Segment(inkData, i); @@ -897,7 +896,7 @@ export class CollectionFreeFormView extends CollectionSubView { - const segments: Segment[] = []; var segment1: Segment = []; var segment2: Segment = []; const { inkData } = (ink?.ComponentView as InkingStroke).inkScaledData(); var intersections: number[] = []; // list of the ink stroke's intersections var segmentIndexes: number[] = []; // list of indexes of the curve's segment where each intersection occured - + // loops through each segment and adds intersections to the list for (var i = 0; i < inkData.length - 3; i += 4) { const inkSegment: Bezier = InkField.Segment(inkData, i); var currIntersects = this.getInkIntersections(i, ink, inkSegment).sort(); // get current segments intersections (if any) and add the curve index - currIntersects = currIntersects.map(tVal => tVal + Math.floor(i/4)); + currIntersects = currIntersects.map(tVal => tVal + Math.floor(i / 4)); if (currIntersects.length) { - intersections = [...intersections, ...currIntersects] + intersections = [...intersections, ...currIntersects]; for (var j = 0; j < currIntersects.length; j++) { segmentIndexes.push(Math.floor(i / 4)); } @@ -937,9 +935,7 @@ export class CollectionFreeFormView extends CollectionSubView value > 0.0001 && value < Math.floor(inkData.length / 4) ? index : -1) - .filter(index => index !== -1); + const indices = intersections.map((value, index) => (value > 0.0001 && value < Math.floor(inkData.length / 4) ? index : -1)).filter(index => index !== -1); // Filter intersections and segmentIndexes based on validIndices intersections = indices.map(index => intersections[index]); @@ -959,9 +955,11 @@ export class CollectionFreeFormView extends CollectionSubView { if (tVals[startIndex] >= excludeT) { return [-1, startIndex]; - } - else if (tVals[endIndex] < excludeT) { + } else if (tVals[endIndex] < excludeT) { return [endIndex, -1]; - } - else { + } else { const mid = Math.floor((startIndex + endIndex) / 2); if (excludeT >= tVals[mid]) { if (mid + 1 <= endIndex && tVals[mid + 1] > excludeT) { -- cgit v1.2.3-70-g09d2