Restate imperial lengths and weights in terms of inches and pounds

This commit is contained in:
Juhani Krekelä 2023-05-13 20:29:34 +03:00
parent 06083dbce9
commit c79584d807
1 changed files with 20 additions and 14 deletions

View File

@ -6,36 +6,42 @@ struct Conversion {
} }
fn get_conversion(unit: NonMetric) -> 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 { match unit {
// Length // Length
NonMetric::Foot => Conversion { NonMetric::Foot => Conversion {
from: 10_000.0, from: inch_from,
to: MetricQuantity { amount: 3048.0, unit: Metric::Metre }, to: MetricQuantity { amount: 12.0 * inch_to, unit: Metric::Metre },
}, },
NonMetric::Inch => Conversion { NonMetric::Inch => Conversion {
from: 10_000.0, from: inch_from,
to: MetricQuantity { amount: 254.0, unit: Metric::Metre }, to: MetricQuantity { amount: inch_to, unit: Metric::Metre },
}, },
NonMetric::Yard => Conversion { NonMetric::Yard => Conversion {
from: 10_000.0, from: inch_from,
to: MetricQuantity { amount: 9144.0, unit: Metric::Metre }, to: MetricQuantity { amount: 3.0 * 12.0 * inch_to, unit: Metric::Metre },
}, },
NonMetric::Mile => Conversion { NonMetric::Mile => Conversion {
from: 1_000.0, from: inch_from,
to: MetricQuantity { amount: 1609344.0, unit: Metric::Metre }, to: MetricQuantity { amount: 1760.0 * 3.0 * 12.0 * inch_to, unit: Metric::Metre },
}, },
// Weight // Weight
NonMetric::Ounce => Conversion { NonMetric::Ounce => Conversion {
from: 1_000_000_000.0, from: 16.0 * pound_from,
to: MetricQuantity { amount: 28349523125.0, unit: Metric::Gram }, to: MetricQuantity { amount: pound_to, unit: Metric::Gram },
}, },
NonMetric::Pound => Conversion { NonMetric::Pound => Conversion {
from: 100_000.0, from: pound_from,
to: MetricQuantity { amount: 45359237.0, unit: Metric::Gram }, to: MetricQuantity { amount: pound_to, unit: Metric::Gram },
}, },
NonMetric::Stone => Conversion { NonMetric::Stone => Conversion {
from: 100_000.0, from: pound_from,
to: MetricQuantity { amount: 635029318.0, unit: Metric::Gram }, to: MetricQuantity { amount: 14.0 * pound_to, unit: Metric::Gram },
}, },
} }
} }