File indexing completed on 2024-04-21 03:58:32

0001 /*
0002  *   SPDX-FileCopyrightText: 2008-2009 Petri Damstén <damu@iki.fi>
0003  *   SPDX-FileCopyrightText: 2014 John Layt <jlayt@kde.org>
0004  *
0005  *   SPDX-License-Identifier: LGPL-2.0-or-later
0006  */
0007 
0008 #include "unit_p.h"
0009 #include "velocity_p.h"
0010 
0011 #include <KLocalizedString>
0012 
0013 #include <math.h>
0014 
0015 namespace KUnitConversion
0016 {
0017 class BeaufortUnitPrivate : public UnitPrivate
0018 {
0019 public:
0020     BeaufortUnitPrivate(CategoryId categoryId,
0021                         UnitId id,
0022                         qreal multiplier,
0023                         const QString &symbol,
0024                         const QString &description,
0025                         const QString &matchString,
0026                         const KLocalizedString &symbolString,
0027                         const KLocalizedString &realString,
0028                         const KLocalizedString &integerString)
0029         : UnitPrivate(categoryId, id, multiplier, symbol, description, matchString, symbolString, realString, integerString)
0030     {
0031     }
0032 
0033     qreal toDefault(qreal value) const override
0034     {
0035         return 0.836 * pow(value, 3.0 / 2.0);
0036     }
0037 
0038     qreal fromDefault(qreal value) const override
0039     {
0040         return pow(value / 0.836, 2.0 / 3.0);
0041     }
0042 };
0043 
0044 UnitCategory Velocity::makeCategory()
0045 {
0046     auto c = UnitCategoryPrivate::makeCategory(VelocityCategory, i18n("Speed"), i18n("Speed"));
0047     auto d = UnitCategoryPrivate::get(c);
0048     KLocalizedString symbolString = ki18nc("%1 value, %2 unit symbol (velocity)", "%1 %2");
0049 
0050     d->addDefaultUnit(UnitPrivate::makeUnit(VelocityCategory,
0051                               MeterPerSecond,
0052                               1,
0053                               i18nc("velocity unit symbol", "m/s"),
0054                               i18nc("unit description in lists", "meters per second"),
0055                               i18nc("unit synonyms for matching user input", "meter per second;meters per second;m/s;ms"),
0056                               symbolString,
0057                               ki18nc("amount in units (real)", "%1 meters per second"),
0058                               ki18ncp("amount in units (integer)", "%1 meter per second", "%1 meters per second")));
0059 
0060     d->addCommonUnit(UnitPrivate::makeUnit(VelocityCategory,
0061                              KilometerPerHour,
0062                              0.277778,
0063                              i18nc("velocity unit symbol", "km/h"),
0064                              i18nc("unit description in lists", "kilometers per hour"),
0065                              i18nc("unit synonyms for matching user input", "kilometer per hour;kilometers per hour;km/h;kmh;kph"),
0066                              symbolString,
0067                              ki18nc("amount in units (real)", "%1 kilometers per hour"),
0068                              ki18ncp("amount in units (integer)", "%1 kilometer per hour", "%1 kilometers per hour")));
0069 
0070     d->addCommonUnit(UnitPrivate::makeUnit(VelocityCategory,
0071                              MilePerHour,
0072                              0.44704,
0073                              i18nc("velocity unit symbol", "mph"),
0074                              i18nc("unit description in lists", "miles per hour"),
0075                              i18nc("unit synonyms for matching user input", "mile per hour;miles per hour;mph"),
0076                              symbolString,
0077                              ki18nc("amount in units (real)", "%1 miles per hour"),
0078                              ki18ncp("amount in units (integer)", "%1 mile per hour", "%1 miles per hour")));
0079 
0080     d->addUnit(UnitPrivate::makeUnit(VelocityCategory,
0081                        FootPerSecond,
0082                        0.3048,
0083                        i18nc("velocity unit symbol", "ft/s"),
0084                        i18nc("unit description in lists", "feet per second"),
0085                        i18nc("unit synonyms for matching user input", "foot per second;feet per second;ft/s;ft/sec;fps"),
0086                        symbolString,
0087                        ki18nc("amount in units (real)", "%1 feet per second"),
0088                        ki18ncp("amount in units (integer)", "%1 foot per second", "%1 feet per second")));
0089 
0090     d->addUnit(UnitPrivate::makeUnit(VelocityCategory,
0091                        InchPerSecond,
0092                        0.0254,
0093                        i18nc("velocity unit symbol", "in/s"),
0094                        i18nc("unit description in lists", "inches per second"),
0095                        i18nc("unit synonyms for matching user input", "inch per second;inches per second;in/s;in/sec;ips"),
0096                        symbolString,
0097                        ki18nc("amount in units (real)", "%1 inches per second"),
0098                        ki18ncp("amount in units (integer)", "%1 inch per second", "%1 inches per second")));
0099 
0100     d->addCommonUnit(UnitPrivate::makeUnit(VelocityCategory,
0101                              Knot,
0102                              0.514444,
0103                              i18nc("velocity unit symbol", "kt"),
0104                              i18nc("unit description in lists", "knots"),
0105                              i18nc("unit synonyms for matching user input", "knot;knots;kt;nautical miles per hour"),
0106                              symbolString,
0107                              ki18nc("amount in units (real)", "%1 knots"),
0108                              ki18ncp("amount in units (integer)", "%1 knot", "%1 knots")));
0109 
0110     // http://en.wikipedia.org/wiki/Speed_of_sound
0111     d->addCommonUnit(UnitPrivate::makeUnit(VelocityCategory,
0112                              Mach,
0113                              343,
0114                              i18nc("velocity unit symbol", "Ma"),
0115                              i18nc("unit description in lists", "Mach"),
0116                              i18nc("unit synonyms for matching user input", "mach;machs;Ma;speed of sound"),
0117                              symbolString,
0118                              ki18nc("amount in units (real)", "Mach %1"),
0119                              ki18ncp("amount in units (integer)", "Mach %1", "Mach %1")));
0120 
0121     d->addUnit(UnitPrivate::makeUnit(VelocityCategory,
0122                        SpeedOfLight,
0123                        2.99792458e+08,
0124                        i18nc("velocity unit symbol", "c"),
0125                        i18nc("unit description in lists", "speed of light"),
0126                        i18nc("unit synonyms for matching user input", "speed of light;c"),
0127                        symbolString,
0128                        ki18nc("amount in units (real)", "%1 speed of light"),
0129                        ki18ncp("amount in units (integer)", "%1 speed of light", "%1 speed of light")));
0130 
0131     // http://en.wikipedia.org/wiki/Beaufort_scale
0132     d->addUnit(UnitPrivate::makeUnit(new BeaufortUnitPrivate(VelocityCategory,
0133                                                Beaufort,
0134                                                1.0,
0135                                                i18nc("velocity unit symbol", "bft"),
0136                                                i18nc("unit description in lists", "Beaufort"),
0137                                                i18nc("unit synonyms for matching user input", "Beaufort;Bft"),
0138                                                symbolString,
0139                                                ki18nc("amount in units (real)", "%1 on the Beaufort scale"),
0140                                                ki18ncp("amount in units (integer)", "%1 on the Beaufort scale", "%1 on the Beaufort scale"))));
0141 
0142     return c;
0143 }
0144 
0145 } // KUnitConversion namespace