From 54fa0c908969236908aab47b908fb648ddc01cb8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1rk=20Tolm=C3=A1cs?= Date: Mon, 26 Jan 2026 20:52:13 +0100 Subject: [PATCH] fix: Increase iteration on curve intersection calc (#10707) Signed-off-by: Mark Tolmacs --- .../data/__snapshots__/restore.test.ts.snap | 47 ------------------- packages/math/src/curve.ts | 20 +------- 2 files changed, 1 insertion(+), 66 deletions(-) diff --git a/packages/excalidraw/tests/data/__snapshots__/restore.test.ts.snap b/packages/excalidraw/tests/data/__snapshots__/restore.test.ts.snap index 802edcc373..e3c0581522 100644 --- a/packages/excalidraw/tests/data/__snapshots__/restore.test.ts.snap +++ b/packages/excalidraw/tests/data/__snapshots__/restore.test.ts.snap @@ -428,50 +428,3 @@ exports[`restoreElements > should restore text element correctly with unknown fo "y": 0, } `; - -exports[`restoreElements > should strip arrow binding if repair throws 1`] = ` -{ - "angle": 0, - "backgroundColor": "transparent", - "boundElements": [], - "customData": undefined, - "elbowed": false, - "endArrowhead": null, - "endBinding": null, - "fillStyle": "solid", - "frameId": null, - "groupIds": [], - "height": 100, - "id": "id-arrow01", - "index": "a0", - "isDeleted": false, - "link": null, - "locked": false, - "opacity": 100, - "points": [ - [ - 0, - 0, - ], - [ - 100, - 100, - ], - ], - "roughness": 1, - "roundness": null, - "seed": Any, - "startArrowhead": null, - "startBinding": null, - "strokeColor": "#1e1e1e", - "strokeStyle": "solid", - "strokeWidth": 2, - "type": "arrow", - "updated": 1, - "version": 2, - "versionNonce": Any, - "width": 100, - "x": 0, - "y": 0, -} -`; diff --git a/packages/math/src/curve.ts b/packages/math/src/curve.ts index 55db76877e..32f537f434 100644 --- a/packages/math/src/curve.ts +++ b/packages/math/src/curve.ts @@ -1,7 +1,6 @@ import { isPoint, pointDistance, pointFrom, pointFromVector } from "./point"; import { vector, vectorNormal, vectorNormalize, vectorScale } from "./vector"; import { LegendreGaussN24CValues, LegendreGaussN24TValues } from "./constants"; -import { lineSegment, lineSegmentIntersectionPoints } from "./segment"; import type { Curve, GlobalPoint, LineSegment, LocalPoint } from "./types"; @@ -139,7 +138,7 @@ const calculate = ( l: LineSegment, c: Curve, ) => { - const solution = solveWithAnalyticalJacobian(c, l, t0, s0, 1e-2, 3); + const solution = solveWithAnalyticalJacobian(c, l, t0, s0, 1e-2, 4); if (!solution) { return null; @@ -175,23 +174,6 @@ export function curveIntersectLineSegment< return [solution]; } - // Fallback: approximate the curve with short segments to catch near-endpoint hits. - const startHit = lineSegmentIntersectionPoints( - lineSegment(bezierEquation(c, 0), bezierEquation(c, 1 / 20)), - l, - ); - if (startHit) { - return [startHit]; - } - - const endHit = lineSegmentIntersectionPoints( - lineSegment(bezierEquation(c, 19 / 20), bezierEquation(c, 1)), - l, - ); - if (endHit) { - return [endHit]; - } - return []; }