siderust-js 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (272) hide show
  1. package/.github/workflows/ci.yml +166 -0
  2. package/.gitmodules +9 -0
  3. package/CHANGELOG.md +26 -0
  4. package/LICENSE +661 -0
  5. package/README.md +138 -0
  6. package/package.json +12 -0
  7. package/qtty-js/.github/workflows/ci.yml +151 -0
  8. package/qtty-js/.gitmodules +3 -0
  9. package/qtty-js/CHANGELOG.md +31 -0
  10. package/qtty-js/LICENSE +661 -0
  11. package/qtty-js/README.md +132 -0
  12. package/qtty-js/package.json +20 -0
  13. package/qtty-js/qtty/.github/workflows/ci.yml +155 -0
  14. package/qtty-js/qtty/CHANGELOG.md +120 -0
  15. package/qtty-js/qtty/Cargo.lock +1462 -0
  16. package/qtty-js/qtty/Cargo.toml +12 -0
  17. package/qtty-js/qtty/LICENSE +661 -0
  18. package/qtty-js/qtty/README.md +9 -0
  19. package/qtty-js/qtty/qtty/Cargo.toml +41 -0
  20. package/qtty-js/qtty/qtty/README.md +8 -0
  21. package/qtty-js/qtty/qtty/examples/angles.rs +14 -0
  22. package/qtty-js/qtty/qtty/examples/astronomy.rs +17 -0
  23. package/qtty-js/qtty/qtty/examples/dimensional_arithmetic.rs +83 -0
  24. package/qtty-js/qtty/qtty/examples/python_integration.rs +61 -0
  25. package/qtty-js/qtty/qtty/examples/quickstart.rs +15 -0
  26. package/qtty-js/qtty/qtty/examples/ratios.rs +12 -0
  27. package/qtty-js/qtty/qtty/examples/serde_with_unit.rs +234 -0
  28. package/qtty-js/qtty/qtty/examples/serialization.rs +141 -0
  29. package/qtty-js/qtty/qtty/examples/serialization_advanced.rs +155 -0
  30. package/qtty-js/qtty/qtty/src/f32.rs +108 -0
  31. package/qtty-js/qtty/qtty/src/f64.rs +30 -0
  32. package/qtty-js/qtty/qtty/src/i128.rs +111 -0
  33. package/qtty-js/qtty/qtty/src/i16.rs +111 -0
  34. package/qtty-js/qtty/qtty/src/i32.rs +111 -0
  35. package/qtty-js/qtty/qtty/src/i64.rs +111 -0
  36. package/qtty-js/qtty/qtty/src/i8.rs +111 -0
  37. package/qtty-js/qtty/qtty/src/lib.rs +238 -0
  38. package/qtty-js/qtty/qtty/tests/fixtures/qtty-vec-no-std/Cargo.lock +83 -0
  39. package/qtty-js/qtty/qtty/tests/fixtures/qtty-vec-no-std/Cargo.toml +10 -0
  40. package/qtty-js/qtty/qtty/tests/fixtures/qtty-vec-no-std/src/lib.rs +7 -0
  41. package/qtty-js/qtty/qtty/tests/fixtures/qtty-vec-no-std-alloc/Cargo.lock +83 -0
  42. package/qtty-js/qtty/qtty/tests/fixtures/qtty-vec-no-std-alloc/Cargo.toml +10 -0
  43. package/qtty-js/qtty/qtty/tests/fixtures/qtty-vec-no-std-alloc/src/lib.rs +7 -0
  44. package/qtty-js/qtty/qtty/tests/fixtures/qtty-vec-std/Cargo.lock +83 -0
  45. package/qtty-js/qtty/qtty/tests/fixtures/qtty-vec-std/Cargo.toml +10 -0
  46. package/qtty-js/qtty/qtty/tests/fixtures/qtty-vec-std/src/lib.rs +5 -0
  47. package/qtty-js/qtty/qtty/tests/integration_tests.rs +529 -0
  48. package/qtty-js/qtty/qtty/tests/qtty_vec_feature_matrix.rs +58 -0
  49. package/qtty-js/qtty/qtty-core/Cargo.toml +41 -0
  50. package/qtty-js/qtty/qtty-core/README.md +8 -0
  51. package/qtty-js/qtty/qtty-core/examples/diesel_integration.rs +145 -0
  52. package/qtty-js/qtty/qtty-core/examples/quantity_db_serde.rs +215 -0
  53. package/qtty-js/qtty/qtty-core/src/dimension.rs +249 -0
  54. package/qtty-js/qtty/qtty-core/src/feature_diesel.rs +318 -0
  55. package/qtty-js/qtty/qtty-core/src/feature_pyo3.rs +27 -0
  56. package/qtty-js/qtty/qtty-core/src/feature_serde.rs +203 -0
  57. package/qtty-js/qtty/qtty-core/src/feature_tiberius.rs +28 -0
  58. package/qtty-js/qtty/qtty-core/src/lib.rs +744 -0
  59. package/qtty-js/qtty/qtty-core/src/macros.rs +93 -0
  60. package/qtty-js/qtty/qtty-core/src/quantity.rs +810 -0
  61. package/qtty-js/qtty/qtty-core/src/scalar.rs +1742 -0
  62. package/qtty-js/qtty/qtty-core/src/unit.rs +332 -0
  63. package/qtty-js/qtty/qtty-core/src/units/angular.rs +1228 -0
  64. package/qtty-js/qtty/qtty-core/src/units/area.rs +243 -0
  65. package/qtty-js/qtty/qtty-core/src/units/frequency.rs +179 -0
  66. package/qtty-js/qtty/qtty-core/src/units/length.rs +1270 -0
  67. package/qtty-js/qtty/qtty-core/src/units/mass.rs +488 -0
  68. package/qtty-js/qtty/qtty-core/src/units/mod.rs +26 -0
  69. package/qtty-js/qtty/qtty-core/src/units/power.rs +324 -0
  70. package/qtty-js/qtty/qtty-core/src/units/time.rs +667 -0
  71. package/qtty-js/qtty/qtty-core/src/units/unitless.rs +212 -0
  72. package/qtty-js/qtty/qtty-core/src/units/velocity.rs +210 -0
  73. package/qtty-js/qtty/qtty-core/src/units/volume.rs +269 -0
  74. package/qtty-js/qtty/qtty-core/tests/core.rs +628 -0
  75. package/qtty-js/qtty/qtty-core/tests/diesel.rs +461 -0
  76. package/qtty-js/qtty/qtty-core/tests/integers.rs +632 -0
  77. package/qtty-js/qtty/qtty-core/tests/no_cross_unit_ops.rs +35 -0
  78. package/qtty-js/qtty/qtty-core/tests/pyo3.rs +334 -0
  79. package/qtty-js/qtty/qtty-core/tests/quantity_f32.rs +276 -0
  80. package/qtty-js/qtty/qtty-core/tests/scalar_decimal.rs +258 -0
  81. package/qtty-js/qtty/qtty-core/tests/scalar_f32.rs +286 -0
  82. package/qtty-js/qtty/qtty-core/tests/scalar_f64_real.rs +287 -0
  83. package/qtty-js/qtty/qtty-core/tests/scalar_rational.rs +260 -0
  84. package/qtty-js/qtty/qtty-core/tests/serde.rs +256 -0
  85. package/qtty-js/qtty/qtty-core/tests/tiberius.rs +208 -0
  86. package/qtty-js/qtty/qtty-derive/Cargo.toml +23 -0
  87. package/qtty-js/qtty/qtty-derive/README.md +8 -0
  88. package/qtty-js/qtty/qtty-derive/src/lib.rs +340 -0
  89. package/qtty-js/qtty/qtty-ffi/ARCHITECTURE.md +3 -0
  90. package/qtty-js/qtty/qtty-ffi/Cargo.toml +31 -0
  91. package/qtty-js/qtty/qtty-ffi/README.md +9 -0
  92. package/qtty-js/qtty/qtty-ffi/build.rs +326 -0
  93. package/qtty-js/qtty/qtty-ffi/cbindgen.toml +105 -0
  94. package/qtty-js/qtty/qtty-ffi/include/qtty_ffi.h +1126 -0
  95. package/qtty-js/qtty/qtty-ffi/src/ffi.rs +1251 -0
  96. package/qtty-js/qtty/qtty-ffi/src/ffi_serde.rs +294 -0
  97. package/qtty-js/qtty/qtty-ffi/src/helpers.rs +310 -0
  98. package/qtty-js/qtty/qtty-ffi/src/lib.rs +229 -0
  99. package/qtty-js/qtty/qtty-ffi/src/macros.rs +121 -0
  100. package/qtty-js/qtty/qtty-ffi/src/registry.rs +274 -0
  101. package/qtty-js/qtty/qtty-ffi/src/types.rs +620 -0
  102. package/qtty-js/qtty/qtty-ffi/tests/integration_tests.rs +842 -0
  103. package/qtty-js/qtty/qtty-ffi/units.csv +156 -0
  104. package/qtty-js/qtty/qtty-ffi/units.csv.md +3 -0
  105. package/qtty-js/qtty-node/.prettierignore +6 -0
  106. package/qtty-js/qtty-node/.prettierrc.json +6 -0
  107. package/qtty-js/qtty-node/README.md +250 -0
  108. package/qtty-js/qtty-node/c8.config.json +11 -0
  109. package/qtty-js/qtty-node/eslint.config.js +31 -0
  110. package/qtty-js/qtty-node/examples/arithmetic.mjs +64 -0
  111. package/qtty-js/qtty-node/examples/astronomy.mjs +90 -0
  112. package/qtty-js/qtty-node/examples/quickstart.mjs +36 -0
  113. package/qtty-js/qtty-node/examples/serialization.mjs +125 -0
  114. package/qtty-js/qtty-node/examples/unit_factories.mjs +74 -0
  115. package/qtty-js/qtty-node/index.d.ts +219 -0
  116. package/qtty-js/qtty-node/index.js +323 -0
  117. package/qtty-js/qtty-node/lib/DerivedQuantity.js +122 -0
  118. package/qtty-js/qtty-node/lib/Quantity.js +151 -0
  119. package/qtty-js/qtty-node/lib/backend.js +25 -0
  120. package/qtty-js/qtty-node/native.cjs +306 -0
  121. package/qtty-js/qtty-node/package-lock.json +3223 -0
  122. package/qtty-js/qtty-node/package.json +70 -0
  123. package/qtty-js/qtty-node/units.d.ts +299 -0
  124. package/qtty-js/qtty-node/units.js +210 -0
  125. package/qtty-js/qtty-web/Cargo.lock +767 -0
  126. package/qtty-js/qtty-web/Cargo.toml +21 -0
  127. package/qtty-js/qtty-web/index.d.ts +140 -0
  128. package/qtty-js/qtty-web/index.js +20 -0
  129. package/qtty-js/qtty-web/lib/DerivedQuantity.js +58 -0
  130. package/qtty-js/qtty-web/lib/Quantity.js +75 -0
  131. package/qtty-js/qtty-web/lib/backend.js +80 -0
  132. package/qtty-js/qtty-web/package.json +45 -0
  133. package/qtty-js/qtty-web/src/lib.rs +111 -0
  134. package/qtty-js/scripts/ci.sh +73 -0
  135. package/scripts/ci.sh +123 -0
  136. package/siderust-core/Cargo.lock +787 -0
  137. package/siderust-core/Cargo.toml +18 -0
  138. package/siderust-core/DEDUPLICATION.md +124 -0
  139. package/siderust-core/src/body.rs +120 -0
  140. package/siderust-core/src/events.rs +184 -0
  141. package/siderust-core/src/lib.rs +20 -0
  142. package/siderust-core/src/observer.rs +55 -0
  143. package/siderust-core/src/position.rs +213 -0
  144. package/siderust-node/.prettierignore +7 -0
  145. package/siderust-node/.prettierrc.json +6 -0
  146. package/siderust-node/Cargo.lock +906 -0
  147. package/siderust-node/Cargo.toml +29 -0
  148. package/siderust-node/README.md +109 -0
  149. package/siderust-node/__test__/index.test.mjs +248 -0
  150. package/siderust-node/build.rs +5 -0
  151. package/siderust-node/c8.config.json +3 -0
  152. package/siderust-node/eslint.config.js +31 -0
  153. package/siderust-node/examples/01_basic_coordinates.mjs +24 -0
  154. package/siderust-node/examples/02_coordinate_transformations.mjs +25 -0
  155. package/siderust-node/examples/03_all_frames_conversions.mjs +26 -0
  156. package/siderust-node/examples/04_all_center_conversions.mjs +24 -0
  157. package/siderust-node/examples/05_target_tracking.mjs +22 -0
  158. package/siderust-node/examples/06_night_events.mjs +18 -0
  159. package/siderust-node/examples/07_moon_properties.mjs +21 -0
  160. package/siderust-node/examples/08_solar_system.mjs +19 -0
  161. package/siderust-node/examples/09_star_observability.mjs +22 -0
  162. package/siderust-node/examples/10_time_periods.mjs +9 -0
  163. package/siderust-node/examples/11_serialization.mjs +31 -0
  164. package/siderust-node/examples/12_runtime_ephemeris.mjs +27 -0
  165. package/siderust-node/examples/13_coordinate_operations.mjs +20 -0
  166. package/siderust-node/index.d.ts +623 -0
  167. package/siderust-node/index.js +79 -0
  168. package/siderust-node/lib/Observer.js +112 -0
  169. package/siderust-node/lib/Star.js +118 -0
  170. package/siderust-node/lib/backend.js +63 -0
  171. package/siderust-node/lib/wrappers.js +566 -0
  172. package/siderust-node/main.js +20 -0
  173. package/siderust-node/native.cjs +360 -0
  174. package/siderust-node/package-lock.json +3261 -0
  175. package/siderust-node/package.json +71 -0
  176. package/siderust-node/src/body.rs +74 -0
  177. package/siderust-node/src/coordinates.rs +372 -0
  178. package/siderust-node/src/ephemeris.rs +462 -0
  179. package/siderust-node/src/events.rs +577 -0
  180. package/siderust-node/src/lib.rs +43 -0
  181. package/siderust-node/src/observer.rs +132 -0
  182. package/siderust-node/src/phase.rs +218 -0
  183. package/siderust-node/src/position.rs +292 -0
  184. package/siderust-node/src/star.rs +200 -0
  185. package/siderust-web/Cargo.lock +855 -0
  186. package/siderust-web/Cargo.toml +34 -0
  187. package/siderust-web/README.md +100 -0
  188. package/siderust-web/__test__/index.test.mjs +118 -0
  189. package/siderust-web/examples/github-pages/README.md +31 -0
  190. package/siderust-web/examples/github-pages/index.html +135 -0
  191. package/siderust-web/index.d.ts +311 -0
  192. package/siderust-web/index.js +66 -0
  193. package/siderust-web/lib/Observer.js +103 -0
  194. package/siderust-web/lib/Star.js +116 -0
  195. package/siderust-web/lib/backend.js +400 -0
  196. package/siderust-web/lib/wrappers.js +512 -0
  197. package/siderust-web/package.json +55 -0
  198. package/siderust-web/src/body.rs +69 -0
  199. package/siderust-web/src/coordinates.rs +302 -0
  200. package/siderust-web/src/ephemeris.rs +456 -0
  201. package/siderust-web/src/events.rs +520 -0
  202. package/siderust-web/src/lib.rs +51 -0
  203. package/siderust-web/src/observer.rs +117 -0
  204. package/siderust-web/src/phase.rs +190 -0
  205. package/siderust-web/src/position.rs +291 -0
  206. package/siderust-web/src/star.rs +178 -0
  207. package/tempoch-js/.github/workflows/ci.yml +142 -0
  208. package/tempoch-js/.gitmodules +3 -0
  209. package/tempoch-js/CHANGELOG.md +25 -0
  210. package/tempoch-js/LICENSE +661 -0
  211. package/tempoch-js/README.md +126 -0
  212. package/tempoch-js/package.json +20 -0
  213. package/tempoch-js/scripts/ci.sh +73 -0
  214. package/tempoch-js/tempoch/.github/workflows/ci.yml +113 -0
  215. package/tempoch-js/tempoch/CHANGELOG.md +82 -0
  216. package/tempoch-js/tempoch/Cargo.lock +947 -0
  217. package/tempoch-js/tempoch/Cargo.toml +3 -0
  218. package/tempoch-js/tempoch/LICENSE +661 -0
  219. package/tempoch-js/tempoch/README.md +76 -0
  220. package/tempoch-js/tempoch/tempoch/Cargo.toml +27 -0
  221. package/tempoch-js/tempoch/tempoch/examples/periods.rs +45 -0
  222. package/tempoch-js/tempoch/tempoch/examples/quickstart.rs +13 -0
  223. package/tempoch-js/tempoch/tempoch/src/lib.rs +49 -0
  224. package/tempoch-js/tempoch/tempoch/tests/integration.rs +57 -0
  225. package/tempoch-js/tempoch/tempoch-core/Cargo.toml +24 -0
  226. package/tempoch-js/tempoch/tempoch-core/src/delta_t.rs +345 -0
  227. package/tempoch-js/tempoch/tempoch-core/src/instant.rs +811 -0
  228. package/tempoch-js/tempoch/tempoch-core/src/julian_date_ext.rs +142 -0
  229. package/tempoch-js/tempoch/tempoch-core/src/lib.rs +81 -0
  230. package/tempoch-js/tempoch/tempoch-core/src/period.rs +1168 -0
  231. package/tempoch-js/tempoch/tempoch-core/src/scales.rs +779 -0
  232. package/tempoch-js/tempoch/tempoch-ffi/Cargo.lock +889 -0
  233. package/tempoch-js/tempoch/tempoch-ffi/Cargo.toml +26 -0
  234. package/tempoch-js/tempoch/tempoch-ffi/build.rs +24 -0
  235. package/tempoch-js/tempoch/tempoch-ffi/cbindgen.toml +30 -0
  236. package/tempoch-js/tempoch/tempoch-ffi/src/error.rs +19 -0
  237. package/tempoch-js/tempoch/tempoch-ffi/src/lib.rs +82 -0
  238. package/tempoch-js/tempoch/tempoch-ffi/src/period.rs +101 -0
  239. package/tempoch-js/tempoch/tempoch-ffi/src/time.rs +711 -0
  240. package/tempoch-js/tempoch/tempoch-ffi/tests/ffi.rs +265 -0
  241. package/tempoch-js/tempoch-node/.prettierignore +6 -0
  242. package/tempoch-js/tempoch-node/.prettierrc.json +6 -0
  243. package/tempoch-js/tempoch-node/Cargo.lock +496 -0
  244. package/tempoch-js/tempoch-node/Cargo.toml +29 -0
  245. package/tempoch-js/tempoch-node/README.md +265 -0
  246. package/tempoch-js/tempoch-node/__test__/index.test.mjs +598 -0
  247. package/tempoch-js/tempoch-node/build.rs +5 -0
  248. package/tempoch-js/tempoch-node/c8.config.json +3 -0
  249. package/tempoch-js/tempoch-node/eslint.config.js +31 -0
  250. package/tempoch-js/tempoch-node/examples/periods.mjs +79 -0
  251. package/tempoch-js/tempoch-node/examples/quickstart.mjs +71 -0
  252. package/tempoch-js/tempoch-node/examples/timescales.mjs +92 -0
  253. package/tempoch-js/tempoch-node/index.d.ts +280 -0
  254. package/tempoch-js/tempoch-node/index.js +32 -0
  255. package/tempoch-js/tempoch-node/lib/JulianDate.js +176 -0
  256. package/tempoch-js/tempoch-node/lib/ModifiedJulianDate.js +156 -0
  257. package/tempoch-js/tempoch-node/lib/Period.js +133 -0
  258. package/tempoch-js/tempoch-node/lib/backend.js +38 -0
  259. package/tempoch-js/tempoch-node/lib/qttyCompat.js +92 -0
  260. package/tempoch-js/tempoch-node/native.cjs +317 -0
  261. package/tempoch-js/tempoch-node/package-lock.json +3223 -0
  262. package/tempoch-js/tempoch-node/package.json +56 -0
  263. package/tempoch-js/tempoch-node/src/lib.rs +573 -0
  264. package/tempoch-js/tempoch-web/Cargo.toml +23 -0
  265. package/tempoch-js/tempoch-web/index.d.ts +95 -0
  266. package/tempoch-js/tempoch-web/index.js +27 -0
  267. package/tempoch-js/tempoch-web/lib/JulianDate.js +170 -0
  268. package/tempoch-js/tempoch-web/lib/ModifiedJulianDate.js +145 -0
  269. package/tempoch-js/tempoch-web/lib/Period.js +121 -0
  270. package/tempoch-js/tempoch-web/lib/backend.js +118 -0
  271. package/tempoch-js/tempoch-web/package.json +46 -0
  272. package/tempoch-js/tempoch-web/src/lib.rs +184 -0
