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