This commit is contained in:
Mark Tolmacs 2025-05-19 17:20:38 +02:00
parent 83abf2cd94
commit 71e13c363e
No known key found for this signature in database
2 changed files with 2 additions and 5 deletions

View File

@ -428,26 +428,23 @@ export function curvePointAtLength<P extends GlobalPoint | LocalPoint>(
let currentLength = 0;
// Tolerance for length comparison and iteration limit to avoid infinite loops
const tolerance = totalLength * 0.0001; // 0.01% of total length
const tolerance = totalLength * 0.0001;
const maxIterations = 20;
for (let iteration = 0; iteration < maxIterations; iteration++) {
currentLength = curveLengthAtParameter(c, t);
const error = Math.abs(currentLength - targetLength);
// If we're close enough, return the point
if (error < tolerance) {
break;
}
// Update search range
if (currentLength < targetLength) {
tMin = t;
} else {
tMax = t;
}
// Update parameter using bisection method
t = (tMin + tMax) / 2;
}