From c79584d807ac64862b429b487ae7b84294ed80ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juhani=20Krekel=C3=A4?= Date: Sat, 13 May 2023 20:29:34 +0300 Subject: [PATCH] Restate imperial lengths and weights in terms of inches and pounds --- src/conversions.rs | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/src/conversions.rs b/src/conversions.rs index 963f8a4..9f65182 100644 --- a/src/conversions.rs +++ b/src/conversions.rs @@ -6,36 +6,42 @@ struct Conversion { } fn get_conversion(unit: NonMetric) -> Conversion { + let inch_from = 10_000.0; + let inch_to = 254.0; + + let pound_from = 100_000.0; + let pound_to = 45359237.0; + match unit { // Length NonMetric::Foot => Conversion { - from: 10_000.0, - to: MetricQuantity { amount: 3048.0, unit: Metric::Metre }, + from: inch_from, + to: MetricQuantity { amount: 12.0 * inch_to, unit: Metric::Metre }, }, NonMetric::Inch => Conversion { - from: 10_000.0, - to: MetricQuantity { amount: 254.0, unit: Metric::Metre }, + from: inch_from, + to: MetricQuantity { amount: inch_to, unit: Metric::Metre }, }, NonMetric::Yard => Conversion { - from: 10_000.0, - to: MetricQuantity { amount: 9144.0, unit: Metric::Metre }, + from: inch_from, + to: MetricQuantity { amount: 3.0 * 12.0 * inch_to, unit: Metric::Metre }, }, NonMetric::Mile => Conversion { - from: 1_000.0, - to: MetricQuantity { amount: 1609344.0, unit: Metric::Metre }, + from: inch_from, + to: MetricQuantity { amount: 1760.0 * 3.0 * 12.0 * inch_to, unit: Metric::Metre }, }, // Weight NonMetric::Ounce => Conversion { - from: 1_000_000_000.0, - to: MetricQuantity { amount: 28349523125.0, unit: Metric::Gram }, + from: 16.0 * pound_from, + to: MetricQuantity { amount: pound_to, unit: Metric::Gram }, }, NonMetric::Pound => Conversion { - from: 100_000.0, - to: MetricQuantity { amount: 45359237.0, unit: Metric::Gram }, + from: pound_from, + to: MetricQuantity { amount: pound_to, unit: Metric::Gram }, }, NonMetric::Stone => Conversion { - from: 100_000.0, - to: MetricQuantity { amount: 635029318.0, unit: Metric::Gram }, + from: pound_from, + to: MetricQuantity { amount: 14.0 * pound_to, unit: Metric::Gram }, }, } }