diff --git a/src/AdvancedCalculator.js b/src/AdvancedCalculator.js index 5ca8feb..a13914f 100644 --- a/src/AdvancedCalculator.js +++ b/src/AdvancedCalculator.js @@ -300,7 +300,8 @@ const AdvancedCalculator = () => { const convertUnit = () => { try { const result = math.evaluate(`${unitConversion.fromValue} ${unitConversion.fromUnit} to ${unitConversion.toUnit}`); - return result.toString(); + // Return just the numeric value, without units + return result.toString().replace(unitConversion.toUnit, '').trim(); } catch (error) { return 'Error: Invalid conversion'; } @@ -397,23 +398,23 @@ const AdvancedCalculator = () => { impactTime = Math.max(t1, t2); } - // Add points to ensure smooth landing - const impactX = vx * impactTime; + // Make sure we have the right data array to work with + newData = simulationData.slice(0, -1); // Remove the last point (which is below ground) - // Add a data point just before landing + // Add a point just before landing for a smooth curve if (impactTime > 0.1) { const preImpactTime = impactTime - 0.05; const preImpactX = vx * preImpactTime; const preImpactY = height + vy * preImpactTime - 0.5 * gravity * preImpactTime * preImpactTime; - newData = [...simulationData, { x: preImpactX, y: preImpactY }]; + + if (preImpactY > 0) { + newData.push({ x: preImpactX, y: preImpactY }); + } } - // Add exact landing point and range point - newData = [...newData || simulationData, - { x: impactX, y: 0 }, - // Add the theoretical endpoint to match the calculated range - { x: theoreticalRange, y: 0 } - ]; + // Add the exact landing point (y = 0) + const impactX = vx * impactTime; + newData.push({ x: impactX, y: 0 }); } else { newData = [...simulationData]; } @@ -1068,22 +1069,150 @@ const AdvancedCalculator = () => { )} - {/* Other categories as in your original code */} - {/* I've truncated these for brevity but you should include all original options */} - {unitConversion.category === 'mass' && ( + {unitConversion.category === 'volume' && ( <> - - - - - - - - - + + + + + + + + + + + + + + + + + )} + {unitConversion.category === 'temperature' && ( + <> + + + + + + )} + {unitConversion.category === 'area' && ( + <> + + + + + + + + + + + + )} + {unitConversion.category === 'time' && ( + <> + + + + + + + + + + + + + + )} + {unitConversion.category === 'speed' && ( + <> + + + + + + + + + + )} + {unitConversion.category === 'pressure' && ( + <> + + + + + + + + + + + + + + )} + {unitConversion.category === 'energy' && ( + <> + + + + + + + + + + + + + + )} + {unitConversion.category === 'power' && ( + <> + + + + + + + + + + )} + {unitConversion.category === 'angle' && ( + <> + + + + + + + + + + + )} + {unitConversion.category === 'digital' && ( + <> + + + + + + + + + + + + + + )} - {/* Include the rest of your category options here */} @@ -1108,20 +1237,150 @@ const AdvancedCalculator = () => { )} {/* Other categories as in your original code */} {/* I've truncated these for brevity but you should include all original options */} - {unitConversion.category === 'mass' && ( + {unitConversion.category === 'volume' && ( <> - - - - - - - - - + + + + + + + + + + + + + + + + + )} + {unitConversion.category === 'temperature' && ( + <> + + + + + + )} + {unitConversion.category === 'area' && ( + <> + + + + + + + + + + + + )} + {unitConversion.category === 'time' && ( + <> + + + + + + + + + + + + + + )} + {unitConversion.category === 'speed' && ( + <> + + + + + + + + + + )} + {unitConversion.category === 'pressure' && ( + <> + + + + + + + + + + + + + + )} + {unitConversion.category === 'energy' && ( + <> + + + + + + + + + + + + + + )} + {unitConversion.category === 'power' && ( + <> + + + + + + + + + + )} + {unitConversion.category === 'angle' && ( + <> + + + + + + + + + + + )} + {unitConversion.category === 'digital' && ( + <> + + + + + + + + + + + + + + )} - {/* Include the rest of your category options here */}