diff options
Diffstat (limited to 'src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx')
| -rw-r--r-- | src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx | 81 |
1 files changed, 34 insertions, 47 deletions
diff --git a/src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx b/src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx index 110f7816c..be96b914c 100644 --- a/src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx +++ b/src/client/views/collections/collectionFreeForm/CollectionFreeFormView.tsx @@ -517,6 +517,7 @@ export class CollectionFreeFormView extends CollectionSubView<Partial<collection setupMoveUpEvents(this, e, this.onPointerMove, emptyFunction, emptyFunction, hit !== -1, false); } break; + default: } } } @@ -767,10 +768,8 @@ export class CollectionFreeFormView extends CollectionSubView<Partial<collection insideEraserOutline = (eraserOutline: InkData, point: { X: number; Y: number }) => { let isInside = false; if (!isNaN(eraserOutline[0].X) && !isNaN(eraserOutline[0].Y)) { - let minX = eraserOutline[0].X, - maxX = eraserOutline[0].X; - let minY = eraserOutline[0].Y, - maxY = eraserOutline[0].Y; + let [minX, minY] = [eraserOutline[0].X, eraserOutline[0].Y]; + let [maxX, maxY] = [eraserOutline[0].X, eraserOutline[0].Y]; for (let i = 1; i < eraserOutline.length; i++) { const currPoint: { X: number; Y: number } = eraserOutline[i]; minX = Math.min(currPoint.X, minX); @@ -784,7 +783,7 @@ export class CollectionFreeFormView extends CollectionSubView<Partial<collection } for (let i = 0, j = eraserOutline.length - 1; i < eraserOutline.length; j = i, i++) { - if (eraserOutline[i].Y > point.Y != eraserOutline[j].Y > point.Y && point.X < ((eraserOutline[j].X - eraserOutline[i].X) * (point.Y - eraserOutline[i].Y)) / (eraserOutline[j].Y - eraserOutline[i].Y) + eraserOutline[i].X) { + if (eraserOutline[i].Y > point.Y !== eraserOutline[j].Y > point.Y && point.X < ((eraserOutline[j].X - eraserOutline[i].X) * (point.Y - eraserOutline[i].Y)) / (eraserOutline[j].Y - eraserOutline[i].Y) + eraserOutline[i].X) { isInside = !isInside; } } @@ -845,7 +844,7 @@ export class CollectionFreeFormView extends CollectionSubView<Partial<collection getRadiusEraserIntersections = (lastPoint: { X: number; Y: number }, currPoint: { X: number; Y: number }) => { // set distance of the eraser's bounding box based on the zoom let boundingBoxDist = ActiveEraserWidth() + 5; - this.zoomScaling() < 1 ? (boundingBoxDist = boundingBoxDist / (this.zoomScaling() * 1.5)) : (boundingBoxDist *= this.zoomScaling()); + this.zoomScaling() < 1 ? (boundingBoxDist /= this.zoomScaling() * 1.5) : (boundingBoxDist *= this.zoomScaling()); const eraserMin = { X: Math.min(lastPoint.X, currPoint.X) - boundingBoxDist, Y: Math.min(lastPoint.Y, currPoint.Y) - boundingBoxDist }; const eraserMax = { X: Math.max(lastPoint.X, currPoint.X) + boundingBoxDist, Y: Math.max(lastPoint.Y, currPoint.Y) + boundingBoxDist }; @@ -961,29 +960,25 @@ export class CollectionFreeFormView extends CollectionSubView<Partial<collection } else if (segmentTs[j] === Math.floor(inkData.length / 4) + 1) { // the last end break; + } else if (!continueErasing) { + currSegment.push(inkBezier.split(0, segmentTs[j] - currCurveT)); + continueErasing = true; } else { - if (!continueErasing) { - currSegment.push(inkBezier.split(0, segmentTs[j] - currCurveT)); - continueErasing = true; - } else { - // we've reached the end of the part to take out... - continueErasing = false; - if (currSegment.length > 0) { - segments.push(currSegment); // ...so we add it to the list and reset currSegment - if (firstSegment.length === 0) { - firstSegment = currSegment; - } - currSegment = []; + // we've reached the end of the part to take out... + continueErasing = false; + if (currSegment.length > 0) { + segments.push(currSegment); // ...so we add it to the list and reset currSegment + if (firstSegment.length === 0) { + firstSegment = currSegment; } - currSegment.push(inkBezier.split(segmentTs[j] - currCurveT, 1)); + currSegment = []; } + currSegment.push(inkBezier.split(segmentTs[j] - currCurveT, 1)); } } - } else { - if (!continueErasing) { - // push the bezier piece if not in the eraser circle - currSegment.push(inkBezier); - } + } else if (!continueErasing) { + // push the bezier piece if not in the eraser circle + currSegment.push(inkBezier); } } @@ -1078,13 +1073,11 @@ export class CollectionFreeFormView extends CollectionSubView<Partial<collection segment2.push(inkSegment.split(intersections[closestTs[1]] - currCurveT, 1)); continueErasing = false; hasSplit = true; - } else { - if (!continueErasing && !hasSplit) { - // segment doesn't get pushed if continueErasing is true - segment1.push(inkSegment); - } else if (!continueErasing && hasSplit) { - segment2.push(inkSegment); - } + } else if (!continueErasing && !hasSplit) { + // segment doesn't get pushed if continueErasing is true + segment1.push(inkSegment); + } else if (!continueErasing && hasSplit) { + segment2.push(inkSegment); } } else if (splitSegment1 === -1) { // case where first end is erased @@ -1096,13 +1089,11 @@ export class CollectionFreeFormView extends CollectionSubView<Partial<collection segment2.push(inkSegment.split(intersections[closestTs[1]] - currCurveT, 1)); } hasSplit = true; - } else { - if (isClosedCurve && currCurveT === segmentIndexes.lastElement()) { - segment2.push(inkSegment.split(0, intersections.lastElement() - currCurveT)); - continueErasing = true; - } else if (hasSplit && !continueErasing) { - segment2.push(inkSegment); - } + } else if (isClosedCurve && currCurveT === segmentIndexes.lastElement()) { + segment2.push(inkSegment.split(0, intersections.lastElement() - currCurveT)); + continueErasing = true; + } else if (hasSplit && !continueErasing) { + segment2.push(inkSegment); } } else { // case where last end is erased @@ -1118,10 +1109,8 @@ export class CollectionFreeFormView extends CollectionSubView<Partial<collection segment1.push(inkSegment.split(0, intersections[closestTs[0]] - currCurveT)); hasSplit = true; continueErasing = true; - } else { - if ((isClosedCurve && hasSplit && !continueErasing) || (!isClosedCurve && !hasSplit)) { - segment1.push(inkSegment); - } + } else if ((isClosedCurve && hasSplit && !continueErasing) || (!isClosedCurve && !hasSplit)) { + segment1.push(inkSegment); } } } @@ -1165,12 +1154,10 @@ export class CollectionFreeFormView extends CollectionSubView<Partial<collection } else { return this.getClosestTs(tVals, excludeT, mid + 1, endIndex); } + } else if (mid - 1 >= startIndex && tVals[mid - 1] < excludeT) { + return [mid - 1, mid]; } else { - if (mid - 1 >= startIndex && tVals[mid - 1] < excludeT) { - return [mid - 1, mid]; - } else { - return this.getClosestTs(tVals, excludeT, startIndex, mid - 1); - } + return this.getClosestTs(tVals, excludeT, startIndex, mid - 1); } } }; |
