Skip to content

Commit d444af8

Browse files
committed
fix(physics): add explicit input validation for launch parameters
Resolves negative speed bug by halting the simulation and rendering clear UI error messages instead of silently clamping invalid inputs.
1 parent 80aecc3 commit d444af8

1 file changed

Lines changed: 18 additions & 2 deletions

File tree

web-app/js/projects/projectile-motion.js

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,8 +221,24 @@ function initProjectileMotion() {
221221
}
222222

223223
function simulate() {
224-
const speed = Math.max(1, Number(speedInput.value) || 1);
225-
const angle = Math.min(89, Math.max(1, Number(angleInput.value) || 45));
224+
const speed = Number(speedInput.value);
225+
const angle = Number(angleInput.value);
226+
227+
// Reset previous states
228+
resultEl.style.color = "";
229+
230+
// Comprehensive Validation Check
231+
if (isNaN(speed) || speed < 1 || speed > 200) {
232+
resultEl.textContent = "❌ Error: Speed must be between 1 and 200 m/s.";
233+
resultEl.style.color = "#ef4444";
234+
return;
235+
}
236+
237+
if (isNaN(angle) || angle < 1 || angle > 89) {
238+
resultEl.textContent = "❌ Error: Angle must be between 1° and 89°.";
239+
resultEl.style.color = "#ef4444";
240+
return;
241+
}
226242

227243
const stats = projectileStats(speed, angle);
228244
const points = trajectoryPoints(speed, angle);

0 commit comments

Comments
 (0)