@zodiacs/engine 0.1.1-rc.16 → 1.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 (80) hide show
  1. package/CHANGELOG.md +1478 -0
  2. package/LICENSING.md +184 -30
  3. package/NOTICE +81 -14
  4. package/README.md +345 -67
  5. package/dist/{api-VOW6Umy5.d.ts → api-ChL1N2Sr.d.ts} +44 -7
  6. package/dist/ayanamsa-ClFzkKmV.d.ts +135 -0
  7. package/dist/calc.d.ts +218 -21
  8. package/dist/calc.js +580 -160
  9. package/dist/chunk-2PZYJQV5.js +83 -0
  10. package/dist/chunk-47ERTK5X.js +27 -0
  11. package/dist/{chunk-O3NJRGJ2.js → chunk-4XOYTBLS.js} +1 -1
  12. package/dist/chunk-767FTO7O.js +48 -0
  13. package/dist/{chunk-N4B5JNMA.js → chunk-7Y2F2IWN.js} +40 -28
  14. package/dist/chunk-B4M2Y7FT.js +96 -0
  15. package/dist/{chunk-KHBLFXFG.js → chunk-B5LKF437.js} +29 -28
  16. package/dist/{chunk-ONBZ4HK7.js → chunk-BHJXUY67.js} +4 -2
  17. package/dist/{chunk-PFGUCNOK.js → chunk-BMDASNPB.js} +6 -6
  18. package/dist/chunk-I3L4POY7.js +18 -0
  19. package/dist/{chunk-I7O5EGFV.js → chunk-LNGURVNH.js} +3 -3
  20. package/dist/{chunk-4NV4ZEFZ.js → chunk-NNOSOOWS.js} +4 -4
  21. package/dist/chunk-OVXQQEXL.js +41 -0
  22. package/dist/{chunk-WOU7JVD3.js → chunk-QLIEEICB.js} +205 -194
  23. package/dist/chunk-RMBWKZI2.js +130 -0
  24. package/dist/{chunk-AECKV73C.js → chunk-TSS2SZWQ.js} +8 -2
  25. package/dist/{chunk-L6ZHWJZ6.js → chunk-TZVPZHZM.js} +51 -29
  26. package/dist/chunk-WBTWY2OB.js +478 -0
  27. package/dist/chunk-Y4E3WJU5.js +87 -0
  28. package/dist/chunk-YPU3MDNI.js +852 -0
  29. package/dist/conventions.d.ts +70 -0
  30. package/dist/conventions.js +26 -0
  31. package/dist/crossings.d.ts +22 -10
  32. package/dist/crossings.js +1 -1
  33. package/dist/de440-pack.d.ts +43 -0
  34. package/dist/de440-pack.js +16 -0
  35. package/dist/de440.d.ts +113 -0
  36. package/dist/de440.js +19 -0
  37. package/dist/deltat.d.ts +28 -3
  38. package/dist/deltat.js +1 -1
  39. package/dist/ephemeris-exTSqBgb.d.ts +60 -0
  40. package/dist/geo.d.ts +46 -13
  41. package/dist/geo.js +4 -2
  42. package/dist/{houses-q1O2GGp4.d.ts → houses-Bh7GCnPi.d.ts} +14 -4
  43. package/dist/houses-extra.d.ts +22 -7
  44. package/dist/houses-extra.js +4 -2
  45. package/dist/index.d.ts +36 -49
  46. package/dist/index.js +54 -34
  47. package/dist/{internal-math-CmJ9xtaW.d.ts → internal-math-CxenuGfm.d.ts} +41 -27
  48. package/dist/internal-math.d.ts +4 -3
  49. package/dist/internal-math.js +14 -12
  50. package/dist/internal.d.ts +16 -7
  51. package/dist/internal.js +27 -6
  52. package/dist/lite-composite.js +114 -0
  53. package/dist/lite-declinations.js +253 -0
  54. package/dist/lite-dignities.js +333 -0
  55. package/dist/lite-sect.js +72 -0
  56. package/dist/lite.d.ts +82 -0
  57. package/dist/lite.js +4 -0
  58. package/dist/receipt.d.ts +3 -268
  59. package/dist/receipt.js +202 -89
  60. package/dist/reference-span-CILpclrz.d.ts +40 -0
  61. package/dist/{rulers-9wljfVaO.d.ts → rulers-CSSWtiWF.d.ts} +7 -2
  62. package/dist/sky.d.ts +26 -10
  63. package/dist/sky.js +23 -14
  64. package/dist/techniques.d.ts +160 -21
  65. package/dist/techniques.js +157 -89
  66. package/dist/time-bands-CZA9AlLg.d.ts +36 -0
  67. package/dist/time-scale-DIFNa0gz.d.ts +47 -0
  68. package/dist/time.d.ts +81 -0
  69. package/dist/time.js +74 -0
  70. package/dist/timing.d.ts +55 -17
  71. package/dist/timing.js +33 -45
  72. package/dist/types-DpPdtXgO.d.ts +335 -0
  73. package/dist/vedic.d.ts +150 -123
  74. package/dist/vedic.js +398 -440
  75. package/dist/window.d.ts +102 -80
  76. package/dist/window.js +108 -51
  77. package/dist/zone-history-BxmDCcTK.d.ts +290 -0
  78. package/package.json +26 -3
  79. package/dist/chunk-2OWGBT3O.js +0 -219
  80. package/dist/types-B4MCoCCS.d.ts +0 -228
package/dist/calc.js CHANGED
@@ -1,37 +1,59 @@
1
+ import {
2
+ AYANAMSAS,
3
+ ayanamsaAt,
4
+ isUserAyanamsaName,
5
+ outsideSpanEpoch,
6
+ siderealChartOf,
7
+ userAyanamsa,
8
+ wholeSignCusps,
9
+ wrap360
10
+ } from "./chunk-WBTWY2OB.js";
1
11
  import {
2
12
  eclipticRows,
3
13
  equatorRows
4
- } from "./chunk-O3NJRGJ2.js";
14
+ } from "./chunk-4XOYTBLS.js";
5
15
  import {
6
- dateFrom
7
- } from "./chunk-CPALRSPC.js";
8
- import {
9
- searchLongitudeCrossingsWith
10
- } from "./chunk-AECKV73C.js";
11
- import {
12
- assertDerivedFlags,
13
- snapshotFlags,
14
- timeFlags,
15
- validateBirthSettings
16
- } from "./chunk-PFGUCNOK.js";
16
+ timeBands
17
+ } from "./chunk-I3L4POY7.js";
18
+ import "./chunk-47ERTK5X.js";
17
19
  import {
18
20
  bodyLongitude,
19
21
  computeChart,
20
- eclipticFrame,
21
- eclipticOfDate,
22
+ deltaTExtrapolated,
23
+ ephemerisAt,
22
24
  gastHours,
23
25
  meanApogee,
24
- meanEcliptic,
25
26
  meanNodeLongitude,
26
27
  onChartClock,
27
- tilt
28
- } from "./chunk-WOU7JVD3.js";
28
+ refuseUnderSource
29
+ } from "./chunk-QLIEEICB.js";
29
30
  import {
31
+ dateFrom
32
+ } from "./chunk-CPALRSPC.js";
33
+ import {
34
+ ENGINE_VERSION,
35
+ EPHEMERIS
36
+ } from "./chunk-B4M2Y7FT.js";
37
+ import {
38
+ eclipticFrame,
39
+ eclipticOfDate,
40
+ meanEcliptic
41
+ } from "./chunk-2PZYJQV5.js";
42
+ import {
43
+ EPHEMERIS_SPAN,
30
44
  REFERENCE_SPAN,
45
+ TIME_SCALE_NAMES,
31
46
  elapsedDays,
32
47
  timeBasis
33
- } from "./chunk-KHBLFXFG.js";
34
- import "./chunk-ONBZ4HK7.js";
48
+ } from "./chunk-B5LKF437.js";
49
+ import {
50
+ searchLongitudeCrossingsWith
51
+ } from "./chunk-TSS2SZWQ.js";
52
+ import "./chunk-767FTO7O.js";
53
+ import "./chunk-YPU3MDNI.js";
54
+ import {
55
+ tilt
56
+ } from "./chunk-Y4E3WJU5.js";
35
57
  import {
36
58
  computeAngles,
37
59
  computeHouses,
@@ -39,18 +61,27 @@ import {
39
61
  isPolarUndefinedHouseSystem,
40
62
  ramcOf,
41
63
  vertexOf
42
- } from "./chunk-4NV4ZEFZ.js";
64
+ } from "./chunk-NNOSOOWS.js";
43
65
  import {
44
- ENGINE_VERSION,
45
- EPHEMERIS,
46
66
  normalizeLongitude
47
- } from "./chunk-2OWGBT3O.js";
67
+ } from "./chunk-RMBWKZI2.js";
68
+ import "./chunk-BHJXUY67.js";
69
+ import {
70
+ assertDerivedFlags,
71
+ snapshotFlags,
72
+ timeFlags,
73
+ validateBirthSettings
74
+ } from "./chunk-BMDASNPB.js";
48
75
 
49
76
  // src/calc.ts
50
- import { GeoMoonState } from "astronomy-engine";
77
+ import { AstroTime, GeoMoonState, KM_PER_AU as KM_PER_AU2 } from "astronomy-engine";
51
78
 
