add miss files, add PIUnits::Distance and PIUnits::Mass
This commit is contained in:
@@ -23,6 +23,12 @@
|
||||
PIString PIUnits::Class::Distance::name(int type) const {
|
||||
switch (type) {
|
||||
case Meter: return "meter"_tr("PIUnitsDistance");
|
||||
case Inch: return "inch"_tr("PIUnitsDistance");
|
||||
case Mil: return "mil"_tr("PIUnitsDistance");
|
||||
case Foot: return "foot"_tr("PIUnitsDistance");
|
||||
case Yard: return "yard"_tr("PIUnitsDistance");
|
||||
case Angstrom: return "angstrom"_tr("PIUnitsDistance");
|
||||
case AstronomicalUnit: return "astronomical unit"_tr("PIUnitsDistance");
|
||||
}
|
||||
return Class::Internal::unknown;
|
||||
}
|
||||
@@ -31,16 +37,42 @@ PIString PIUnits::Class::Distance::name(int type) const {
|
||||
PIString PIUnits::Class::Distance::unit(int type) const {
|
||||
switch (type) {
|
||||
case Meter: return "m"_tr("PIUnitsDistance");
|
||||
case Inch: return "\""_tr("PIUnitsDistance");
|
||||
case Mil: return "thou"_tr("PIUnitsDistance");
|
||||
case Foot: return "ft"_tr("PIUnitsDistance");
|
||||
case Yard: return "yd"_tr("PIUnitsDistance");
|
||||
case Angstrom: return "Å"_tr("PIUnitsDistance");
|
||||
case AstronomicalUnit: return "au"_tr("PIUnitsDistance");
|
||||
}
|
||||
return Class::Internal::unknown;
|
||||
}
|
||||
|
||||
|
||||
double PIUnits::Class::Distance::convert(double v, int from, int to) const {
|
||||
switch (to) {
|
||||
case Meter: return v;
|
||||
static constexpr double inch_to_m = 0.254;
|
||||
static constexpr double mil_to_m = 0.254 * 1E-3;
|
||||
static constexpr double foot_to_m = 0.3048;
|
||||
static constexpr double yard_to_m = 0.9144;
|
||||
static constexpr double angstrom_to_m = 1E-10;
|
||||
static constexpr double astronomical_unit_to_m = 149597870700.;
|
||||
double m = v;
|
||||
switch (from) {
|
||||
case Inch: m *= inch_to_m; break;
|
||||
case Mil: m *= mil_to_m; break;
|
||||
case Foot: m *= foot_to_m; break;
|
||||
case Yard: m *= yard_to_m; break;
|
||||
case Angstrom: m *= angstrom_to_m; break;
|
||||
case AstronomicalUnit: m *= astronomical_unit_to_m; break;
|
||||
}
|
||||
return v;
|
||||
switch (to) {
|
||||
case Inch: m /= inch_to_m; break;
|
||||
case Mil: m /= mil_to_m; break;
|
||||
case Foot: m /= foot_to_m; break;
|
||||
case Yard: m /= yard_to_m; break;
|
||||
case Angstrom: m /= angstrom_to_m; break;
|
||||
case AstronomicalUnit: m /= astronomical_unit_to_m; break;
|
||||
}
|
||||
return m;
|
||||
}
|
||||
|
||||
|
||||
@@ -50,12 +82,12 @@ PIString PIUnits::Class::Distance::valueToString(double v, char format, int prec
|
||||
|
||||
|
||||
bool PIUnits::Class::Distance::supportPrefixes(int type) const {
|
||||
return true;
|
||||
return type == Meter;
|
||||
}
|
||||
|
||||
|
||||
bool PIUnits::Class::Distance::supportPrefixesNon3(int type) const {
|
||||
return true;
|
||||
return type == Meter;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user