@@ -0,0 +1,462 @@
1
+ // SPDX-License-Identifier: AGPL-3.0-only
2
+ // Copyright (C) 2026 Vallés Puig, Ramon
3
+
4
+ //! VSOP87 ephemeris — solar-system body positions at a given epoch.
5
+
6
+ use napi_derive::napi;
7
+
8
+ use qtty::*;
9
+ use siderust::bodies::solar_system::{
10
+ Earth, Jupiter, Mars, Mercury, Neptune, Saturn, Uranus, Venus,
11
+ };
12
+ use siderust::calculus::ephemeris::{Ephemeris, Vsop87Ephemeris};
13
+ use siderust::coordinates::cartesian::position::EclipticMeanJ2000;
14
+ use siderust::coordinates::centers::{Barycentric, Geocentric, Heliocentric};
15
+ use siderust::coordinates::transform::TransformCenter;
16
+ use siderust::time::JulianDate;
17
+
18
+ // ─────────────────────────────────────────────────────────────────────────────
19
+ // Result types
20
+ // ─────────────────────────────────────────────────────────────────────────────
21
+
22
+ /// A 3D Cartesian position with frame and center metadata.
23
+ #[napi(object)]
24
+ pub struct CartesianPosition {
25
+ /// X coordinate (AU for solar-system, km for Moon geocentric).
26
+ pub x: f64,
27
+ /// Y coordinate.
28
+ pub y: f64,
29
+ /// Z coordinate.
30
+ pub z: f64,
31
+ /// Reference frame (e.g. `"EclipticMeanJ2000"`).
32
+ pub frame: String,
33
+ /// Reference center (e.g. `"Heliocentric"`, `"Barycentric"`, `"Geocentric"`).
34
+ pub center: String,
35
+ }
36
+
37
+ // ─────────────────────────────────────────────────────────────────────────────
38
+ // VSOP87 queries
39
+ // ─────────────────────────────────────────────────────────────────────────────
40
+
41
+ /// Compute the heliocentric ecliptic position of a planet via VSOP87 (Series A).
42
+ ///
43
+ /// Returns Cartesian coordinates in AU, in the EclipticMeanJ2000 frame,
44
+ /// centered on the Sun.
45
+ ///
46
+ /// @param body — Planet name: Mercury, Venus, Mars, Jupiter, Saturn, Uranus, Neptune.
47
+ /// @param jd — Julian Date of the epoch.
48
+ ///
49
+ /// ```js
50
+ /// const { vsop87Heliocentric } = require('@siderust/siderust');
51
+ /// const mars = vsop87Heliocentric('Mars', 2451545.0);
52
+ /// console.log(mars.x, mars.y, mars.z);
53
+ /// ```
54
+ #[napi(js_name = "vsop87Heliocentric")]
55
+ pub fn vsop87_heliocentric(body: String, jd: f64) -> napi::Result<CartesianPosition> {
56
+ if !jd.is_finite() {
57
+ return Err(napi::Error::from_reason("jd must be finite"));
58
+ }
59
+ let t = JulianDate::new(jd);
60
+
61
+ macro_rules! helio {
62
+ ($planet:ty) => {{
63
+ let pos = <$planet>::vsop87a(t);
64
+ Ok(CartesianPosition {
65
+ x: pos.x().value(),
66
+ y: pos.y().value(),
67
+ z: pos.z().value(),
68
+ frame: "EclipticMeanJ2000".to_string(),
69
+ center: "Heliocentric".to_string(),
70
+ })
71
+ }};
72
+ }
73
+
74
+ match body.as_str() {
75
+ "Mercury" | "mercury" => helio!(Mercury),
76
+ "Venus" | "venus" => helio!(Venus),
77
+ "Earth" | "earth" => helio!(Earth),
78
+ "Mars" | "mars" => helio!(Mars),
79
+ "Jupiter" | "jupiter" => helio!(Jupiter),
80
+ "Saturn" | "saturn" => helio!(Saturn),
81
+ "Uranus" | "uranus" => helio!(Uranus),
82
+ "Neptune" | "neptune" => helio!(Neptune),
83
+ _ => Err(napi::Error::from_reason(format!(
84
+ "Unknown planet for VSOP87 heliocentric: \"{body}\". Valid: Mercury, Venus, Earth, Mars, Jupiter, Saturn, Uranus, Neptune.",
85
+ ))),
86
+ }
87
+ }
88
+
89
+ /// Compute the barycentric ecliptic position of a planet via VSOP87 (Series E).
90
+ ///
91
+ /// Returns Cartesian coordinates in AU, in the EclipticMeanJ2000 frame,
92
+ /// centered on the solar-system barycentre.
93
+ ///
94
+ /// @param body — Planet name or `"Sun"`.
95
+ /// @param jd — Julian Date of the epoch.
96
+ #[napi(js_name = "vsop87Barycentric")]
97
+ pub fn vsop87_barycentric(body: String, jd: f64) -> napi::Result<CartesianPosition> {
98
+ if !jd.is_finite() {
99
+ return Err(napi::Error::from_reason("jd must be finite"));
100
+ }
101
+ let t = JulianDate::new(jd);
102
+
103
+ macro_rules! bary {
104
+ ($planet:ty) => {{
105
+ let pos = <$planet>::vsop87e(t);
106
+ Ok(CartesianPosition {
107
+ x: pos.x().value(),
108
+ y: pos.y().value(),
109
+ z: pos.z().value(),
110
+ frame: "EclipticMeanJ2000".to_string(),
111
+ center: "Barycentric".to_string(),
112
+ })
113
+ }};
114
+ }
115
+
116
+ match body.as_str() {
117
+ "Mercury" | "mercury" => bary!(Mercury),
118
+ "Venus" | "venus" => bary!(Venus),
119
+ "Earth" | "earth" => bary!(Earth),
120
+ "Mars" | "mars" => bary!(Mars),
121
+ "Jupiter" | "jupiter" => bary!(Jupiter),
122
+ "Saturn" | "saturn" => bary!(Saturn),
123
+ "Uranus" | "uranus" => bary!(Uranus),
124
+ "Neptune" | "neptune" => bary!(Neptune),
125
+ _ => Err(napi::Error::from_reason(format!(
126
+ "Unknown planet for VSOP87 barycentric: \"{body}\". Valid: Mercury, Venus, Earth, Mars, Jupiter, Saturn, Uranus, Neptune.",
127
+ ))),
128
+ }
129
+ }
130
+
131
+ /// Get the Sun's barycentric position via VSOP87.
132
+ ///
133
+ /// @param jd — Julian Date.
134
+ /// @returns Cartesian position in AU (EclipticMeanJ2000, Barycentric).
135
+ #[napi(js_name = "vsop87SunBarycentric")]
136
+ pub fn vsop87_sun_barycentric(jd: f64) -> napi::Result<CartesianPosition> {
137
+ if !jd.is_finite() {
138
+ return Err(napi::Error::from_reason("jd must be finite"));
139
+ }
140
+ let t = JulianDate::new(jd);
141
+ let pos = Vsop87Ephemeris::sun_barycentric(t);
142
+ Ok(CartesianPosition {
143
+ x: pos.x().value(),
144
+ y: pos.y().value(),
145
+ z: pos.z().value(),
146
+ frame: "EclipticMeanJ2000".to_string(),
147
+ center: "Barycentric".to_string(),
148
+ })
149
+ }
150
+
151
+ /// Get the Earth's barycentric position via VSOP87.
152
+ ///
153
+ /// @param jd — Julian Date.
154
+ /// @returns Cartesian position in AU (EclipticMeanJ2000, Barycentric).
155
+ #[napi(js_name = "vsop87EarthBarycentric")]
156
+ pub fn vsop87_earth_barycentric(jd: f64) -> napi::Result<CartesianPosition> {
157
+ if !jd.is_finite() {
158
+ return Err(napi::Error::from_reason("jd must be finite"));
159
+ }
160
+ let t = JulianDate::new(jd);
161
+ let pos = Vsop87Ephemeris::earth_barycentric(t);
162
+ Ok(CartesianPosition {
163
+ x: pos.x().value(),
164
+ y: pos.y().value(),
165
+ z: pos.z().value(),
166
+ frame: "EclipticMeanJ2000".to_string(),
167
+ center: "Barycentric".to_string(),
168
+ })
169
+ }
170
+
171
+ /// Get the Earth's heliocentric position via VSOP87.
172
+ ///
173
+ /// @param jd — Julian Date.
174
+ /// @returns Cartesian position in AU (EclipticMeanJ2000, Heliocentric).
175
+ #[napi(js_name = "vsop87EarthHeliocentric")]
176
+ pub fn vsop87_earth_heliocentric(jd: f64) -> napi::Result<CartesianPosition> {
177
+ if !jd.is_finite() {
178
+ return Err(napi::Error::from_reason("jd must be finite"));
179
+ }
180
+ let t = JulianDate::new(jd);
181
+ let pos = Vsop87Ephemeris::earth_heliocentric(t);
182
+ Ok(CartesianPosition {
183
+ x: pos.x().value(),
184
+ y: pos.y().value(),
185
+ z: pos.z().value(),
186
+ frame: "EclipticMeanJ2000".to_string(),
187
+ center: "Heliocentric".to_string(),
188
+ })
189
+ }
190
+
191
+ /// Get the Moon's geocentric position via ELP2000.
192
+ ///
193
+ /// @param jd — Julian Date.
194
+ /// @returns Cartesian position in **km** (EclipticMeanJ2000, Geocentric).
195
+ #[napi(js_name = "vsop87MoonGeocentric")]
196
+ pub fn vsop87_moon_geocentric(jd: f64) -> napi::Result<CartesianPosition> {
197
+ if !jd.is_finite() {
198
+ return Err(napi::Error::from_reason("jd must be finite"));
199
+ }
200
+ let t = JulianDate::new(jd);
201
+ let pos = Vsop87Ephemeris::moon_geocentric(t);
202
+ Ok(CartesianPosition {
203
+ x: pos.x().value(),
204
+ y: pos.y().value(),
205
+ z: pos.z().value(),
206
+ frame: "EclipticMeanJ2000".to_string(),
207
+ center: "Geocentric".to_string(),
208
+ })
209
+ }
210
+
211
+ // ─────────────────────────────────────────────────────────────────────────────
212
+ // Center transforms
213
+ // ─────────────────────────────────────────────────────────────────────────────
214
+
215
+ /// Transform a Cartesian position from one reference center to another.
216
+ ///
217
+ /// Stays in the EclipticMeanJ2000 frame (the natural VSOP87 frame).
218
+ /// Units are AU (except Geocentric Moon which is km).
219
+ ///
220
+ /// Supported center pairs: Heliocentric ↔ Geocentric, Heliocentric ↔ Barycentric,
221
+ /// Geocentric ↔ Barycentric.
222
+ ///
223
+ /// @param x, y, z — Cartesian coordinates.
224
+ /// @param srcCenter — Source center: `"Heliocentric"`, `"Barycentric"`, `"Geocentric"`.
225
+ /// @param dstCenter — Destination center.
226
+ /// @param jd — Julian Date.
227
+ ///
228
+ /// ```js
229
+ /// const mars = vsop87Heliocentric('Mars', 2451545.0);
230
+ /// const marsGeo = transformPositionCenter(mars.x, mars.y, mars.z, 'Heliocentric', 'Geocentric', 2451545.0);
231
+ /// ```
232
+ #[napi(js_name = "transformPositionCenter")]
233
+ pub fn transform_position_center(
234
+ x: f64,
235
+ y: f64,
236
+ z: f64,
237
+ src_center: String,
238
+ dst_center: String,
239
+ jd: f64,
240
+ ) -> napi::Result<CartesianPosition> {
241
+ if !x.is_finite() || !y.is_finite() || !z.is_finite() || !jd.is_finite() {
242
+ return Err(napi::Error::from_reason(
243
+ "x, y, z and jd must be finite",
244
+ ));
245
+ }
246
+ let t = JulianDate::new(jd);
247
+
248
+ match (src_center.as_str(), dst_center.as_str()) {
249
+ // Identity
250
+ (s, d) if s == d => Ok(CartesianPosition {
251
+ x, y, z,
252
+ frame: "EclipticMeanJ2000".to_string(),
253
+ center: dst_center,
254
+ }),
255
+ // Heliocentric → Geocentric
256
+ ("Heliocentric", "Geocentric") => {
257
+ let pos = EclipticMeanJ2000::<AstronomicalUnit, Heliocentric>::new(x, y, z);
258
+ let out: EclipticMeanJ2000<AstronomicalUnit, Geocentric> = pos.to_center(t);
259
+ Ok(CartesianPosition {
260
+ x: out.x().value(), y: out.y().value(), z: out.z().value(),
261
+ frame: "EclipticMeanJ2000".to_string(),
262
+ center: "Geocentric".to_string(),
263
+ })
264
+ }
265
+ // Geocentric → Heliocentric
266
+ ("Geocentric", "Heliocentric") => {
267
+ let pos = EclipticMeanJ2000::<AstronomicalUnit, Geocentric>::new(x, y, z);
268
+ let out: EclipticMeanJ2000<AstronomicalUnit, Heliocentric> = pos.to_center(t);
269
+ Ok(CartesianPosition {
270
+ x: out.x().value(), y: out.y().value(), z: out.z().value(),
271
+ frame: "EclipticMeanJ2000".to_string(),
272
+ center: "Heliocentric".to_string(),
273
+ })
274
+ }
275
+ // Heliocentric → Barycentric
276
+ ("Heliocentric", "Barycentric") => {
277
+ let pos = EclipticMeanJ2000::<AstronomicalUnit, Heliocentric>::new(x, y, z);
278
+ let out: EclipticMeanJ2000<AstronomicalUnit, Barycentric> = pos.to_center(t);
279
+ Ok(CartesianPosition {
280
+ x: out.x().value(), y: out.y().value(), z: out.z().value(),
281
+ frame: "EclipticMeanJ2000".to_string(),
282
+ center: "Barycentric".to_string(),
283
+ })
284
+ }
285
+ // Barycentric → Heliocentric
286
+ ("Barycentric", "Heliocentric") => {
287
+ let pos = EclipticMeanJ2000::<AstronomicalUnit, Barycentric>::new(x, y, z);
288
+ let out: EclipticMeanJ2000<AstronomicalUnit, Heliocentric> = pos.to_center(t);
289
+ Ok(CartesianPosition {
290
+ x: out.x().value(), y: out.y().value(), z: out.z().value(),
291
+ frame: "EclipticMeanJ2000".to_string(),
292
+ center: "Heliocentric".to_string(),
293
+ })
294
+ }
295
+ // Barycentric → Geocentric
296
+ ("Barycentric", "Geocentric") => {
297
+ let pos = EclipticMeanJ2000::<AstronomicalUnit, Barycentric>::new(x, y, z);
298
+ let out: EclipticMeanJ2000<AstronomicalUnit, Geocentric> = pos.to_center(t);
299
+ Ok(CartesianPosition {
300
+ x: out.x().value(), y: out.y().value(), z: out.z().value(),
301
+ frame: "EclipticMeanJ2000".to_string(),
302
+ center: "Geocentric".to_string(),
303
+ })
304
+ }
305
+ // Geocentric → Barycentric
306
+ ("Geocentric", "Barycentric") => {
307
+ let pos = EclipticMeanJ2000::<AstronomicalUnit, Geocentric>::new(x, y, z);
308
+ let out: EclipticMeanJ2000<AstronomicalUnit, Barycentric> = pos.to_center(t);
309
+ Ok(CartesianPosition {
310
+ x: out.x().value(), y: out.y().value(), z: out.z().value(),
311
+ frame: "EclipticMeanJ2000".to_string(),
312
+ center: "Barycentric".to_string(),
313
+ })
314
+ }
315
+ _ => Err(napi::Error::from_reason(format!(
316
+ "Unsupported center transform: \"{}\" → \"{}\". Valid centers: Heliocentric, Barycentric, Geocentric.",
317
+ src_center, dst_center
318
+ ))),
319
+ }
320
+ }
321
+
322
+ /// Transform a Cartesian position between celestial reference frames.
323
+ ///
324
+ /// Stays in the same center. Coordinates are in AU.
325
+ ///
326
+ /// Supported frames: `"ICRS"`, `"EclipticMeanJ2000"`, `"EquatorialMeanJ2000"`.
327
+ ///
328
+ /// @param x, y, z — Cartesian coordinates in AU.
329
+ /// @param srcFrame — Source frame name.
330
+ /// @param dstFrame — Destination frame name.
331
+ /// @param jd — Julian Date.
332
+ #[napi(js_name = "transformPositionFrame")]
333
+ pub fn transform_position_frame(
334
+ x: f64,
335
+ y: f64,
336
+ z: f64,
337
+ src_frame: String,
338
+ dst_frame: String,
339
+ jd: f64,
340
+ ) -> napi::Result<CartesianPosition> {
341
+ use siderust::coordinates::cartesian::Position;
342
+ use siderust::coordinates::frames;
343
+ use siderust::coordinates::transform::PositionAstroExt;
344
+
345
+ if !x.is_finite() || !y.is_finite() || !z.is_finite() || !jd.is_finite() {
346
+ return Err(napi::Error::from_reason(
347
+ "x, y, z and jd must be finite",
348
+ ));
349
+ }
350
+ let t = JulianDate::new(jd);
351
+
352
+ // We use Heliocentric as the Center parameter (arbitrary, since frame rotations don't depend on center)
353
+ type C = Heliocentric;
354
+
355
+ macro_rules! frame_convert {
356
+ ($src_type:ty, $dst_type:ty, $dst_name:expr) => {{
357
+ let pos = Position::<C, $src_type, AstronomicalUnit>::new(x, y, z);
358
+ let out: Position<C, $dst_type, AstronomicalUnit> = PositionAstroExt::to_frame(&pos, &t);
359
+ Ok(CartesianPosition {
360
+ x: out.x().value(), y: out.y().value(), z: out.z().value(),
361
+ frame: $dst_name.to_string(),
362
+ center: "Heliocentric".to_string(),
363
+ })
364
+ }};
365
+ }
366
+
367
+ match (src_frame.as_str(), dst_frame.as_str()) {
368
+ (s, d) if s == d => Ok(CartesianPosition {
369
+ x, y, z,
370
+ frame: dst_frame,
371
+ center: "Heliocentric".to_string(),
372
+ }),
373
+ ("EclipticMeanJ2000", "EquatorialMeanJ2000") => frame_convert!(frames::EclipticMeanJ2000, frames::EquatorialMeanJ2000, "EquatorialMeanJ2000"),
374
+ ("EquatorialMeanJ2000", "EclipticMeanJ2000") => frame_convert!(frames::EquatorialMeanJ2000, frames::EclipticMeanJ2000, "EclipticMeanJ2000"),
375
+ ("ICRS", "EclipticMeanJ2000") => frame_convert!(frames::ICRS, frames::EclipticMeanJ2000, "EclipticMeanJ2000"),
376
+ ("EclipticMeanJ2000", "ICRS") => frame_convert!(frames::EclipticMeanJ2000, frames::ICRS, "ICRS"),
377
+ ("ICRS", "EquatorialMeanJ2000") => frame_convert!(frames::ICRS, frames::EquatorialMeanJ2000, "EquatorialMeanJ2000"),
378
+ ("EquatorialMeanJ2000", "ICRS") => frame_convert!(frames::EquatorialMeanJ2000, frames::ICRS, "ICRS"),
379
+ ("EquatorialMeanJ2000", "EquatorialMeanOfDate") => frame_convert!(frames::EquatorialMeanJ2000, frames::EquatorialMeanOfDate, "EquatorialMeanOfDate"),
380
+ ("EquatorialMeanOfDate", "EquatorialMeanJ2000") => frame_convert!(frames::EquatorialMeanOfDate, frames::EquatorialMeanJ2000, "EquatorialMeanJ2000"),
381
+ ("EquatorialMeanOfDate", "EquatorialTrueOfDate") => frame_convert!(frames::EquatorialMeanOfDate, frames::EquatorialTrueOfDate, "EquatorialTrueOfDate"),
382
+ ("EquatorialTrueOfDate", "EquatorialMeanOfDate") => frame_convert!(frames::EquatorialTrueOfDate, frames::EquatorialMeanOfDate, "EquatorialMeanOfDate"),
383
+ ("ICRS", "EquatorialMeanOfDate") => frame_convert!(frames::ICRS, frames::EquatorialMeanOfDate, "EquatorialMeanOfDate"),
384
+ ("EquatorialMeanOfDate", "ICRS") => frame_convert!(frames::EquatorialMeanOfDate, frames::ICRS, "ICRS"),
385
+ ("ICRS", "EquatorialTrueOfDate") => frame_convert!(frames::ICRS, frames::EquatorialTrueOfDate, "EquatorialTrueOfDate"),
386
+ ("EquatorialTrueOfDate", "ICRS") => frame_convert!(frames::EquatorialTrueOfDate, frames::ICRS, "ICRS"),
387
+ ("EquatorialMeanJ2000", "EquatorialTrueOfDate") => frame_convert!(frames::EquatorialMeanJ2000, frames::EquatorialTrueOfDate, "EquatorialTrueOfDate"),
388
+ ("EquatorialTrueOfDate", "EquatorialMeanJ2000") => frame_convert!(frames::EquatorialTrueOfDate, frames::EquatorialMeanJ2000, "EquatorialMeanJ2000"),
389
+ ("EclipticMeanJ2000", "EquatorialMeanOfDate") => {
390
+ // Route through ICRS: EclipticMeanJ2000 → ICRS → EquatorialMeanOfDate
391
+ let pos = Position::<C, frames::EclipticMeanJ2000, AstronomicalUnit>::new(x, y, z);
392
+ let via: Position<C, frames::ICRS, AstronomicalUnit> = PositionAstroExt::to_frame(&pos, &t);
393
+ let out: Position<C, frames::EquatorialMeanOfDate, AstronomicalUnit> = PositionAstroExt::to_frame(&via, &t);
394
+ Ok(CartesianPosition {
395
+ x: out.x().value(), y: out.y().value(), z: out.z().value(),
396
+ frame: "EquatorialMeanOfDate".to_string(),
397
+ center: "Heliocentric".to_string(),
398
+ })
399
+ }
400
+ ("EquatorialMeanOfDate", "EclipticMeanJ2000") => {
401
+ let pos = Position::<C, frames::EquatorialMeanOfDate, AstronomicalUnit>::new(x, y, z);
402
+ let via: Position<C, frames::ICRS, AstronomicalUnit> = PositionAstroExt::to_frame(&pos, &t);
403
+ let out: Position<C, frames::EclipticMeanJ2000, AstronomicalUnit> = PositionAstroExt::to_frame(&via, &t);
404
+ Ok(CartesianPosition {
405
+ x: out.x().value(), y: out.y().value(), z: out.z().value(),
406
+ frame: "EclipticMeanJ2000".to_string(),
407
+ center: "Heliocentric".to_string(),
408
+ })
409
+ }
410
+ ("EclipticMeanJ2000", "EquatorialTrueOfDate") => {
411
+ let pos = Position::<C, frames::EclipticMeanJ2000, AstronomicalUnit>::new(x, y, z);
412
+ let via: Position<C, frames::ICRS, AstronomicalUnit> = PositionAstroExt::to_frame(&pos, &t);
413
+ let out: Position<C, frames::EquatorialTrueOfDate, AstronomicalUnit> = PositionAstroExt::to_frame(&via, &t);
414
+ Ok(CartesianPosition {
415
+ x: out.x().value(), y: out.y().value(), z: out.z().value(),
416
+ frame: "EquatorialTrueOfDate".to_string(),
417
+ center: "Heliocentric".to_string(),
418
+ })
419
+ }
420
+ ("EquatorialTrueOfDate", "EclipticMeanJ2000") => {
421
+ let pos = Position::<C, frames::EquatorialTrueOfDate, AstronomicalUnit>::new(x, y, z);
422
+ let via: Position<C, frames::ICRS, AstronomicalUnit> = PositionAstroExt::to_frame(&pos, &t);
423
+ let out: Position<C, frames::EclipticMeanJ2000, AstronomicalUnit> = PositionAstroExt::to_frame(&via, &t);
424
+ Ok(CartesianPosition {
425
+ x: out.x().value(), y: out.y().value(), z: out.z().value(),
426
+ frame: "EclipticMeanJ2000".to_string(),
427
+ center: "Heliocentric".to_string(),
428
+ })
429
+ }
430
+ _ => Err(napi::Error::from_reason(format!(
431
+ "Unsupported frame transform: \"{}\" → \"{}\". Valid frames: ICRS, EclipticMeanJ2000, EquatorialMeanJ2000, EquatorialMeanOfDate, EquatorialTrueOfDate.",
432
+ src_frame, dst_frame
433
+ ))),
434
+ }
435
+ }
436
+
437
+ /// Compute the orbital period of a named planet in days (Keplerian).
438
+ ///
439
+ /// @param name — Planet name.
440
+ /// @returns Orbital period in days.
441
+ #[napi(js_name = "orbitalPeriodDays")]
442
+ pub fn orbital_period_days(name: String) -> napi::Result<f64> {
443
+ use siderust::bodies::planets::OrbitExt;
444
+ use siderust::bodies::solar_system;
445
+
446
+ let period_days = match name.as_str() {
447
+ "Mercury" | "mercury" => solar_system::MERCURY.orbit.period().to::<Day>().value(),
448
+ "Venus" | "venus" => solar_system::VENUS.orbit.period().to::<Day>().value(),
449
+ "Earth" | "earth" => solar_system::EARTH.orbit.period().to::<Day>().value(),
450
+ "Mars" | "mars" => solar_system::MARS.orbit.period().to::<Day>().value(),
451
+ "Jupiter" | "jupiter" => solar_system::JUPITER.orbit.period().to::<Day>().value(),
452
+ "Saturn" | "saturn" => solar_system::SATURN.orbit.period().to::<Day>().value(),
453
+ "Uranus" | "uranus" => solar_system::URANUS.orbit.period().to::<Day>().value(),
454
+ "Neptune" | "neptune" => solar_system::NEPTUNE.orbit.period().to::<Day>().value(),
455
+ _ => {
456
+ return Err(napi::Error::from_reason(format!(
457
+ "Unknown planet: \"{name}\". Valid: Mercury, Venus, Earth, Mars, Jupiter, Saturn, Uranus, Neptune."
458
+ )));
459
+ }
460
+ };
461
+ Ok(period_days)
462
+ }