52
79
  // src/calc-bounds.ts
80
+ var SWEPT_BASIS = "largest difference from JPL's DE440 found at noon TT on each of 146,097 days, JD 2378497.0 to 2524593.0 (TT), in all eight frames; docs/evidence/de440-sweep-20261111";
81
+ var SWEPT = ["geocentric/apparent", "geocentric/astrometric", "geocentric/geometric"];
53
82
  var MEASURED_BASIS = "largest difference from JPL Horizons (DE441) over 32 instants from JD 2379457.498125 to 2520522.646618 (TT), in all eight frames; docs/evidence/calc-api/rc16";
83
+ var MEAN_POINTS_BASIS = "largest difference from the same definition evaluated with ERFA's fundamental arguments (faom03, faf03, fal03) and nut06a's nutation in longitude, over 32 instants from JD 2379457.498125 to 2520522.646618 (TT), in all eight frames: a check of the implementation, not of an ephemeris; docs/evidence/calc-api/rc16";
84
+ var MEAN_POINTS_SPEED_BASIS = "largest difference from the rate of the same definition evaluated with ERFA's fundamental arguments (faom03, faf03, fal03) and nut06a's nutation in longitude, taken over 0.0001 day either side, over 32 instants from JD 2379457.498125 to 2520522.646618 (TT), in the true ecliptic of date only: a check of the implementation, not of an ephemeris; docs/evidence/calc-api/rc16";
54
85
  var BARYCENTRIC_APPARENT = {
55
86
  "Earth": [3, 14e-6, 0.18],
56
87
  "Jupiter": [13, 4e-5, 0.025],
@@ -63,6 +94,18 @@ var BARYCENTRIC_APPARENT = {
63
94
  "Uranus": [19, 43e-6, 86e-4],
64
95
  "Venus": [7.4, 15e-6, 0.22]
65
96
  };
97
+ var GEOCENTRIC_ASTROMETRIC = {
98
+ "Jupiter": [17, 79e-6, 0.11],
99
+ "Mars": [23, 87e-6, 0.74],
100
+ "Mercury": [17, 78e-6, 3.6],
101
+ "Moon": [12, 48e-6, 2.9],
102
+ "Neptune": [22, 47e-6, 0.019],
103
+ "Pluto": [30, 63e-6, 0.018],
104
+ "Saturn": [24, 77e-6, 0.06],
105
+ "Sun": [3.4, 17e-6, 0.24],
106
+ "Uranus": [20, 56e-6, 0.03],
107
+ "Venus": [24, 83e-6, 1.4]
108
+ };
66
109
  var HELIOCENTRIC_APPARENT = {
67
110
  "Earth": [3, 15e-6, 0.18],
68
111
  "Jupiter": [13, 4e-5, 0.025],
@@ -92,45 +135,23 @@ var MEASURED = {
92
135
  },
93
136
  "geocentric/apparent": {
94
137
  "Black Moon Lilith": [23e-4, null, 32e-4],
95
- "Jupiter": [13, 47e-6, 0.061],
96
- "Mars": [6.6, 58e-6, 0.45],
138
+ "Jupiter": [17, 79e-6, 0.11],
139
+ "Mars": [23, 87e-6, 0.74],
97
140
  "Mean Node": [23e-4, null, 81e-5],
98
141
  "Mean South Node": [23e-4, null, 81e-5],
99
- "Mercury": [9.3, 36e-6, 2.2],
100
- "Moon": [8.3, 14e-5, 1.1],
101
- "Neptune": [21, 42e-6, 0.013],
102
- "North Node": [16, null, null],
103
- "Pluto": [25, 63e-6, 0.014],
104
- "Saturn": [18, 68e-6, 0.03],
105
- "South Node": [16, null, null],
106
- "Sun": [3, 15e-6, 0.18],
107
- "Uranus": [20, 42e-6, 0.02],
108
- "Venus": [11, 32e-6, 0.64]
109
- },
110
- "geocentric/astrometric": {
111
- "Jupiter": [13, 47e-6, 0.061],
112
- "Mars": [6.6, 58e-6, 0.45],
113
- "Mercury": [9.3, 36e-6, 2.2],
114
- "Moon": [7.6, 36e-6, 1.1],
115
- "Neptune": [21, 42e-6, 0.013],
116
- "Pluto": [25, 63e-6, 0.014],
117
- "Saturn": [18, 68e-6, 0.03],
118
- "Sun": [3, 15e-6, 0.18],
119
- "Uranus": [20, 42e-6, 0.02],
120
- "Venus": [11, 32e-6, 0.64]
121
- },
122
- "geocentric/geometric": {
123
- "Jupiter": [13, 47e-6, 0.061],
124
- "Mars": [6.6, 58e-6, 0.45],
125
- "Mercury": [9.3, 36e-6, 2.2],
126
- "Moon": [7.6, 36e-6, 0.97],
127
- "Neptune": [21, 42e-6, 0.013],
128
- "Pluto": [25, 63e-6, 0.014],
129
- "Saturn": [18, 68e-6, 0.03],
130
- "Sun": [3, 15e-6, 0.18],
131
- "Uranus": [20, 42e-6, 0.02],
132
- "Venus": [11, 32e-6, 0.64]
142
+ "Mercury": [17, 78e-6, 3.6],
143
+ "Moon": [12, 15e-5, 2.9],
144
+ "Neptune": [22, 47e-6, 0.019],
145
+ "North Node": [33, null, null],
146
+ "Pluto": [30, 63e-6, 0.018],
147
+ "Saturn": [24, 77e-6, 0.06],
148
+ "South Node": [33, null, null],
149
+ "Sun": [3.4, 17e-6, 0.24],
150
+ "Uranus": [20, 56e-6, 0.03],
151
+ "Venus": [24, 83e-6, 1.4]
133
152
  },
153
+ "geocentric/astrometric": GEOCENTRIC_ASTROMETRIC,
154
+ "geocentric/geometric": GEOCENTRIC_ASTROMETRIC,
134
155
  "heliocentric/apparent": HELIOCENTRIC_APPARENT,
135
156
  "heliocentric/astrometric": HELIOCENTRIC_APPARENT,
136
157
  "heliocentric/geometric": {
@@ -144,24 +165,28 @@ var MEASURED = {
144
165
  "Saturn": [18, 65e-6, 0.023],
145
166
  "Uranus": [19, 42e-6, 9e-3],
146
167
  "Venus": [6.6, 12e-6, 0.21]
147
- },
148
- "topocentric/apparent": {
149
- "Mars": [6.6, 58e-6, 0.46],
150
- "Moon": [7.8, 36e-6, 1.4],
151
- "Sun": [3, 15e-6, 0.19]
152
- },
153
- "topocentric/astrometric": {
154
- "Mars": [6.6, 58e-6, 0.45],
155
- "Moon": [7.8, 36e-6, 1.4],
156
- "Sun": [3, 15e-6, 0.18]
157
- },
158
- "topocentric/geometric": {
159
- "Mars": [6.6, 58e-6, 0.45],
160
- "Moon": [7.8, 36e-6, 1.5],
161
- "Sun": [3, 15e-6, 0.18]
162
168
  }
163
169
  };
164
170
 
171
+ // src/calc-bounds-de440.ts
172
+ var DE440_MEASURED_BASIS = "largest angle from JPL Horizons's apparent geocentric place (DE441) at the conformance suite's L1 vectors, 24 TT instants a body from 1851 to 2148, in the true ecliptic of date, and from NAIF's de440.bsp at noon TT every day from 1800 to 2199 in all eight frames, the larger, on the shipped DE440 pack; src/calc-bounds-de440.ts";
173
+ var DE440_TURNED_BASIS = "the bound measured in the true ecliptic of date (JPL Horizons, DE441, the conformance suite's L1 vectors; NAIF's de440.bsp every day from 1800 to 2199, which also covers this frame), on the shipped DE440 pack, reached in this frame with the engine's own nutation and precession; Horizons not compared in this frame; src/calc-bounds-de440.ts";
174
+ var DE440_MEASURED = {
175
+ Jupiter: 4e-3,
176
+ Mars: 4e-3,
177
+ Mercury: 4e-3,
178
+ Moon: 0.013,
179
+ Neptune: 4e-3,
180
+ Pluto: 4e-3,
181
+ Saturn: 39e-4,
182
+ Sun: 4e-3,
183
+ Uranus: 4e-3,
184
+ Venus: 4e-3
185
+ };
186
+ var DE440_AT_LIMB = 1.8;
187
+ var DE440_LIMB_BAND = 3;
188
+ var DE440_AT_LIMB_BASIS = "within 3 arcseconds of the Sun's limb, where JPL Horizons and this engine may put the planet on different sides of it and so apply the light deflection there (at most 4GM/c^2R = 1.7512 arcseconds) in one and not the other: the step and the body's own bound, an estimate; src/calc-bounds-de440.ts";
189
+
165
190
  // src/calc-frames.ts
166
191
  var CALC_FRAMES = [
167
192
  "ecliptic-true-of-date",
@@ -315,6 +340,7 @@ function sunMotion(left, time) {
315
340
  return sub(vec(BaryState(Body.Sun, left)), vec(BaryState(Body.Sun, time)));
316
341
  }
317
342
  function locate(body, center, correction, time) {
343
+ refuseUnderSource("@zodiacs/engine/calc");
318
344
  const found = (v2, dist = length(v2)) => ({ v: v2, dist });
319
345
  if (center.kind === "barycentric") {
320
346
  const bary = (t) => vec(BaryState(body, t));
@@ -340,6 +366,7 @@ function locate(body, center, correction, time) {
340
366
  return found(apparent, length(astrometric));
341
367
  }
342
368
  function geometricState(body, center, time) {
369
+ refuseUnderSource("@zodiacs/engine/calc");
343
370
  if (body === Body.Moon) return null;
344
371
  const split = (s) => ({ r: vec(s), v: [s.vx, s.vy, s.vz] });
345
372
  if (center.kind === "barycentric") return split(BaryState(body, time));
@@ -353,23 +380,61 @@ function geometricState(body, center, time) {
353
380
  return { r: sub(r, site.r), v: sub(v, site.v) };
354
381
  }
355
382
 
383
+ // src/calc-ayanamsa.ts
384
+ var NEAR_SUN_DEGREES = 2;
385
+ var AT_SUN_DEGREES = 0.3;
386
+ var AYANAMSA_BOUNDS = {
387
+ /**
388
+ * Epoch and linear definitions, built-in and callers': values from −359.9° to 359.9°, an epoch definition's
389
+ * epoch anywhere in the span, a linear one's anywhere a Date reaches, rates to ±3,600″ a year; 134,833 comparisons.
390
+ * A linear one's rate rounds by up to 1.5 units of 2⁻⁴⁴° in 0.002 day; calc's speeds add their own (docs/calc.md).
391
+ */
392
+ epochOrLinear: { position: 46e-8, rate: 16e-8 },
393
+ /**
394
+ * Callers' epoch definitions on the engine's precession (IAU 2006) whose epoch is outside the span but inside
395
+ * EPHEMERIS_SPAN, beyond which calc refuses them: the engine's precession and ERFA's part the further the
396
+ * epoch is from J2000.0, most at the span's ends; 21,658 comparisons (docs/evidence/calc-epochs-2026-10-06).
397
+ */
398
+ epochOutsideSpan: { position: 37e-4, rate: 13e-8 },
399
+ /**
400
+ * The same on Newcomb's or IAU 1976's precession, whose zodiac is held where that model puts it at J2000.0, so
401
+ * that most of the precession's difference from ERFA's cancels; 43,316 comparisons.
402
+ */
403
+ olderEpochOutsideSpan: { position: 18e-6, rate: 12e-8 },
404
+ /** Star definitions, the star 2° or more from the Sun: 306,850 comparisons. */
405
+ star: { position: 13e-4, rate: 39e-5 },
406
+ /** Star definitions, the star 0.3° to 2° from the Sun: 238,364 comparisons. */
407
+ starNearSun: { position: 48e-4, rate: 0.026 },
408
+ /** Star definitions, the star within 0.3° of the Sun, on or near its disc: 1,653,932 comparisons. */
409
+ starAtSun: { position: 0.058, rate: 27 }
410
+ };
411
+ var AYANAMSA_BASIS = "largest difference of the mean ayanamsa from ERFA's construction of the same definition; docs/evidence/calc-sidereal-2026-10-05";
412
+ var AYANAMSA_EPOCH_BASIS = "largest difference of the mean ayanamsa from ERFA's construction of the same definition, for epochs from 0001 to 3998 outside 1800 to 2200; docs/evidence/calc-epochs-2026-10-06";
413
+ function ayanamsaBand(definition, elongation) {
414
+ if (definition.kind === "epoch" && outsideSpanEpoch(definition)) {
415
+ return definition.model === "engine" ? "epochOutsideSpan" : "olderEpochOutsideSpan";
416
+ }
417
+ if (definition.kind !== "star") return "epochOrLinear";
418
+ if (elongation === null || elongation < AT_SUN_DEGREES) return "starAtSun";
419
+ return elongation < NEAR_SUN_DEGREES ? "starNearSun" : "star";
420
+ }
421
+ function ayanamsaBound(definition, elongation) {
422
+ const band = ayanamsaBand(definition, elongation);
423
+ const outside = band === "epochOutsideSpan" || band === "olderEpochOutsideSpan";
424
+ return { ...AYANAMSA_BOUNDS[band], basis: outside ? AYANAMSA_EPOCH_BASIS : AYANAMSA_BASIS };
425
+ }
426
+ function addBounds(a, b) {
427
+ return Math.ceil(Number(((a + b) * 1e9).toPrecision(15))) / 1e9;
428
+ }
429
+
356
430
  // src/calc.ts
357
431
  var PLANETS = ["Sun", "Moon", "Mercury", "Venus", "Earth", "Mars", "Jupiter", "Saturn", "Uranus", "Neptune", "Pluto"];
358
432
  var POINTS = ["North Node", "South Node", "Mean Node", "Mean South Node", "Black Moon Lilith"];
359
- var CALC_BODIES = [...PLANETS, ...POINTS];
433
+ var CALC_BODIES = Object.freeze([...PLANETS, ...POINTS]);
360
434
  var CHART_BODIES = CALC_BODIES.filter((body) => body !== "Earth" && !/^Mean|Lilith/.test(body));
361
- var CALC_AYANAMSAS = [
362
- "lahiri",
363
- "fagan-bradley",
364
- "krishnamurti",
365
- "raman",
366
- "yukteswar",
367
- "true-chitra",
368
- "true-revati",
369
- "true-pushya",
370
- "galactic-center"
371
- ];
372
- var CALC_RECEIPT_SCHEMA = "zodiacs.calc-receipt.draft-v1";
435
+ var CALC_FRAMES2 = Object.freeze([...CALC_FRAMES]);
436
+ var CALC_AYANAMSAS = Object.freeze(Object.keys(AYANAMSAS));
437
+ var CALC_RECEIPT_SCHEMA = "zodiacs.calc-receipt.v1";
373
438
  var CALC_SPAN = REFERENCE_SPAN;
374
439
  var DEG2 = Math.PI / 180;
375
440
  var RAD2 = 180 / Math.PI;
@@ -406,7 +471,6 @@ function yesNo(value, label, fallback) {
406
471
  if (typeof value !== "boolean") throw new RangeError(`${label} must be true or false.`);
407
472
  return value;
408
473
  }
409
- var SCALES = { UTC: "utc", UT1: "ut1", TT: "tt" };
410
474
  function readTime(value, label) {
411
475
  const iso = (text) => {
412
476
  try {
@@ -431,8 +495,11 @@ function readTime(value, label) {
431
495
  }
432
496
  const jd = time.jd;
433
497
  if (typeof jd !== "number" || !Number.isFinite(jd)) throw new RangeError(`${label}.jd must be a finite Julian date.`);
434
- const scale = oneOf(time.scale, ["UTC", "UT1", "TT"], `${label}.scale`);
435
- return { record: { jd, scale, ...pinned }, ms: J2000_MS + (jd - J2000_JD) * DAY_MS, scale: SCALES[scale], pin, civil: false };
498
+ if (typeof time.scale === "string" && TIME_SCALE_NAMES.includes(time.scale.toLowerCase()) && !TIME_SCALE_NAMES.includes(time.scale)) {
499
+ throw new RangeError(`${label}.scale must be one of ${TIME_SCALE_NAMES.join(", ")}: lowercase since 1.0.0.`);
500
+ }
501
+ const scale = oneOf(time.scale, TIME_SCALE_NAMES, `${label}.scale`);
502
+ return { record: { jd, scale, ...pinned }, ms: J2000_MS + (jd - J2000_JD) * DAY_MS, scale, pin, civil: false };
436
503
  }
437
504
  function readPlace(value, label, withHeight = false) {
438
505
  const place = fields(value, label, withHeight ? ["latitude", "longitude", "height"] : ["latitude", "longitude"]);
@@ -445,17 +512,84 @@ function readPlace(value, label, withHeight = false) {
445
512
  function refuse(reason, detail) {
446
513
  return { status: "refused", reason, detail };
447
514
  }
448
- function sidereal(value) {
449
- if (value === void 0 || value === "tropical") return null;
450
- const name = oneOf(fields(value, "zodiac", ["sidereal"]).sidereal, CALC_AYANAMSAS, "zodiac.sidereal");
451
- return refuse("not-in-this-version", `The sidereal zodiac (${name}) is not in the calc entry in this version; @zodiacs/engine/vedic gives sidereal longitudes on this ayanamsa.`);
452
- }
453
515
  var outOfRange = () => ({
454
516
  status: "refused",
455
517
  reason: "out-of-range",
456
518
  detail: `The instant's UT1 or TT is outside ${CALC_SPAN.from} to ${CALC_SPAN.to}, where the engine's positions have been compared with an independent ephemeris.`,
457
519
  span: CALC_SPAN
458
520
  });
521
+ var TROPICAL = { record: "tropical", definition: null, ids: ["zodiac:tropical"] };
522
+ var UNIX_JD = 24405875e-1;
523
+ function epochTT(epoch, label) {
524
+ const record = epoch.record;
525
+ const message = `${label} must be an instant in the range of a Date.`;
526
+ let jd;
527
+ if ("jd" in record && record.scale === "tt") {
528
+ jd = record.jd;
529
+ } else {
530
+ if (!(Math.abs(epoch.ms) <= 864e13)) throw new RangeError(message);
531
+ jd = J2000_JD + timeBasis(epoch.ms, epoch.scale, epoch.pin).ttDays;
532
+ }
533
+ if (!(Math.abs(jd - UNIX_JD) <= 1e8)) throw new RangeError(message);
534
+ return jd;
535
+ }
536
+ function readZodiac(value) {
537
+ if (value === void 0 || value === "tropical") return TROPICAL;
538
+ const sidereal = fields(value, "zodiac", ["sidereal"]).sidereal;
539
+ if (sidereal === void 0 || typeof sidereal === "string") {
540
+ const name = oneOf(sidereal, CALC_AYANAMSAS, "zodiac.sidereal");
541
+ return { record: { sidereal: name }, definition: AYANAMSAS[name], ids: ["zodiac:sidereal", `ayanamsa:${name}`] };
542
+ }
543
+ const label = "zodiac.sidereal";
544
+ const given = fields(sidereal, label, ["name", "epoch", "value", "rate", "model"]);
545
+ if (given.name !== void 0 && !isUserAyanamsaName(given.name)) {
546
+ throw new RangeError(`${label}.name must be a lowercase identifier of at most 64 characters that is not a built-in name.`);
547
+ }
548
+ const epoch = readTime(given.epoch, `${label}.epoch`);
549
+ const value_ = within(given.value, `${label}.value`, -360, 360);
550
+ if (given.rate !== void 0 && given.model !== void 0) throw new RangeError(`${label} takes a rate or a model, not both.`);
551
+ const rate = given.rate === void 0 ? void 0 : within(given.rate, `${label}.rate`, -3600, 3600);
552
+ const model = given.model === void 0 ? void 0 : oneOf(given.model, ["engine", "newcomb", "iau1976"], `${label}.model`);
553
+ const definition = userAyanamsa({
554
+ ...given.name === void 0 ? {} : { name: given.name },
555
+ epoch: { julianDateTT: epochTT(epoch, `${label}.epoch`) },
556
+ value: value_,
557
+ ...rate === void 0 ? {} : { rate },
558
+ ...model === void 0 ? {} : { model }
559
+ });
560
+ const user = rate === void 0 ? { name: definition.name, epoch: epoch.record, value: value_, model: model ?? "engine" } : { name: definition.name, epoch: epoch.record, value: value_, rate };
561
+ return { record: { sidereal: user }, definition, ids: ["zodiac:sidereal", `ayanamsa:user-${definition.kind}`] };
562
+ }
563
+ var insideEphemerisSpan = (definition) => definition.kind !== "epoch" || definition.epochTT - J2000_JD >= EPHEMERIS_SPAN.daysFromJ2000.from && definition.epochTT - J2000_JD <= EPHEMERIS_SPAN.daysFromJ2000.to;
564
+ function epochRefusal(zodiac) {
565
+ return zodiac.definition && !insideEphemerisSpan(zodiac.definition) ? {
566
+ status: "refused",
567
+ reason: "epoch-out-of-range",
568
+ detail: `The ayanamsa's epoch is outside ${EPHEMERIS_SPAN.fromTT} to ${EPHEMERIS_SPAN.toTT} TT (EPHEMERIS_SPAN), where the precession that carries it has been compared with ERFA's.`,
569
+ epochSpan: EPHEMERIS_SPAN
570
+ } : null;
571
+ }
572
+ var siderealFrame = (frame) => frame === "ecliptic-true-of-date" || frame === "ecliptic-mean-of-date";
573
+ function frameRefusal(zodiac, frame) {
574
+ return zodiac.definition && !siderealFrame(frame) ? refuse(
575
+ "unsupported-combination",
576
+ `The sidereal zodiac is counted along the ecliptic of date; frame ${frame} is not offered with it, only ecliptic-true-of-date and ecliptic-mean-of-date.`
577
+ ) : null;
578
+ }
579
+ function ayanamsaValue(definition, value, subtracted, k) {
580
+ return {
581
+ name: definition.name,
582
+ mean: value.mean * k,
583
+ nutation: value.nutation * k,
584
+ true: value.true * k,
585
+ subtracted,
586
+ bound: { value: ayanamsaBound(definition, value.elongation).position, unit: "arcsec", label: "measured", basis: ayanamsaBound(definition, value.elongation).basis }
587
+ };
588
+ }
589
+ function withAyanamsa(b, add2) {
590
+ if (add2 === null || b.value === null) return b;
591
+ return { ...b, value: addBounds(b.value, add2.value), basis: `${b.basis}; plus the ayanamsa's, ${add2.value} ${b.unit}: ${add2.basis}` };
592
+ }
459
593
  function resolve(time) {
460
594
  const inside = (days2, margin = 0) => days2 >= SPAN_DAYS[0] - margin && days2 < SPAN_DAYS[1] + margin;
461
595
  const days = (time.ms - J2000_MS) / DAY_MS;
@@ -481,18 +615,19 @@ function instant(basis) {
481
615
  };
482
616
  }
483
617
  var TIME_BASIS_ID = "time:tt-from-leap-seconds-and-ut1-from-iers-1972-to-table-end;delta-t-model-otherwise";
484
- function receipt(request, instants, ids, pin) {
618
+ function receipt(request, instants, ids, pin, banded = true, ephemeris = EPHEMERIS) {
485
619
  return {
486
620
  schema: CALC_RECEIPT_SCHEMA,
487
621
  request,
488
622
  instants,
489
623
  conventions: [
490
624
  ...ids,
491
- `ephemeris:astronomy-engine@${EPHEMERIS.version}`,
625
+ `ephemeris:${ephemeris.name}@${ephemeris.version}`,
492
626
  pin === void 0 ? "deltat:time-basis" : "deltat:pinned",
493
- TIME_BASIS_ID
627
+ TIME_BASIS_ID,
628
+ ...banded ? ["time-band:first-order"] : []
494
629
  ],
495
- engine: { name: "@zodiacs/engine", version: ENGINE_VERSION, ephemeris: { ...EPHEMERIS } }
630
+ engine: { name: "@zodiacs/engine", version: ENGINE_VERSION, ephemeris: { name: ephemeris.name, version: ephemeris.version } }
496
631
  };
497
632
  }
498
633
  var isPoint = (body) => POINTS.includes(body);
@@ -523,6 +658,44 @@ function pointAt(body, at2) {
523
658
  const raw = meanNodeLongitude(centuries, nutation);
524
659
  return row(raw, normalizeLongitude(body === "Mean Node" ? raw : raw + 180));
525
660
  }
661
+ var BARYCENTRES = ["Mars", "Jupiter", "Saturn", "Uranus", "Neptune", "Pluto"];
662
+ var packGives = (body, kind, correction) => kind === "geocentric" && (isTrueNode(body) || !isPoint(body) && body !== "Earth" && correction === "apparent");
663
+ function packed(from, body, frame, behind) {
664
+ const tidy = (lon) => lon === 360 ? 0 : lon + 0;
665
+ return (at2, basis) => {
666
+ let lon;
667
+ let lat = 0;
668
+ let dist = null;
669
+ if (isTrueNode(body)) {
670
+ const node = from.trueNode(basis.ttDays);
671
+ lon = body === "North Node" ? tidy(node) : normalizeLongitude(node + 180);
672
+ } else {
673
+ const place = from.place(body, basis.ttDays, behind);
674
+ lon = tidy(place.lon);
675
+ lat = place.lat;
676
+ dist = place.dist ?? null;
677
+ }
678
+ const scaled = (v) => dist === null ? null : [v[0] * dist, v[1] * dist, v[2] * dist];
679
+ const along = fromSpherical(lon, lat, 1);
680
+ if (frame === "ecliptic-true-of-date") return { lon, lat, dist, xyz: scaled(along), raw: lon };
681
+ const turned = apply(frameMatrix(frame, at2), apply(transpose(frameMatrix("ecliptic-true-of-date", at2)), along));
682
+ const there = toSpherical(turned);
683
+ return { lon: there.lon, lat: there.lat, dist, xyz: scaled(turned), raw: there.lon };
684
+ };
685
+ }
686
+ var SUN_RADIUS_KM = 695700;
687
+ function atLimb(from, body, ttDays) {
688
+ if (body === "Sun" || body === "Moon" || isPoint(body) || isTrueNode(body) || body === "Earth") return false;
689
+ const sun = from.place("Sun", ttDays);
690
+ const place = from.place(body, ttDays);
691
+ if (sun.dist === void 0 || place.dist === void 0 || !(place.dist > sun.dist)) return false;
692
+ const a = fromSpherical(sun.lon, sun.lat, 1);
693
+ const b = fromSpherical(place.lon, place.lat, 1);
694
+ const cross = Math.hypot(a[1] * b[2] - a[2] * b[1], a[2] * b[0] - a[0] * b[2], a[0] * b[1] - a[1] * b[0]);
695
+ const apart = Math.atan2(cross, a[0] * b[0] + a[1] * b[1] + a[2] * b[2]) * RAD2 * 3600;
696
+ const radius = Math.asin(SUN_RADIUS_KM / (sun.dist * KM_PER_AU2)) * RAD2 * 3600;
697
+ return Math.abs(apart - radius) <= DE440_LIMB_BAND;
698
+ }
526
699
  function evaluator(body, frame, center, correction) {
527
700
  if (isPoint(body)) {
528
701
  return (at2) => {
@@ -542,10 +715,36 @@ function evaluator(body, frame, center, correction) {
542
715
  return { lon, lat, dist, xyz: [turned[0] * k, turned[1] * k, turned[2] * k], raw: lon };
543
716
  };
544
717
  }
545
- function positionIds(body, frame, kind, correction) {
546
- const ids = ["zodiac:tropical", `frame:${frame}`, `center:${kind}`];
718
+ function turnedBack([x, y, z], angle) {
719
+ const c = Math.cos(angle * DEG2);
720
+ const s = Math.sin(angle * DEG2);
721
+ return [x * c + y * s, y * c - x * s, z];
722
+ }
723
+ function siderealOf(evaluate, definition, frame) {
724
+ const trueOfDate = frame === "ecliptic-true-of-date";
725
+ return (at2, basis) => {
726
+ const row = evaluate(at2, basis);
727
+ const value = ayanamsaAt(definition, at2);
728
+ const subtracted = trueOfDate ? value.true : value.mean;
729
+ return {
730
+ lon: wrap360(wrap360(row.lon) - subtracted),
731
+ lat: row.lat,
732
+ dist: row.dist,
733
+ xyz: row.xyz && turnedBack(row.xyz, subtracted),
734
+ raw: row.raw - subtracted,
735
+ ayanamsa: value
736
+ };
737
+ };
738
+ }
739
+ function positionIds(body, frame, kind, correction, zodiac, onPack = false) {
740
+ const ids = [...zodiac.ids, `frame:${frame}`, `center:${kind}`];
547
741
  if (isPoint(body)) {
548
742
  ids.push("correction:not-applicable", body.endsWith("Lilith") ? "lilith:mean" : body.startsWith("Mean") ? "node:mean" : "node:true-osculating");
743
+ if (onPack) ids.push(...PACK_PLACE_IDS);
744
+ } else if (onPack) {
745
+ ids.push(`correction:${correction}`, "light-time:iterated", "deflection:sun-outside-disc", "aberration:relativistic-annual");
746
+ if (BARYCENTRES.includes(body)) ids.push("target:system-barycentre");
747
+ ids.push(...PACK_PLACE_IDS);
549
748
  } else {
550
749
  ids.push(`correction:${correction}`);
551
750
  if (body === "Moon" && kind === "geocentric" && correction !== "astrometric") ids.push("moon:series-at-instant");
@@ -554,6 +753,12 @@ function positionIds(body, frame, kind, correction) {
554
753
  if (correction === "apparent" && kind !== "barycentric") ids.push("aberration:backdated-observer");
555
754
  }
556
755
  }
756
+ if (onPack) {
757
+ ids.push("precession:iau2006", "obliquity:iau2006");
758
+ if (frame !== "ecliptic-true-of-date") ids.push("frame-turn:from-true-ecliptic-of-date", "nutation:iau2000b");
759
+ if (frame.endsWith("icrs")) ids.push("frame-bias:iau2000");
760
+ return ids;
761
+ }
557
762
  if (isPoint(body) || !inertial(frame)) ids.push("precession:iau2006");
558
763
  if (frame.includes("true")) ids.push("nutation:iau2000b");
559
764
  if (isPoint(body) || frame.startsWith("ecliptic")) ids.push("obliquity:iau2006");
@@ -562,9 +767,12 @@ function positionIds(body, frame, kind, correction) {
562
767
  if (kind === "topocentric") ids.push("observer:iers2003-ellipsoid;no-polar-motion");
563
768
  return ids;
564
769
  }
565
- function bound(value, unit, estimated) {
566
- return value === void 0 || value === null ? { value: null, unit, label: "estimated", basis: "not compared with an independent ephemeris" } : { value, unit, label: estimated === null ? "measured" : "estimated", basis: estimated ?? MEASURED_BASIS };
770
+ var PACK_PLACE_IDS = ["place:icrf-to-true-ecliptic-of-date", "frame-bias:iau2006-fukushima-williams", "nutation:iau2000b-p03", "time:tdb-three-term"];
771
+ var MEAN_POINTS = ["Mean Node", "Mean South Node", "Black Moon Lilith"];
772
+ function bound(value, unit, estimated, measured) {
773
+ return value === void 0 || value === null ? { value: null, unit, label: "estimated", basis: "not compared with an independent ephemeris" } : { value, unit, label: estimated === null ? "measured" : "estimated", basis: estimated ?? measured };
567
774
  }
775
+ var stretched = (b, extra) => !extra || b.value === null ? b : { ...b, value: addBounds(b.value, extra), label: "estimated", basis: `${b.basis}; plus ${+extra.toPrecision(3)} ${b.unit}, \u0394T extrapolated (docs/calc.md, "Bounds")` };
568
776
  function up2(x) {
569
777
  const unit = 10 ** (Math.floor(Math.log10(x)) - 1);
570
778
  return Number((Math.ceil(x / unit) * unit).toPrecision(2));
@@ -575,10 +783,11 @@ function barycentricSun(r, v) {
575
783
  return [up2(Math.asin(e / r) * RAD2 * 3600), up2(e / (r - e)), rate === null ? null : up2(rate * RAD2 * 3600)];
576
784
  }
577
785
  function calc(request) {
786
+ refuseUnderSource("@zodiacs/engine/calc");
578
787
  const asked = fields(request, "calc request", ["body", "time", "frame", "center", "zodiac", "flags"]);
579
788
  const body = oneOf(asked.body, CALC_BODIES, "body");
580
789
  const time = readTime(asked.time, "time");
581
- const frame = oneOf(asked.frame, CALC_FRAMES, "frame", "ecliptic-true-of-date");
790
+ const frame = oneOf(asked.frame, CALC_FRAMES2, "frame", "ecliptic-true-of-date");
582
791
  let center;
583
792
  let centerRecord;
584
793
  if (asked.center === void 0 || typeof asked.center === "string") {
@@ -598,18 +807,35 @@ function calc(request) {
598
807
  units: oneOf(given.units, ["degrees", "radians"], "flags.units", "degrees"),
599
808
  deflection: yesNo(given.deflection, "flags.deflection", false)
600
809
  };
810
+ const zodiac = readZodiac(asked.zodiac);
601
811
  const point = isPoint(body);
602
812
  const kind = center.kind;
603
- const refusal = sidereal(asked.zodiac) ?? (flags.deflection ? refuse("not-in-this-version", "Gravitational light deflection is not modelled in this version.") : point && kind !== "geocentric" ? refuse("unsupported-combination", `${body} is a point of the Moon's geocentric orbit; only the geocentric center is offered.`) : point && flags.cartesian ? refuse("unsupported-combination", `${body} has no distance, so no cartesian position.`) : body === "Sun" && kind === "heliocentric" ? refuse("unsupported-combination", "The Sun is the heliocentric origin.") : body === "Earth" && (kind === "geocentric" || kind === "topocentric") ? refuse("unsupported-combination", "The Earth is offered heliocentric or barycentric only.") : null);
813
+ const refusal = (flags.deflection ? refuse("not-in-this-version", "Gravitational light deflection is not modelled in this version.") : point && kind !== "geocentric" ? refuse("unsupported-combination", `${body} is a point of the Moon's geocentric orbit; only the geocentric center is offered.`) : point && flags.cartesian ? refuse("unsupported-combination", `${body} has no distance, so no cartesian position.`) : body === "Sun" && kind === "heliocentric" ? refuse("unsupported-combination", "The Sun is the heliocentric origin.") : body === "Earth" && (kind === "geocentric" || kind === "topocentric") ? refuse("unsupported-combination", "The Earth is offered heliocentric or barycentric only.") : frameRefusal(zodiac, frame)) ?? epochRefusal(zodiac);
604
814
  if (refusal) return refusal;
605
815
  const correction = flags.correction;
816
+ const definition = zodiac.definition;
606
817
  return inSpan(time, (basis) => {
607
- const evaluate = evaluator(body, frame, center, correction);
818
+ const chosen = packGives(body, kind, correction) ? ephemerisAt(time.ms, time.scale, time.pin) : null;
819
+ const from = chosen?.from ?? null;
820
+ const tropical = from ? packed(from, body, frame) : evaluator(body, frame, center, correction);
821
+ const evaluate = definition === null ? tropical : siderealOf(tropical, definition, frame);
608
822
  const now = onInput(time, time.ms, evaluate);
609
823
  const step = isTrueNode(body) ? NODE_STEP_DAYS : STEP_DAYS;
610
824
  const analytic = flags.speeds && correction === "geometric" && inertial(frame) && !point && body !== "Moon";
611
825
  let speeds = null;
612
826
  let velocity = null;
827
+ let samples = null;
828
+ const sampling = () => {
829
+ if (samples) return samples;
830
+ const side = from && !isTrueNode(body) ? from.place(body, basis.ttDays).behindDisc : void 0;
831
+ const tropicalSamples = from && side !== void 0 ? packed(from, body, frame, side) : tropical;
832
+ return samples = definition === null ? tropicalSamples : siderealOf(tropicalSamples, definition, frame);
833
+ };
834
+ const shift = (days) => {
835
+ const ms = time.ms + days * DAY_MS;
836
+ const at2 = sampling();
837
+ return onInput(time, ms, (instant2, sampled) => ({ row: at2(instant2, sampled), basis: sampled }));
838
+ };
613
839
  if (analytic) {
614
840
  const { state, turn } = onInput(time, time.ms, (at2) => ({
615
841
  state: geometricState(body, center, at2),
@@ -618,10 +844,6 @@ function calc(request) {
618
844
  velocity = apply(turn, state.v);
619
845
  speeds = sphericalRates(apply(turn, state.r), velocity);
620
846
  } else if (flags.speeds) {
621
- const shift = (days) => {
622
- const ms = time.ms + days * DAY_MS;
623
- return onInput(time, ms, (at2, sampled) => ({ row: evaluate(at2), basis: sampled }));
624
- };
625
847
  const before = shift(-step);
626
848
  const after = shift(step);
627
849
  const elapsed = elapsedDays(before.basis, after.basis, 2 * step);
@@ -639,17 +861,63 @@ function calc(request) {
639
861
  }
640
862
  const method = !flags.speeds ? null : analytic ? "analytic" : "central-difference";
641
863
  const k = flags.units === "radians" ? DEG2 : 1;
642
- let row = MEASURED[`${kind}/${point ? "apparent" : correction}`]?.[body];
864
+ const group = `${kind}/${point ? "apparent" : correction}`;
865
+ let row = MEASURED[group]?.[body];
643
866
  let estimated = null;
644
- if (!row && kind === "topocentric") {
867
+ const mean = MEAN_POINTS.includes(body);
868
+ const swept = SWEPT.includes(group) ? SWEPT_BASIS : MEASURED_BASIS;
869
+ let measured = mean ? MEAN_POINTS_BASIS : swept;
870
+ if (from) {
871
+ const position = DE440_MEASURED[body];
872
+ row = position === void 0 ? void 0 : [position, null, null];
873
+ measured = DE440_MEASURED_BASIS;
874
+ if (frame !== "ecliptic-true-of-date") estimated = DE440_TURNED_BASIS;
875
+ if (position !== void 0 && atLimb(from, body, basis.ttDays)) {
876
+ row = [DE440_AT_LIMB, null, null];
877
+ estimated = DE440_AT_LIMB_BASIS;
878
+ }
879
+ } else if (!row && kind === "topocentric") {
645
880
  row = MEASURED[`geocentric/${correction}`]?.[body];
646
- estimated = "the geocentric bound for this correction; topocentric positions were compared only for the Sun, the Moon and Mars";
881
+ estimated = "the geocentric bound for this correction; the Sun, Moon and Mars, compared topocentric on 32 instants, fall within it";
647
882
  } else if (kind === "barycentric" && body === "Sun") {
648
883
  row = barycentricSun(now.dist, velocity && length(velocity));
649
884
  estimated = `the largest angle, relative distance and rate of direction that the error of astronomy-engine's barycentre, ${BARYCENTRE_ERROR.au.toExponential()} au and ${BARYCENTRE_ERROR.auPerDay.toExponential()} au/day from 1800 to 2200, allows at this distance and speed; docs/evidence/calc-api`;
650
885
  }
651
- const ids = positionIds(body, frame, kind, correction);
886
+ const ids = positionIds(body, frame, kind, correction, zodiac, from !== null);
652
887
  if (method) ids.push(method === "analytic" ? "speed:analytic" : `speed:central-difference-${step}d`);
888
+ const v = center.kind === "topocentric" ? ANGVEL * (EARTH_EQUATORIAL_RADIUS_KM + Math.max(center.site.height, 0) / 1e3) / KM_PER_AU2 : 0;
889
+ const w = v && v / (now.dist * (1 - 1e-3)) * RAD2 * 3600;
890
+ const bands = timeBands(basis);
891
+ const { tt, ut1 } = bands;
892
+ const extrapolated = deltaTExtrapolated(basis, w);
893
+ let widen = [0, 0, 0];
894
+ if (extrapolated) {
895
+ const [after, before] = [shift(step), shift(-step)];
896
+ const [a, b] = [after.row, before.row];
897
+ const h = elapsedDays(before.basis, after.basis, 2 * step) / 2;
898
+ const turn = (x, y) => (x - y + 540) % 360 - 180;
899
+ const cos = Math.cos(now.lat * DEG2);
900
+ const spin = w * ANGVEL * 86400;
901
+ const r = now.dist;
902
+ widen = [
903
+ (Math.hypot(turn(a.raw, b.raw) * cos, a.lat - b.lat) / h / 48 + w) * tt + w * ut1,
904
+ r && (Math.abs(a.dist - b.dist) / h / 172800 + v) / r * tt + v / r * ut1,
905
+ (Math.hypot((turn(a.raw, now.raw) - turn(now.raw, b.raw)) * cos, a.lat - 2 * now.lat + b.lat) / h / h / 24 + spin) * tt + spin * ut1
906
+ ];
907
+ ids.push("bounds:plus-delta-t-band");
908
+ }
909
+ const sidereal = definition === null ? null : now.ayanamsa;
910
+ const added = sidereal && ayanamsaBound(definition, sidereal.elongation);
911
+ let band = null;
912
+ if (speeds) {
913
+ const across = w / Math.cos(now.lat * DEG2);
914
+ band = {
915
+ time: bands,
916
+ lon: (Math.abs(speeds.lon) / 24 + across) * tt + across * ut1,
917
+ lat: (Math.abs(speeds.lat) / 24 + w) * tt + w * ut1,
918
+ dist: speeds.dist === null ? null : (Math.abs(speeds.dist) / 86400 + v) * tt + v * ut1
919
+ };
920
+ }
653
921
  return {
654
922
  status: "ok",
655
923
  body,
@@ -659,59 +927,146 @@ function calc(request) {
659
927
  dist: now.dist,
660
928
  speeds: speeds && { lon: speeds.lon * k, lat: speeds.lat * k, dist: speeds.dist },
661
929
  cartesian: flags.cartesian && now.xyz ? { x: now.xyz[0], y: now.xyz[1], z: now.xyz[2], vx: velocity?.[0] ?? null, vy: velocity?.[1] ?? null, vz: velocity?.[2] ?? null } : null,
930
+ ayanamsa: sidereal && ayanamsaValue(definition, sidereal, frame === "ecliptic-true-of-date" ? "true" : "mean", k),
662
931
  bounds: {
663
- position: bound(row?.[0], "arcsec", estimated),
664
- distance: point ? null : bound(row?.[1], "relative", estimated),
665
- speed: method && { ...bound(row?.[2], "arcsec/day", estimated), method, stepDays: analytic ? null : step }
932
+ position: stretched(
933
+ withAyanamsa(bound(row?.[0], "arcsec", estimated, measured), added && { value: added.position, basis: added.basis }),
934
+ widen[0]
935
+ ),
936
+ distance: point ? null : stretched(bound(row?.[1], "relative", estimated, from ? measured : swept), widen[1]),
937
+ speed: method && {
938
+ ...stretched(
939
+ withAyanamsa(
940
+ bound(row?.[2], "arcsec/day", estimated, mean ? MEAN_POINTS_SPEED_BASIS : from ? measured : swept),
941
+ added && { value: added.rate, basis: added.basis }
942
+ ),
943
+ widen[2]
944
+ ),
945
+ method,
946
+ stepDays: analytic ? null : step
947
+ }
666
948
  },
949
+ band,
950
+ // Last, a position the pack gives that astronomy-engine gave instead says why.
951
+ flags: [...extrapolated ? ["delta-t-extrapolated"] : [], ...chosen?.fallback ? [chosen.fallback] : []],
667
952
  receipt: receipt(
668
- { body, time: time.record, frame, center: centerRecord, zodiac: "tropical", flags },
953
+ { body, time: time.record, frame, center: centerRecord, zodiac: zodiac.record, flags },
669
954
  [instant(basis)],
670
955
  ids,
671
- time.pin
956
+ time.pin,
957
+ band !== null,
958
+ chosen?.ephemeris
672
959
  )
673
960
  };
674
961
  });
675
962
  }
963
+ var UT1_SECOND = 1.0027378119113546 / 3600;
964
+ var TT_STEP = 600 / 86400;
965
+ function movedOnTt(at2, place, definition) {
966
+ return [TT_STEP, -TT_STEP].map((days) => {
967
+ const moved = at2.AddDays(days);
968
+ return {
969
+ input: { gastHours: gastHours({ ut: at2.ut, tt: moved.tt }), ...place, obliquity: tilt(moved.tt).tobl },
970
+ less: definition === null ? 0 : ayanamsaAt(definition, moved).true
971
+ };
972
+ });
973
+ }
974
+ function angleBands(input, system, bands, moved, less = 0) {
975
+ const values = (at2, by = 0) => {
976
+ const angles = computeAngles(at2);
977
+ return [angles.asc, angles.mc, vertexOf(at2, angles), eastPointOf(at2), ...system === "whole" ? [] : computeHouses(system, at2, angles).houses.cusps].map(
978
+ (value) => value - by
979
+ );
980
+ };
981
+ const rates = (before2, after, seconds) => after.map((value, index) => {
982
+ let turn = value - before2[index];
983
+ if (turn > 180) turn -= 360;
984
+ else if (turn <= -180) turn += 360;
985
+ return Math.abs(turn) * 3600 / seconds;
986
+ });
987
+ const before = values({ ...input, gastHours: input.gastHours - UT1_SECOND });
988
+ const onUt1 = rates(before, values({ ...input, gastHours: input.gastHours + UT1_SECOND }), 2);
989
+ let onTt = null;
990
+ if (moved) {
991
+ const [plus, minus] = moved.map((side) => values(side.input, side.less));
992
+ onTt = rates(minus, plus, 2 * TT_STEP * 86400);
993
+ const [up, down] = moved.map((side) => isPolarUndefinedHouseSystem(system) && Math.abs(side.input.latitude) >= 90 - side.input.obliquity);
994
+ if (up || down) {
995
+ const here = values(input, less);
996
+ const one = up ? down ? null : rates(minus, here, TT_STEP * 86400) : rates(here, plus, TT_STEP * 86400);
997
+ for (let index = 4; index < onTt.length; index += 1) onTt[index] = one ? one[index] : 0;
998
+ }
999
+ }
1000
+ const [asc, mc, vertex, eastPoint, ...cusps] = onUt1.map((rate, index) => rate * bands.ut1 + (onTt ? onTt[index] * bands.tt : 0));
1001
+ return { asc, mc, vertex, eastPoint, cusps: system === "whole" ? Array(12).fill(0) : cusps };
1002
+ }
676
1003
  function houses(request) {
677
- const asked = fields(request, "houses request", ["time", "place", "system", "zodiac"]);
1004
+ const asked = fields(request, "houses request", ["time", "place", "houseSystem", "zodiac"]);
678
1005
  const time = readTime(asked.time, "time");
679
1006
  const { latitude, longitude } = readPlace(asked.place, "place");
680
- const system = validateBirthSettings({ houseSystem: asked.system }).houseSystem ?? "whole";
681
- const refusal = sidereal(asked.zodiac);
1007
+ const system = validateBirthSettings({ houseSystem: asked.houseSystem }).houseSystem ?? "whole";
1008
+ const zodiac = readZodiac(asked.zodiac);
1009
+ const refusal = epochRefusal(zodiac);
682
1010
  if (refusal) return refusal;
1011
+ const definition = zodiac.definition;
683
1012
  return inSpan(time, (used) => {
684
- const input = onInput(time, time.ms, (at2) => ({ gastHours: gastHours(at2), latitude, longitude, obliquity: tilt(at2.tt).tobl }));
685
- const angles = computeAngles(input);
686
- const { houses: computed, fellBack } = computeHouses(system, input, angles);
1013
+ const bands = timeBands(used);
1014
+ const { input, value, moved } = onInput(time, time.ms, (at2) => ({
1015
+ input: { gastHours: gastHours(at2), latitude, longitude, obliquity: tilt(at2.tt).tobl },
1016
+ value: definition && ayanamsaAt(definition, at2),
1017
+ moved: bands.tt === 0 ? null : movedOnTt(at2, { latitude, longitude }, definition)
1018
+ }));
1019
+ const tropical = computeAngles(input);
1020
+ const { houses: computed, fellBack } = computeHouses(system, input, tropical);
1021
+ const zodiacal = value === null ? (lon) => lon : (lon) => wrap360(wrap360(lon) - value.true);
1022
+ const angles = value === null ? tropical : { asc: zodiacal(tropical.asc), mc: zodiacal(tropical.mc), dsc: zodiacal(tropical.dsc), ic: zodiacal(tropical.ic) };
1023
+ const cusps = value === null ? computed.cusps : computed.system === "whole" ? wholeSignCusps(angles.asc) : computed.cusps.map(zodiacal);
1024
+ const bounded = definition && value && ayanamsaBound(definition, value.elongation);
1025
+ const added = bounded && { value: bounded.position, basis: bounded.basis };
687
1026
  const basis = (what) => `largest difference over the conformance suite's L2 ${what}, whose arbiter is ERFA with each system's definition`;
1027
+ const turned = angleBands(input, computed.system, bands, moved, value === null ? 0 : value.true);
1028
+ const late = deltaTExtrapolated(used, 1);
1029
+ const flags = fellBack ? ["polar-fallback"] : [];
1030
+ if (late) flags.push("delta-t-extrapolated");
688
1031
  return {
689
1032
  status: "ok",
690
1033
  requested: system,
691
1034
  system: computed.system,
692
- cusps: computed.cusps,
1035
+ cusps,
693
1036
  angles,
694
1037
  // Normalized once more, as chartPoints() reports them.
695
- vertex: normalizeLongitude(vertexOf(input, angles)),
696
- eastPoint: normalizeLongitude(eastPointOf(input)),
1038
+ vertex: zodiacal(normalizeLongitude(vertexOf(input, tropical))),
1039
+ eastPoint: zodiacal(normalizeLongitude(eastPointOf(input))),
697
1040
  armc: ramcOf(input),
698
1041
  obliquity: input.obliquity,
699
- flags: fellBack ? ["polar-fallback"] : [],
1042
+ flags,
1043
+ ayanamsa: value && ayanamsaValue(definition, value, "true", 1),
700
1044
  bounds: {
701
- angles: { value: 0.02, unit: "arcsec", label: "measured", basis: basis("vectors of the ascendant, midheaven, Vertex and East Point") },
702
- cusps: { value: 0.08, unit: "arcsec", label: "measured", basis: basis("cusp vectors, thirteen systems") }
1045
+ angles: stretched(
1046
+ withAyanamsa(
1047
+ { value: 0.02, unit: "arcsec", label: "measured", basis: basis("vectors of the ascendant, midheaven, Vertex and East Point") },
1048
+ added
1049
+ ),
1050
+ late ? Math.max(turned.asc, turned.mc, turned.vertex, turned.eastPoint) : 0
1051
+ ),
1052
+ cusps: stretched(
1053
+ withAyanamsa({ value: 0.08, unit: "arcsec", label: "measured", basis: basis("cusp vectors, thirteen systems") }, added),
1054
+ late ? Math.max(...turned.cusps) : 0
1055
+ )
703
1056
  },
1057
+ band: { time: bands, ...turned },
704
1058
  receipt: receipt(
705
- { time: time.record, place: { latitude, longitude }, system, zodiac: "tropical" },
1059
+ { time: time.record, place: { latitude, longitude }, houseSystem: system, zodiac: zodiac.record },
706
1060
  [instant(used)],
707
1061
  [
708
- "zodiac:tropical",
1062
+ ...zodiac.ids,
709
1063
  `house:${system}`,
710
1064
  ...fellBack ? ["polar-fallback:whole"] : [],
711
1065
  "angles:gast-and-true-obliquity",
712
1066
  "sidereal-time:gast-iau2006-era",
713
1067
  "nutation:iau2000b",
714
- "obliquity:iau2006"
1068
+ "obliquity:iau2006",
1069
+ ...late ? ["bounds:plus-delta-t-band"] : []
715
1070
  ],
716
1071
  time.pin
717
1072
  )
@@ -719,6 +1074,7 @@ function houses(request) {
719
1074
  });
720
1075
  }
721
1076
  function events(request) {
1077
+ refuseUnderSource("@zodiacs/engine/calc");
722
1078
  const asked = fields(request, "events request", ["kind", "body", "longitude", "from", "to", "zodiac", "stepDays", "maxSamples"]);
723
1079
  const kind = oneOf(asked.kind, ["longitude-crossing"], "kind");
724
1080
  const body = oneOf(asked.body, CALC_BODIES, "body");
@@ -728,15 +1084,22 @@ function events(request) {
728
1084
  const stepDays = asked.stepDays === void 0 ? 5 : asked.stepDays;
729
1085
  const budget = asked.maxSamples === Infinity ? void 0 : asked.maxSamples;
730
1086
  const limit = budget === void 0 ? {} : { maxSamples: budget };
731
- const refusal = sidereal(asked.zodiac) ?? (!CHART_BODIES.includes(body) ? refuse("unsupported-combination", `Crossings are searched for the bodies positions() gives; ${body} is not one.`) : from.pin !== void 0 || to.pin !== void 0 ? refuse("unsupported-combination", "Crossing searches run on the engine's \u0394T model; a pinned \u0394T is not offered.") : null);
1087
+ const zodiac = readZodiac(asked.zodiac);
1088
+ const refusal = (!CHART_BODIES.includes(body) ? refuse("unsupported-combination", `Crossings are searched for the bodies positions() gives; ${body} is not one.`) : from.pin !== void 0 || to.pin !== void 0 ? refuse("unsupported-combination", "Crossing searches run on the engine's \u0394T model; a pinned \u0394T is not offered.") : null) ?? epochRefusal(zodiac);
732
1089
  if (refusal) return refusal;
1090
+ const definition = zodiac.definition;
1091
+ const longitudeAt = definition === null ? bodyLongitude : (b, date) => {
1092
+ const tropical = bodyLongitude(b, date);
1093
+ return wrap360(wrap360(tropical) - onChartClock(date.getTime(), "utc", void 0, (at2) => ayanamsaAt(definition, at2).true));
1094
+ };
733
1095
  const start = resolve(from);
734
1096
  const end = resolve(to);
735
1097
  if (start === null || end === null) return outOfRange();
736
1098
  {
1099
+ const chosen = ephemerisAt(Math.round(start.utcMs));
737
1100
  const dated = (basis) => new Date(Math.round(basis.utcMs));
738
1101
  const found = searchLongitudeCrossingsWith(
739
- bodyLongitude,
1102
+ longitudeAt,
740
1103
  body,
741
1104
  longitude,
742
1105
  dated(start),
@@ -747,38 +1110,74 @@ function events(request) {
747
1110
  const { samples, maxSamples } = found;
748
1111
  return { status: "refused", reason: "sample-budget", detail: `The search needs more than ${maxSamples} evaluations.`, samples, maxSamples };
749
1112
  }
1113
+ let late = 0;
1114
+ const events2 = found.crossings.map(({ at: at2, retrograde }) => {
1115
+ const basis = timeBasis(at2.getTime(), "utc");
1116
+ const utc = timeBands(basis).tt;
1117
+ if (deltaTExtrapolated(basis)) late = Math.max(late, utc);
1118
+ return {
1119
+ at: at2.toISOString(),
1120
+ jdUt1: J2000_JD + basis.ut1Days,
1121
+ jdTt: J2000_JD + basis.ttDays,
1122
+ retrograde,
1123
+ band: { utc, ut1: basis.deltaT.sigma ?? 0 }
1124
+ };
1125
+ });
750
1126
  return {
751
1127
  status: "ok",
752
1128
  kind,
753
- events: found.crossings.map(({ at: at2, retrograde }) => {
754
- const { ut1Days, ttDays } = timeBasis(at2.getTime(), "utc");
755
- return { at: at2.toISOString(), jdUt1: J2000_JD + ut1Days, jdTt: J2000_JD + ttDays, retrograde };
756
- }),
1129
+ events: events2,
757
1130
  samples: found.samples,
1131
+ flags: [...late ? ["delta-t-extrapolated"] : [], ...chosen.fallback ? [chosen.fallback] : []],
758
1132
  bounds: {
759
- timing: {
760
- value: stepDays * 86400 / 2 ** 24,
761
- unit: "s",
762
- label: "estimated",
763
- basis: "the bisection bracket, step / 2^24, on the engine's own longitudes; the ephemeris's error over the body's speed adds to it"
764
- }
1133
+ timing: stretched(
1134
+ {
1135
+ value: stepDays * 86400 / 2 ** 24,
1136
+ unit: "s",
1137
+ label: "estimated",
1138
+ basis: "the bisection bracket, step / 2^24, on the engine's own longitudes; the ephemeris's error over the body's speed adds to it" + (definition === null ? "" : ", and in the sidereal zodiac the ayanamsa's")
1139
+ },
1140
+ late
1141
+ )
765
1142
  },
766
1143
  receipt: receipt(
767
- { kind, body, longitude, from: from.record, to: to.record, zodiac: "tropical", stepDays, ...limit },
1144
+ { kind, body, longitude, from: from.record, to: to.record, zodiac: zodiac.record, stepDays, ...limit },
768
1145
  [instant(start), instant(end)],
769
- [...positionIds(body, "ecliptic-true-of-date", "geocentric", "apparent"), "search:scan-and-bisect"]
1146
+ [
1147
+ ...positionIds(body, "ecliptic-true-of-date", "geocentric", "apparent", zodiac, chosen.from !== null),
1148
+ "search:scan-and-bisect",
1149
+ ...late ? ["bounds:plus-delta-t-band"] : []
1150
+ ],
1151
+ void 0,
1152
+ true,
1153
+ chosen.ephemeris
770
1154
  )
771
1155
  };
772
1156
  }
773
1157
  }
1158
+ function siderealOfChart(computed, definition) {
1159
+ const sidereal = siderealChartOf(computed, definition);
1160
+ const value = sidereal.ayanamsaValue;
1161
+ const { elongation } = ayanamsaAt(definition, AstroTime.FromTerrestrialTime(value.julianDateTT - J2000_JD));
1162
+ return {
1163
+ ayanamsa: ayanamsaValue(definition, { mean: value.mean, nutation: value.nutation, true: value.true, elongation }, "true", 1),
1164
+ bodies: sidereal.bodies.map(({ body, lon }) => ({ body, lon })),
1165
+ ascendant: sidereal.ascendant === null ? null : sidereal.ascendant.lon,
1166
+ midheaven: sidereal.midheaven === null ? null : sidereal.midheaven.lon,
1167
+ houseSystem: sidereal.houseSystem,
1168
+ cusps: sidereal.cusps === null ? null : sidereal.cusps.map((cusp) => cusp.lon)
1169
+ };
1170
+ }
774
1171
  function chart(request) {
1172
+ refuseUnderSource("@zodiacs/engine/calc");
775
1173
  const asked = fields(request, "chart request", ["time", "place", "houseSystem", "timeKnown", "timeFlags", "zodiac"]);
776
1174
  const time = readTime(asked.time, "time");
777
1175
  const site = asked.place === void 0 ? null : readPlace(asked.place, "place");
778
1176
  const place = site === null ? null : { latitude: site.latitude, longitude: site.longitude };
779
1177
  const settings = validateBirthSettings({ houseSystem: asked.houseSystem, timeKnown: asked.timeKnown });
780
1178
  const supplied = asked.timeFlags === void 0 ? void 0 : snapshotFlags(asked.timeFlags).values;
781
- const refusal = sidereal(asked.zodiac);
1179
+ const zodiac = readZodiac(asked.zodiac);
1180
+ const refusal = epochRefusal(zodiac);
782
1181
  if (refusal) return refusal;
783
1182
  const whole = { ...time, ms: Math.round(time.ms) };
784
1183
  return inSpan(whole, (basis) => {
@@ -786,6 +1185,7 @@ function chart(request) {
786
1185
  const houseSystem = settings.houseSystem ?? "whole";
787
1186
  const timeKnown = settings.timeKnown ?? true;
788
1187
  const possible = !timeKnown ? ["no-time"] : settings.houseSystem && isPolarUndefinedHouseSystem(houseSystem) && place ? ["polar-fallback"] : [];
1188
+ possible.push("delta-t-extrapolated", "de440-unavailable", "outside-de440-span");
789
1189
  assertDerivedFlags(supplied ?? [], possible);
790
1190
  const input = {
791
1191
  utc,
@@ -798,10 +1198,26 @@ function chart(request) {
798
1198
  };
799
1199
  const used = instant(basis);
800
1200
  const computed = computeChart(input);
1201
+ const onPack = computed.ephemeris !== void 0 && computed.ephemeris.name !== EPHEMERIS.name;
801
1202
  assertDerivedFlags(supplied ?? [], computed.flags);
1203
+ const bands = timeBands(basis);
1204
+ const turned = computed.angles && place && (() => {
1205
+ const { input: angleInput, moved } = onInput(whole, whole.ms, (at2) => ({
1206
+ input: { gastHours: gastHours(at2), ...place, obliquity: tilt(at2.tt).tobl },
1207
+ moved: bands.tt === 0 ? null : movedOnTt(at2, place, null)
1208
+ }));
1209
+ return angleBands(angleInput, "whole", bands, moved);
1210
+ })();
802
1211
  return {
803
1212
  status: "ok",
804
1213
  chart: computed,
1214
+ sidereal: zodiac.definition && siderealOfChart(computed, zodiac.definition),
1215
+ band: {
1216
+ time: bands,
1217
+ bodies: computed.bodies.map(({ body, speed }) => ({ body, lon: Math.abs(speed) / 24 * bands.tt })),
1218
+ asc: turned ? turned.asc : null,
1219
+ mc: turned ? turned.mc : null
1220
+ },
805
1221
  receipt: receipt(
806
1222
  {
807
1223
  time: time.record,
@@ -809,20 +1225,22 @@ function chart(request) {
809
1225
  houseSystem,
810
1226
  timeKnown,
811
1227
  ...supplied && { timeFlags: supplied },
812
- zodiac: "tropical"
1228
+ zodiac: zodiac.record
813
1229
  },
814
1230
  [used],
815
1231
  [
816
- "zodiac:tropical",
1232
+ ...zodiac.ids,
817
1233
  "frame:ecliptic-true-of-date",
818
1234
  "center:geocentric",
819
1235
  "correction:apparent",
820
- "light-time:newtonian",
821
- "deflection:none",
822
- "aberration:backdated-observer",
823
- "moon:series-at-instant",
824
- "node:true-osculating",
825
- "precession:iau2006",
1236
+ ...onPack ? ["light-time:iterated", "deflection:sun-outside-disc", "aberration:relativistic-annual", "target:system-barycentre", "node:true-osculating", ...PACK_PLACE_IDS, "precession:iau2006"] : [
1237
+ "light-time:newtonian",
1238
+ "deflection:none",
1239
+ "aberration:backdated-observer",
1240
+ "moon:series-at-instant",
1241
+ "node:true-osculating",
1242
+ "precession:iau2006"
1243
+ ],
826
1244
  "nutation:iau2000b",
827
1245
  "obliquity:iau2006",
828
1246
  ...computed.houses === null ? [] : [
@@ -835,7 +1253,9 @@ function chart(request) {
835
1253
  `speed:central-difference-${STEP_DAYS}d`,
836
1254
  `speed:central-difference-${NODE_STEP_DAYS}d`
837
1255
  ],
838
- time.pin
1256
+ time.pin,
1257
+ true,
1258
+ computed.ephemeris
839
1259
  )
840
1260
  };
841
1261
  });
@@ -843,7 +1263,7 @@ function chart(request) {
843
1263
  export {
844
1264
  CALC_AYANAMSAS,
845
1265
  CALC_BODIES,
846
- CALC_FRAMES,
1266
+ CALC_FRAMES2 as CALC_FRAMES,
847
1267
  CALC_RECEIPT_SCHEMA,
848
1268
  CALC_SPAN,
849
1269
  calc,