From 42961eb08ef78eb263456c3b669c51383934e5d7 Mon Sep 17 00:00:00 2001 From: Taylor Courage Date: Fri, 24 Jan 2025 09:45:10 -0500 Subject: [PATCH] Fixed bug where removing too many dies would create "negative drafts" which doesn't make sense and was detrimental to the calculations --- analyser.js | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/analyser.js b/analyser.js index ae6a7c0..fcde79b 100644 --- a/analyser.js +++ b/analyser.js @@ -9,7 +9,7 @@ var dataElong = []; var dataAngle = []; var dataDelta = []; -///// START OF MATHS FUNCTIONS ///// +///// MATHS FUNCTIONS ///// // This function gets the reduction of area with two provided sizes, and returns it function getReduction(startSize, finalSize) { @@ -45,7 +45,7 @@ function getRoDiameter(startSize, finishSize){ ///// END OF MATHS SECTION ///// -///// START OF DISPLAY SECTION ///// +///// DISPLAY SECTION ///// function addReduction() { numDies ++; // Increment our die count @@ -72,23 +72,27 @@ function addReduction() { } function removeReduction() { // function to remove the last row - numDies --; - document.getElementById("data").deleteRow(-1); // delete the last row in the table - - // Remove the last item in each array to remove the tick from the graph - dieCount.splice(-1); - dataROA.splice(-1); - dataElong.splice(-1); - dataDelta.splice(-1); + if (numDies > 1) { + numDies--; + document.getElementById("data").deleteRow(-1); // delete the last row in the table - if (outputVisible == 1) { // Check if out output is visible and update immediately when adding dies - doMath(); + // Remove the last item in each array to remove the tick from the graph + dieCount.splice(-1); + dataROA.splice(-1); + dataElong.splice(-1); + dataDelta.splice(-1); + + if (outputVisible == 1) { // Check if out output is visible and update immediately when adding dies + doMath(); + } + } else { + numDies = 1; } } ///// END OF DISPLAY SECTION ///// -///// START OF ALGORITHMS SECTION ///// +///// ALGORITHMS SECTION ///// function doMath() { outputVisible = 1; // set visible status to enabled @@ -526,7 +530,7 @@ function clearScreen() { } -///// END OF ALGORITHMS SECTION ///// +///// END ALGORITHMS SECTION ///// ///// EXTRA SECTION /////