@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.
- package/CHANGELOG.md +1478 -0
- package/LICENSING.md +184 -30
- package/NOTICE +81 -14
- package/README.md +345 -67
- package/dist/{api-VOW6Umy5.d.ts → api-ChL1N2Sr.d.ts} +44 -7
- package/dist/ayanamsa-ClFzkKmV.d.ts +135 -0
- package/dist/calc.d.ts +218 -21
- package/dist/calc.js +580 -160
- package/dist/chunk-2PZYJQV5.js +83 -0
- package/dist/chunk-47ERTK5X.js +27 -0
- package/dist/{chunk-O3NJRGJ2.js → chunk-4XOYTBLS.js} +1 -1
- package/dist/chunk-767FTO7O.js +48 -0
- package/dist/{chunk-N4B5JNMA.js → chunk-7Y2F2IWN.js} +40 -28
- package/dist/chunk-B4M2Y7FT.js +96 -0
- package/dist/{chunk-KHBLFXFG.js → chunk-B5LKF437.js} +29 -28
- package/dist/{chunk-ONBZ4HK7.js → chunk-BHJXUY67.js} +4 -2
- package/dist/{chunk-PFGUCNOK.js → chunk-BMDASNPB.js} +6 -6
- package/dist/chunk-I3L4POY7.js +18 -0
- package/dist/{chunk-I7O5EGFV.js → chunk-LNGURVNH.js} +3 -3
- package/dist/{chunk-4NV4ZEFZ.js → chunk-NNOSOOWS.js} +4 -4
- package/dist/chunk-OVXQQEXL.js +41 -0
- package/dist/{chunk-WOU7JVD3.js → chunk-QLIEEICB.js} +205 -194
- package/dist/chunk-RMBWKZI2.js +130 -0
- package/dist/{chunk-AECKV73C.js → chunk-TSS2SZWQ.js} +8 -2
- package/dist/{chunk-L6ZHWJZ6.js → chunk-TZVPZHZM.js} +51 -29
- package/dist/chunk-WBTWY2OB.js +478 -0
- package/dist/chunk-Y4E3WJU5.js +87 -0
- package/dist/chunk-YPU3MDNI.js +852 -0
- package/dist/conventions.d.ts +70 -0
- package/dist/conventions.js +26 -0
- package/dist/crossings.d.ts +22 -10
- package/dist/crossings.js +1 -1
- package/dist/de440-pack.d.ts +43 -0
- package/dist/de440-pack.js +16 -0
- package/dist/de440.d.ts +113 -0
- package/dist/de440.js +19 -0
- package/dist/deltat.d.ts +28 -3
- package/dist/deltat.js +1 -1
- package/dist/ephemeris-exTSqBgb.d.ts +60 -0
- package/dist/geo.d.ts +46 -13
- package/dist/geo.js +4 -2
- package/dist/{houses-q1O2GGp4.d.ts → houses-Bh7GCnPi.d.ts} +14 -4
- package/dist/houses-extra.d.ts +22 -7
- package/dist/houses-extra.js +4 -2
- package/dist/index.d.ts +36 -49
- package/dist/index.js +54 -34
- package/dist/{internal-math-CmJ9xtaW.d.ts → internal-math-CxenuGfm.d.ts} +41 -27
- package/dist/internal-math.d.ts +4 -3
- package/dist/internal-math.js +14 -12
- package/dist/internal.d.ts +16 -7
- package/dist/internal.js +27 -6
- package/dist/lite-composite.js +114 -0
- package/dist/lite-declinations.js +253 -0
- package/dist/lite-dignities.js +333 -0
- package/dist/lite-sect.js +72 -0
- package/dist/lite.d.ts +82 -0
- package/dist/lite.js +4 -0
- package/dist/receipt.d.ts +3 -268
- package/dist/receipt.js +202 -89
- package/dist/reference-span-CILpclrz.d.ts +40 -0
- package/dist/{rulers-9wljfVaO.d.ts → rulers-CSSWtiWF.d.ts} +7 -2
- package/dist/sky.d.ts +26 -10
- package/dist/sky.js +23 -14
- package/dist/techniques.d.ts +160 -21
- package/dist/techniques.js +157 -89
- package/dist/time-bands-CZA9AlLg.d.ts +36 -0
- package/dist/time-scale-DIFNa0gz.d.ts +47 -0
- package/dist/time.d.ts +81 -0
- package/dist/time.js +74 -0
- package/dist/timing.d.ts +55 -17
- package/dist/timing.js +33 -45
- package/dist/types-DpPdtXgO.d.ts +335 -0
- package/dist/vedic.d.ts +150 -123
- package/dist/vedic.js +398 -440
- package/dist/window.d.ts +102 -80
- package/dist/window.js +108 -51
- package/dist/zone-history-BxmDCcTK.d.ts +290 -0
- package/package.json +26 -3
- package/dist/chunk-2OWGBT3O.js +0 -219
- package/dist/types-B4MCoCCS.d.ts +0 -228
|
@@ -0,0 +1,852 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ARGUMENTS,
|
|
3
|
+
MULTIPLIERS,
|
|
4
|
+
NUTATION_TERMS,
|
|
5
|
+
OFFSETS,
|
|
6
|
+
coefficients
|
|
7
|
+
} from "./chunk-Y4E3WJU5.js";
|
|
8
|
+
|
|
9
|
+
// src/de440/pack.ts
|
|
10
|
+
var De440Error = class extends Error {
|
|
11
|
+
code;
|
|
12
|
+
constructor(code, message) {
|
|
13
|
+
super(message);
|
|
14
|
+
this.name = "De440Error";
|
|
15
|
+
this.code = code;
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
function fail(code, message) {
|
|
19
|
+
throw new De440Error(code, message);
|
|
20
|
+
}
|
|
21
|
+
var MAGIC_V2 = "ZODEPH02";
|
|
22
|
+
var TRAILER_BYTES = 32;
|
|
23
|
+
var PROLOGUE_BYTES = 16;
|
|
24
|
+
var LIMITS = /* @__PURE__ */ Object.freeze({
|
|
25
|
+
/** 256 MiB. */
|
|
26
|
+
maxFileBytes: 268435456,
|
|
27
|
+
/** 4 MiB. */
|
|
28
|
+
maxHeaderBytes: 4194304,
|
|
29
|
+
maxBodies: 64,
|
|
30
|
+
maxCoefficients: 512,
|
|
31
|
+
maxRecords: 2e7,
|
|
32
|
+
minIntervalSec: 1,
|
|
33
|
+
/** 4000 Julian years. */
|
|
34
|
+
maxIntervalSec: 1262304e5
|
|
35
|
+
});
|
|
36
|
+
var isSafeCount = (n) => Number.isSafeInteger(n) && n >= 0;
|
|
37
|
+
function safeExtent(where, a, b, c = 0) {
|
|
38
|
+
if (!isSafeCount(a) || !isSafeCount(b) || !isSafeCount(c)) {
|
|
39
|
+
fail("bad-header", `${where}: extent operands must be safe non-negative integers`);
|
|
40
|
+
}
|
|
41
|
+
const product = a * b;
|
|
42
|
+
if (!Number.isSafeInteger(product)) fail("bad-header", `${where}: extent overflows exact integer range`);
|
|
43
|
+
const total = product + c;
|
|
44
|
+
if (!Number.isSafeInteger(total)) fail("bad-header", `${where}: extent overflows exact integer range`);
|
|
45
|
+
return total;
|
|
46
|
+
}
|
|
47
|
+
function parsePack(u8) {
|
|
48
|
+
const total = u8.byteLength;
|
|
49
|
+
if (total > LIMITS.maxFileBytes) fail("too-large", `pack is ${total} bytes; the limit is ${LIMITS.maxFileBytes}`);
|
|
50
|
+
if (total < PROLOGUE_BYTES + TRAILER_BYTES + 2) fail("truncated", `pack is ${total} bytes, too short to be one`);
|
|
51
|
+
const magic = String.fromCharCode(...u8.subarray(0, 8));
|
|
52
|
+
if (magic !== MAGIC_V2) fail("not-a-pack", "not a sealed zodiacs ephemeris pack (ZODEPH02)");
|
|
53
|
+
const dv = new DataView(u8.buffer, u8.byteOffset, u8.byteLength);
|
|
54
|
+
const headerLen = dv.getUint32(8, true);
|
|
55
|
+
const payloadOffset = dv.getUint32(12, true);
|
|
56
|
+
if (headerLen === 0 || headerLen > LIMITS.maxHeaderBytes) {
|
|
57
|
+
fail("bad-header", `header length ${headerLen} is outside 1..${LIMITS.maxHeaderBytes}`);
|
|
58
|
+
}
|
|
59
|
+
const headerEnd = safeExtent("header", PROLOGUE_BYTES, 1, headerLen);
|
|
60
|
+
if (headerEnd > total) fail("truncated", `header claims ${headerLen} bytes; only ${total - PROLOGUE_BYTES} remain`);
|
|
61
|
+
if (payloadOffset < headerEnd || payloadOffset > total) {
|
|
62
|
+
fail("bad-header", `payload offset ${payloadOffset} is not inside the file after the header`);
|
|
63
|
+
}
|
|
64
|
+
let header;
|
|
65
|
+
try {
|
|
66
|
+
header = JSON.parse(new TextDecoder().decode(u8.subarray(PROLOGUE_BYTES, headerEnd)));
|
|
67
|
+
} catch (error) {
|
|
68
|
+
fail("bad-header", `header is not valid JSON: ${error.message}`);
|
|
69
|
+
}
|
|
70
|
+
if (!header || typeof header !== "object") fail("bad-header", "header is not an object");
|
|
71
|
+
const digestRegionEnd = total - TRAILER_BYTES;
|
|
72
|
+
const payloadEnd = header.payloadEndOffset;
|
|
73
|
+
if (!isSafeCount(payloadEnd)) fail("bad-header", "payloadEndOffset is not a safe non-negative integer");
|
|
74
|
+
if (payloadEnd > digestRegionEnd) {
|
|
75
|
+
fail("truncated", `header declares ${payloadEnd} bytes of pack; only ${digestRegionEnd} precede the digest trailer`);
|
|
76
|
+
}
|
|
77
|
+
if (header.format !== "zodiacs-ephemeris-pack") fail("bad-header", "format is not zodiacs-ephemeris-pack");
|
|
78
|
+
if (header.formatVersion !== 2) fail("unsupported-version", `formatVersion ${JSON.stringify(header.formatVersion)} is not 2`);
|
|
79
|
+
const conventions = header.conventions;
|
|
80
|
+
if (!conventions || conventions.chebyshev !== "spk-type-2" || conventions.units !== "km,km/s") {
|
|
81
|
+
fail("bad-header", "the pack does not declare SPK type-2 Chebyshev series in km and km/s");
|
|
82
|
+
}
|
|
83
|
+
const coverage = header.coverage;
|
|
84
|
+
const start = coverage?.startEtSecTdb;
|
|
85
|
+
const stop = coverage?.stopEtSecTdb;
|
|
86
|
+
if (typeof start !== "number" || typeof stop !== "number" || !Number.isFinite(start) || !Number.isFinite(stop) || !(stop > start)) {
|
|
87
|
+
fail("bad-header", "coverage is missing, not finite or not increasing");
|
|
88
|
+
}
|
|
89
|
+
const emrat = header.derived?.earth399?.emrat;
|
|
90
|
+
if (typeof emrat !== "number" || !Number.isFinite(emrat) || emrat < 80 || emrat > 83) {
|
|
91
|
+
fail("bad-header", "the pack carries no plausible Earth/Moon mass ratio");
|
|
92
|
+
}
|
|
93
|
+
const bodies = checkBodies(header.bodies, payloadOffset, payloadEnd, start, stop);
|
|
94
|
+
return { coverage: { startEtSecTdb: start, stopEtSecTdb: stop }, bodies, emrat, raw: header, payloadEnd, digestRegionEnd };
|
|
95
|
+
}
|
|
96
|
+
function checkBodies(list, payloadOffset, payloadEnd, covStart, covStop) {
|
|
97
|
+
if (!Array.isArray(list) || list.length === 0) fail("bad-header", "header declares no bodies");
|
|
98
|
+
if (list.length > LIMITS.maxBodies) fail("bad-header", `header declares ${list.length} bodies; the limit is ${LIMITS.maxBodies}`);
|
|
99
|
+
const seen = /* @__PURE__ */ new Set();
|
|
100
|
+
const spans = [];
|
|
101
|
+
for (const b of list) {
|
|
102
|
+
if (!b || typeof b.name !== "string" || b.name.length === 0 || b.name.length > 64) fail("bad-header", "a body has no usable name");
|
|
103
|
+
if (seen.has(b.name)) fail("bad-header", `body ${b.name} is declared twice`);
|
|
104
|
+
seen.add(b.name);
|
|
105
|
+
for (const [k, v] of [["ncoef", b.ncoef], ["nrec", b.nrec], ["offset", b.offset]]) {
|
|
106
|
+
if (!isSafeCount(v)) fail("bad-header", `body ${b.name}: ${k} is not a safe non-negative integer`);
|
|
107
|
+
}
|
|
108
|
+
if (b.ncoef < 2 || b.ncoef > LIMITS.maxCoefficients) fail("bad-header", `body ${b.name}: ncoef ${b.ncoef} is out of range`);
|
|
109
|
+
if (b.nrec < 1 || b.nrec > LIMITS.maxRecords) fail("bad-header", `body ${b.name}: nrec ${b.nrec} is out of range`);
|
|
110
|
+
if (!Number.isFinite(b.initEt)) fail("bad-header", `body ${b.name}: initEt is not finite`);
|
|
111
|
+
if (!Number.isFinite(b.intervalSec) || b.intervalSec < LIMITS.minIntervalSec || b.intervalSec > LIMITS.maxIntervalSec) {
|
|
112
|
+
fail("bad-header", `body ${b.name}: intervalSec ${b.intervalSec} is out of range`);
|
|
113
|
+
}
|
|
114
|
+
if (!["ssb", "sun", "native"].includes(b.frame)) fail("bad-header", `body ${b.name}: frame ${JSON.stringify(b.frame)} is not supported`);
|
|
115
|
+
const layout = b.layout;
|
|
116
|
+
if (!layout || typeof layout !== "object") fail("bad-header", `body ${b.name}: no layout`);
|
|
117
|
+
if (layout.enc !== "q" && layout.enc !== "f64") fail("bad-header", `body ${b.name}: encoding is not supported`);
|
|
118
|
+
for (const [k, v] of [["stride", layout.stride], ["midsOffset", layout.midsOffset], ["recordsOffset", layout.recordsOffset]]) {
|
|
119
|
+
if (!isSafeCount(v)) fail("bad-header", `body ${b.name}: layout.${k} is not a safe non-negative integer`);
|
|
120
|
+
}
|
|
121
|
+
if (layout.stride === 0) fail("bad-header", `body ${b.name}: layout.stride is zero`);
|
|
122
|
+
const fields = safeExtent(`body ${b.name} fields`, 3, b.ncoef);
|
|
123
|
+
if (layout.enc === "q") {
|
|
124
|
+
if (!Number.isFinite(layout.q) || layout.q <= 0) fail("bad-header", `body ${b.name}: quantum q must be finite and positive`);
|
|
125
|
+
if (!Array.isArray(layout.widths) || layout.widths.length !== fields) fail("bad-header", `body ${b.name}: widths has the wrong length`);
|
|
126
|
+
if (!Array.isArray(layout.fieldOffset) || layout.fieldOffset.length !== fields) fail("bad-header", `body ${b.name}: fieldOffset has the wrong length`);
|
|
127
|
+
for (let f = 0; f < fields; f += 1) {
|
|
128
|
+
const w = layout.widths[f];
|
|
129
|
+
const off = layout.fieldOffset[f];
|
|
130
|
+
if (![0, 1, 2, 3, 4, 5, 8].includes(w)) fail("bad-header", `body ${b.name}: field width ${w} is not supported`);
|
|
131
|
+
if (!isSafeCount(off)) fail("bad-header", `body ${b.name}: fieldOffset[${f}] is not a safe non-negative integer`);
|
|
132
|
+
if (safeExtent(`body ${b.name} field ${f}`, off, 1, w) > layout.stride) fail("bad-geometry", `body ${b.name}: field ${f} ends past the stride`);
|
|
133
|
+
}
|
|
134
|
+
if (safeExtent(`body ${b.name} mids`, fields, 8, layout.midsOffset) > layout.recordsOffset) {
|
|
135
|
+
fail("bad-geometry", `body ${b.name}: the mid-point table runs into the records`);
|
|
136
|
+
}
|
|
137
|
+
} else if (safeExtent(`body ${b.name} stride`, fields, 8) > layout.stride) {
|
|
138
|
+
fail("bad-geometry", `body ${b.name}: a float64 record does not fit the stride`);
|
|
139
|
+
}
|
|
140
|
+
const recBytes = safeExtent(`body ${b.name} records`, b.nrec, layout.stride, layout.recordsOffset);
|
|
141
|
+
const start = b.offset;
|
|
142
|
+
const end = safeExtent(`body ${b.name} end`, start, 1, recBytes);
|
|
143
|
+
if (start < payloadOffset) fail("bad-geometry", `body ${b.name} starts before the payload`);
|
|
144
|
+
if (end > payloadEnd) fail("truncated", `body ${b.name} runs past the payload`);
|
|
145
|
+
const spanEnd = b.initEt + b.nrec * b.intervalSec;
|
|
146
|
+
if (!Number.isFinite(spanEnd)) fail("bad-header", `body ${b.name}: record span is not finite`);
|
|
147
|
+
if (b.initEt > covStart + 1 || spanEnd < covStop - 1) fail("bad-geometry", `body ${b.name} does not span the pack's coverage`);
|
|
148
|
+
spans.push({ name: b.name, start, end });
|
|
149
|
+
}
|
|
150
|
+
spans.sort((x, y) => x.start - y.start);
|
|
151
|
+
for (let i = 1; i < spans.length; i += 1) {
|
|
152
|
+
if (spans[i].start < spans[i - 1].end) fail("bad-geometry", `bodies ${spans[i - 1].name} and ${spans[i].name} overlap`);
|
|
153
|
+
}
|
|
154
|
+
return list;
|
|
155
|
+
}
|
|
156
|
+
function readField(dv, base, w) {
|
|
157
|
+
switch (w) {
|
|
158
|
+
case 0:
|
|
159
|
+
return 0;
|
|
160
|
+
case 1:
|
|
161
|
+
return dv.getInt8(base);
|
|
162
|
+
case 2:
|
|
163
|
+
return dv.getInt16(base, true);
|
|
164
|
+
case 3: {
|
|
165
|
+
const lo = dv.getUint16(base, true);
|
|
166
|
+
const hi = dv.getInt8(base + 2);
|
|
167
|
+
return hi * 65536 + lo;
|
|
168
|
+
}
|
|
169
|
+
case 4:
|
|
170
|
+
return dv.getInt32(base, true);
|
|
171
|
+
case 5: {
|
|
172
|
+
const lo = dv.getUint32(base, true);
|
|
173
|
+
const hi = dv.getInt8(base + 4);
|
|
174
|
+
return hi * 4294967296 + lo;
|
|
175
|
+
}
|
|
176
|
+
default:
|
|
177
|
+
return dv.getFloat64(base, true);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
var PACK_NAME = /* @__PURE__ */ Object.freeze({
|
|
181
|
+
Mercury: "mercuryBary",
|
|
182
|
+
Venus: "venusBary",
|
|
183
|
+
Mars: "marsBary",
|
|
184
|
+
Jupiter: "jupiterBary",
|
|
185
|
+
Saturn: "saturnBary",
|
|
186
|
+
Uranus: "uranusBary",
|
|
187
|
+
Neptune: "neptuneBary",
|
|
188
|
+
Pluto: "plutoBary"
|
|
189
|
+
});
|
|
190
|
+
var PackEphemeris = class {
|
|
191
|
+
coverage;
|
|
192
|
+
u8;
|
|
193
|
+
bodies = /* @__PURE__ */ new Map();
|
|
194
|
+
k;
|
|
195
|
+
scratch = new Float64Array(6);
|
|
196
|
+
scratch2 = new Float64Array(6);
|
|
197
|
+
constructor(u8, header) {
|
|
198
|
+
this.u8 = u8;
|
|
199
|
+
this.coverage = header.coverage;
|
|
200
|
+
this.k = 1 / header.emrat;
|
|
201
|
+
for (const b of header.bodies) {
|
|
202
|
+
const fields = 3 * b.ncoef;
|
|
203
|
+
this.bodies.set(b.name, {
|
|
204
|
+
...b,
|
|
205
|
+
coefficients: new Float64Array(fields),
|
|
206
|
+
cachedRecord: -1,
|
|
207
|
+
mids: b.layout.enc === "q" ? this.readMids(b, fields) : null
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
for (const name of ["sun", "emb", "moon", ...Object.values(PACK_NAME)]) {
|
|
211
|
+
if (!this.bodies.has(name)) fail("bad-header", `the pack does not contain ${name}`);
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
window(offset, length) {
|
|
215
|
+
if (!Number.isSafeInteger(offset) || !Number.isSafeInteger(length) || offset < 0 || offset + length > this.u8.byteLength) fail("truncated", "a read runs past the end of the pack");
|
|
216
|
+
return new DataView(this.u8.buffer, this.u8.byteOffset + offset, length);
|
|
217
|
+
}
|
|
218
|
+
readMids(b, fields) {
|
|
219
|
+
const out = new Float64Array(fields);
|
|
220
|
+
const dv = this.window(b.offset + b.layout.midsOffset, fields * 8);
|
|
221
|
+
for (let i = 0; i < fields; i += 1) out[i] = dv.getFloat64(i * 8, true);
|
|
222
|
+
return out;
|
|
223
|
+
}
|
|
224
|
+
decode(b, record) {
|
|
225
|
+
if (b.cachedRecord === record) return;
|
|
226
|
+
const L = b.layout;
|
|
227
|
+
const fields = 3 * b.ncoef;
|
|
228
|
+
const base = b.offset + (L.enc === "f64" ? 0 : L.recordsOffset) + record * L.stride;
|
|
229
|
+
const dv = this.window(base, L.enc === "f64" ? fields * 8 : L.stride);
|
|
230
|
+
if (L.enc === "f64") {
|
|
231
|
+
for (let f = 0; f < fields; f += 1) b.coefficients[f] = dv.getFloat64(f * 8, true);
|
|
232
|
+
} else {
|
|
233
|
+
const { widths, fieldOffset, q } = L;
|
|
234
|
+
const mids = b.mids;
|
|
235
|
+
for (let f = 0; f < fields; f += 1) {
|
|
236
|
+
const w = widths[f];
|
|
237
|
+
b.coefficients[f] = w === 0 ? mids[f] : w === 8 ? readField(dv, fieldOffset[f], 8) : mids[f] + readField(dv, fieldOffset[f], w) * q;
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
b.cachedRecord = record;
|
|
241
|
+
}
|
|
242
|
+
/** Is `et` (TDB seconds past J2000) inside the pack's declared coverage? */
|
|
243
|
+
covers(et) {
|
|
244
|
+
const c = this.coverage;
|
|
245
|
+
return Number.isFinite(et) && et >= c.startEtSecTdb && et <= c.stopEtSecTdb;
|
|
246
|
+
}
|
|
247
|
+
boundaries(from, to) {
|
|
248
|
+
const found = /* @__PURE__ */ new Set();
|
|
249
|
+
if (!(from <= to)) return [];
|
|
250
|
+
for (const b of this.bodies.values()) {
|
|
251
|
+
const first = Math.max(1, Math.ceil((from - b.initEt) / b.intervalSec));
|
|
252
|
+
const last = Math.min(b.nrec - 1, Math.floor((to - b.initEt) / b.intervalSec));
|
|
253
|
+
for (let record = first; record <= last; record += 1) found.add(b.initEt + record * b.intervalSec);
|
|
254
|
+
}
|
|
255
|
+
return [...found].sort((x, y) => x - y);
|
|
256
|
+
}
|
|
257
|
+
/** Position (km) and velocity (km/s) of one stored body, as stored. */
|
|
258
|
+
raw(name, et, out) {
|
|
259
|
+
const b = this.bodies.get(name);
|
|
260
|
+
if (!b) return fail("unknown-body", `the pack does not contain ${name}`);
|
|
261
|
+
const span = b.nrec * b.intervalSec;
|
|
262
|
+
if (et < b.initEt || et > b.initEt + span) fail("out-of-coverage", `${name}: ${et} s TDB is outside the pack's records`);
|
|
263
|
+
let index = Math.floor((et - b.initEt) / b.intervalSec);
|
|
264
|
+
if (index < 0) index = 0;
|
|
265
|
+
if (index > b.nrec - 1) index = b.nrec - 1;
|
|
266
|
+
while (index > 0 && b.initEt + index * b.intervalSec > et) index -= 1;
|
|
267
|
+
while (index < b.nrec - 1 && b.initEt + (index + 1) * b.intervalSec <= et) index += 1;
|
|
268
|
+
this.decode(b, index);
|
|
269
|
+
const mid = b.initEt + (index + 0.5) * b.intervalSec;
|
|
270
|
+
const radius = b.intervalSec / 2;
|
|
271
|
+
const tau = (et - mid) / radius;
|
|
272
|
+
const n = b.ncoef;
|
|
273
|
+
const c = b.coefficients;
|
|
274
|
+
for (let comp = 0; comp < 3; comp += 1) {
|
|
275
|
+
const off = comp * n;
|
|
276
|
+
let b1 = 0;
|
|
277
|
+
let b2 = 0;
|
|
278
|
+
let d1 = 0;
|
|
279
|
+
let d2 = 0;
|
|
280
|
+
for (let k = n - 1; k >= 1; k -= 1) {
|
|
281
|
+
const t = b1;
|
|
282
|
+
b1 = 2 * tau * b1 - b2 + c[off + k];
|
|
283
|
+
b2 = t;
|
|
284
|
+
const td = d1;
|
|
285
|
+
d1 = 2 * tau * d1 - d2 + 2 * t;
|
|
286
|
+
d2 = td;
|
|
287
|
+
}
|
|
288
|
+
out[comp] = tau * b1 - b2 + c[off];
|
|
289
|
+
out[comp + 3] = (tau * d1 - d2 + b1) / radius;
|
|
290
|
+
}
|
|
291
|
+
return out;
|
|
292
|
+
}
|
|
293
|
+
ssb(name, et, out) {
|
|
294
|
+
const b = this.bodies.get(name);
|
|
295
|
+
this.raw(name, et, out);
|
|
296
|
+
if (b.frame === "sun") {
|
|
297
|
+
this.raw("sun", et, this.scratch2);
|
|
298
|
+
for (let i = 0; i < 6; i += 1) out[i] = out[i] + this.scratch2[i];
|
|
299
|
+
}
|
|
300
|
+
return out;
|
|
301
|
+
}
|
|
302
|
+
/** A body relative to the solar-system barycentre: Sun, Earth, Moon, Mercury to Pluto (Mars to Pluto as system barycentres). */
|
|
303
|
+
state(body, et, out) {
|
|
304
|
+
if (out === this.scratch || out === this.scratch2) fail("bad-header", "state(): out must not be an internal buffer");
|
|
305
|
+
if (body === "Sun") return this.ssb("sun", et, out);
|
|
306
|
+
if (body === "Moon" || body === "Earth") {
|
|
307
|
+
this.ssb("emb", et, out);
|
|
308
|
+
this.ssb("moon", et, this.scratch);
|
|
309
|
+
const f = body === "Moon" ? 1 : -this.k;
|
|
310
|
+
for (let i = 0; i < 6; i += 1) out[i] = out[i] + f * this.scratch[i];
|
|
311
|
+
return out;
|
|
312
|
+
}
|
|
313
|
+
const key = PACK_NAME[body];
|
|
314
|
+
if (!key) return fail("unknown-body", `unknown body ${body}`);
|
|
315
|
+
return this.ssb(key, et, out);
|
|
316
|
+
}
|
|
317
|
+
lunar(et, emb, moon, earth) {
|
|
318
|
+
this.ssb("emb", et, emb);
|
|
319
|
+
this.ssb("moon", et, moon);
|
|
320
|
+
const f = -this.k;
|
|
321
|
+
for (let i = 0; i < 6; i += 1) earth[i] = f * moon[i];
|
|
322
|
+
}
|
|
323
|
+
};
|
|
324
|
+
|
|
325
|
+
// src/de440/nutation.ts
|
|
326
|
+
var TURNAS = 1296e3;
|
|
327
|
+
var DAS2R = Math.PI / (180 * 3600);
|
|
328
|
+
var D2PI = 2 * Math.PI;
|
|
329
|
+
var U2A = 1e-7;
|
|
330
|
+
var fmod = (x, y) => x % y;
|
|
331
|
+
var arcsecArg = (a) => fmod(a, TURNAS) * DAS2R;
|
|
332
|
+
var rows;
|
|
333
|
+
function series() {
|
|
334
|
+
if (!rows) {
|
|
335
|
+
const c = coefficients();
|
|
336
|
+
const out = [];
|
|
337
|
+
for (let i = 0; i < NUTATION_TERMS; i += 1) {
|
|
338
|
+
const row = [];
|
|
339
|
+
for (let k = 0; k < 5; k += 1) row.push(Number(MULTIPLIERS[i * 5 + k]) - 2);
|
|
340
|
+
for (let k = 0; k < 6; k += 1) row.push(c[i * 6 + k]);
|
|
341
|
+
out.push(row);
|
|
342
|
+
}
|
|
343
|
+
rows = out;
|
|
344
|
+
}
|
|
345
|
+
return rows;
|
|
346
|
+
}
|
|
347
|
+
function nut00b(t) {
|
|
348
|
+
const [l0, l1, lp0, lp1, f0, f1, d0, d1, om0, om1] = ARGUMENTS;
|
|
349
|
+
const el = arcsecArg(l0 + l1 * t);
|
|
350
|
+
const elp = arcsecArg(lp0 + lp1 * t);
|
|
351
|
+
const f = arcsecArg(f0 + f1 * t);
|
|
352
|
+
const d = arcsecArg(d0 + d1 * t);
|
|
353
|
+
const om = arcsecArg(om0 + om1 * t);
|
|
354
|
+
let dp = 0;
|
|
355
|
+
let de = 0;
|
|
356
|
+
const terms = series();
|
|
357
|
+
for (let i = terms.length - 1; i >= 0; i -= 1) {
|
|
358
|
+
const r = terms[i];
|
|
359
|
+
const arg = fmod(r[0] * el + r[1] * elp + r[2] * f + r[3] * d + r[4] * om, D2PI);
|
|
360
|
+
const s = Math.sin(arg);
|
|
361
|
+
const c = Math.cos(arg);
|
|
362
|
+
dp += (r[5] + r[6] * t) * s + r[7] * c;
|
|
363
|
+
de += (r[8] + r[9] * t) * c + r[10] * s;
|
|
364
|
+
}
|
|
365
|
+
return { dpsi: dp * U2A + OFFSETS[0], deps: de * U2A + OFFSETS[1] };
|
|
366
|
+
}
|
|
367
|
+
function meanObliquityArcsec(t) {
|
|
368
|
+
return ((((-434e-10 * t - 576e-9) * t + 20034e-7) * t - 1831e-7) * t - 46.836769) * t + 84381.406;
|
|
369
|
+
}
|
|
370
|
+
function adjustToP03(nut, t) {
|
|
371
|
+
const fj2 = -27774e-10 * t;
|
|
372
|
+
return {
|
|
373
|
+
dpsi: nut.dpsi + nut.dpsi * (4697e-10 + fj2),
|
|
374
|
+
deps: nut.deps + nut.deps * fj2
|
|
375
|
+
};
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
// src/de440/frames.ts
|
|
379
|
+
var DAS2R2 = Math.PI / (180 * 3600);
|
|
380
|
+
function mul(a, b) {
|
|
381
|
+
const row = (r) => [
|
|
382
|
+
r[0] * b[0][0] + r[1] * b[1][0] + r[2] * b[2][0],
|
|
383
|
+
r[0] * b[0][1] + r[1] * b[1][1] + r[2] * b[2][1],
|
|
384
|
+
r[0] * b[0][2] + r[1] * b[1][2] + r[2] * b[2][2]
|
|
385
|
+
];
|
|
386
|
+
return [row(a[0]), row(a[1]), row(a[2])];
|
|
387
|
+
}
|
|
388
|
+
function apply(m, v) {
|
|
389
|
+
return [
|
|
390
|
+
m[0][0] * v[0] + m[0][1] * v[1] + m[0][2] * v[2],
|
|
391
|
+
m[1][0] * v[0] + m[1][1] * v[1] + m[1][2] * v[2],
|
|
392
|
+
m[2][0] * v[0] + m[2][1] * v[1] + m[2][2] * v[2]
|
|
393
|
+
];
|
|
394
|
+
}
|
|
395
|
+
var R1 = (a) => {
|
|
396
|
+
const s = Math.sin(a);
|
|
397
|
+
const c = Math.cos(a);
|
|
398
|
+
return [
|
|
399
|
+
[1, 0, 0],
|
|
400
|
+
[0, c, s],
|
|
401
|
+
[0, -s, c]
|
|
402
|
+
];
|
|
403
|
+
};
|
|
404
|
+
var R3 = (a) => {
|
|
405
|
+
const s = Math.sin(a);
|
|
406
|
+
const c = Math.cos(a);
|
|
407
|
+
return [
|
|
408
|
+
[c, s, 0],
|
|
409
|
+
[-s, c, 0],
|
|
410
|
+
[0, 0, 1]
|
|
411
|
+
];
|
|
412
|
+
};
|
|
413
|
+
function pfw06(t) {
|
|
414
|
+
const gamb = (-0.052928 + (10.556378 + (0.4932044 + (-31238e-8 + (-2788e-9 + 26e-9 * t) * t) * t) * t) * t) * DAS2R2;
|
|
415
|
+
const phib = (84381.412819 + (-46.811016 + (0.0511268 + (53289e-8 + (-44e-8 + -176e-10 * t) * t) * t) * t) * t) * DAS2R2;
|
|
416
|
+
const psib = (-0.041775 + (5038.481484 + (1.5584175 + (-18522e-8 + (-26452e-9 + -148e-10 * t) * t) * t) * t) * t) * DAS2R2;
|
|
417
|
+
const epsa = meanObliquityArcsec(t) * DAS2R2;
|
|
418
|
+
return { gamb, phib, psib, epsa };
|
|
419
|
+
}
|
|
420
|
+
function fw2m(gamb, phib, psi, eps) {
|
|
421
|
+
return mul(R1(-eps), mul(R3(-psi), mul(R1(phib), R3(gamb))));
|
|
422
|
+
}
|
|
423
|
+
function npbMatrix(t) {
|
|
424
|
+
const nut = adjustToP03(nut00b(t), t);
|
|
425
|
+
const { gamb, phib, psib, epsa } = pfw06(t);
|
|
426
|
+
const matrix = fw2m(gamb, phib, psib + nut.dpsi * DAS2R2, epsa + nut.deps * DAS2R2);
|
|
427
|
+
return { matrix, epsTrue: epsa + nut.deps * DAS2R2, dpsiArcsec: nut.dpsi, depsArcsec: nut.deps };
|
|
428
|
+
}
|
|
429
|
+
function equToEcl(v, epsTrue) {
|
|
430
|
+
const c = Math.cos(epsTrue);
|
|
431
|
+
const s = Math.sin(epsTrue);
|
|
432
|
+
return [v[0], v[1] * c + v[2] * s, -v[1] * s + v[2] * c];
|
|
433
|
+
}
|
|
434
|
+
function eclipticLonLatDeg(v) {
|
|
435
|
+
let lon = Math.atan2(v[1], v[0]) * 180 / Math.PI;
|
|
436
|
+
if (lon < 0) lon += 360;
|
|
437
|
+
const lat = Math.atan2(v[2], Math.sqrt(v[0] * v[0] + v[1] * v[1])) * 180 / Math.PI;
|
|
438
|
+
return { lon, lat };
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
// src/de440/reduce.ts
|
|
442
|
+
var AU_KM = 1495978707e-1;
|
|
443
|
+
var LIGHT_TIME_AU = 499.004783836;
|
|
444
|
+
var C_KM_S = AU_KM / LIGHT_TIME_AU;
|
|
445
|
+
var DAY = 86400;
|
|
446
|
+
var SRS = 197412574336e-19;
|
|
447
|
+
var LIGHT_TIME_ITERATIONS = 12;
|
|
448
|
+
var LIGHT_TIME_TOLERANCE_SEC = 1e-11;
|
|
449
|
+
var DEFLECTION_LIMIT = 1e-14;
|
|
450
|
+
var SUN_RADIUS_KM = 695700;
|
|
451
|
+
var NEAR_DISC_COS = Math.cos(Math.PI / 180 / 3);
|
|
452
|
+
var ACCELERATION_STEP_SEC = 60;
|
|
453
|
+
var REDUCED_BODIES = /* @__PURE__ */ Object.freeze([
|
|
454
|
+
"Sun",
|
|
455
|
+
"Moon",
|
|
456
|
+
"Mercury",
|
|
457
|
+
"Venus",
|
|
458
|
+
"Mars",
|
|
459
|
+
"Jupiter",
|
|
460
|
+
"Saturn",
|
|
461
|
+
"Uranus",
|
|
462
|
+
"Neptune",
|
|
463
|
+
"Pluto"
|
|
464
|
+
]);
|
|
465
|
+
var BARYCENTRE_NOT_CENTRE = /* @__PURE__ */ Object.freeze(["Mars", "Jupiter", "Saturn", "Uranus", "Neptune", "Pluto"]);
|
|
466
|
+
var norm = (v) => Math.sqrt(v[0] * v[0] + v[1] * v[1] + v[2] * v[2]);
|
|
467
|
+
var sub = (a, b) => [a[0] - b[0], a[1] - b[1], a[2] - b[2]];
|
|
468
|
+
var addv = (a, b) => [a[0] + b[0], a[1] + b[1], a[2] + b[2]];
|
|
469
|
+
var scale = (v, k) => [v[0] * k, v[1] * k, v[2] * k];
|
|
470
|
+
var unit = (v) => scale(v, 1 / norm(v));
|
|
471
|
+
var dot = (a, b) => a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
|
|
472
|
+
var cross = (a, b) => [a[1] * b[2] - a[2] * b[1], a[2] * b[0] - a[0] * b[2], a[0] * b[1] - a[1] * b[0]];
|
|
473
|
+
var position = (s) => [s[0], s[1], s[2]];
|
|
474
|
+
var velocity = (s) => [s[3], s[4], s[5]];
|
|
475
|
+
function tdbMinusTt(jdTt) {
|
|
476
|
+
const g = (357.53 + 0.9856003 * (jdTt - 2451545)) * Math.PI / 180;
|
|
477
|
+
const l = (246.11 + 0.90251792 * (jdTt - 2451545)) * Math.PI / 180;
|
|
478
|
+
return 1658e-6 * Math.sin(g) + 14e-6 * Math.sin(2 * g) + 224e-7 * Math.sin(l);
|
|
479
|
+
}
|
|
480
|
+
function etOf(ttDays) {
|
|
481
|
+
const jdTt = ttDays + 2451545;
|
|
482
|
+
return ttDays * DAY + tdbMinusTt(jdTt);
|
|
483
|
+
}
|
|
484
|
+
var Reducer = class {
|
|
485
|
+
backend;
|
|
486
|
+
a = new Float64Array(6);
|
|
487
|
+
b = new Float64Array(6);
|
|
488
|
+
c = new Float64Array(6);
|
|
489
|
+
emb = new Float64Array(6);
|
|
490
|
+
moon = new Float64Array(6);
|
|
491
|
+
earth = new Float64Array(6);
|
|
492
|
+
constructor(backend) {
|
|
493
|
+
this.backend = backend;
|
|
494
|
+
}
|
|
495
|
+
pos(body, et, buf) {
|
|
496
|
+
this.backend.state(body, et, buf);
|
|
497
|
+
return position(buf);
|
|
498
|
+
}
|
|
499
|
+
/** The Earth relative to the barycentre at et, and the barycentre's velocity and acceleration there. */
|
|
500
|
+
lunarBasis(et) {
|
|
501
|
+
this.backend.lunar(et + ACCELERATION_STEP_SEC, this.emb, this.moon, this.earth);
|
|
502
|
+
const after = velocity(this.emb);
|
|
503
|
+
this.backend.lunar(et - ACCELERATION_STEP_SEC, this.emb, this.moon, this.earth);
|
|
504
|
+
const before = velocity(this.emb);
|
|
505
|
+
this.backend.lunar(et, this.emb, this.moon, this.earth);
|
|
506
|
+
const span = 2 * ACCELERATION_STEP_SEC;
|
|
507
|
+
return {
|
|
508
|
+
earth: position(this.earth),
|
|
509
|
+
embVelocity: velocity(this.emb),
|
|
510
|
+
embAcceleration: [(after[0] - before[0]) / span, (after[1] - before[1]) / span, (after[2] - before[2]) / span]
|
|
511
|
+
};
|
|
512
|
+
}
|
|
513
|
+
/** MoonRelEMB(emission) - EarthRelEMB(et) + (-v tau + a tau^2 / 2). */
|
|
514
|
+
geocentricMoon(emission, tau, basis) {
|
|
515
|
+
this.backend.lunar(emission, this.emb, this.moon, this.earth);
|
|
516
|
+
const m = position(this.moon);
|
|
517
|
+
const v = basis.embVelocity;
|
|
518
|
+
const acc = basis.embAcceleration;
|
|
519
|
+
const e = basis.earth;
|
|
520
|
+
return [
|
|
521
|
+
m[0] - e[0] + (-v[0] * tau + 0.5 * acc[0] * tau * tau),
|
|
522
|
+
m[1] - e[1] + (-v[1] * tau + 0.5 * acc[1] * tau * tau),
|
|
523
|
+
m[2] - e[2] + (-v[2] * tau + 0.5 * acc[2] * tau * tau)
|
|
524
|
+
];
|
|
525
|
+
}
|
|
526
|
+
/**
|
|
527
|
+
* The apparent place of `body` at `ttDays` (TT days past J2000). `behind`,
|
|
528
|
+
* when given, is taken as whether the body is behind the Sun's disc instead
|
|
529
|
+
* of deciding it at `ttDays`: a speed's two samples take the decision of the
|
|
530
|
+
* instant the speed is for, so that it is the rate of the place on that
|
|
531
|
+
* instant's side of the step at the limb, not the step.
|
|
532
|
+
*/
|
|
533
|
+
apparent(body, ttDays, behind) {
|
|
534
|
+
if (!REDUCED_BODIES.includes(body)) fail("unknown-body", `${String(body)} is not a body this reduction places`);
|
|
535
|
+
if (!Number.isFinite(ttDays)) fail("bad-instant", "ttDays must be a finite number");
|
|
536
|
+
const jdTt = ttDays + 2451545;
|
|
537
|
+
const et = ttDays * DAY + tdbMinusTt(jdTt);
|
|
538
|
+
const t = ttDays / 36525;
|
|
539
|
+
if (!this.backend.covers(et)) fail("out-of-coverage", "the instant is outside the pack's coverage");
|
|
540
|
+
this.backend.state("Earth", et, this.b);
|
|
541
|
+
const observer = position(this.b);
|
|
542
|
+
const observerVel = velocity(this.b);
|
|
543
|
+
const lunar = body === "Moon" ? this.lunarBasis(et) : null;
|
|
544
|
+
const geoAt = (tau2) => lunar ? this.geocentricMoon(et - tau2, tau2, lunar) : sub(this.pos(body, et - tau2, this.a), observer);
|
|
545
|
+
let tau = 0;
|
|
546
|
+
let geo = geoAt(0);
|
|
547
|
+
for (let i = 0; i < LIGHT_TIME_ITERATIONS; i += 1) {
|
|
548
|
+
const next = norm(geo) / AU_KM * LIGHT_TIME_AU;
|
|
549
|
+
if (Math.abs(next - tau) < LIGHT_TIME_TOLERANCE_SEC) {
|
|
550
|
+
tau = next;
|
|
551
|
+
break;
|
|
552
|
+
}
|
|
553
|
+
tau = next;
|
|
554
|
+
if (!this.backend.covers(et - tau)) fail("out-of-coverage", "the light-time lookback reaches outside the pack's coverage");
|
|
555
|
+
geo = geoAt(tau);
|
|
556
|
+
}
|
|
557
|
+
const distKm = norm(geo);
|
|
558
|
+
let p = unit(geo);
|
|
559
|
+
const sunAtRecv = body === "Sun" ? null : this.pos("Sun", et, this.c);
|
|
560
|
+
const behindDisc = sunAtRecv !== null && (behind ?? this.behindDisc(p, distKm, et, observer, sunAtRecv));
|
|
561
|
+
if (sunAtRecv !== null && !behindDisc) {
|
|
562
|
+
const eVec = sub(observer, sunAtRecv);
|
|
563
|
+
const emAu = norm(eVec) / AU_KM;
|
|
564
|
+
const e = unit(eVec);
|
|
565
|
+
const sunAtEmit = this.pos("Sun", et - tau, this.c);
|
|
566
|
+
const q = unit(sub(addv(observer, geo), sunAtEmit));
|
|
567
|
+
const qdqpe = dot(q, addv(q, e));
|
|
568
|
+
const w = SRS / emAu / Math.max(qdqpe, DEFLECTION_LIMIT);
|
|
569
|
+
const peq = cross(p, cross(e, q));
|
|
570
|
+
p = unit(addv(p, scale(peq, w)));
|
|
571
|
+
}
|
|
572
|
+
const v = scale(observerVel, 1 / C_KM_S);
|
|
573
|
+
const v2 = dot(v, v);
|
|
574
|
+
const bm1 = Math.sqrt(1 - v2);
|
|
575
|
+
const pdv = dot(p, v);
|
|
576
|
+
const w1 = 1 + pdv / (1 + bm1);
|
|
577
|
+
p = unit([(bm1 * p[0] + w1 * v[0]) / (1 + pdv), (bm1 * p[1] + w1 * v[1]) / (1 + pdv), (bm1 * p[2] + w1 * v[2]) / (1 + pdv)]);
|
|
578
|
+
if (!Number.isFinite(p[0]) || !Number.isFinite(p[1]) || !Number.isFinite(p[2]) || !Number.isFinite(distKm)) {
|
|
579
|
+
fail("bad-geometry-of-sky", `${body} has no determinable direction at this instant`);
|
|
580
|
+
}
|
|
581
|
+
const { matrix, epsTrue } = npbMatrix(t);
|
|
582
|
+
const { lon, lat } = eclipticLonLatDeg(equToEcl(apply(matrix, p), epsTrue));
|
|
583
|
+
return { lon, lat, distKm, lightTimeSec: tau, behindDisc };
|
|
584
|
+
}
|
|
585
|
+
/**
|
|
586
|
+
* Whether a body at geometric direction `p` (a unit vector) and distance
|
|
587
|
+
* `distKm` from the observer at `observer` is behind the Sun's disc at
|
|
588
|
+
* `et`: farther than the Sun, and within its apparent radius of the Sun's
|
|
589
|
+
* direction, the Sun taken at its own light time.
|
|
590
|
+
*/
|
|
591
|
+
behindDisc(p, distKm, et, observer, sunAtRecv) {
|
|
592
|
+
const near = sub(sunAtRecv, observer);
|
|
593
|
+
if (!(distKm > norm(near)) || dot(p, unit(near)) < NEAR_DISC_COS) return false;
|
|
594
|
+
const sun = sub(this.pos("Sun", et - norm(near) / AU_KM * LIGHT_TIME_AU, this.c), observer);
|
|
595
|
+
const d = norm(sun);
|
|
596
|
+
if (!(distKm > d)) return false;
|
|
597
|
+
const s = unit(sun);
|
|
598
|
+
const apart = Math.atan2(norm(cross(p, s)), dot(p, s));
|
|
599
|
+
return apart < Math.asin(SUN_RADIUS_KM / d);
|
|
600
|
+
}
|
|
601
|
+
/**
|
|
602
|
+
* The instants in [fromTtDays, toTtDays] (TT days past J2000) at which a
|
|
603
|
+
* place this reduction gives, or the true node, may step by more than
|
|
604
|
+
* rounding, in ascending order: where one of its reads passes a record
|
|
605
|
+
* boundary of the pack. For each boundary B (TDB) of any stored series
|
|
606
|
+
* these are B itself (the observer, the Sun at reception, the node), B - 60 s
|
|
607
|
+
* and B + 60 s (the two reads the barycentre's acceleration is differenced
|
|
608
|
+
* from), and for each body the instant whose light left it at B (its own
|
|
609
|
+
* state, and the Sun's at emission). The list is one for every body: a
|
|
610
|
+
* superset for each. Between two neighbours of it every read stays inside
|
|
611
|
+
* one record of every series, so each place is a smooth function of time.
|
|
612
|
+
*/
|
|
613
|
+
steps(fromTtDays, toTtDays) {
|
|
614
|
+
if (!Number.isFinite(fromTtDays) || !Number.isFinite(toTtDays)) fail("bad-instant", "ttDays must be a finite number");
|
|
615
|
+
const coverage = { from: etOf(fromTtDays), to: etOf(toTtDays) };
|
|
616
|
+
const instants = [];
|
|
617
|
+
const ttOf = (et) => (et - tdbMinusTt(et / DAY + 2451545)) / DAY;
|
|
618
|
+
for (const boundary of this.backend.boundaries(coverage.from - DAY, coverage.to + 2 * ACCELERATION_STEP_SEC)) {
|
|
619
|
+
instants.push(boundary, boundary - ACCELERATION_STEP_SEC, boundary + ACCELERATION_STEP_SEC);
|
|
620
|
+
for (const body of REDUCED_BODIES) {
|
|
621
|
+
let at = boundary;
|
|
622
|
+
for (let round = 0; round < 4; round += 1) {
|
|
623
|
+
if (!this.backend.covers(at) || !this.backend.covers(at - DAY)) break;
|
|
624
|
+
at = boundary + this.apparent(body, ttOf(at)).lightTimeSec;
|
|
625
|
+
}
|
|
626
|
+
instants.push(at);
|
|
627
|
+
}
|
|
628
|
+
}
|
|
629
|
+
return [...new Set(instants.map(ttOf))].filter((tt) => tt >= fromTtDays && tt <= toTtDays).sort((x, y) => x - y);
|
|
630
|
+
}
|
|
631
|
+
/**
|
|
632
|
+
* The Moon's true node: the ascending node, on the true ecliptic and
|
|
633
|
+
* equinox of date, of the plane of r x v, r and v the Moon's geometric
|
|
634
|
+
* geocentric position and velocity in the ICRF at TDB (no light-time,
|
|
635
|
+
* aberration or deflection). Degrees in [0, 360).
|
|
636
|
+
*/
|
|
637
|
+
trueNode(ttDays) {
|
|
638
|
+
if (!Number.isFinite(ttDays)) fail("bad-instant", "ttDays must be a finite number");
|
|
639
|
+
const jdTt = ttDays + 2451545;
|
|
640
|
+
const et = ttDays * DAY + tdbMinusTt(jdTt);
|
|
641
|
+
const t = ttDays / 36525;
|
|
642
|
+
if (!this.backend.covers(et)) fail("out-of-coverage", "the instant is outside the pack's coverage");
|
|
643
|
+
this.backend.lunar(et, this.emb, this.moon, this.earth);
|
|
644
|
+
const r = sub(position(this.moon), position(this.earth));
|
|
645
|
+
const vel = sub(velocity(this.moon), velocity(this.earth));
|
|
646
|
+
const h = cross(r, vel);
|
|
647
|
+
const { matrix, epsTrue } = npbMatrix(t);
|
|
648
|
+
const ecl = equToEcl(apply(matrix, h), epsTrue);
|
|
649
|
+
let lon = Math.atan2(ecl[0], -ecl[1]) * 180 / Math.PI;
|
|
650
|
+
if (lon < 0) lon += 360;
|
|
651
|
+
return lon;
|
|
652
|
+
}
|
|
653
|
+
};
|
|
654
|
+
|
|
655
|
+
// src/de440/sha256.ts
|
|
656
|
+
var K = /* @__PURE__ */ new Uint32Array([
|
|
657
|
+
1116352408,
|
|
658
|
+
1899447441,
|
|
659
|
+
3049323471,
|
|
660
|
+
3921009573,
|
|
661
|
+
961987163,
|
|
662
|
+
1508970993,
|
|
663
|
+
2453635748,
|
|
664
|
+
2870763221,
|
|
665
|
+
3624381080,
|
|
666
|
+
310598401,
|
|
667
|
+
607225278,
|
|
668
|
+
1426881987,
|
|
669
|
+
1925078388,
|
|
670
|
+
2162078206,
|
|
671
|
+
2614888103,
|
|
672
|
+
3248222580,
|
|
673
|
+
3835390401,
|
|
674
|
+
4022224774,
|
|
675
|
+
264347078,
|
|
676
|
+
604807628,
|
|
677
|
+
770255983,
|
|
678
|
+
1249150122,
|
|
679
|
+
1555081692,
|
|
680
|
+
1996064986,
|
|
681
|
+
2554220882,
|
|
682
|
+
2821834349,
|
|
683
|
+
2952996808,
|
|
684
|
+
3210313671,
|
|
685
|
+
3336571891,
|
|
686
|
+
3584528711,
|
|
687
|
+
113926993,
|
|
688
|
+
338241895,
|
|
689
|
+
666307205,
|
|
690
|
+
773529912,
|
|
691
|
+
1294757372,
|
|
692
|
+
1396182291,
|
|
693
|
+
1695183700,
|
|
694
|
+
1986661051,
|
|
695
|
+
2177026350,
|
|
696
|
+
2456956037,
|
|
697
|
+
2730485921,
|
|
698
|
+
2820302411,
|
|
699
|
+
3259730800,
|
|
700
|
+
3345764771,
|
|
701
|
+
3516065817,
|
|
702
|
+
3600352804,
|
|
703
|
+
4094571909,
|
|
704
|
+
275423344,
|
|
705
|
+
430227734,
|
|
706
|
+
506948616,
|
|
707
|
+
659060556,
|
|
708
|
+
883997877,
|
|
709
|
+
958139571,
|
|
710
|
+
1322822218,
|
|
711
|
+
1537002063,
|
|
712
|
+
1747873779,
|
|
713
|
+
1955562222,
|
|
714
|
+
2024104815,
|
|
715
|
+
2227730452,
|
|
716
|
+
2361852424,
|
|
717
|
+
2428436474,
|
|
718
|
+
2756734187,
|
|
719
|
+
3204031479,
|
|
720
|
+
3329325298
|
|
721
|
+
]);
|
|
722
|
+
function sha256Hex(bytes) {
|
|
723
|
+
const h = new Uint32Array([1779033703, 3144134277, 1013904242, 2773480762, 1359893119, 2600822924, 528734635, 1541459225]);
|
|
724
|
+
const w = new Uint32Array(64);
|
|
725
|
+
const length = bytes.byteLength;
|
|
726
|
+
const tail = new Uint8Array(length % 64 + 9 > 64 ? 128 : 64);
|
|
727
|
+
tail.set(bytes.subarray(length - length % 64));
|
|
728
|
+
tail[length % 64] = 128;
|
|
729
|
+
const bits = length * 8;
|
|
730
|
+
const view = new DataView(tail.buffer);
|
|
731
|
+
view.setUint32(tail.length - 8, Math.floor(bits / 4294967296));
|
|
732
|
+
view.setUint32(tail.length - 4, bits >>> 0);
|
|
733
|
+
const block = (data, at) => {
|
|
734
|
+
for (let i = 0; i < 16; i += 1) {
|
|
735
|
+
const o = at + i * 4;
|
|
736
|
+
w[i] = (data[o] << 24 | data[o + 1] << 16 | data[o + 2] << 8 | data[o + 3]) >>> 0;
|
|
737
|
+
}
|
|
738
|
+
for (let i = 16; i < 64; i += 1) {
|
|
739
|
+
const a2 = w[i - 15];
|
|
740
|
+
const b2 = w[i - 2];
|
|
741
|
+
const s0 = (a2 >>> 7 | a2 << 25) ^ (a2 >>> 18 | a2 << 14) ^ a2 >>> 3;
|
|
742
|
+
const s1 = (b2 >>> 17 | b2 << 15) ^ (b2 >>> 19 | b2 << 13) ^ b2 >>> 10;
|
|
743
|
+
w[i] = w[i - 16] + s0 + w[i - 7] + s1 >>> 0;
|
|
744
|
+
}
|
|
745
|
+
let a = h[0], b = h[1], c = h[2], d = h[3], e = h[4], f = h[5], g = h[6], k = h[7];
|
|
746
|
+
for (let i = 0; i < 64; i += 1) {
|
|
747
|
+
const s1 = (e >>> 6 | e << 26) ^ (e >>> 11 | e << 21) ^ (e >>> 25 | e << 7);
|
|
748
|
+
const t1 = k + s1 + (e & f ^ ~e & g) + K[i] + w[i] >>> 0;
|
|
749
|
+
const s0 = (a >>> 2 | a << 30) ^ (a >>> 13 | a << 19) ^ (a >>> 22 | a << 10);
|
|
750
|
+
const t2 = s0 + (a & b ^ a & c ^ b & c) >>> 0;
|
|
751
|
+
k = g;
|
|
752
|
+
g = f;
|
|
753
|
+
f = e;
|
|
754
|
+
e = d + t1 >>> 0;
|
|
755
|
+
d = c;
|
|
756
|
+
c = b;
|
|
757
|
+
b = a;
|
|
758
|
+
a = t1 + t2 >>> 0;
|
|
759
|
+
}
|
|
760
|
+
h[0] = h[0] + a >>> 0;
|
|
761
|
+
h[1] = h[1] + b >>> 0;
|
|
762
|
+
h[2] = h[2] + c >>> 0;
|
|
763
|
+
h[3] = h[3] + d >>> 0;
|
|
764
|
+
h[4] = h[4] + e >>> 0;
|
|
765
|
+
h[5] = h[5] + f >>> 0;
|
|
766
|
+
h[6] = h[6] + g >>> 0;
|
|
767
|
+
h[7] = h[7] + k >>> 0;
|
|
768
|
+
};
|
|
769
|
+
for (let at = 0; at + 64 <= length; at += 64) block(bytes, at);
|
|
770
|
+
for (let at = 0; at < tail.length; at += 64) block(tail, at);
|
|
771
|
+
return Array.from(h, (word) => word.toString(16).padStart(8, "0")).join("");
|
|
772
|
+
}
|
|
773
|
+
|
|
774
|
+
// src/de440.ts
|
|
775
|
+
var DE440_EPHEMERIS_NAME = "jpl-de440";
|
|
776
|
+
var AU_KM2 = 1495978707e-1;
|
|
777
|
+
var hex = (buffer) => Array.from(new Uint8Array(buffer), (b) => b.toString(16).padStart(2, "0")).join("");
|
|
778
|
+
async function sha256Hex2(view) {
|
|
779
|
+
const subtle = globalThis.crypto?.subtle;
|
|
780
|
+
if (!subtle) throw new TypeError("openDe440Pack needs WebCrypto (crypto.subtle) to check the pack's digest");
|
|
781
|
+
const copy = new Uint8Array(view.byteLength);
|
|
782
|
+
copy.set(view);
|
|
783
|
+
return hex(await subtle.digest("SHA-256", copy.buffer));
|
|
784
|
+
}
|
|
785
|
+
async function openDe440Pack(bytes, options) {
|
|
786
|
+
if (!(bytes instanceof Uint8Array)) throw new TypeError("openDe440Pack: bytes must be a Uint8Array");
|
|
787
|
+
const expect = options?.expectDigest;
|
|
788
|
+
if (typeof expect !== "string" || !/^[0-9a-f]{64}$/.test(expect)) {
|
|
789
|
+
throw new TypeError("openDe440Pack: expectDigest must be 64 lower-case hexadecimal digits");
|
|
790
|
+
}
|
|
791
|
+
const copy = new Uint8Array(bytes.byteLength);
|
|
792
|
+
copy.set(bytes);
|
|
793
|
+
const digest = await sha256Hex2(copy);
|
|
794
|
+
if (digest !== expect) throw new De440Error("digest-mismatch", "the pack's SHA-256 is not the one expected");
|
|
795
|
+
const header = parsePack(copy);
|
|
796
|
+
const trailer = Array.from(copy.subarray(header.digestRegionEnd), (b) => b.toString(16).padStart(2, "0")).join("");
|
|
797
|
+
if (await sha256Hex2(copy.subarray(0, header.digestRegionEnd)) !== trailer) {
|
|
798
|
+
throw new De440Error("digest-mismatch", "the pack's own trailer does not match its contents");
|
|
799
|
+
}
|
|
800
|
+
return sourceOf(copy, digest, header);
|
|
801
|
+
}
|
|
802
|
+
function sourceOf(copy, digest, header) {
|
|
803
|
+
const reducer = new Reducer(new PackEphemeris(copy, header));
|
|
804
|
+
const compiler = header.raw.compiler;
|
|
805
|
+
const pack = Object.freeze({
|
|
806
|
+
sha256: digest,
|
|
807
|
+
bytes: copy.byteLength,
|
|
808
|
+
startEtSecTdb: header.coverage.startEtSecTdb,
|
|
809
|
+
stopEtSecTdb: header.coverage.stopEtSecTdb,
|
|
810
|
+
compiler: typeof compiler?.name === "string" && typeof compiler.version === "string" ? Object.freeze({ name: compiler.name, version: compiler.version }) : null
|
|
811
|
+
});
|
|
812
|
+
return Object.freeze({
|
|
813
|
+
ephemeris: Object.freeze({ name: DE440_EPHEMERIS_NAME, version: digest }),
|
|
814
|
+
pack,
|
|
815
|
+
place(body, ttDays, behind) {
|
|
816
|
+
const place = reducer.apparent(body, ttDays, behind);
|
|
817
|
+
return { lon: place.lon, lat: place.lat, dist: place.distKm / AU_KM2, behindDisc: place.behindDisc };
|
|
818
|
+
},
|
|
819
|
+
trueNode(ttDays) {
|
|
820
|
+
return reducer.trueNode(ttDays);
|
|
821
|
+
},
|
|
822
|
+
steps(fromTtDays, toTtDays) {
|
|
823
|
+
return reducer.steps(fromTtDays, toTtDays);
|
|
824
|
+
}
|
|
825
|
+
});
|
|
826
|
+
}
|
|
827
|
+
function openDe440PackSync(bytes, options) {
|
|
828
|
+
if (!(bytes instanceof Uint8Array)) throw new TypeError("openDe440PackSync: bytes must be a Uint8Array");
|
|
829
|
+
const expect = options?.expectDigest;
|
|
830
|
+
if (typeof expect !== "string" || !/^[0-9a-f]{64}$/.test(expect)) {
|
|
831
|
+
throw new TypeError("openDe440PackSync: expectDigest must be 64 lower-case hexadecimal digits");
|
|
832
|
+
}
|
|
833
|
+
const copy = new Uint8Array(bytes.byteLength);
|
|
834
|
+
copy.set(bytes);
|
|
835
|
+
const digest = sha256Hex(copy);
|
|
836
|
+
if (digest !== expect) throw new De440Error("digest-mismatch", "the pack's SHA-256 is not the one expected");
|
|
837
|
+
const header = parsePack(copy);
|
|
838
|
+
const trailer = Array.from(copy.subarray(header.digestRegionEnd), (b) => b.toString(16).padStart(2, "0")).join("");
|
|
839
|
+
if (sha256Hex(copy.subarray(0, header.digestRegionEnd)) !== trailer) {
|
|
840
|
+
throw new De440Error("digest-mismatch", "the pack's own trailer does not match its contents");
|
|
841
|
+
}
|
|
842
|
+
return sourceOf(copy, digest, header);
|
|
843
|
+
}
|
|
844
|
+
|
|
845
|
+
export {
|
|
846
|
+
De440Error,
|
|
847
|
+
REDUCED_BODIES,
|
|
848
|
+
BARYCENTRE_NOT_CENTRE,
|
|
849
|
+
DE440_EPHEMERIS_NAME,
|
|
850
|
+
openDe440Pack,
|
|
851
|
+
openDe440PackSync
|
|
852
|
+
};
|