@zodiacs/engine 0.1.1-rc.14
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 +502 -0
- package/LICENSE +21 -0
- package/LICENSING.md +99 -0
- package/NOTICE +58 -0
- package/README.md +785 -0
- package/dist/chunk-4OSOCZY2.js +340 -0
- package/dist/chunk-AECKV73C.js +231 -0
- package/dist/chunk-CPALRSPC.js +35 -0
- package/dist/chunk-GFT24GFR.js +25 -0
- package/dist/chunk-NAJ735VN.js +219 -0
- package/dist/chunk-ONBZ4HK7.js +285 -0
- package/dist/chunk-PFGUCNOK.js +87 -0
- package/dist/chunk-RETEVD4F.js +681 -0
- package/dist/crossings.d.ts +91 -0
- package/dist/crossings.js +8 -0
- package/dist/deltat.d.ts +73 -0
- package/dist/deltat.js +12 -0
- package/dist/geo.d.ts +58 -0
- package/dist/geo.js +312 -0
- package/dist/index.d.ts +478 -0
- package/dist/index.js +682 -0
- package/dist/internal-math-BE2hcSHd.d.ts +271 -0
- package/dist/internal-math.d.ts +3 -0
- package/dist/internal-math.js +76 -0
- package/dist/internal.d.ts +9 -0
- package/dist/internal.js +16 -0
- package/dist/receipt.d.ts +224 -0
- package/dist/receipt.js +824 -0
- package/dist/types-CeafogFp.d.ts +197 -0
- package/package.json +94 -0
|
@@ -0,0 +1,340 @@
|
|
|
1
|
+
import {
|
|
2
|
+
normalizeLongitude
|
|
3
|
+
} from "./chunk-NAJ735VN.js";
|
|
4
|
+
|
|
5
|
+
// src/houses.ts
|
|
6
|
+
var DEG = Math.PI / 180;
|
|
7
|
+
var RAD = 180 / Math.PI;
|
|
8
|
+
var HOUSE_SYSTEMS = [
|
|
9
|
+
"whole",
|
|
10
|
+
"placidus",
|
|
11
|
+
"porphyry",
|
|
12
|
+
"equal",
|
|
13
|
+
"equal-mc",
|
|
14
|
+
"vehlow",
|
|
15
|
+
"koch",
|
|
16
|
+
"regiomontanus",
|
|
17
|
+
"campanus",
|
|
18
|
+
"topocentric",
|
|
19
|
+
"alcabitius",
|
|
20
|
+
"morinus",
|
|
21
|
+
"meridian"
|
|
22
|
+
];
|
|
23
|
+
var POLAR_UNDEFINED_HOUSE_SYSTEMS = ["placidus", "koch"];
|
|
24
|
+
var POLAR_FALLBACK = "whole";
|
|
25
|
+
var PLACIDUS_POLAR_FALLBACK = POLAR_FALLBACK;
|
|
26
|
+
function isPolarUndefinedHouseSystem(system) {
|
|
27
|
+
return POLAR_UNDEFINED_HOUSE_SYSTEMS.includes(system);
|
|
28
|
+
}
|
|
29
|
+
function meanObliquity(julianCenturies) {
|
|
30
|
+
const t = julianCenturies;
|
|
31
|
+
const arcseconds = 84381.406 - 46.836769 * t - 1831e-7 * t * t + 20034e-7 * t ** 3 - 576e-9 * t ** 4 - 434e-10 * t ** 5;
|
|
32
|
+
return arcseconds / 3600;
|
|
33
|
+
}
|
|
34
|
+
function eclipticLongitudeOfRightAscension(ra, obliquity) {
|
|
35
|
+
return normalizeLongitude(
|
|
36
|
+
Math.atan2(Math.sin(ra * DEG), Math.cos(ra * DEG) * Math.cos(obliquity * DEG)) * RAD
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
function declinationOfLongitude(lon, obliquity) {
|
|
40
|
+
return Math.asin(Math.sin(obliquity * DEG) * Math.sin(lon * DEG)) * RAD;
|
|
41
|
+
}
|
|
42
|
+
function obliqueLongitude(ascension, pole, obliquity) {
|
|
43
|
+
const a = ascension * DEG;
|
|
44
|
+
const e = obliquity * DEG;
|
|
45
|
+
return normalizeLongitude(
|
|
46
|
+
Math.atan2(Math.sin(a), Math.cos(a) * Math.cos(e) - Math.tan(pole * DEG) * Math.sin(e)) * RAD
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
function quadrantCusps(asc, mc, cusp11, cusp12, cusp2, cusp3) {
|
|
50
|
+
return [
|
|
51
|
+
asc,
|
|
52
|
+
cusp2,
|
|
53
|
+
cusp3,
|
|
54
|
+
mc + 180,
|
|
55
|
+
cusp11 + 180,
|
|
56
|
+
cusp12 + 180,
|
|
57
|
+
asc + 180,
|
|
58
|
+
cusp2 + 180,
|
|
59
|
+
cusp3 + 180,
|
|
60
|
+
mc,
|
|
61
|
+
cusp11,
|
|
62
|
+
cusp12
|
|
63
|
+
].map(normalizeLongitude);
|
|
64
|
+
}
|
|
65
|
+
function ramcOf(input) {
|
|
66
|
+
return normalizeLongitude(input.gastHours * 15 + input.longitude);
|
|
67
|
+
}
|
|
68
|
+
function computeAngles(input) {
|
|
69
|
+
const ramc = ramcOf(input);
|
|
70
|
+
const mc = eclipticLongitudeOfRightAscension(ramc, input.obliquity);
|
|
71
|
+
const ra = ramc * DEG;
|
|
72
|
+
const eps = input.obliquity * DEG;
|
|
73
|
+
const phi = input.latitude * DEG;
|
|
74
|
+
let asc = normalizeLongitude(
|
|
75
|
+
Math.atan2(Math.cos(ra), -(Math.sin(ra) * Math.cos(eps) + Math.tan(phi) * Math.sin(eps))) * RAD
|
|
76
|
+
);
|
|
77
|
+
if (normalizeLongitude(asc - mc) >= 180) asc = normalizeLongitude(asc + 180);
|
|
78
|
+
return {
|
|
79
|
+
asc,
|
|
80
|
+
mc,
|
|
81
|
+
dsc: normalizeLongitude(asc + 180),
|
|
82
|
+
ic: normalizeLongitude(mc + 180)
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
function wholeSignCusps(ascendant) {
|
|
86
|
+
const first = Math.floor(normalizeLongitude(ascendant) / 30) * 30;
|
|
87
|
+
return Array.from({ length: 12 }, (_, index) => normalizeLongitude(first + index * 30));
|
|
88
|
+
}
|
|
89
|
+
function placidusCusps(input, angles) {
|
|
90
|
+
if (Math.abs(input.latitude) >= 90 - input.obliquity) return null;
|
|
91
|
+
const ramc = ramcOf(input);
|
|
92
|
+
const phi = input.latitude * DEG;
|
|
93
|
+
function iterate(offset, multiplier) {
|
|
94
|
+
let ra = ramc + offset;
|
|
95
|
+
let converged = false;
|
|
96
|
+
for (let index = 0; index < 64; index += 1) {
|
|
97
|
+
const lon = eclipticLongitudeOfRightAscension(normalizeLongitude(ra), input.obliquity);
|
|
98
|
+
const declination = declinationOfLongitude(lon, input.obliquity);
|
|
99
|
+
const argument = Math.tan(phi) * Math.tan(declination * DEG);
|
|
100
|
+
if (Math.abs(argument) >= 1) return null;
|
|
101
|
+
const ascensionalDifference = Math.asin(argument) * RAD;
|
|
102
|
+
const next = ramc + offset + multiplier * ascensionalDifference;
|
|
103
|
+
if (Math.abs(normalizeLongitude(next - ra + 180) - 180) < 1e-9) {
|
|
104
|
+
ra = next;
|
|
105
|
+
converged = true;
|
|
106
|
+
break;
|
|
107
|
+
}
|
|
108
|
+
ra = next;
|
|
109
|
+
}
|
|
110
|
+
return converged ? eclipticLongitudeOfRightAscension(normalizeLongitude(ra), input.obliquity) : null;
|
|
111
|
+
}
|
|
112
|
+
const cusp11 = iterate(30, 1 / 3);
|
|
113
|
+
const cusp12 = iterate(60, 2 / 3);
|
|
114
|
+
const cusp2 = iterate(120, 2 / 3);
|
|
115
|
+
const cusp3 = iterate(150, 1 / 3);
|
|
116
|
+
if (cusp11 === null || cusp12 === null || cusp2 === null || cusp3 === null) {
|
|
117
|
+
return null;
|
|
118
|
+
}
|
|
119
|
+
return [
|
|
120
|
+
angles.asc,
|
|
121
|
+
cusp2,
|
|
122
|
+
cusp3,
|
|
123
|
+
angles.ic,
|
|
124
|
+
normalizeLongitude(cusp11 + 180),
|
|
125
|
+
normalizeLongitude(cusp12 + 180),
|
|
126
|
+
angles.dsc,
|
|
127
|
+
normalizeLongitude(cusp2 + 180),
|
|
128
|
+
normalizeLongitude(cusp3 + 180),
|
|
129
|
+
angles.mc,
|
|
130
|
+
cusp11,
|
|
131
|
+
cusp12
|
|
132
|
+
];
|
|
133
|
+
}
|
|
134
|
+
function porphyryCusps(angles) {
|
|
135
|
+
const upper = normalizeLongitude(angles.asc - angles.mc);
|
|
136
|
+
const lower = normalizeLongitude(angles.ic - angles.asc);
|
|
137
|
+
const cusp11 = normalizeLongitude(angles.mc + upper / 3);
|
|
138
|
+
const cusp12 = normalizeLongitude(angles.mc + 2 * upper / 3);
|
|
139
|
+
const cusp2 = normalizeLongitude(angles.asc + lower / 3);
|
|
140
|
+
const cusp3 = normalizeLongitude(angles.asc + 2 * lower / 3);
|
|
141
|
+
return [
|
|
142
|
+
angles.asc,
|
|
143
|
+
cusp2,
|
|
144
|
+
cusp3,
|
|
145
|
+
angles.ic,
|
|
146
|
+
normalizeLongitude(cusp11 + 180),
|
|
147
|
+
normalizeLongitude(cusp12 + 180),
|
|
148
|
+
angles.dsc,
|
|
149
|
+
normalizeLongitude(cusp2 + 180),
|
|
150
|
+
normalizeLongitude(cusp3 + 180),
|
|
151
|
+
angles.mc,
|
|
152
|
+
cusp11,
|
|
153
|
+
cusp12
|
|
154
|
+
];
|
|
155
|
+
}
|
|
156
|
+
function equalCusps(angles) {
|
|
157
|
+
return Array.from({ length: 12 }, (_, index) => normalizeLongitude(angles.asc + index * 30));
|
|
158
|
+
}
|
|
159
|
+
function equalMcCusps(angles) {
|
|
160
|
+
return Array.from({ length: 12 }, (_, index) => normalizeLongitude(angles.mc + (index - 9) * 30));
|
|
161
|
+
}
|
|
162
|
+
function vehlowCusps(angles) {
|
|
163
|
+
return Array.from({ length: 12 }, (_, index) => normalizeLongitude(angles.asc - 15 + index * 30));
|
|
164
|
+
}
|
|
165
|
+
function kochCusps(input, angles) {
|
|
166
|
+
if (Math.abs(input.latitude) >= 90 - input.obliquity) return null;
|
|
167
|
+
const ramc = ramcOf(input);
|
|
168
|
+
const argument = Math.tan(input.latitude * DEG) * Math.tan(declinationOfLongitude(angles.mc, input.obliquity) * DEG);
|
|
169
|
+
const third = (90 + Math.asin(argument) * RAD) / 3;
|
|
170
|
+
const at = (offset) => obliqueLongitude(ramc + 90 + offset, input.latitude, input.obliquity);
|
|
171
|
+
return quadrantCusps(angles.asc, angles.mc, at(-2 * third), at(-third), at(third), at(2 * third));
|
|
172
|
+
}
|
|
173
|
+
function circleCusps(input, angles, circles) {
|
|
174
|
+
const ramc = ramcOf(input);
|
|
175
|
+
const [c11, c12, c2, c3] = circles.map(
|
|
176
|
+
([ascension, pole]) => obliqueLongitude(ramc + ascension, pole, input.obliquity)
|
|
177
|
+
);
|
|
178
|
+
const asc = obliqueLongitude(ramc + 90, input.latitude, input.obliquity);
|
|
179
|
+
const cusps = quadrantCusps(asc, angles.mc, c11, c12, c2, c3);
|
|
180
|
+
const turned = normalizeLongitude(asc - angles.mc) >= 180;
|
|
181
|
+
return turned ? cusps.map((cusp) => normalizeLongitude(cusp + 180)) : cusps;
|
|
182
|
+
}
|
|
183
|
+
function regiomontanusCusps(input, angles) {
|
|
184
|
+
const tangent = Math.tan(input.latitude * DEG);
|
|
185
|
+
const near = Math.atan(tangent * 0.5) * RAD;
|
|
186
|
+
const far = Math.atan(tangent * Math.cos(30 * DEG)) * RAD;
|
|
187
|
+
return circleCusps(input, angles, [
|
|
188
|
+
[30, near],
|
|
189
|
+
[60, far],
|
|
190
|
+
[120, far],
|
|
191
|
+
[150, near]
|
|
192
|
+
]);
|
|
193
|
+
}
|
|
194
|
+
function campanusCusps(input, angles) {
|
|
195
|
+
const sine = Math.sin(input.latitude * DEG);
|
|
196
|
+
const cosine = Math.cos(input.latitude * DEG);
|
|
197
|
+
const near = Math.asin(sine / 2) * RAD;
|
|
198
|
+
const far = Math.asin(Math.sqrt(3) / 2 * sine) * RAD;
|
|
199
|
+
const wide = Math.atan(Math.sqrt(3) / cosine) * RAD;
|
|
200
|
+
const narrow = Math.atan(1 / (Math.sqrt(3) * cosine)) * RAD;
|
|
201
|
+
return circleCusps(input, angles, [
|
|
202
|
+
[90 - wide, near],
|
|
203
|
+
[90 - narrow, far],
|
|
204
|
+
[90 + narrow, far],
|
|
205
|
+
[90 + wide, near]
|
|
206
|
+
]);
|
|
207
|
+
}
|
|
208
|
+
function topocentricCusps(input, angles) {
|
|
209
|
+
const tangent = Math.tan(input.latitude * DEG);
|
|
210
|
+
const near = Math.atan(tangent / 3) * RAD;
|
|
211
|
+
const far = Math.atan(tangent * 2 / 3) * RAD;
|
|
212
|
+
return circleCusps(input, angles, [
|
|
213
|
+
[30, near],
|
|
214
|
+
[60, far],
|
|
215
|
+
[120, far],
|
|
216
|
+
[150, near]
|
|
217
|
+
]);
|
|
218
|
+
}
|
|
219
|
+
function alcabitiusCusps(input, angles) {
|
|
220
|
+
const ramc = ramcOf(input);
|
|
221
|
+
const declination = declinationOfLongitude(angles.asc, input.obliquity);
|
|
222
|
+
const argument = -Math.tan(input.latitude * DEG) * Math.tan(declination * DEG);
|
|
223
|
+
const day = Math.acos(Math.min(1, Math.max(-1, argument))) * RAD;
|
|
224
|
+
const night = 180 - day;
|
|
225
|
+
const at = (ascension) => obliqueLongitude(ramc + ascension, 0, input.obliquity);
|
|
226
|
+
return quadrantCusps(
|
|
227
|
+
angles.asc,
|
|
228
|
+
angles.mc,
|
|
229
|
+
at(day / 3),
|
|
230
|
+
at(2 * day / 3),
|
|
231
|
+
at(180 - 2 * night / 3),
|
|
232
|
+
at(180 - night / 3)
|
|
233
|
+
);
|
|
234
|
+
}
|
|
235
|
+
function equatorialCusps(input, project) {
|
|
236
|
+
const ramc = ramcOf(input);
|
|
237
|
+
return Array.from({ length: 12 }, (_, index) => project(ramc + 90 + index * 30));
|
|
238
|
+
}
|
|
239
|
+
function meridianCusps(input) {
|
|
240
|
+
return equatorialCusps(input, (ascension) => obliqueLongitude(ascension, 0, input.obliquity));
|
|
241
|
+
}
|
|
242
|
+
function morinusCusps(input) {
|
|
243
|
+
const e = input.obliquity * DEG;
|
|
244
|
+
return equatorialCusps(
|
|
245
|
+
input,
|
|
246
|
+
(ascension) => normalizeLongitude(
|
|
247
|
+
Math.atan2(Math.sin(ascension * DEG) * Math.cos(e), Math.cos(ascension * DEG)) * RAD
|
|
248
|
+
)
|
|
249
|
+
);
|
|
250
|
+
}
|
|
251
|
+
function eastPointOf(input) {
|
|
252
|
+
return obliqueLongitude(ramcOf(input) + 90, 0, input.obliquity);
|
|
253
|
+
}
|
|
254
|
+
function vertexOf(input, angles) {
|
|
255
|
+
const colatitude = input.latitude >= 0 ? 90 - input.latitude : -90 - input.latitude;
|
|
256
|
+
const vertex = obliqueLongitude(ramcOf(input) - 90, colatitude, input.obliquity);
|
|
257
|
+
return normalizeLongitude(vertex - angles.mc) >= 180 ? vertex : normalizeLongitude(vertex + 180);
|
|
258
|
+
}
|
|
259
|
+
function computeHouses(system, input, angles) {
|
|
260
|
+
const as = (cusps) => ({
|
|
261
|
+
houses: { system, cusps },
|
|
262
|
+
fellBack: false,
|
|
263
|
+
fallbackSystem: null
|
|
264
|
+
});
|
|
265
|
+
const polar = (cusps) => cusps ? as(cusps) : {
|
|
266
|
+
houses: { system: POLAR_FALLBACK, cusps: wholeSignCusps(angles.asc) },
|
|
267
|
+
fellBack: true,
|
|
268
|
+
fallbackSystem: POLAR_FALLBACK
|
|
269
|
+
};
|
|
270
|
+
switch (system) {
|
|
271
|
+
case "placidus":
|
|
272
|
+
return polar(placidusCusps(input, angles));
|
|
273
|
+
case "koch":
|
|
274
|
+
return polar(kochCusps(input, angles));
|
|
275
|
+
case "porphyry":
|
|
276
|
+
return as(porphyryCusps(angles));
|
|
277
|
+
case "equal":
|
|
278
|
+
return as(equalCusps(angles));
|
|
279
|
+
case "equal-mc":
|
|
280
|
+
return as(equalMcCusps(angles));
|
|
281
|
+
case "vehlow":
|
|
282
|
+
return as(vehlowCusps(angles));
|
|
283
|
+
case "regiomontanus":
|
|
284
|
+
return as(regiomontanusCusps(input, angles));
|
|
285
|
+
case "campanus":
|
|
286
|
+
return as(campanusCusps(input, angles));
|
|
287
|
+
case "topocentric":
|
|
288
|
+
return as(topocentricCusps(input, angles));
|
|
289
|
+
case "alcabitius":
|
|
290
|
+
return as(alcabitiusCusps(input, angles));
|
|
291
|
+
case "morinus":
|
|
292
|
+
return as(morinusCusps(input));
|
|
293
|
+
case "meridian":
|
|
294
|
+
return as(meridianCusps(input));
|
|
295
|
+
case "whole":
|
|
296
|
+
return as(wholeSignCusps(angles.asc));
|
|
297
|
+
default:
|
|
298
|
+
throw new RangeError(`Unknown house system ${String(system)}.`);
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
function houseOf(longitude, cusps) {
|
|
302
|
+
if (cusps.length !== 12) throw new RangeError("House cusps must contain 12 longitudes.");
|
|
303
|
+
for (let index = 0; index < 12; index += 1) {
|
|
304
|
+
const start = cusps[index];
|
|
305
|
+
const end = cusps[(index + 1) % 12];
|
|
306
|
+
if (start === void 0 || end === void 0) continue;
|
|
307
|
+
const span = normalizeLongitude(end - start);
|
|
308
|
+
const offset = normalizeLongitude(longitude - start);
|
|
309
|
+
if (offset < span || span === 0) return index + 1;
|
|
310
|
+
}
|
|
311
|
+
return 12;
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
export {
|
|
315
|
+
HOUSE_SYSTEMS,
|
|
316
|
+
POLAR_UNDEFINED_HOUSE_SYSTEMS,
|
|
317
|
+
POLAR_FALLBACK,
|
|
318
|
+
PLACIDUS_POLAR_FALLBACK,
|
|
319
|
+
isPolarUndefinedHouseSystem,
|
|
320
|
+
meanObliquity,
|
|
321
|
+
ramcOf,
|
|
322
|
+
computeAngles,
|
|
323
|
+
wholeSignCusps,
|
|
324
|
+
placidusCusps,
|
|
325
|
+
porphyryCusps,
|
|
326
|
+
equalCusps,
|
|
327
|
+
equalMcCusps,
|
|
328
|
+
vehlowCusps,
|
|
329
|
+
kochCusps,
|
|
330
|
+
regiomontanusCusps,
|
|
331
|
+
campanusCusps,
|
|
332
|
+
topocentricCusps,
|
|
333
|
+
alcabitiusCusps,
|
|
334
|
+
meridianCusps,
|
|
335
|
+
morinusCusps,
|
|
336
|
+
eastPointOf,
|
|
337
|
+
vertexOf,
|
|
338
|
+
computeHouses,
|
|
339
|
+
houseOf
|
|
340
|
+
};
|
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
// src/crossings.ts
|
|
2
|
+
var DAY = 864e5;
|
|
3
|
+
var REFINE_STEPS = 24;
|
|
4
|
+
var EDGE_PROBE_MAX_MS = 6e4;
|
|
5
|
+
var DUPLICATE_MS = 1e3;
|
|
6
|
+
var GOLDEN = (Math.sqrt(5) - 1) / 2;
|
|
7
|
+
var SampleBudgetReached = class {
|
|
8
|
+
};
|
|
9
|
+
function signedDelta(from, to) {
|
|
10
|
+
const difference = ((to - from) % 360 + 360) % 360;
|
|
11
|
+
return difference > 180 ? difference - 360 : difference;
|
|
12
|
+
}
|
|
13
|
+
function turn(before, after) {
|
|
14
|
+
if (before > 0 && after <= 0 || before === 0 && after < 0) return 1;
|
|
15
|
+
if (before < 0 && after >= 0 || before === 0 && after > 0) return -1;
|
|
16
|
+
return 0;
|
|
17
|
+
}
|
|
18
|
+
function sameSideNear(...offsets) {
|
|
19
|
+
const side = Math.sign(offsets[0] ?? 0);
|
|
20
|
+
return offsets.every(
|
|
21
|
+
(offset) => offset !== 0 && Math.abs(offset) < 90 && Math.sign(offset) === side
|
|
22
|
+
);
|
|
23
|
+
}
|
|
24
|
+
function reachOf(before, middle, after) {
|
|
25
|
+
const g0 = signedDelta(before.longitude, middle.longitude);
|
|
26
|
+
const g1 = signedDelta(middle.longitude, after.longitude);
|
|
27
|
+
const h0 = middle.time - before.time;
|
|
28
|
+
const h1 = after.time - middle.time;
|
|
29
|
+
return 2 * Math.abs(g1 / h1 - g0 / h0) / (h0 + h1) * Math.max(h0, h1) ** 2;
|
|
30
|
+
}
|
|
31
|
+
function windowTime(date, label) {
|
|
32
|
+
if (!(date instanceof Date)) throw new RangeError(`${label} must be a valid Date.`);
|
|
33
|
+
const milliseconds = Date.prototype.getTime.call(date);
|
|
34
|
+
if (!Number.isFinite(milliseconds)) throw new RangeError(`${label} must be a valid Date.`);
|
|
35
|
+
return milliseconds;
|
|
36
|
+
}
|
|
37
|
+
function validWindow(targetLongitude, from, to, stepDays) {
|
|
38
|
+
const fromTime = windowTime(from, "Crossing window start");
|
|
39
|
+
const toTime = windowTime(to, "Crossing window end");
|
|
40
|
+
if (fromTime > toTime) throw new RangeError("Crossing window must have from <= to.");
|
|
41
|
+
if (!Number.isFinite(targetLongitude)) throw new RangeError("targetLongitude must be finite.");
|
|
42
|
+
if (typeof stepDays !== "number" || !Number.isFinite(stepDays) || stepDays <= 0) {
|
|
43
|
+
throw new RangeError("stepDays must be positive.");
|
|
44
|
+
}
|
|
45
|
+
const step = stepDays * DAY;
|
|
46
|
+
if (!Number.isFinite(step) || step < 1) {
|
|
47
|
+
throw new RangeError("stepDays must represent a finite step of at least one millisecond.");
|
|
48
|
+
}
|
|
49
|
+
return { fromTime, toTime, step };
|
|
50
|
+
}
|
|
51
|
+
function validBudget(maxSamples) {
|
|
52
|
+
if (maxSamples === void 0 || maxSamples === Number.POSITIVE_INFINITY) {
|
|
53
|
+
return Number.POSITIVE_INFINITY;
|
|
54
|
+
}
|
|
55
|
+
if (!Number.isInteger(maxSamples) || maxSamples < 1) {
|
|
56
|
+
throw new RangeError("maxSamples must be a positive integer or Infinity.");
|
|
57
|
+
}
|
|
58
|
+
return maxSamples;
|
|
59
|
+
}
|
|
60
|
+
function coarseSampleCount({ fromTime, toTime, step }) {
|
|
61
|
+
const estimate = Math.ceil((toTime - fromTime) / step) - 1;
|
|
62
|
+
if (!(estimate < 2 ** 52)) return estimate + 2;
|
|
63
|
+
let interior = Math.max(0, estimate);
|
|
64
|
+
while (interior > 0 && fromTime + interior * step >= toTime) interior -= 1;
|
|
65
|
+
while (fromTime + (interior + 1) * step < toTime) interior += 1;
|
|
66
|
+
return interior + 2;
|
|
67
|
+
}
|
|
68
|
+
function solve(longitudeAt, targetLongitude, { fromTime, toTime, step }, count) {
|
|
69
|
+
const found = [];
|
|
70
|
+
const offsetAt = (time) => signedDelta(targetLongitude, longitudeAt(time));
|
|
71
|
+
const sampleAt = (time) => {
|
|
72
|
+
const longitude = longitudeAt(time);
|
|
73
|
+
return { time, longitude, offset: signedDelta(targetLongitude, longitude) };
|
|
74
|
+
};
|
|
75
|
+
const keep = (time, retrograde) => {
|
|
76
|
+
if (time > fromTime && time <= toTime) found.push({ at: new Date(time), retrograde });
|
|
77
|
+
};
|
|
78
|
+
const bisect = (low, high, rising) => {
|
|
79
|
+
let lower = low;
|
|
80
|
+
let upper = high;
|
|
81
|
+
for (let iteration = 0; iteration < REFINE_STEPS; iteration += 1) {
|
|
82
|
+
const middle = (lower + upper) / 2;
|
|
83
|
+
if (offsetAt(middle) > 0 === rising) upper = middle;
|
|
84
|
+
else lower = middle;
|
|
85
|
+
}
|
|
86
|
+
return upper;
|
|
87
|
+
};
|
|
88
|
+
const completePair = (low, high, maximize, side) => {
|
|
89
|
+
let a = low;
|
|
90
|
+
let b = high;
|
|
91
|
+
let x1 = b - GOLDEN * (b - a);
|
|
92
|
+
let x2 = a + GOLDEN * (b - a);
|
|
93
|
+
let v1 = offsetAt(x1);
|
|
94
|
+
let v2 = offsetAt(x2);
|
|
95
|
+
while (b - a > 1) {
|
|
96
|
+
if (maximize ? v1 < v2 : v1 > v2) {
|
|
97
|
+
a = x1;
|
|
98
|
+
x1 = x2;
|
|
99
|
+
v1 = v2;
|
|
100
|
+
x2 = a + GOLDEN * (b - a);
|
|
101
|
+
v2 = offsetAt(x2);
|
|
102
|
+
} else {
|
|
103
|
+
b = x2;
|
|
104
|
+
x2 = x1;
|
|
105
|
+
v2 = v1;
|
|
106
|
+
x1 = b - GOLDEN * (b - a);
|
|
107
|
+
v1 = offsetAt(x1);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
const extremum = (a + b) / 2;
|
|
111
|
+
const extremeOffset = offsetAt(extremum);
|
|
112
|
+
if (extremeOffset === 0) {
|
|
113
|
+
keep(extremum, false);
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
if (Math.sign(extremeOffset) === side) return;
|
|
117
|
+
keep(bisect(low, extremum, maximize), !maximize);
|
|
118
|
+
keep(bisect(extremum, high, !maximize), maximize);
|
|
119
|
+
};
|
|
120
|
+
const signChange = (previous2, current) => {
|
|
121
|
+
if (current.offset === 0 && previous2.offset !== 0 && Math.abs(previous2.offset) < 90) {
|
|
122
|
+
found.push({ at: new Date(current.time), retrograde: previous2.offset > 0 });
|
|
123
|
+
} else if (previous2.offset !== 0 && current.offset !== 0 && Math.sign(current.offset) !== Math.sign(previous2.offset) && Math.abs(current.offset) < 90 && Math.abs(previous2.offset) < 90) {
|
|
124
|
+
const rising = current.offset > previous2.offset;
|
|
125
|
+
found.push({ at: new Date(bisect(previous2.time, current.time, rising)), retrograde: !rising });
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
const interiorTurn = (before, middle, after) => {
|
|
129
|
+
const kind = turn(
|
|
130
|
+
signedDelta(before.longitude, middle.longitude),
|
|
131
|
+
signedDelta(middle.longitude, after.longitude)
|
|
132
|
+
);
|
|
133
|
+
if (kind === 0 || !sameSideNear(before.offset, middle.offset, after.offset)) return;
|
|
134
|
+
const maximize = kind > 0;
|
|
135
|
+
if (maximize !== middle.offset < 0) return;
|
|
136
|
+
if (Math.abs(middle.offset) > reachOf(before, middle, after) + 1e-12) return;
|
|
137
|
+
completePair(before.time, after.time, maximize, Math.sign(middle.offset));
|
|
138
|
+
};
|
|
139
|
+
const edgeCell = (low, high, reach, first) => {
|
|
140
|
+
if (!sameSideNear(low.offset, high.offset)) return;
|
|
141
|
+
if (Math.min(Math.abs(low.offset), Math.abs(high.offset)) > reach + 1e-12) return;
|
|
142
|
+
const probe = Math.min(EDGE_PROBE_MAX_MS, (high.time - low.time) / 1e3);
|
|
143
|
+
if (!(probe > 0)) return;
|
|
144
|
+
const cell = signedDelta(low.longitude, high.longitude);
|
|
145
|
+
const probeLongitude = longitudeAt(first ? low.time + probe : high.time - probe);
|
|
146
|
+
const local = first ? signedDelta(low.longitude, probeLongitude) : signedDelta(probeLongitude, high.longitude);
|
|
147
|
+
const kind = first ? turn(local, cell) : turn(cell, local);
|
|
148
|
+
if (kind === 0) return;
|
|
149
|
+
const maximize = kind > 0;
|
|
150
|
+
if (maximize !== low.offset < 0) return;
|
|
151
|
+
completePair(low.time, high.time, maximize, Math.sign(low.offset));
|
|
152
|
+
};
|
|
153
|
+
let secondLast;
|
|
154
|
+
let last = sampleAt(fromTime);
|
|
155
|
+
for (let index = 1; index < count; index += 1) {
|
|
156
|
+
const current = sampleAt(index === count - 1 ? toTime : fromTime + index * step);
|
|
157
|
+
signChange(last, current);
|
|
158
|
+
if (secondLast) {
|
|
159
|
+
interiorTurn(secondLast, last, current);
|
|
160
|
+
if (index === 2 || index === count - 1) {
|
|
161
|
+
const reach = 4 * reachOf(secondLast, last, current);
|
|
162
|
+
if (index === 2) edgeCell(secondLast, last, reach, true);
|
|
163
|
+
if (index === count - 1) edgeCell(last, current, reach, false);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
secondLast = last;
|
|
167
|
+
last = current;
|
|
168
|
+
}
|
|
169
|
+
if (count === 2 && secondLast) {
|
|
170
|
+
edgeCell(secondLast, last, Number.POSITIVE_INFINITY, true);
|
|
171
|
+
edgeCell(secondLast, last, Number.POSITIVE_INFINITY, false);
|
|
172
|
+
}
|
|
173
|
+
found.sort((a, b) => a.at.getTime() - b.at.getTime());
|
|
174
|
+
const crossings = [];
|
|
175
|
+
let previous;
|
|
176
|
+
for (const crossing of found) {
|
|
177
|
+
if (!previous || crossing.at.getTime() - previous.at.getTime() >= DUPLICATE_MS) {
|
|
178
|
+
crossings.push(crossing);
|
|
179
|
+
}
|
|
180
|
+
previous = crossing;
|
|
181
|
+
}
|
|
182
|
+
return crossings;
|
|
183
|
+
}
|
|
184
|
+
function run(longitudeAt, body, targetLongitude, window, maxSamples) {
|
|
185
|
+
const refused = (samples2) => ({
|
|
186
|
+
status: "refused",
|
|
187
|
+
reason: "sample-budget",
|
|
188
|
+
samples: samples2,
|
|
189
|
+
maxSamples,
|
|
190
|
+
crossings: []
|
|
191
|
+
});
|
|
192
|
+
if (window.toTime === window.fromTime) return { status: "complete", crossings: [], samples: 0 };
|
|
193
|
+
const count = coarseSampleCount(window);
|
|
194
|
+
if (count > maxSamples) return refused(0);
|
|
195
|
+
let samples = 0;
|
|
196
|
+
const sample = (time) => {
|
|
197
|
+
if (samples >= maxSamples) throw new SampleBudgetReached();
|
|
198
|
+
samples += 1;
|
|
199
|
+
const longitude = longitudeAt(body, new Date(time));
|
|
200
|
+
if (!Number.isFinite(longitude)) {
|
|
201
|
+
throw new RangeError("Ephemeris returned a non-finite longitude.");
|
|
202
|
+
}
|
|
203
|
+
return longitude;
|
|
204
|
+
};
|
|
205
|
+
try {
|
|
206
|
+
const crossings = solve(sample, targetLongitude, window, count);
|
|
207
|
+
return { status: "complete", crossings, samples };
|
|
208
|
+
} catch (error) {
|
|
209
|
+
if (error instanceof SampleBudgetReached) return refused(samples);
|
|
210
|
+
throw error;
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
function findLongitudeCrossingsWith(longitudeAt, body, targetLongitude, from, to, stepDays = 5) {
|
|
214
|
+
const window = validWindow(targetLongitude, from, to, stepDays);
|
|
215
|
+
const result = run(longitudeAt, body, targetLongitude, window, Number.POSITIVE_INFINITY);
|
|
216
|
+
return result.crossings;
|
|
217
|
+
}
|
|
218
|
+
function searchLongitudeCrossingsWith(longitudeAt, body, targetLongitude, from, to, options = {}) {
|
|
219
|
+
if (options === null || typeof options !== "object") {
|
|
220
|
+
throw new RangeError("Crossing search options must be an object.");
|
|
221
|
+
}
|
|
222
|
+
const stepDays = options.stepDays === void 0 ? 5 : options.stepDays;
|
|
223
|
+
const window = validWindow(targetLongitude, from, to, stepDays);
|
|
224
|
+
const maxSamples = validBudget(options.maxSamples);
|
|
225
|
+
return run(longitudeAt, body, targetLongitude, window, maxSamples);
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
export {
|
|
229
|
+
findLongitudeCrossingsWith,
|
|
230
|
+
searchLongitudeCrossingsWith
|
|
231
|
+
};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
// src/date-input.ts
|
|
2
|
+
var ISO_INSTANT = /^(\d{4}|[+-]\d{6})-(\d{2})-(\d{2})(?:T(\d{2}):(\d{2})(?::(\d{2})(?:\.(\d{1,3}))?)?(Z|[+-](\d{2}):(\d{2})))?$/;
|
|
3
|
+
function validIsoInput(input) {
|
|
4
|
+
const match = ISO_INSTANT.exec(input);
|
|
5
|
+
if (!match || match[0] !== input || match[1] === "-000000") return false;
|
|
6
|
+
const year = Number(match[1]);
|
|
7
|
+
const month = Number(match[2]);
|
|
8
|
+
const day = Number(match[3]);
|
|
9
|
+
if (month < 1 || month > 12) return false;
|
|
10
|
+
const leap = year % 4 === 0 && (year % 100 !== 0 || year % 400 === 0);
|
|
11
|
+
const monthDays = [31, leap ? 29 : 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
|
|
12
|
+
if (day < 1 || day > monthDays[month - 1]) return false;
|
|
13
|
+
return Number(match[4] ?? 0) <= 23 && Number(match[5] ?? 0) <= 59 && Number(match[6] ?? 0) <= 59 && Number(match[9] ?? 0) <= 23 && Number(match[10] ?? 0) <= 59;
|
|
14
|
+
}
|
|
15
|
+
function dateFrom(input, label) {
|
|
16
|
+
const invalid = () => new RangeError(
|
|
17
|
+
`${label} must be a valid Date, finite epoch-millisecond timestamp, or ISO calendar date/date-time with an explicit UTC offset.`
|
|
18
|
+
);
|
|
19
|
+
let date;
|
|
20
|
+
if (input instanceof Date) {
|
|
21
|
+
date = new Date(Date.prototype.getTime.call(input));
|
|
22
|
+
} else if (typeof input === "number" && Number.isFinite(input)) {
|
|
23
|
+
date = new Date(input);
|
|
24
|
+
} else if (typeof input === "string" && validIsoInput(input)) {
|
|
25
|
+
date = new Date(input);
|
|
26
|
+
} else {
|
|
27
|
+
throw invalid();
|
|
28
|
+
}
|
|
29
|
+
if (!Number.isFinite(date.getTime())) throw invalid();
|
|
30
|
+
return date;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export {
|
|
34
|
+
dateFrom
|
|
35
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// src/reference-span.ts
|
|
2
|
+
var REFERENCE_SPAN = Object.freeze({
|
|
3
|
+
from: "1800-01-01T00:00:00.000Z",
|
|
4
|
+
to: "2200-01-01T00:00:00.000Z"
|
|
5
|
+
});
|
|
6
|
+
var EPHEMERIS_SPAN = Object.freeze({
|
|
7
|
+
timeScale: "TT",
|
|
8
|
+
/** Days of Terrestrial Time from J2000.0, 2000-01-01T12:00 TT, inclusive. */
|
|
9
|
+
daysFromJ2000: Object.freeze({ from: -73e4, to: 73e4 }),
|
|
10
|
+
/** The same bounds as Terrestrial Time labels (not UTC). */
|
|
11
|
+
fromTT: "0001-04-30T12:00:00",
|
|
12
|
+
toTT: "3998-09-03T12:00:00"
|
|
13
|
+
});
|
|
14
|
+
var FROM = Date.UTC(1800, 0, 1);
|
|
15
|
+
var TO = Date.UTC(2200, 0, 1);
|
|
16
|
+
function outsideReferenceSpan(utc) {
|
|
17
|
+
const time = Date.prototype.getTime.call(utc);
|
|
18
|
+
return !(time >= FROM && time < TO);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export {
|
|
22
|
+
REFERENCE_SPAN,
|
|
23
|
+
EPHEMERIS_SPAN,
|
|
24
|
+
outsideReferenceSpan
|
|
25
|
+
};
|