Skip to content

Commit 76b569f

Browse files
Add VSOP87A/ELPMPP02 fallback, CI and tests
Introduce built-in planetary series fallback (VSOP87A + ELPMPP02) and test/CI support. Adds elpmpp02 and vsop87a source data and headers, new CMake options LUNAR_ENABLE_SERIES_FALLBACK and LUNAR_BUILD_TESTS, and refactors CMake to produce a lunar_core static library used by executables and DLL. Adds GitHub Actions CI workflow and updates Release workflow to enable the fallback flag and include series data in packaged artifacts. README updated to document the fallback behavior, new build/test instructions and configuration options; tests/ subdirectory and ctest integration added.
1 parent 36c1f18 commit 76b569f

File tree

74 files changed

+155455
-885
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+155455
-885
lines changed

.github/workflows/CI.yml

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
pull_request:
6+
7+
jobs:
8+
test:
9+
name: ${{ matrix.name }}
10+
strategy:
11+
fail-fast: false
12+
matrix:
13+
include:
14+
- os: ubuntu-latest
15+
name: linux-x64
16+
cmake_args: ""
17+
18+
- os: ubuntu-24.04-arm
19+
name: linux-arm64
20+
cmake_args: ""
21+
22+
- os: windows-latest
23+
name: windows-x64
24+
cmake_args: "-A x64"
25+
26+
- os: windows-11-arm
27+
name: windows-arm64
28+
cmake_args: "-A ARM64"
29+
30+
- os: macos-15-intel
31+
name: macos-x64
32+
cmake_args: ""
33+
34+
- os: macos-latest
35+
name: macos-arm64
36+
cmake_args: ""
37+
38+
runs-on: ${{ matrix.os }}
39+
40+
steps:
41+
- uses: actions/checkout@v4
42+
43+
- name: Configure
44+
run: >
45+
cmake -S . -B build
46+
-DCMAKE_BUILD_TYPE=Release
47+
-DLUNAR_ENABLE_SERIES_FALLBACK=ON
48+
-DLUNAR_BUILD_TESTS=ON
49+
${{ matrix.cmake_args }}
50+
51+
- name: Build
52+
run: cmake --build build --config Release --parallel
53+
54+
- name: Test
55+
run: ctest --test-dir build -C Release --output-on-failure

.github/workflows/Release.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ jobs:
5454

5555
- name: Configure (native)
5656
if: matrix.kind == 'native'
57-
run: cmake -S . -B build -DCMAKE_BUILD_TYPE=Release ${{ matrix.cmake_args }}
57+
run: cmake -S . -B build -DCMAKE_BUILD_TYPE=Release -DLUNAR_ENABLE_SERIES_FALLBACK=ON ${{ matrix.cmake_args }}
5858

5959
- name: Build (native)
6060
if: matrix.kind == 'native'
@@ -85,6 +85,7 @@ jobs:
8585
8686
cmake -S . -B build \
8787
-DCMAKE_BUILD_TYPE=Release \
88+
-DLUNAR_ENABLE_SERIES_FALLBACK=ON \
8889
-DCMAKE_C_COMPILER="$PWD/zigcc" \
8990
-DCMAKE_CXX_COMPILER="$PWD/zigcxx" \
9091
-DCMAKE_C_FLAGS="-Wno-error=date-time -Wno-date-time" \
@@ -114,6 +115,8 @@ jobs:
114115
mkdir -p package
115116
cp README.md package/
116117
cp LICENSE package/
118+
cp -R vsop87a package/
119+
cp -R elpmpp02 package/
117120
118121
if [ "${{ runner.os }}" = "Windows" ]; then
119122
cp build/Release/lunar.exe package/

CMakeLists.txt

Lines changed: 81 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,45 @@ cmake_minimum_required(VERSION 3.20)
22

33
project(lunar LANGUAGES C CXX)
44

5+
include(CTest)
6+
57
set(CMAKE_CXX_STANDARD 20)
68
set(CMAKE_CXX_STANDARD_REQUIRED ON)
79
set(CMAKE_CXX_EXTENSIONS OFF)
810

