diff options
author | eleanor-park <eleanor_park@brown.edu> | 2024-10-01 18:45:03 -0400 |
---|---|---|
committer | eleanor-park <eleanor_park@brown.edu> | 2024-10-01 18:45:03 -0400 |
commit | 5d859cab5fa714860723fa252498c407d5909cdc (patch) | |
tree | a8366cbcacdbb18fb24204e8b89187db49a26785 /src/fields/InkField.ts | |
parent | 06ab521c759e44a26be58fdf7ffc8d790e551236 (diff) | |
parent | 39dc004c0f8e4bcc21ca0c2ecb0b665037f3d1ad (diff) |
Merge branch 'eleanor-gptdraw' of https://github.com/brown-dash/Dash-Web into eleanor-gptdraw
Diffstat (limited to 'src/fields/InkField.ts')
-rw-r--r-- | src/fields/InkField.ts | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/src/fields/InkField.ts b/src/fields/InkField.ts index 123d32301..17b99b033 100644 --- a/src/fields/InkField.ts +++ b/src/fields/InkField.ts @@ -14,6 +14,7 @@ export enum InkTool { StrokeEraser = 'strokeeraser', SegmentEraser = 'segmenteraser', RadiusEraser = 'radiuseraser', + Eraser = 'eraser', // not a real tool, but a class of tools Stamp = 'stamp', Write = 'write', PresentationPin = 'presentationpin', @@ -103,6 +104,26 @@ export class InkField extends ObjectField { const top = Math.min(...ys); return { right, left, bottom, top, width: right - left, height: bottom - top }; } + + // for some reason bezier.js doesn't handle the case of intersecting a linear curve, so we wrap the intersection + // call in a test for linearity + public static bintersects(curve: Bezier, otherCurve: Bezier) { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + if ((curve as any)._linear) { + // bezier.js doesn't intersect properly if the curve is actually a line -- so get intersect other curve against this line, then figure out the t coordinates of the intersection on this line + const intersections = otherCurve.lineIntersects({ p1: curve.points[0], p2: curve.points[3] }); + if (intersections.length) { + const intPt = otherCurve.get(intersections[0]); + const intT = curve.project(intPt).t; + return intT ? [intT] : []; + } + } + // eslint-disable-next-line @typescript-eslint/no-explicit-any + if ((otherCurve as any)._linear) { + return curve.lineIntersects({ p1: otherCurve.points[0], p2: otherCurve.points[3] }); + } + return curve.intersects(otherCurve); + } } ScriptingGlobals.add('InkField', InkField); |