| 1 | /* |
| 2 | * SPDX-FileCopyrightText: 2010 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 "angle_p.h" |
| 9 | #include "unit_p.h" |
| 10 | |
| 11 | #include <KLocalizedString> |
| 12 | |
| 13 | #include <math.h> |
| 14 | |
| 15 | namespace KUnitConversion |
| 16 | { |
| 17 | class RadiansUnitPrivate : public UnitPrivate |
| 18 | { |
| 19 | public: |
| 20 | RadiansUnitPrivate(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 (value / (2 * M_PI)) * 360.0; |
| 36 | } |
| 37 | qreal fromDefault(qreal value) const override |
| 38 | { |
| 39 | return (value / 360.0) * (2 * M_PI); |
| 40 | } |
| 41 | }; |
| 42 | |
| 43 | UnitCategory Angle::makeCategory() |
| 44 | { |
| 45 | auto c = UnitCategoryPrivate::makeCategory(id: AngleCategory, i18n("Angle" ), i18n("Angle" )); |
| 46 | auto d = UnitCategoryPrivate::get(category: c); |
| 47 | KLocalizedString symbolString = ki18nc("%1 value, %2 unit symbol (angle)" , "%1 %2" ); |
| 48 | |
| 49 | d->addDefaultUnit(unit: UnitPrivate::makeUnit(categoryId: AngleCategory, |
| 50 | id: Degree, |
| 51 | multiplier: 1, |
| 52 | i18nc("angle unit symbol" , "°" ), |
| 53 | i18nc("unit description in lists" , "degrees" ), |
| 54 | i18nc("unit synonyms for matching user input" , "deg;degree;degrees;°" ), |
| 55 | symbolString, |
| 56 | ki18nc("amount in units (real)" , "%1 degrees" ), |
| 57 | ki18ncp("amount in units (integer)" , "%1 degree" , "%1 degrees" ))); |
| 58 | |
| 59 | d->addCommonUnit(unit: UnitPrivate::makeUnit(dd: new RadiansUnitPrivate(AngleCategory, |
| 60 | Radian, |
| 61 | 1.0, |
| 62 | i18nc("angle unit symbol" , "rad" ), |
| 63 | i18nc("unit description in lists" , "radians" ), |
| 64 | i18nc("unit synonyms for matching user input" , "rad;radian;radians" ), |
| 65 | symbolString, |
| 66 | ki18nc("amount in units (real)" , "%1 radians" ), |
| 67 | ki18ncp("amount in units (integer)" , "%1 radian" , "%1 radians" )))); |
| 68 | |
| 69 | d->addUnit(unit: UnitPrivate::makeUnit(categoryId: AngleCategory, |
| 70 | id: Gradian, |
| 71 | multiplier: 360.0 / 400.0, |
| 72 | i18nc("angle unit symbol" , "grad" ), |
| 73 | i18nc("unit description in lists" , "gradians" ), |
| 74 | i18nc("unit synonyms for matching user input" , "grad;gradian;gradians;grade;gon" ), |
| 75 | symbolString, |
| 76 | ki18nc("amount in units (real)" , "%1 gradians" ), |
| 77 | ki18ncp("amount in units (integer)" , "%1 gradian" , "%1 gradians" ))); |
| 78 | |
| 79 | d->addCommonUnit(unit: UnitPrivate::makeUnit(categoryId: AngleCategory, |
| 80 | id: ArcMinute, |
| 81 | multiplier: 1.0 / 60.0, |
| 82 | i18nc("angle unit symbol" , "'" ), |
| 83 | i18nc("unit description in lists" , "arc minutes" ), |
| 84 | i18nc("unit synonyms for matching user input" , "minute of arc;MOA;arcminute;minute;'" ), |
| 85 | symbolString, |
| 86 | ki18nc("amount in units (real)" , "%1 arc minutes" ), |
| 87 | ki18ncp("amount in units (integer)" , "%1 arc minute" , "%1 arc minutes" ))); |
| 88 | |
| 89 | d->addCommonUnit(unit: UnitPrivate::makeUnit(categoryId: AngleCategory, |
| 90 | id: ArcSecond, |
| 91 | multiplier: 1.0 / 3600.0, |
| 92 | i18nc("angle unit symbol" , "\"" ), |
| 93 | i18nc("unit description in lists" , "arc seconds" ), |
| 94 | i18nc("unit synonyms for matching user input" , "second of arc;arcsecond;second;\"" ), |
| 95 | symbolString, |
| 96 | ki18nc("amount in units (real)" , "%1 arc seconds" ), |
| 97 | ki18ncp("amount in units (integer)" , "%1 arc second" , "%1 arc seconds" ))); |
| 98 | |
| 99 | return c; |
| 100 | } |
| 101 | |
| 102 | } // KUnitConversion namespace |
| 103 | |