Tidy up
This commit is contained in:
parent
83abf2cd94
commit
71e13c363e
@ -57,4 +57,4 @@
|
|||||||
"gen:types": "rimraf types && tsc",
|
"gen:types": "rimraf types && tsc",
|
||||||
"build:esm": "rimraf dist && node ../../scripts/buildBase.js && yarn gen:types"
|
"build:esm": "rimraf dist && node ../../scripts/buildBase.js && yarn gen:types"
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -428,26 +428,23 @@ export function curvePointAtLength<P extends GlobalPoint | LocalPoint>(
|
|||||||
let currentLength = 0;
|
let currentLength = 0;
|
||||||
|
|
||||||
// Tolerance for length comparison and iteration limit to avoid infinite loops
|
// 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;
|
const maxIterations = 20;
|
||||||
|
|
||||||
for (let iteration = 0; iteration < maxIterations; iteration++) {
|
for (let iteration = 0; iteration < maxIterations; iteration++) {
|
||||||
currentLength = curveLengthAtParameter(c, t);
|
currentLength = curveLengthAtParameter(c, t);
|
||||||
const error = Math.abs(currentLength - targetLength);
|
const error = Math.abs(currentLength - targetLength);
|
||||||
|
|
||||||
// If we're close enough, return the point
|
|
||||||
if (error < tolerance) {
|
if (error < tolerance) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update search range
|
|
||||||
if (currentLength < targetLength) {
|
if (currentLength < targetLength) {
|
||||||
tMin = t;
|
tMin = t;
|
||||||
} else {
|
} else {
|
||||||
tMax = t;
|
tMax = t;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update parameter using bisection method
|
|
||||||
t = (tMin + tMax) / 2;
|
t = (tMin + tMax) / 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user