11+
option(LUNAR_ENABLE_DIMENSION_TYPES "Enable compile-time tagged physical vectors" ON)
12+
option(LUNAR_ENABLE_SERIES_FALLBACK "Enable VSOP87A/ELPMPP02 fallback when BSP is unavailable" ON)
13+
option(LUNAR_BUILD_TESTS "Build GoogleTest-based test targets" ${BUILD_TESTING})
14+
15+
set(LUNAR_SERIES_SOURCES
16+
vsop87a/vsop87a.cpp
17+
vsop87a/vsop87a_ear.cpp
18+
vsop87a/vsop87a_emb.cpp
19+
vsop87a/vsop87a_jup.cpp
20+
vsop87a/vsop87a_mar.cpp
21+
vsop87a/vsop87a_mer.cpp
22+
vsop87a/vsop87a_nep.cpp
23+
vsop87a/vsop87a_sat.cpp
24+
vsop87a/vsop87a_ura.cpp
25+
vsop87a/vsop87a_ven.cpp
26+
elpmpp02/elpmpp02.cpp
27+
elpmpp02/elpmpp02_data_main_distance.cpp
28+
elpmpp02/elpmpp02_data_main_latitude.cpp
29+
elpmpp02/elpmpp02_data_main_longitude.cpp
30+
elpmpp02/elpmpp02_data_pert_distance_t0.cpp
31+
elpmpp02/elpmpp02_data_pert_distance_t1.cpp
32+
elpmpp02/elpmpp02_data_pert_distance_t2.cpp
33+
elpmpp02/elpmpp02_data_pert_distance_t3.cpp
34+
elpmpp02/elpmpp02_data_pert_latitude_t0.cpp
35+
elpmpp02/elpmpp02_data_pert_latitude_t1.cpp
36+
elpmpp02/elpmpp02_data_pert_latitude_t2.cpp
37+
elpmpp02/elpmpp02_data_pert_latitude_t3.cpp
38+
elpmpp02/elpmpp02_data_pert_longitude_t0.cpp
39+
elpmpp02/elpmpp02_data_pert_longitude_t1.cpp
40+
elpmpp02/elpmpp02_data_pert_longitude_t2.cpp
41+
elpmpp02/elpmpp02_data_pert_longitude_t3.cpp
42+
)
43+
944
if(MSVC)
1045
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
1146
endif()
@@ -43,27 +78,60 @@ set(LUNAR_CORE_SOURCES
4378
src/entry.cpp
4479
)
4580

81+
if(LUNAR_ENABLE_SERIES_FALLBACK)
82+
list(APPEND LUNAR_CORE_SOURCES
83+
${LUNAR_SERIES_SOURCES}
84+
)
85+
endif()
86+
87+
add_library(lunar_core STATIC
88+
${LUNAR_CORE_SOURCES}
89+
)
90+
91+
set_target_properties(lunar_core PROPERTIES
92+
POSITION_INDEPENDENT_CODE ON
93+
)
94+
95+
target_include_directories(lunar_core PUBLIC
96+
${CMAKE_CURRENT_SOURCE_DIR}/include
97+
${CMAKE_CURRENT_SOURCE_DIR}
98+
)
99+
target_compile_definitions(lunar_core PUBLIC
100+
LUNAR_ENABLE_DIMENSION_TYPES=$<BOOL:${LUNAR_ENABLE_DIMENSION_TYPES}>
101+
LUNAR_ENABLE_SERIES_FALLBACK=$<BOOL:${LUNAR_ENABLE_SERIES_FALLBACK}>
102+
)
103+
if(MSVC)
104+
target_compile_options(lunar_core PRIVATE /utf-8)
105+
endif()
106+
46107
add_executable(lunar
47108
src/main.cpp
48-
${LUNAR_CORE_SOURCES}
49109
)
110+
target_link_libraries(lunar PRIVATE lunar_core)
111+
target_include_directories(lunar PRIVATE
112+
${CMAKE_CURRENT_SOURCE_DIR}/include
113+
${CMAKE_CURRENT_SOURCE_DIR}
114+
)
115+
if(MSVC)
116+
target_compile_options(lunar PRIVATE /utf-8)
117+
endif()
50118

