From a10c84d0771e6472a267e930abd3e9fa2b233983 Mon Sep 17 00:00:00 2001 From: Taylor Courage Date: Fri, 24 Jan 2025 10:09:18 -0500 Subject: [PATCH] Altered layout and fixed some comments, fixed total reduction of diameter display (was only two-digit accuracy is now three) --- analyser.js | 43 +++++++++++++++++-------------------------- 1 file changed, 17 insertions(+), 26 deletions(-) diff --git a/analyser.js b/analyser.js index fcde79b..a9b4770 100644 --- a/analyser.js +++ b/analyser.js @@ -11,7 +11,7 @@ var dataDelta = []; ///// MATHS FUNCTIONS ///// -// This function gets the reduction of area with two provided sizes, and returns it +// Calculate Reduction of Area function getReduction(startSize, finalSize) { var startArea = Math.PI * ((startSize / 2) * (startSize / 2)); var finalArea = Math.PI * ((finalSize / 2) * (finalSize / 2)); @@ -24,28 +24,33 @@ function getElongation(startSize, finalSize) { return (Math.pow(startSize / finalSize, 2) - 1) * 100; } + // Calculate delta function getDelta(startSize, finalSize, angle) { angle = (angle * 0.5) * (Math.PI / 180); // Convert to semi-angle and radians return ((startSize + finalSize) / (startSize - finalSize)) * Math.sin(angle); } +// Calculate Reduction of Diameter +function getRoDiameter(startSize, finishSize){ + return (startSize - finishSize) / ((startSize + finishSize) / 2) * 100; +} + +// Convert number to millimetres function toMillimetres(size) { //convert to mm size = Math.round((size * 100) * 25.4) / 100; return size; } +// Convert number to inches function toInches(size) { //convert to inches size = Math.round((size * 1000) / 25.4) / 1000; return size; } -function getRoDiameter(startSize, finishSize){ - return (startSize - finishSize) / ((startSize + finishSize) / 2) * 100; -} - ///// END OF MATHS SECTION ///// -///// DISPLAY SECTION ///// + +///// ALGORITHMS SECTION ///// function addReduction() { numDies ++; // Increment our die count @@ -90,10 +95,6 @@ function removeReduction() { // function to remove the last row } } -///// END OF DISPLAY SECTION ///// - -///// ALGORITHMS SECTION ///// - function doMath() { outputVisible = 1; // set visible status to enabled outputTable = document.getElementById("output"); // Select our output data table @@ -142,20 +143,11 @@ function doMath() { } // Format our numbers to prevent maximum user stupidity - if (inSize < 10.0 && inSize > 0) { // If we have a 'proper' number i.e. ".130" - inSize = Number(inSize); - } else { // re-format the number if it's 'wrong' i.e. "130" - inSize = inSize / 1000; - } - if (outSize < 10.0 && outSize > 0) { // If we have a 'proper' number i.e. ".130" - outSize = Number(outSize); - } else { // re-format the number if it's 'wrong' i.e. "130" - outSize = outSize / 1000; - } + inSize = formatCheck(inSize); + outSize = formatCheck(outSize); row[i] = outputTable.insertRow(i); // Add a new row to the END of the table - // Add all our cells to the table // We also give them HTML ID's to format things with CSS nicely cell1 = row[i].insertCell(0); @@ -434,7 +426,7 @@ function getStatistics() { // COL 1 c1.innerHTML = "Total R. Of Diameter: "; c1.id = "statsCol4"; - c2.innerHTML = "" + (Math.round((startSize - finalSize) * 1000) / 1000).toFixed(2) + "\""; + c2.innerHTML = "" + (Math.round((startSize - finalSize) * 1000) / 1000).toFixed(3) + "\""; c2.id = "statsCol5"; // c3.innerHTML = "|  "; @@ -529,11 +521,12 @@ function clearScreen() { addReduction(); } - ///// END ALGORITHMS SECTION ///// -///// EXTRA SECTION ///// +///// EXTRAs SECTION ///// + +// Convert the page to a print layout, and open the OS/browser print dialog function printScreen() { var subtitle = document.getElementById("subtitle"); var reductionCount = document.getElementById("numReductions"); @@ -541,7 +534,6 @@ function printScreen() { // Get input size, and format it var inputSize = document.getElementById("die0").value; - // If our start size is metric show that, otherwise swap them to show 'murican first if (document.getElementById("metric").checked) { var inputText = inputSize + " mm (" + toInches(inputSize) + "\")"; @@ -549,7 +541,6 @@ function printScreen() { var inputText = formatCheck(inputSize) + "\" (" + toMillimetres(formatCheck(inputSize)) + " mm)"; } - // Get the final size and format it var outputSize = document.getElementById("die" + numDies).value; outputSize = formatCheck(outputSize).toFixed(3);