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 }, }, } }