51119
add_library(lunar_dll SHARED
52120
src/c_api.cpp
53-
${LUNAR_CORE_SOURCES}
54121
)
55-
122+
target_link_libraries(lunar_dll PRIVATE lunar_core)
123+
target_include_directories(lunar_dll PRIVATE
124+
${CMAKE_CURRENT_SOURCE_DIR}/include
125+
${CMAKE_CURRENT_SOURCE_DIR}
126+
)
127+
target_compile_definitions(lunar_dll PRIVATE LUNAR_BUILD_DLL)
56128
set_target_properties(lunar_dll PROPERTIES
57129
OUTPUT_NAME lunar
58130
)
59-
target_compile_definitions(lunar_dll PRIVATE LUNAR_BUILD_DLL)
60-
61-
foreach(tgt lunar lunar_dll)
62-
target_include_directories(${tgt} PRIVATE
63-
${CMAKE_CURRENT_SOURCE_DIR}/include
64-
)
131+
if(MSVC)
132+
target_compile_options(lunar_dll PRIVATE /utf-8)
133+
endif()
65134

66-
if(MSVC)
67-
target_compile_options(${tgt} PRIVATE /utf-8)
68-
endif()
69-
endforeach()
135+
if(LUNAR_BUILD_TESTS)
136+
add_subdirectory(tests)
137+
endif()

README.md

Lines changed: 37 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# CalcChineseCalendar(lunar)
22

3-
CalcChineseCalendar 是一个基于 JPL DE BSP 星历文件的历法与天文计算工具,提供:
3+
CalcChineseCalendar 是一个优先使用 JPL DE BSP 星历、在缺失 BSP 时可自动回退到仓库内置 VSOP87A + ELPMPP02 的历法与天文计算工具,提供:
44

55
- 命令行工具 `lunar`
66
- 动态库 `lunar_dll`(导出 C API)
@@ -22,7 +22,7 @@ CalcChineseCalendar 是一个基于 JPL DE BSP 星历文件的历法与天文计
2222
- 事件检索:`next``range``search`
2323
- 日月食:`eclipse`
2424
- 传统节日与黄历摘要:`festival``almanac`
25-
- 星历信息与自检`info``selftest`
25+
- 星历信息`info`
2626
- 配置管理与补全脚本:`config``completion`
2727
- 交互式模式(无参数启动)
2828

@@ -32,7 +32,7 @@ CalcChineseCalendar 是一个基于 JPL DE BSP 星历文件的历法与天文计
3232

