From 3b278de5e4069b9eb90f19e005841a042ad5d1a2 Mon Sep 17 00:00:00 2001 From: Pyro Nicampt <81565698+PyroNicampt@users.noreply.github.com> Date: Sat, 28 Dec 2024 02:52:04 -0600 Subject: [PATCH] Fix invalid cases for curvature and grade. --- js/bezierlib.js | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) 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