diff --git a/js/bezierlib.js b/js/bezierlib.js index aa6f0a3..a30f981 100644 --- a/js/bezierlib.js +++ b/js/bezierlib.js @@ -21,9 +21,12 @@ export function estimateGrade(p1, h1, h2, p2, iterationCount = 50){ for(let i=0; i<=iterationCount; i++){ let tan = evaluateVelocity(p1, h1, h2, p2, i/iterationCount); let newGrade = Math.abs(tan.y)/Math.sqrt(tan.x*tan.x + tan.z*tan.z); - grade = Math.max(grade, newGrade); - totalGrade += newGrade; + if(!Number.isNaN(newGrade)){ + grade = Math.max(grade, newGrade); + totalGrade += newGrade; + } } + if(!grade) return 0; return grade; } @@ -59,14 +62,20 @@ export function estimateCurvature(p1, h1, h2, p2, iterationCount = 50){ let curvature = 0; let t = 0; let vel = {}; + let totalCount = 0; for(let i=0; i