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: |
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 | |
33 | qreal toDefault(qreal value) const override |
34 | { |
35 | return 0.836 * pow(x: value, y: 3.0 / 2.0); |
36 | } |
37 | |
38 | qreal fromDefault(qreal value) const override |
39 | { |
40 | return pow(x: value / 0.836, y: 2.0 / 3.0); |
41 | } |
42 | }; |
43 | |
44 | UnitCategory Velocity::makeCategory() |
45 | { |
46 | auto c = UnitCategoryPrivate::makeCategory(id: VelocityCategory, i18n("Speed" ), i18n("Speed" )); |
47 | auto d = UnitCategoryPrivate::get(category: c); |
48 | KLocalizedString symbolString = ki18nc("%1 value, %2 unit symbol (velocity)" , "%1 %2" ); |
49 | |
50 | d->addDefaultUnit(unit: UnitPrivate::makeUnit(categoryId: VelocityCategory, |
51 | id: MeterPerSecond, |
52 | multiplier: 1, |
53 | i18nc("velocity unit symbol" , "m/s" ), |
54 | i18nc("unit description in lists" , "meters per second" ), |
55 | i18nc("unit synonyms for matching user input" , "meter per second;meters per second;m/s;ms" ), |
56 | symbolString, |
57 | ki18nc("amount in units (real)" , "%1 meters per second" ), |
58 | ki18ncp("amount in units (integer)" , "%1 meter per second" , "%1 meters per second" ))); |
59 | |
60 | d->addCommonUnit(unit: UnitPrivate::makeUnit(categoryId: VelocityCategory, |
61 | id: KilometerPerHour, |
62 | multiplier: 0.277778, |
63 | i18nc("velocity unit symbol" , "km/h" ), |
64 | i18nc("unit description in lists" , "kilometers per hour" ), |
65 | i18nc("unit synonyms for matching user input" , "kilometer per hour;kilometers per hour;km/h;kmh;kph" ), |
66 | symbolString, |
67 | ki18nc("amount in units (real)" , "%1 kilometers per hour" ), |
68 | ki18ncp("amount in units (integer)" , "%1 kilometer per hour" , "%1 kilometers per hour" ))); |
69 | |
70 | d->addCommonUnit(unit: UnitPrivate::makeUnit(categoryId: VelocityCategory, |
71 | id: MilePerHour, |
72 | multiplier: 0.44704, |
73 | i18nc("velocity unit symbol" , "mph" ), |
74 | i18nc("unit description in lists" , "miles per hour" ), |
75 | i18nc("unit synonyms for matching user input" , "mile per hour;miles per hour;mph" ), |
76 | symbolString, |
77 | ki18nc("amount in units (real)" , "%1 miles per hour" ), |
78 | ki18ncp("amount in units (integer)" , "%1 mile per hour" , "%1 miles per hour" ))); |
79 | |
80 | d->addUnit(unit: UnitPrivate::makeUnit(categoryId: VelocityCategory, |
81 | id: FootPerSecond, |
82 | multiplier: 0.3048, |
83 | i18nc("velocity unit symbol" , "ft/s" ), |
84 | i18nc("unit description in lists" , "feet per second" ), |
85 | i18nc("unit synonyms for matching user input" , "foot per second;feet per second;ft/s;ft/sec;fps" ), |
86 | symbolString, |
87 | ki18nc("amount in units (real)" , "%1 feet per second" ), |
88 | ki18ncp("amount in units (integer)" , "%1 foot per second" , "%1 feet per second" ))); |
89 | |
90 | d->addUnit(unit: UnitPrivate::makeUnit(categoryId: VelocityCategory, |
91 | id: InchPerSecond, |
92 | multiplier: 0.0254, |
93 | i18nc("velocity unit symbol" , "in/s" ), |
94 | i18nc("unit description in lists" , "inches per second" ), |
95 | i18nc("unit synonyms for matching user input" , "inch per second;inches per second;in/s;in/sec;ips" ), |
96 | symbolString, |
97 | ki18nc("amount in units (real)" , "%1 inches per second" ), |
98 | ki18ncp("amount in units (integer)" , "%1 inch per second" , "%1 inches per second" ))); |
99 | |
100 | d->addCommonUnit(unit: UnitPrivate::makeUnit(categoryId: VelocityCategory, |
101 | id: Knot, |
102 | multiplier: 0.514444, |
103 | i18nc("velocity unit symbol" , "kt" ), |
104 | i18nc("unit description in lists" , "knots" ), |
105 | i18nc("unit synonyms for matching user input" , "knot;knots;kt;nautical miles per hour" ), |
106 | symbolString, |
107 | ki18nc("amount in units (real)" , "%1 knots" ), |
108 | ki18ncp("amount in units (integer)" , "%1 knot" , "%1 knots" ))); |
109 | |
110 | // http://en.wikipedia.org/wiki/Speed_of_sound |
111 | d->addCommonUnit(unit: UnitPrivate::makeUnit(categoryId: VelocityCategory, |
112 | id: Mach, |
113 | multiplier: 343, |
114 | i18nc("velocity unit symbol" , "Ma" ), |
115 | i18nc("unit description in lists" , "Mach" ), |
116 | i18nc("unit synonyms for matching user input" , "mach;machs;Ma;speed of sound" ), |
117 | symbolString, |
118 | ki18nc("amount in units (real)" , "Mach %1" ), |
119 | ki18ncp("amount in units (integer)" , "Mach %1" , "Mach %1" ))); |
120 | |
121 | d->addUnit(unit: UnitPrivate::makeUnit(categoryId: VelocityCategory, |
122 | id: SpeedOfLight, |
123 | multiplier: 2.99792458e+08, |
124 | i18nc("velocity unit symbol" , "c" ), |
125 | i18nc("unit description in lists" , "speed of light" ), |
126 | i18nc("unit synonyms for matching user input" , "speed of light;c" ), |
127 | symbolString, |
128 | ki18nc("amount in units (real)" , "%1 speed of light" ), |
129 | ki18ncp("amount in units (integer)" , "%1 speed of light" , "%1 speed of light" ))); |
130 | |
131 | // http://en.wikipedia.org/wiki/Beaufort_scale |
132 | d->addUnit(unit: UnitPrivate::makeUnit(dd: new BeaufortUnitPrivate(VelocityCategory, |
133 | Beaufort, |
134 | 1.0, |
135 | i18nc("velocity unit symbol" , "bft" ), |
136 | i18nc("unit description in lists" , "Beaufort" ), |
137 | i18nc("unit synonyms for matching user input" , "Beaufort;Bft" ), |
138 | symbolString, |
139 | ki18nc("amount in units (real)" , "%1 on the Beaufort scale" ), |
140 | ki18ncp("amount in units (integer)" , "%1 on the Beaufort scale" , "%1 on the Beaufort scale" )))); |
141 | |
142 | return c; |
143 | } |
144 | |
145 | } // KUnitConversion namespace |
146 | |