1 | /* |
2 | * Copyright (C) 2008-2009 Petri Damstén <damu@iki.fi> |
3 | * |
4 | * This program is free software; you can redistribute it and/or modify |
5 | * it under the terms of the GNU Library General Public License as |
6 | * published by the Free Software Foundation; either version 2, or |
7 | * (at your option) any later version. |
8 | * |
9 | * This program is distributed in the hope that it will be useful, |
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 | * GNU General Public License for more details |
13 | * |
14 | * You should have received a copy of the GNU Library General Public |
15 | * License along with this program; if not, write to the |
16 | * Free Software Foundation, Inc., |
17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
18 | */ |
19 | |
20 | #include "velocity.h" |
21 | #include "converter.h" |
22 | #include <math.h> |
23 | #include <klocale.h> |
24 | |
25 | using namespace KUnitConversion; |
26 | |
27 | class BeaufortConv : public Complex |
28 | { |
29 | double toDefault(double value) const { return 0.836 * pow(value, 3.0 / 2.0); }; |
30 | double fromDefault(double value) const { return pow(value / 0.836, 2.0 / 3.0); }; |
31 | }; |
32 | |
33 | Velocity::Velocity() : UnitCategory(VelocityCategory) |
34 | { |
35 | setName(i18n("Speed" )); |
36 | setSymbolStringFormat(ki18nc("%1 value, %2 unit symbol (velocity)" , "%1 %2" )); |
37 | |
38 | setDefaultUnit(UP(MeterPerSecond, 1, |
39 | i18nc("velocity unit symbol" , "m/s" ), |
40 | i18nc("unit description in lists" , "meters per second" ), |
41 | i18nc("unit synonyms for matching user input" , "meter per second;meters per second;m/s;ms" ), |
42 | ki18nc("amount in units (real)" , "%1 meters per second" ), |
43 | ki18ncp("amount in units (integer)" , "%1 meter per second" , "%1 meters per second" ) |
44 | )); |
45 | U(KilometerPerHour, 0.277778, |
46 | i18nc("velocity unit symbol" , "km/h" ), |
47 | i18nc("unit description in lists" , "kilometers per hour" ), |
48 | i18nc("unit synonyms for matching user input" , |
49 | "kilometer per hour;kilometers per hour;km/h;kmh" ), |
50 | ki18nc("amount in units (real)" , "%1 kilometers per hour" ), |
51 | ki18ncp("amount in units (integer)" , "%1 kilometer per hour" , "%1 kilometers per hour" ) |
52 | ); |
53 | U(MilePerHour, 0.44704, |
54 | i18nc("velocity unit symbol" , "mph" ), |
55 | i18nc("unit description in lists" , "miles per hour" ), |
56 | i18nc("unit synonyms for matching user input" , "mile per hour;miles per hour;mph" ), |
57 | ki18nc("amount in units (real)" , "%1 miles per hour" ), |
58 | ki18ncp("amount in units (integer)" , "%1 mile per hour" , "%1 miles per hour" ) |
59 | ); |
60 | U(FootPerSecond, 0.3048, |
61 | i18nc("velocity unit symbol" , "ft/s" ), |
62 | i18nc("unit description in lists" , "feet per second" ), |
63 | i18nc("unit synonyms for matching user input" , |
64 | "foot per second;feet per second;ft/s;ft/sec;fps" ), |
65 | ki18nc("amount in units (real)" , "%1 feet per second" ), |
66 | ki18ncp("amount in units (integer)" , "%1 foot per second" , "%1 feet per second" ) |
67 | ); |
68 | U(InchPerSecond, 0.0254, |
69 | i18nc("velocity unit symbol" , "in/s" ), |
70 | i18nc("unit description in lists" , "inches per second" ), |
71 | i18nc("unit synonyms for matching user input" , |
72 | "inch per second;inches per second;in/s;in/sec;ips" ), |
73 | ki18nc("amount in units (real)" , "%1 inches per second" ), |
74 | ki18ncp("amount in units (integer)" , "%1 inch per second" , "%1 inches per second" ) |
75 | ); |
76 | U(Knot, 0.514444, |
77 | i18nc("velocity unit symbol" , "kt" ), |
78 | i18nc("unit description in lists" , "knots" ), |
79 | i18nc("unit synonyms for matching user input" , "knot;knots;kt;nautical miles per hour" ), |
80 | ki18nc("amount in units (real)" , "%1 knots" ), |
81 | ki18ncp("amount in units (integer)" , "%1 knot" , "%1 knots" ) |
82 | ); |
83 | // http://en.wikipedia.org/wiki/Speed_of_sound |
84 | U(Mach, 343, |
85 | i18nc("velocity unit symbol" , "Ma" ), |
86 | i18nc("unit description in lists" , "Mach" ), |
87 | i18nc("unit synonyms for matching user input" , "mach;machs;Ma;speed of sound" ), |
88 | ki18nc("amount in units (real)" , "Mach %1" ), |
89 | ki18ncp("amount in units (integer)" , "Mach %1" , "Mach %1" ) |
90 | ); |
91 | U(SpeedOfLight, 2.99792458e+08, |
92 | i18nc("velocity unit symbol" , "c" ), |
93 | i18nc("unit description in lists" , "speed of light" ), |
94 | i18nc("unit synonyms for matching user input" , "speed of light;c" ), |
95 | ki18nc("amount in units (real)" , "%1 speed of light" ), |
96 | ki18ncp("amount in units (integer)" , "%1 speed of light" , "%1 speed of light" ) |
97 | ); |
98 | // http://en.wikipedia.org/wiki/Beaufort_scale |
99 | U(Beaufort, new BeaufortConv(), |
100 | i18nc("velocity unit symbol" , "bft" ), |
101 | i18nc("unit description in lists" , "Beaufort" ), |
102 | i18nc("unit synonyms for matching user input" , "Beaufort;Bft" ), |
103 | ki18nc("amount in units (real)" , "%1 on the Beaufort scale" ), |
104 | ki18ncp("amount in units (integer)" , "%1 on the Beaufort scale" , "%1 on the Beaufort scale" ) |
105 | ); |
106 | |
107 | setMostCommonUnits(QList<int>() << |
108 | MeterPerSecond << KilometerPerHour << MilePerHour << Knot << Mach); |
109 | } |
110 | |