KUnitConversion

velocity.cpp
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
15namespace KUnitConversion
16{
17class BeaufortUnitPrivate : public UnitPrivate
18{
19public:
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(value, 3.0 / 2.0);
36 }
37
38 qreal fromDefault(qreal value) const override
39 {
40 return pow(value / 0.836, 2.0 / 3.0);
41 }
42};
43
44UnitCategory Velocity::makeCategory()
45{
46 auto c = UnitCategoryPrivate::makeCategory(VelocityCategory, i18n("Speed"), i18n("Speed"));
47 auto d = UnitCategoryPrivate::get(c);
48 KLocalizedString symbolString = ki18nc("%1 value, %2 unit symbol (velocity)", "%1 %2");
49
50 d->addDefaultUnit(UnitPrivate::makeUnit(VelocityCategory,
51 MeterPerSecond,
52 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(UnitPrivate::makeUnit(VelocityCategory,
61 KilometerPerHour,
62 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(UnitPrivate::makeUnit(VelocityCategory,
71 MilePerHour,
72 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(UnitPrivate::makeUnit(VelocityCategory,
81 FootPerSecond,
82 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(UnitPrivate::makeUnit(VelocityCategory,
91 InchPerSecond,
92 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(UnitPrivate::makeUnit(VelocityCategory,
101 Knot,
102 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(UnitPrivate::makeUnit(VelocityCategory,
112 Mach,
113 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(UnitPrivate::makeUnit(VelocityCategory,
122 SpeedOfLight,
123 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(UnitPrivate::makeUnit(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
QString i18nc(const char *context, const char *text, const TYPE &arg...)
KLocalizedString KI18N_EXPORT ki18ncp(const char *context, const char *singular, const char *plural)
KLocalizedString KI18N_EXPORT ki18nc(const char *context, const char *text)
QString i18n(const char *text, const TYPE &arg...)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 17:06:12 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.