Celestia

Форк
0
/
units.cpp 
84 строки · 2.4 Кб
1
// units.cpp
2
//
3
// Copyright (C) 2001-2023, the Celestia Development Team
4
//
5
// This program is free software; you can redistribute it and/or
6
// modify it under the terms of the GNU General Public License
7
// as published by the Free Software Foundation; either version 2
8
// of the License, or (at your option) any later version.
9

10
#include "units.h"
11

12
#include <celcompat/numbers.h>
13
#include "astro.h"
14
#include "date.h"
15

16
namespace celestia::astro
17
{
18

19
// Get scale of given length unit in kilometers
20
std::optional<double>
21
getLengthScale(LengthUnit unit)
22
{
23
    switch (unit)
24
    {
25
    case LengthUnit::Kilometer: return 1.0;
26
    case LengthUnit::Meter: return 1e-3;
27
    case LengthUnit::EarthRadius: return EARTH_RADIUS<double>;
28
    case LengthUnit::JupiterRadius: return JUPITER_RADIUS<double>;
29
    case LengthUnit::SolarRadius: return SOLAR_RADIUS<double>;
30
    case LengthUnit::AstronomicalUnit: return KM_PER_AU<double>;
31
    case LengthUnit::LightYear: return KM_PER_LY<double>;
32
    case LengthUnit::Parsec: return KM_PER_PARSEC<double>;
33
    case LengthUnit::Kiloparsec: return 1e3 * KM_PER_PARSEC<double>;
34
    case LengthUnit::Megaparsec: return 1e6 * KM_PER_PARSEC<double>;
35
    default: return std::nullopt;
36
    }
37
}
38

39

40
// Get scale of given time unit in days
41
std::optional<double>
42
getTimeScale(TimeUnit unit)
43
{
44
    switch (unit)
45
    {
46
    case TimeUnit::Second: return 1.0 / SECONDS_PER_DAY;
47
    case TimeUnit::Minute: return 1.0 / MINUTES_PER_DAY;
48
    case TimeUnit::Hour: return 1.0 / HOURS_PER_DAY;
49
    case TimeUnit::Day: return 1.0;
50
    case TimeUnit::JulianYear: return DAYS_PER_YEAR;
51
    default: return std::nullopt;
52
    }
53
}
54

55

56
// Get scale of given angle unit in degrees
57
std::optional<double>
58
getAngleScale(AngleUnit unit)
59
{
60
    switch (unit)
61
    {
62
    case AngleUnit::Milliarcsecond: return 1e-3 / SECONDS_PER_DEG;
63
    case AngleUnit::Arcsecond: return 1.0 / SECONDS_PER_DEG;
64
    case AngleUnit::Arcminute: return 1.0 / MINUTES_PER_DEG;
65
    case AngleUnit::Degree: return 1.0;
66
    case AngleUnit::Hour: return DEG_PER_HRA;
67
    case AngleUnit::Radian: return 180.0 / celestia::numbers::pi;
68
    default: return std::nullopt;
69
    }
70
}
71

72
std::optional<double>
73
getMassScale(MassUnit unit)
74
{
75
    switch (unit)
76
    {
77
    case MassUnit::Kilogram: return 1.0 / EarthMass;
78
    case MassUnit::EarthMass: return 1.0;
79
    case MassUnit::JupiterMass: return JupiterMass / EarthMass;
80
    default: return std::nullopt;
81
    }
82
}
83

84
} // end namespace celestia::astro
85

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.