3333
- CMake 3.20+
3434
- 支持 C++20 的编译器
35-
- 运行时需要 BSP 文件(`.bsp`
35+
- 运行时优先使用 BSP 文件(`.bsp`;若未找到可自动回退到内置 VSOP87A + ELPMPP02
3636
- `download get` 需要系统中存在 `curl``wget`
3737

3838
### 2.2 Windows(Visual Studio)
@@ -53,8 +53,28 @@ cmake --build build -j
5353

5454
- 可执行程序:`lunar`
5555
- 动态库:`lunar_dll`(输出名为 `lunar`,对应平台扩展名)
56+
- 测试程序:`lunar_tests`(启用 `LUNAR_BUILD_TESTS` 时)
5657

57-
## 3. 运行前准备:BSP 星历
58+
### 2.5 可选构建开关
59+
60+
- `-DLUNAR_ENABLE_SERIES_FALLBACK=ON|OFF`
61+
- `ON`(默认):未找到 BSP 时自动切换到内置 VSOP87A + ELPMPP02
62+
- `OFF`:保持旧行为,必须提供可用 BSP
63+
- `-DLUNAR_BUILD_TESTS=ON|OFF`
64+
- `ON`(默认):构建 gtest/ctest 测试目标
65+
- `OFF`:不构建测试目标
66+
67+
### 2.6 运行测试
68+
69+
```bash
70+
cmake -S . -B build
71+
cmake --build build --config Release
72+
ctest --test-dir build -C Release --output-on-failure
73+
```
74+
75+
若关闭 `LUNAR_ENABLE_SERIES_FALLBACK`,可通过环境变量 `LUNAR_TEST_BSP` 指定测试所用 BSP。
76+
77+
## 3. 运行前准备:BSP 星历(可选但优先)
5878

5979
### 3.1 下载列表
6080

@@ -104,7 +124,7 @@ lunar <command> [args...]
104124

105125
### 4.3 全局 BSP 覆盖参数
106126

107-
所有需要星历的命令都支持
127+
所有需要星历的命令都支持显式指定
108128

109129
- `--bsp <path>`
110130
- `--bsp=<path>`
@@ -129,7 +149,7 @@ lunar <bsp> <years> [months options...]
129149

130150
### 5.1 哪些命令需要 BSP
131151

132-
- `months calendar year event at convert day monthview next range search eclipse festival almanac info selftest`
152+
- `months calendar year event at convert day monthview next range search eclipse festival almanac info`
133153

134154
不需要 BSP 的命令:
135155

@@ -149,7 +169,8 @@ lunar <bsp> <years> [months options...]
149169
- 若命令可推断时间区间,优先选择“完整覆盖该区间”的 BSP。
150170
- 若无完整覆盖,选择与区间重叠最多的 BSP。
151171
- 若无法推断区间,使用候选列表第一个。
152-
- 若没有可用候选,抛出错误并提示使用 `--bsp``lunar config set def_bsp`
172+
- 若没有可用候选且 `LUNAR_ENABLE_SERIES_FALLBACK=ON`,自动切换到内置 VSOP87A + ELPMPP02。
173+
- 若没有可用候选且 `LUNAR_ENABLE_SERIES_FALLBACK=OFF`,抛出错误并提示使用 `--bsp``lunar config set def_bsp`
153174

154175
## 6. 配置文件 `lun_cfg.txt`
155176

@@ -449,26 +470,14 @@ lunar info <bsp> [--format json|txt] [--out ...] [--pretty 0|1] [--quiet]
449470
- 默认格式固定为 `txt`(不读取 `def_fmt`)。
450471
- 输出包含文件存在性、大小、SPK 覆盖区间等信息。
451472
452-
### 9.17 selftest
453-
454-
```bash
455-
lunar selftest <bsp> [--format json|txt] [--out ...] [--pretty 0|1] [--quiet]
456-
```
457-
458-
说明:
459-
460-
- 默认格式固定为 `txt`
461-
- 当前内置测试用例包括 `at_illum``conv_rt``y25_cnt`
462-
- 通过返回码 `0`,失败返回 `1`
463-
464-
### 9.18 config
473+
### 9.17 config
465474
466475
```bash
467476
lunar config show [--format json|txt] [--out ...] [--pretty 0|1] [--quiet]
468477
lunar config set <key> <value>
469478
```
470479
471-
### 9.19 completion
480+
### 9.18 completion
472481
473482
```bash
474483
lunar completion bash|zsh|fish|powershell
@@ -499,14 +508,13 @@ lunar completion bash|zsh|fish|powershell
499508
- `6` next
500509
- `7` festival
501510
- `8` info
502-
- `9` selftest
503-
- `10` monthview
504-
- `11` range
505-
- `12` search
506-
- `13` eclipse
507-
- `14` almanac
508-
- `15` config
509-
- `16` completion
511+
- `9` monthview
512+
- `10` range
513+
- `11` search
514+
- `12` eclipse
515+
- `13` almanac
516+
- `14` config
517+
- `15` completion
510518
- `d` 切换/下载 BSP
511519
- `h` 帮助
512520
- `q` 退出

elpmpp02/README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# ELPMPP02
2+
3+
保留内容:
4+
5+
- `elpmpp02.hpp`
6+
- `elpmpp02.cpp`
7+
- `elpmpp02_data_*.cpp`
8+
- `elpmpp02_data_decl.hpp`
9+
10+
调用:
11+
12+
```cpp
13+
elpmpp02::StateVector state;
14+
elpmpp02::Evaluate(elpmpp02::CorrectionSet::DE405,jd_tdb,state);
15+
```
16+
17+
参数:
18+
19+
- `correction`:`LLR`、`DE405`、`DE406`
20+
- `jd_tdb`:TDB/TT 风格儒略日输入
21+
- `state.position_km`:输出位置,单位 km
22+
- `state.velocity_km_per_day`:输出速度,单位 km/day

0 commit comments

Comments
 (0)