[apps/unit] Add short and long tons

Change-Id: Ib48c6a7c773e9e1d18c9f55e6dda5330fe0a28f9
This commit is contained in:
Gabriel Ozouf
2020-07-24 15:30:48 +02:00
committed by Émilie Feral
parent 284c501532
commit f288573db0
11 changed files with 23 additions and 6 deletions

View File

@@ -143,6 +143,8 @@ const ToolboxMessageTree unitMassGramChildren[] = {
const ToolboxMessageTree unitMassImperialChildren[] = {
ToolboxMessageTree::Leaf(I18n::Message::UnitMassPoundSymbol, I18n::Message::UnitMassPound),
ToolboxMessageTree::Leaf(I18n::Message::UnitMassOunceSymbol, I18n::Message::UnitMassOunce),
ToolboxMessageTree::Leaf(I18n::Message::UnitMassShortTonSymbol, I18n::Message::UnitMassShortTon),
ToolboxMessageTree::Leaf(I18n::Message::UnitMassLongTonSymbol, I18n::Message::UnitMassLongTon)
};
const ToolboxMessageTree unitMassChildren[] = {

View File

@@ -29,7 +29,8 @@ UnitMassGramNanoSymbol = "_ng"
UnitMassTonneSymbol = "_t"
UnitMassOunceSymbol = "_oz"
UnitMassPoundSymbol = "_lb"
UnitMassShortTonSymbol = "_ton"
UnitMassShortTonSymbol = "_shtn"
UnitMassLongTonSymbol = "_lgtn"
UnitCurrentAmpereSymbol = "_A"
UnitCurrentAmpereMilliSymbol = "_mA"
UnitCurrentAmpereMicroSymbol = "_μA"

View File

@@ -36,6 +36,7 @@ UnitMassTonne = "Tonne"
UnitMassOunce = "Ounce"
UnitMassPound = "Pound"
UnitMassShortTon = "Short Ton"
UnitMassLongTon = "Long Ton"
UnitCurrentMenu = "Elektrischer Strom"
UnitCurrentAmpere = "Ampere"
UnitCurrentAmpereMilli = "Milliampere"

View File

@@ -36,6 +36,7 @@ UnitMassTonne = "Tonne"
UnitMassOunce = "Ounce"
UnitMassPound = "Pound"
UnitMassShortTon = "Short Ton"
UnitMassLongTon = "Long Ton"
UnitCurrentMenu = "Electric current"
UnitCurrentAmpere = "Ampere"
UnitCurrentAmpereMilli = "Milliampere"

View File

@@ -36,6 +36,7 @@ UnitMassTonne = "Tonne"
UnitMassOunce = "Ounce"
UnitMassPound = "Pound"
UnitMassShortTon = "Short Ton"
UnitMassLongTon = "Long Ton"
UnitCurrentMenu = "Electric current"
UnitCurrentAmpere = "Ampere"
UnitCurrentAmpereMilli = "Milliampere"

View File

@@ -36,6 +36,7 @@ UnitMassTonne = "Tonne"
UnitMassOunce = "Ounce"
UnitMassPound = "Pound"
UnitMassShortTon = "Short Ton"
UnitMassLongTon = "Long Ton"
UnitCurrentMenu = "Intensité du courant électrique"
UnitCurrentAmpere = "Ampère"
UnitCurrentAmpereMilli = "Milliampère"

View File

@@ -36,6 +36,7 @@ UnitMassTonne = "Tonnellata"
UnitMassOunce = "Ounce"
UnitMassPound = "Pound"
UnitMassShortTon = "Short Ton"
UnitMassLongTon = "Long Ton"
UnitCurrentMenu = "Intensità di corrente elettrica"
UnitCurrentAmpere = "Ampere"
UnitCurrentAmpereMilli = "Milliampere"

View File

@@ -36,6 +36,7 @@ UnitMassTonne = "Ton"
UnitMassOunce = "Ounce"
UnitMassPound = "Pound"
UnitMassShortTon = "Short Ton"
UnitMassLongTon = "Long Ton"
UnitCurrentMenu = "Elektrische stroom"
UnitCurrentAmpere = "Ampère"
UnitCurrentAmpereMilli = "Milliampère"

View File

@@ -36,6 +36,7 @@ UnitMassTonne = "Tonelada"
UnitMassOunce = "Ounce"
UnitMassPound = "Pound"
UnitMassShortTon = "Short Ton"
UnitMassLongTon = "Long Ton"
UnitCurrentMenu = "Intensidade da corrente elétrica"
UnitCurrentAmpere = "Ampere"
UnitCurrentAmpereMilli = "Miliampere"

View File

@@ -349,10 +349,14 @@ public:
Representative::Prefixable::No,
NoPrefix,
Representative::OutputSystem::Imperial),
Representative("ton", "2000*_lb",
Representative("shtn", "2000*_lb",
Representative::Prefixable::No,
NoPrefix,
Representative::OutputSystem::Imperial),
Representative("lgtn", "2240*_lb",
Representative::Prefixable::No,
NoPrefix,
Representative::OutputSystem::None),
},
CurrentRepresentatives[] = {
Representative("A", nullptr,
@@ -513,9 +517,10 @@ public:
static const Representative constexpr * MileRepresentative = &DistanceRepresentatives[7];
static const Representative constexpr * KilogramRepresentative = &MassRepresentatives[0];
static const Representative constexpr * GramRepresentative = &MassRepresentatives[1];
static_assert(sizeof(MassRepresentatives)/sizeof(Representative) == 7, "The Unit::OunceRepresentative et al. might require to be fixed if the MassRepresentatives table was changed.");
static_assert(sizeof(MassRepresentatives)/sizeof(Representative) == 8, "The Unit::OunceRepresentative et al. might require to be fixed if the MassRepresentatives table was changed.");
static const Representative constexpr * OunceRepresentative = &MassRepresentatives[4];
static const Representative constexpr * PoundRepresentative = &MassRepresentatives[5];
static const Representative constexpr * ShortTonRepresentative = &MassRepresentatives[6];
static const Representative constexpr * LiterRepresentative = &VolumeRepresentatives[0];
static_assert(sizeof(VolumeRepresentatives)/sizeof(Representative) == 8, "The Unit::FluidOunceRepresentative et al. might require to be fixed if the VolumeRepresentatives table was changed.");
static const Representative constexpr * FluidOunceRepresentative = &VolumeRepresentatives[3];
@@ -867,6 +872,7 @@ public:
static Unit Gram() { return Builder(MassDimension, GramRepresentative, &EmptyPrefix); }
static Unit Ounce() { return Builder(MassDimension, OunceRepresentative, &EmptyPrefix); }
static Unit Pound() { return Builder(MassDimension, PoundRepresentative, &EmptyPrefix); }
static Unit ShortTon() { return Builder(MassDimension, ShortTonRepresentative, &EmptyPrefix); }
static Unit FluidOunce() { return Builder(VolumeDimension, FluidOunceRepresentative, &EmptyPrefix); }
static Unit Cup() { return Builder(VolumeDimension, CupRepresentative, &EmptyPrefix); }
static Unit Gallon() { return Builder(VolumeDimension, GallonRepresentative, &EmptyPrefix); }
@@ -915,6 +921,7 @@ private:
static constexpr double FeetPerYard = 3.;
static constexpr double YardsPerMile = 1760.;
static constexpr double OuncesPerPound = 16.;
static constexpr double PoundsPerShortTon = 2000.;
static constexpr double FluidOuncesPerCup = 8.;
static constexpr double CupsPerGallon = 16.;
UnitNode * node() const { return static_cast<UnitNode *>(Expression::node()); }

View File

@@ -589,9 +589,9 @@ Expression Unit::BuildImperialDistanceSplit(double inches, Context * context) {
}
Expression Unit::BuildImperialMassSplit(double ounces, Context * context) {
constexpr static int numberOfUnits = 2;
Unit units[numberOfUnits] = {Unit::Pound(), Unit::Ounce()};
constexpr static double factors[numberOfUnits] = {OuncesPerPound, 1.};
constexpr static int numberOfUnits = 3;
Unit units[numberOfUnits] = {Unit::ShortTon(), Unit::Pound(), Unit::Ounce()};
constexpr static double factors[numberOfUnits] = {OuncesPerPound*PoundsPerShortTon, OuncesPerPound, 1.};
return BuildSplit(ounces, units, factors, numberOfUnits, context);
}