1 /*
2  *   SPDX-FileCopyrightText: 2008-2009 Petri Damstén <damu@iki.fi>
3  *   SPDX-FileCopyrightText: 2014 John Layt <jlayt@kde.org>
4  *
5  *   SPDX-License-Identifier: LGPL-2.0-or-later
6  */
7 
8 #include "unit_p.h"
9 #include "velocity_p.h"
10 
11 #include <KLocalizedString>
12 
13 #include <math.h>
14 
15 namespace KUnitConversion
16 {
17 class BeaufortUnitPrivate : public UnitPrivate
18 {
19 public:
BeaufortUnitPrivate(CategoryId categoryId,UnitId id,qreal multiplier,const QString & symbol,const QString & description,const QString & matchString,const KLocalizedString & symbolString,const KLocalizedString & realString,const KLocalizedString & integerString)20     BeaufortUnitPrivate(CategoryId categoryId,
21                         UnitId id,
22                         qreal multiplier,
23                         const QString &symbol,
24                         const QString &description,
25                         const QString &matchString,
26                         const KLocalizedString &symbolString,
27                         const KLocalizedString &realString,
28                         const KLocalizedString &integerString)
29         : UnitPrivate(categoryId, id, multiplier, symbol, description, matchString, symbolString, realString, integerString)
30     {
31     }
32 
toDefault(qreal value) const33     qreal toDefault(qreal value) const override
34     {
35         return 0.836 * pow(value, 3.0 / 2.0);
36     }
37 
fromDefault(qreal value) const38     qreal fromDefault(qreal value) const override
39     {
40         return pow(value / 0.836, 2.0 / 3.0);
41     }
42 };
43 
Velocity()44 Velocity::Velocity()
45     : CustomCategory(VelocityCategory, i18n("Speed"), i18n("Speed"))
46 {
47     KLocalizedString symbolString = ki18nc("%1 value, %2 unit symbol (velocity)", "%1 %2");
48 
49     addDefaultUnit(CustomUnit(VelocityCategory,
50                               MeterPerSecond,
51                               1,
52                               i18nc("velocity unit symbol", "m/s"),
53                               i18nc("unit description in lists", "meters per second"),
54                               i18nc("unit synonyms for matching user input", "meter per second;meters per second;m/s;ms"),
55                               symbolString,
56                               ki18nc("amount in units (real)", "%1 meters per second"),
57                               ki18ncp("amount in units (integer)", "%1 meter per second", "%1 meters per second")));
58 
59     addCommonUnit(CustomUnit(VelocityCategory,
60                              KilometerPerHour,
61                              0.277778,
62                              i18nc("velocity unit symbol", "km/h"),
63                              i18nc("unit description in lists", "kilometers per hour"),
64                              i18nc("unit synonyms for matching user input", "kilometer per hour;kilometers per hour;km/h;kmh"),
65                              symbolString,
66                              ki18nc("amount in units (real)", "%1 kilometers per hour"),
67                              ki18ncp("amount in units (integer)", "%1 kilometer per hour", "%1 kilometers per hour")));
68 
69     addCommonUnit(CustomUnit(VelocityCategory,
70                              MilePerHour,
71                              0.44704,
72                              i18nc("velocity unit symbol", "mph"),
73                              i18nc("unit description in lists", "miles per hour"),
74                              i18nc("unit synonyms for matching user input", "mile per hour;miles per hour;mph"),
75                              symbolString,
76                              ki18nc("amount in units (real)", "%1 miles per hour"),
77                              ki18ncp("amount in units (integer)", "%1 mile per hour", "%1 miles per hour")));
78 
79     addUnit(CustomUnit(VelocityCategory,
80                        FootPerSecond,
81                        0.3048,
82                        i18nc("velocity unit symbol", "ft/s"),
83                        i18nc("unit description in lists", "feet per second"),
84                        i18nc("unit synonyms for matching user input", "foot per second;feet per second;ft/s;ft/sec;fps"),
85                        symbolString,
86                        ki18nc("amount in units (real)", "%1 feet per second"),
87                        ki18ncp("amount in units (integer)", "%1 foot per second", "%1 feet per second")));
88 
89     addUnit(CustomUnit(VelocityCategory,
90                        InchPerSecond,
91                        0.0254,
92                        i18nc("velocity unit symbol", "in/s"),
93                        i18nc("unit description in lists", "inches per second"),
94                        i18nc("unit synonyms for matching user input", "inch per second;inches per second;in/s;in/sec;ips"),
95                        symbolString,
96                        ki18nc("amount in units (real)", "%1 inches per second"),
97                        ki18ncp("amount in units (integer)", "%1 inch per second", "%1 inches per second")));
98 
99     addCommonUnit(CustomUnit(VelocityCategory,
100                              Knot,
101                              0.514444,
102                              i18nc("velocity unit symbol", "kt"),
103                              i18nc("unit description in lists", "knots"),
104                              i18nc("unit synonyms for matching user input", "knot;knots;kt;nautical miles per hour"),
105                              symbolString,
106                              ki18nc("amount in units (real)", "%1 knots"),
107                              ki18ncp("amount in units (integer)", "%1 knot", "%1 knots")));
108 
109     // http://en.wikipedia.org/wiki/Speed_of_sound
110     addCommonUnit(CustomUnit(VelocityCategory,
111                              Mach,
112                              343,
113                              i18nc("velocity unit symbol", "Ma"),
114                              i18nc("unit description in lists", "Mach"),
115                              i18nc("unit synonyms for matching user input", "mach;machs;Ma;speed of sound"),
116                              symbolString,
117                              ki18nc("amount in units (real)", "Mach %1"),
118                              ki18ncp("amount in units (integer)", "Mach %1", "Mach %1")));
119 
120     addUnit(CustomUnit(VelocityCategory,
121                        SpeedOfLight,
122                        2.99792458e+08,
123                        i18nc("velocity unit symbol", "c"),
124                        i18nc("unit description in lists", "speed of light"),
125                        i18nc("unit synonyms for matching user input", "speed of light;c"),
126                        symbolString,
127                        ki18nc("amount in units (real)", "%1 speed of light"),
128                        ki18ncp("amount in units (integer)", "%1 speed of light", "%1 speed of light")));
129 
130     // http://en.wikipedia.org/wiki/Beaufort_scale
131     addUnit(CustomUnit(new BeaufortUnitPrivate(VelocityCategory,
132                                                Beaufort,
133                                                1.0,
134                                                i18nc("velocity unit symbol", "bft"),
135                                                i18nc("unit description in lists", "Beaufort"),
136                                                i18nc("unit synonyms for matching user input", "Beaufort;Bft"),
137                                                symbolString,
138                                                ki18nc("amount in units (real)", "%1 on the Beaufort scale"),
139                                                ki18ncp("amount in units (integer)", "%1 on the Beaufort scale", "%1 on the Beaufort scale"))));
140 }
141 
142 } // KUnitConversion namespace
143