Skip to content

Commit bf469c4

Browse files
committed
ref: JulianDayNumber
1 parent a63c4cd commit bf469c4

7 files changed

Lines changed: 51 additions & 82 deletions

File tree

Library/PAX_MAHOROBA/Map/Tile/MapTileLayer.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ namespace paxs {
6161
const auto& koyomi = app_state_manager_.getKoyomi();
6262

6363
TileRenderer::drawBackground();
64-
TileRenderer::drawTiles(xyz_tile_list, visible, map_viewport, koyomi.jdn.getDay());
64+
const int date = static_cast<int>(koyomi.jdn.getDay());
65+
TileRenderer::drawTiles(xyz_tile_list, visible, map_viewport, date);
6566
}
6667

6768
RenderLayer getLayer() const override { return RenderLayer::MapTile; }

Library/PAX_MAHOROBA/Map/Tile/TileRenderer.hpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
#include <PAX_MAHOROBA/Rendering/BackgroundColor.hpp>
2727
#include <PAX_MAHOROBA/Rendering/FontSystem.hpp>
2828

29-
#include <PAX_SAPIENTICA/Calendar/JulianDayNumber.hpp>
3029
#include <PAX_SAPIENTICA/Core/Type/Vector2.hpp>
3130
#include <PAX_SAPIENTICA/System/FeatureVisibilityManager.hpp>
3231
#include <PAX_SAPIENTICA/Utility/MurMur3.hpp>
@@ -46,16 +45,15 @@ namespace paxs {
4645
/// @param tiles タイルのリスト
4746
/// @param visible 可視性管理
4847
/// @param map_viewport マップビューポート
49-
/// @param jdn ユリウス日
48+
/// @param date 日付
5049
static void drawTiles(
5150
const std::vector<XYZTile>& tiles,
5251
const FeatureVisibilityManager& visible,
5352
const MapViewport& map_viewport,
54-
cal::JDN_F64 jdn
53+
const int date
5554
) {
5655
const Vector2<double> map_viewport_size = map_viewport.getSize();
5756
const Vector2<double> map_viewport_center = map_viewport.getCenter();
58-
const int date = static_cast<int>(jdn.getDay());
5957

6058
for (const auto& tile : tiles) {
6159
// 可視性チェック

Library/PAX_SAPIENTICA/Calendar/JulianDayNumber.hpp

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,16 @@ namespace paxs::cal {
2828
class JulianDayNumber {
2929
private:
3030
Day day{ 1816023 /*西暦260年1月1日*/}; // 1808286 西暦238年10月26日 // 1940571 西暦601年1月1日
31+
32+
// グレゴリオ暦の計算用
33+
constexpr static double getK(const double month) { return std::floor((14 - month) / 12); }
34+
35+
// ヒジュラ暦の閏年かどうか
36+
constexpr bool isIslamicLeapYear(const int year) const { return ((((11 * year) + 14) % 30) < 11); }
37+
// ヒジュラ暦の月の日数計算
38+
constexpr int getLastMonthDay(const int year, const int month) const {
39+
return (((month % 2) == 1) || ((month == 12) && isIslamicLeapYear(year))) ? 30 : 29;
40+
}
3141
public:
3242
constexpr JulianDayNumber() = default;
3343
template<typename T>
@@ -45,25 +55,22 @@ namespace paxs::cal {
4555
constexpr Day operator+=(const Day day_) { return (day += day_); }
4656
constexpr Day operator-=(const Day day_) { return (day -= day_); }
4757

48-
private:
49-
// グレゴリオ暦の計算用
50-
constexpr static double getK(const double month) { return std::floor((14 - month) / 12); }
51-
public:
5258
// グレゴリオ暦からユリウス日を取得
53-
constexpr void fromGregorianCalendar(const double year, const double month = 1.0, const double day_ = 1.0) {
59+
constexpr static JulianDayNumber fromGregorianCalendar(const double year, const double month = 1.0, const double day_ = 1.0) {
5460
const double K = getK(month);
55-
this->day = static_cast<Day>(std::floor((-K + year + 4800) * 1461 / 4)
61+
return JulianDayNumber(static_cast<Day>(std::floor((-K + year + 4800) * 1461 / 4)
5662
+ std::floor((K * 12 + month - 2) * 367 / 12)
5763
- std::floor(std::floor((-K + year + 4900) / 100) * 3 / 4)
58-
+ day_ - 32075);
64+
+ day_ - 32075));
5965
}
6066
// ユリウス暦からユリウス日を取得
61-
constexpr void fromJulianCalendar(const double year, const double month = 1.0, const double day_ = 1.0) {
67+
constexpr static JulianDayNumber fromJulianCalendar(const double year, const double month = 1.0, const double day_ = 1.0) {
6268
const double K = getK(month);
63-
this->day = static_cast<Day>(std::floor((-K + year + 4800) * 1461 / 4)
69+
return JulianDayNumber(static_cast<Day>(std::floor((-K + year + 4800) * 1461 / 4)
6470
+ std::floor((K * 12 + month - 2) * 367 / 12)
65-
+ day_ - 32113);
71+
+ day_ - 32113));
6672
}
73+
6774
// グレゴリオ暦を取得
6875
constexpr GregorianDate toGregorianCalendar() const {
6976
GregorianDate ymd;
@@ -227,14 +234,7 @@ namespace paxs::cal {
227234
else value = 1950 - value;
228235
return CalBP{ value };
229236
}
230-
private:
231-
// ヒジュラ暦の閏年かどうか
232-
constexpr bool isIslamicLeapYear(const int year) const { return ((((11 * year) + 14) % 30) < 11); }
233-
// ヒジュラ暦の月の日数計算
234-
constexpr int getLastMonthDay(const int year, const int month) const {
235-
return (((month % 2) == 1) || ((month == 12) && isIslamicLeapYear(year))) ? 30 : 29;
236-
}
237-
public:
237+
238238
// ヒジュラ暦を取得
239239
constexpr IslamicDate toIslamicCalendar() const {
240240
// islamic_day(227014) = jdn(1948439)

Library/PAX_SAPIENTICA/Calendar/Koyomi.hpp

Lines changed: 29 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -93,16 +93,7 @@ namespace paxs {
9393
static constexpr double time_scale_factor = 18.0; // 時間経過の速度調整係数
9494
static constexpr int calendar_update_threshold = 0; // 暦更新のしきい値
9595

96-
/// @brief グレゴリオ暦に変換
97-
void updateGregorianDate(OutputDate& output_date) const {
98-
output_date.date = jdn.toGregorianCalendar();
99-
}
100-
101-
/// @brief ユリウス暦に変換
102-
void updateJulianDate(OutputDate& output_date) const {
103-
output_date.date = jdn.toJulianCalendar();
104-
}
105-
96+
// TODO: name_keyの仕様を確認する
10697
/// @brief 和暦に変換
10798
void updateJapaneseDate(OutputDate& output_date) const {
10899
const paxs::cal::JapanDate jp_date = jdn.toJapaneseCalendar(japanese_era_list);
@@ -119,57 +110,39 @@ namespace paxs {
119110
output_date.date = cn_date;
120111
}
121112

122-
/// @brief ユリウス通日を格納
123-
void updateJulianDayNumber(OutputDate& output_date) {
124-
output_date.date = jdn;
125-
}
126-
127-
/// @brief BP(年代測定)に変換
128-
void updateCalBP(OutputDate& output_date) const {
129-
output_date.date = jdn.toCalBP();
130-
}
131-
132-
/// @brief イスラム暦(ヒジュラ暦)に変換
133-
void updateIslamicDate(OutputDate& output_date) const {
134-
output_date.date = jdn.toIslamicCalendar();
135-
}
136-
137-
/// @brief シミュレーションステップ数を格納
138-
void updateSimulationSteps(OutputDate& output_date) {
139-
output_date.date = steps;
140-
}
141-
142113
public:
143114
void calcDate() {
144115
// 暦データを更新
145116
for (auto& dl : date_list) {
146117
switch (dl.date.index()) {
147-
case cal::gregorian_date_type:
148-
updateGregorianDate(dl);
149-
break;
150-
case cal::julian_date_type:
151-
updateJulianDate(dl);
152-
break;
153-
case cal::japan_date_type:
154-
updateJapaneseDate(dl);
155-
break;
156-
case cal::china_date_type:
157-
updateChineseDate(dl);
158-
break;
159-
case cal::jdn_f64_type:
160-
case cal::jdn_s32_type:
161-
case cal::jdn_s64_type:
162-
updateJulianDayNumber(dl);
163-
break;
164-
case cal::calbp_type:
165-
updateCalBP(dl);
166-
break;
167-
case cal::islamic_date_type:
168-
updateIslamicDate(dl);
169-
break;
170-
case cal::simulation_steps_type:
171-
updateSimulationSteps(dl);
172-
break;
118+
case cal::gregorian_date_type:
119+
dl.date = jdn.toGregorianCalendar();
120+
break;
121+
case cal::julian_date_type:
122+
dl.date = jdn.toJulianCalendar();
123+
break;
124+
case cal::japan_date_type:
125+
updateJapaneseDate(dl);
126+
break;
127+
case cal::china_date_type:
128+
updateChineseDate(dl);
129+
break;
130+
case cal::jdn_f64_type:
131+
case cal::jdn_s32_type:
132+
case cal::jdn_s64_type:
133+
dl.date = jdn;
134+
break;
135+
case cal::calbp_type:
136+
dl.date = jdn.toCalBP();
137+
break;
138+
case cal::islamic_date_type:
139+
dl.date = jdn.toIslamicCalendar();
140+
break;
141+
case cal::simulation_steps_type:
142+
dl.date = steps;
143+
break;
144+
default:
145+
break;
173146
}
174147
}
175148
}

Library/PAX_SAPIENTICA/Map/Repository/FeatureListLoader.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
#include <functional>
1717
#include <string>
1818

19-
#include <PAX_SAPIENTICA/Calendar/JulianDayNumber.hpp>
2019
#include <PAX_SAPIENTICA/Core/Calendar/Calendar.hpp>
2120
#include <PAX_SAPIENTICA/Core/Type/Range.hpp>
2221
#include <PAX_SAPIENTICA/IO/Data/TsvTable.hpp>

Library/PAX_SAPIENTICA/Map/Repository/LocationDataLoader.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
#include <optional>
1717
#include <string>
1818

19-
#include <PAX_SAPIENTICA/Calendar/JulianDayNumber.hpp>
2019
#include <PAX_SAPIENTICA/Core/Calendar/Calendar.hpp>
2120
#include <PAX_SAPIENTICA/Core/Type/Range.hpp>
2221
#include <PAX_SAPIENTICA/Core/Type/UnorderedMap.hpp>

Library/PAX_SAPIENTICA/Simulation/Manager/SimulationManager.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
#include <string>
1818
#include <utility>
1919

20-
#include <PAX_SAPIENTICA/Calendar/JulianDayNumber.hpp>
2120
#include <PAX_SAPIENTICA/IO/File/FileSystem.hpp>
2221
#include <PAX_SAPIENTICA/Interface/GUIProgressReporter.hpp>
2322
#include <PAX_SAPIENTICA/Simulation/Config/SimulationConst.hpp>

0 commit comments

Comments
 (0)