@math.gl/earth 5.0.0-alpha.19 → 5.0.0-beta.1
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/LICENSE +1015 -0
- package/README.md +7 -2
- package/THIRD-PARTY-NOTICES.md +25 -0
- package/dist/geoid/create-geoid-from-grid.js +1 -1
- package/dist/geoid/create-geoid-from-grid.js.map +1 -1
- package/dist/geoid/geoid.js +1 -1
- package/dist/geoid/geoid.js.map +1 -1
- package/dist/index.cjs +13791 -171
- package/dist/index.cjs.map +3 -3
- package/dist/index.d.ts +17 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +10 -0
- package/dist/index.js.map +1 -1
- package/dist/sun/index.cjs +7905 -0
- package/dist/sun/index.cjs.map +3 -3
- package/dist/sun/index.d.ts +8 -0
- package/dist/sun/index.d.ts.map +1 -1
- package/dist/sun/index.js +5 -0
- package/dist/sun/index.js.map +1 -1
- package/dist/sun/moon.js +1 -1
- package/dist/sun/moon.js.map +1 -1
- package/dist/sun/planet-position.d.ts +1 -1
- package/dist/sun/planet-position.js +1 -1
- package/dist/sun/sky-lighting.js +1 -1
- package/dist/sun/sky-lighting.js.map +1 -1
- package/dist/sun/stars.cjs +18 -16
- package/dist/sun/stars.cjs.map +1 -1
- package/dist/sun/stars.js +3 -2
- package/dist/sun/stars.js.map +1 -1
- package/dist/sun/suncalc.d.ts +1 -0
- package/dist/sun/suncalc.d.ts.map +1 -1
- package/dist/sun/suncalc.js +1 -1
- package/dist/sun/suncalc.js.map +1 -1
- package/dist/sun/sunlight.js +1 -1
- package/dist/sun/sunlight.js.map +1 -1
- package/dist/sun/terminator.d.ts +20 -0
- package/dist/sun/terminator.d.ts.map +1 -0
- package/dist/sun/terminator.js +88 -0
- package/dist/sun/terminator.js.map +1 -0
- package/dist/timezone/index.cjs +5678 -19
- package/dist/timezone/index.cjs.map +3 -3
- package/dist/timezone/index.d.ts +3 -0
- package/dist/timezone/index.d.ts.map +1 -1
- package/dist/timezone/index.js +3 -0
- package/dist/timezone/index.js.map +1 -1
- package/geoid/data/README.md +1 -1
- package/package.json +13 -34
- package/src/geoid/create-geoid-from-grid.ts +1 -1
- package/src/geoid/geoid.ts +1 -1
- package/src/index.ts +100 -0
- package/src/sun/index.ts +38 -0
- package/src/sun/moon.ts +1 -1
- package/src/sun/planet-position.ts +1 -1
- package/src/sun/sky-lighting.ts +1 -1
- package/src/sun/stars.ts +3 -3
- package/src/sun/suncalc.ts +1 -1
- package/src/sun/sunlight.ts +1 -1
- package/src/sun/terminator.ts +112 -0
- package/src/timezone/index.ts +5 -0
- package/dist/geoid/index.cjs +0 -727
- package/dist/geoid/index.cjs.map +0 -6
- package/dist/sun/astronomy.cjs +0 -1729
- package/dist/sun/astronomy.cjs.map +0 -6
- package/dist/sun/planets.cjs +0 -411
- package/dist/sun/planets.cjs.map +0 -6
- package/dist/timezone/lookup.cjs +0 -83
- package/dist/timezone/lookup.cjs.map +0 -6
- package/dist/timezone/temporal.cjs +0 -5696
- package/dist/timezone/temporal.cjs.map +0 -6
package/package.json
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
"publishConfig": {
|
|
7
7
|
"access": "public"
|
|
8
8
|
},
|
|
9
|
-
"version": "5.0.0-
|
|
9
|
+
"version": "5.0.0-beta.1",
|
|
10
10
|
"keywords": [
|
|
11
11
|
"earth",
|
|
12
12
|
"geoid",
|
|
@@ -27,11 +27,6 @@
|
|
|
27
27
|
"import": "./dist/index.js",
|
|
28
28
|
"require": "./dist/index.cjs"
|
|
29
29
|
},
|
|
30
|
-
"./geoid": {
|
|
31
|
-
"types": "./dist/geoid/index.d.ts",
|
|
32
|
-
"import": "./dist/geoid/index.js",
|
|
33
|
-
"require": "./dist/geoid/index.cjs"
|
|
34
|
-
},
|
|
35
30
|
"./sun": {
|
|
36
31
|
"types": "./dist/sun/index.d.ts",
|
|
37
32
|
"import": "./dist/sun/index.js",
|
|
@@ -44,35 +39,15 @@
|
|
|
44
39
|
},
|
|
45
40
|
"./geoid/geoid-egm96-low.pgm": "./geoid/data/geoid-egm96-low.pgm",
|
|
46
41
|
"./geoid/geoid-egm96-hi.pgm": "./geoid/data/geoid-egm96-hi.pgm",
|
|
47
|
-
"./
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
},
|
|
52
|
-
"./sun/astronomy": {
|
|
53
|
-
"types": "./dist/sun/astronomy.d.ts",
|
|
54
|
-
"import": "./dist/sun/astronomy.js",
|
|
55
|
-
"require": "./dist/sun/astronomy.cjs"
|
|
56
|
-
},
|
|
42
|
+
"./timezone/timezone-geometry-low.json": "./timezone/data/timezone-geometry-low.json",
|
|
43
|
+
"./timezone/timezone-geometry-low.parquet": "./timezone/data/timezone-geometry-low.parquet",
|
|
44
|
+
"./timezone/timezone-geometry-hi.json": "./timezone/data/timezone-geometry-hi.json",
|
|
45
|
+
"./timezone/timezone-geometry-hi.parquet": "./timezone/data/timezone-geometry-hi.parquet",
|
|
57
46
|
"./sun/stars": {
|
|
58
47
|
"types": "./dist/sun/stars.d.ts",
|
|
59
48
|
"import": "./dist/sun/stars.js",
|
|
60
49
|
"require": "./dist/sun/stars.cjs"
|
|
61
|
-
}
|
|
62
|
-
"./timezone/lookup": {
|
|
63
|
-
"types": "./dist/timezone/lookup.d.ts",
|
|
64
|
-
"import": "./dist/timezone/lookup.js",
|
|
65
|
-
"require": "./dist/timezone/lookup.cjs"
|
|
66
|
-
},
|
|
67
|
-
"./timezone/temporal": {
|
|
68
|
-
"types": "./dist/timezone/temporal.d.ts",
|
|
69
|
-
"import": "./dist/timezone/temporal.js",
|
|
70
|
-
"require": "./dist/timezone/temporal.cjs"
|
|
71
|
-
},
|
|
72
|
-
"./timezone/timezone-geometry-low.json": "./timezone/data/timezone-geometry-low.json",
|
|
73
|
-
"./timezone/timezone-geometry-low.parquet": "./timezone/data/timezone-geometry-low.parquet",
|
|
74
|
-
"./timezone/timezone-geometry-hi.json": "./timezone/data/timezone-geometry-hi.json",
|
|
75
|
-
"./timezone/timezone-geometry-hi.parquet": "./timezone/data/timezone-geometry-hi.parquet"
|
|
50
|
+
}
|
|
76
51
|
},
|
|
77
52
|
"files": [
|
|
78
53
|
"dist",
|
|
@@ -81,13 +56,17 @@
|
|
|
81
56
|
"sun/LICENSE-HOSEK-WILKIE",
|
|
82
57
|
"sun/LICENSE-SUNCALC",
|
|
83
58
|
"sun/LICENSE-BRIGHT-STARS",
|
|
84
|
-
"timezone/data"
|
|
59
|
+
"timezone/data",
|
|
60
|
+
"LICENSE",
|
|
61
|
+
"THIRD-PARTY-NOTICES.md"
|
|
85
62
|
],
|
|
86
63
|
"sideEffects": false,
|
|
87
64
|
"dependencies": {
|
|
88
|
-
"@math.gl/core": "5.0.0-
|
|
65
|
+
"@math.gl/core": "5.0.0-beta.1",
|
|
66
|
+
"astronomy-engine": "2.1.19"
|
|
89
67
|
},
|
|
90
68
|
"devDependencies": {
|
|
91
69
|
"astronomy-engine": "2.1.19"
|
|
92
|
-
}
|
|
70
|
+
},
|
|
71
|
+
"gitHead": "13b9fae96e2df2010f5528a199316f47c044200b"
|
|
93
72
|
}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
|
|
4
4
|
|
|
5
5
|
import {Geoid} from './geoid';
|
|
6
|
-
import {isUint16Array} from '@math.gl/core
|
|
6
|
+
import {isUint16Array} from '@math.gl/core';
|
|
7
7
|
|
|
8
8
|
/** A complete global grid of raw samples in GeographicLib node order. */
|
|
9
9
|
export type GeoidGridProps = {
|
package/src/geoid/geoid.ts
CHANGED
package/src/index.ts
CHANGED
|
@@ -5,3 +5,103 @@
|
|
|
5
5
|
export * as geoid from './geoid/index';
|
|
6
6
|
export * as sun from './sun/index';
|
|
7
7
|
export * as timezone from './timezone/index';
|
|
8
|
+
|
|
9
|
+
// Public named exports. Implementations remain in independently tree-shakable files.
|
|
10
|
+
export {parsePGM, Geoid, createGeoidFromGrid} from './geoid/index';
|
|
11
|
+
export type {GeoidGridProps} from './geoid/index';
|
|
12
|
+
export {
|
|
13
|
+
getMoonPosition,
|
|
14
|
+
getMoonDirection,
|
|
15
|
+
getMoonIllumination,
|
|
16
|
+
getMoonLight,
|
|
17
|
+
getStarfieldRotation,
|
|
18
|
+
getSunPosition,
|
|
19
|
+
getSunDirection,
|
|
20
|
+
getSunLight,
|
|
21
|
+
createSkyObserver,
|
|
22
|
+
getSkyDirection,
|
|
23
|
+
reverseSkyDirection,
|
|
24
|
+
getSkyHorizonAltitude,
|
|
25
|
+
createSkyAtmosphere,
|
|
26
|
+
getSkyAirMass,
|
|
27
|
+
getSkyTransmission,
|
|
28
|
+
getSkyLuminance,
|
|
29
|
+
getSkyContrastThreshold,
|
|
30
|
+
getMoonAppearance,
|
|
31
|
+
getSkyLighting,
|
|
32
|
+
searchSkyVisibility,
|
|
33
|
+
getScatteredMoonLuminance,
|
|
34
|
+
SKY_GLOBE_EARTH_RADIUS,
|
|
35
|
+
getSkyGlobeRotation,
|
|
36
|
+
skyDirectionToGlobe,
|
|
37
|
+
getSkyGlobePosition,
|
|
38
|
+
skyRotationToGlobe,
|
|
39
|
+
getCloudLighting
|
|
40
|
+
} from './sun/index';
|
|
41
|
+
export type {
|
|
42
|
+
MoonPosition,
|
|
43
|
+
MoonIllumination,
|
|
44
|
+
MoonLight,
|
|
45
|
+
MoonLightOptions,
|
|
46
|
+
StarfieldOptions,
|
|
47
|
+
LightColor,
|
|
48
|
+
SunLight,
|
|
49
|
+
SunLightOptions,
|
|
50
|
+
SkyObserver,
|
|
51
|
+
SkyHorizonProfile,
|
|
52
|
+
SkyAtmosphereOptions,
|
|
53
|
+
MoonAppearanceOptions,
|
|
54
|
+
SkyLightingOptions,
|
|
55
|
+
CloudLighting,
|
|
56
|
+
CloudLightingOptions
|
|
57
|
+
} from './sun/index';
|
|
58
|
+
export {getPlanetSkyInfo, getPlanetVisibility, getPlanetVisibilityTimes} from './sun/planets';
|
|
59
|
+
export type {
|
|
60
|
+
PlanetName,
|
|
61
|
+
GalileanMoonName,
|
|
62
|
+
PlanetSkyOptions,
|
|
63
|
+
PlanetSkyBody,
|
|
64
|
+
PlanetVisibility,
|
|
65
|
+
PlanetVisibilityOptions,
|
|
66
|
+
PlanetVisibilityTimes,
|
|
67
|
+
PlanetVisibilityTimesOptions,
|
|
68
|
+
PlanetVisibilityInterval
|
|
69
|
+
} from './sun/planets';
|
|
70
|
+
export {getSkySnapshot, createSkyContext} from './sun/astronomy';
|
|
71
|
+
export type {SkyTimeScales, SkySnapshotOptions} from './sun/astronomy';
|
|
72
|
+
export {
|
|
73
|
+
getStarPosition,
|
|
74
|
+
getStarPositions,
|
|
75
|
+
getStarColor,
|
|
76
|
+
getGalacticAcceleration,
|
|
77
|
+
getGalacticPotential,
|
|
78
|
+
integrateGalacticOrbit,
|
|
79
|
+
createMilkyWayBackground,
|
|
80
|
+
getStarLayerData
|
|
81
|
+
} from './sun/stars';
|
|
82
|
+
export type {
|
|
83
|
+
StarRecord,
|
|
84
|
+
StarPosition,
|
|
85
|
+
StarPositionOptions,
|
|
86
|
+
MilkyWayBackground,
|
|
87
|
+
MilkyWaySample,
|
|
88
|
+
StarLayerOptions,
|
|
89
|
+
StarLayerDatum
|
|
90
|
+
} from './sun/stars';
|
|
91
|
+
export {
|
|
92
|
+
getTimezoneOffset,
|
|
93
|
+
lookupTimezoneAsync,
|
|
94
|
+
getLocalDateTime,
|
|
95
|
+
getTimezoneLabel,
|
|
96
|
+
isTimezoneSupported
|
|
97
|
+
} from './timezone/index';
|
|
98
|
+
export type {LocalDateTime} from './timezone/index';
|
|
99
|
+
export {lookupTimezone} from './timezone/lookup';
|
|
100
|
+
export {getStartOfDay, localDateTimeToInstant, getTimezoneTransitions} from './timezone/temporal';
|
|
101
|
+
export type {
|
|
102
|
+
LocalDateTimeInput,
|
|
103
|
+
LocalDateTimeOptions,
|
|
104
|
+
TimezoneTransition
|
|
105
|
+
} from './timezone/temporal';
|
|
106
|
+
export {getSunTerminator} from './sun/terminator';
|
|
107
|
+
export type {SunTerminator, SunTerminatorOptions} from './sun/terminator';
|
package/src/sun/index.ts
CHANGED
|
@@ -41,3 +41,41 @@ export {
|
|
|
41
41
|
} from './sky-globe';
|
|
42
42
|
export {getCloudLighting} from './cloud-lighting';
|
|
43
43
|
export type {CloudLighting, CloudLightingOptions} from './cloud-lighting';
|
|
44
|
+
|
|
45
|
+
export {getSunTerminator} from './terminator';
|
|
46
|
+
export type {SunTerminator, SunTerminatorOptions} from './terminator';
|
|
47
|
+
|
|
48
|
+
// Public named exports. Implementations remain in independently tree-shakable files.
|
|
49
|
+
export {getPlanetSkyInfo, getPlanetVisibility, getPlanetVisibilityTimes} from './planets';
|
|
50
|
+
export type {
|
|
51
|
+
PlanetName,
|
|
52
|
+
GalileanMoonName,
|
|
53
|
+
PlanetSkyOptions,
|
|
54
|
+
PlanetSkyBody,
|
|
55
|
+
PlanetVisibility,
|
|
56
|
+
PlanetVisibilityOptions,
|
|
57
|
+
PlanetVisibilityTimes,
|
|
58
|
+
PlanetVisibilityTimesOptions,
|
|
59
|
+
PlanetVisibilityInterval
|
|
60
|
+
} from './planets';
|
|
61
|
+
export {getSkySnapshot, createSkyContext} from './astronomy';
|
|
62
|
+
export type {SkyTimeScales, SkySnapshotOptions} from './astronomy';
|
|
63
|
+
export {
|
|
64
|
+
getStarPosition,
|
|
65
|
+
getStarPositions,
|
|
66
|
+
getStarColor,
|
|
67
|
+
getGalacticAcceleration,
|
|
68
|
+
getGalacticPotential,
|
|
69
|
+
integrateGalacticOrbit,
|
|
70
|
+
createMilkyWayBackground,
|
|
71
|
+
getStarLayerData
|
|
72
|
+
} from './stars';
|
|
73
|
+
export type {
|
|
74
|
+
StarRecord,
|
|
75
|
+
StarPosition,
|
|
76
|
+
StarPositionOptions,
|
|
77
|
+
MilkyWayBackground,
|
|
78
|
+
MilkyWaySample,
|
|
79
|
+
StarLayerOptions,
|
|
80
|
+
StarLayerDatum
|
|
81
|
+
} from './stars';
|
package/src/sun/moon.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
|
|
4
4
|
// SPDX-FileCopyrightText: 2011-2015 Vladimir Agafonkin
|
|
5
5
|
// SPDX-FileCopyrightText: 2014 Vladimir Agafonkin
|
|
6
|
-
// SPDX-FileComment: Adapted from SunCalc 1.9.0 with topocentric parallax and USNO sidereal time; full copyright, conditions and disclaimer in
|
|
6
|
+
// SPDX-FileComment: Adapted from SunCalc 1.9.0 with topocentric parallax and USNO sidereal time; full copyright, conditions and disclaimer in ../../sun/LICENSE-SUNCALC.
|
|
7
7
|
// Reference: https://github.com/mourner/suncalc/tree/v1.9.0
|
|
8
8
|
import {getAzimuth, getDeclination, getRightAscension, getSunCoords, toDays} from './suncalc';
|
|
9
9
|
import {getLocalSiderealTime} from './starfield';
|
|
@@ -102,7 +102,7 @@ const SUN_RADIUS = 695700;
|
|
|
102
102
|
|
|
103
103
|
/**
|
|
104
104
|
* Positions and disk geometry for rendering seven planets and four Galilean moons.
|
|
105
|
-
* Import from @math.gl/earth/sun
|
|
105
|
+
* Import from @math.gl/earth/sun; requires the optional astronomy-engine peer.
|
|
106
106
|
* The ephemeris accounts for light travel, precession and nutation; not aberration.
|
|
107
107
|
*/
|
|
108
108
|
export function getPlanetSkyInfo(
|
package/src/sun/sky-lighting.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// math.gl
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
// SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
|
|
4
|
-
// SPDX-FileComment: Original photometric composition; derived solar data attribution in
|
|
4
|
+
// SPDX-FileComment: Original photometric composition; derived solar data attribution in ../../sun/LICENSE-HOSEK-WILKIE.
|
|
5
5
|
import {getSunLight} from './sunlight';
|
|
6
6
|
import {getMoonLight} from './moonlight';
|
|
7
7
|
import {getMoonAppearance} from './moon-appearance';
|
package/src/sun/stars.ts
CHANGED
|
@@ -25,8 +25,8 @@ export {createMilkyWayBackground} from './star-milky-way';
|
|
|
25
25
|
export type {MilkyWayBackground, MilkyWaySample} from './star-milky-way';
|
|
26
26
|
|
|
27
27
|
/** Brightest 7,000 BSC5 sources, sorted by visual magnitude then HR number. */
|
|
28
|
-
export const STAR_CATALOG: readonly StarRecord[] = Object.freeze(
|
|
29
|
-
STAR_CATALOG_DATA.map(row =>
|
|
28
|
+
export const STAR_CATALOG: readonly StarRecord[] = /* @__PURE__ */ Object.freeze(
|
|
29
|
+
/* @__PURE__ */ STAR_CATALOG_DATA.map(row =>
|
|
30
30
|
Object.freeze({
|
|
31
31
|
id: row[0],
|
|
32
32
|
designation: row[10],
|
|
@@ -46,7 +46,7 @@ export const STAR_CATALOG: readonly StarRecord[] = Object.freeze(
|
|
|
46
46
|
);
|
|
47
47
|
|
|
48
48
|
/** Metadata describes the fixed input selection, not a completeness guarantee at future epochs. */
|
|
49
|
-
export const STAR_CATALOG_INFO = Object.freeze({
|
|
49
|
+
export const STAR_CATALOG_INFO = /* @__PURE__ */ Object.freeze({
|
|
50
50
|
count: 7000,
|
|
51
51
|
epochYear: 2000,
|
|
52
52
|
faintestMagnitude: 6.3,
|
package/src/sun/suncalc.ts
CHANGED
|
@@ -108,7 +108,7 @@ function getAltitude(hourAngle: number, latitudeInRadians: number, declination:
|
|
|
108
108
|
|
|
109
109
|
// https://www.aa.quae.nl/en/reken/zonpositie.html
|
|
110
110
|
// "The Observer section"
|
|
111
|
-
function getSiderealTime(dates: number, longitudeWestInRadians: number): number {
|
|
111
|
+
export function getSiderealTime(dates: number, longitudeWestInRadians: number): number {
|
|
112
112
|
return DEGREES_TO_RADIANS * (THETA0 + THETA1 * dates) - longitudeWestInRadians;
|
|
113
113
|
}
|
|
114
114
|
|
package/src/sun/sunlight.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
// SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
|
|
4
4
|
// SPDX-FileComment: Original wrapper of derived Hošek-Wilkie data; reference: https://cgg.mff.cuni.cz/projects/SkylightModelling/
|
|
5
|
-
// Derived BSD-3-Clause data and notices: ./data/sunlight.ts and
|
|
5
|
+
// Derived BSD-3-Clause data and notices: ./data/sunlight.ts and ../../sun/LICENSE-HOSEK-WILKIE.
|
|
6
6
|
import {SUNLIGHT_DATA} from './data/sunlight';
|
|
7
7
|
|
|
8
8
|
export type SunLightOptions = {
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
// math.gl
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
// SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
|
|
4
|
+
import {getSunCoords, getSiderealTime, toDays} from './suncalc';
|
|
5
|
+
|
|
6
|
+
export type SunTerminatorOptions = {
|
|
7
|
+
/** Geometric solar altitude in degrees, from -18 to 0. Default: 0. */
|
|
8
|
+
altitude?: number;
|
|
9
|
+
/** Number of circle segments before seam splitting. Integer >= 8. Default: 360. */
|
|
10
|
+
resolution?: number;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export type SunTerminator = {
|
|
14
|
+
/** Longitude/latitude degrees, split at the antimeridian and poles. */
|
|
15
|
+
geometry: {type: 'MultiLineString'; coordinates: [number, number][][]};
|
|
16
|
+
/** Unit vector toward the Sun: +X Greenwich, +Y 90°E, +Z north. */
|
|
17
|
+
sunDirection: [number, number, number];
|
|
18
|
+
/** Geometric solar altitude in degrees. Darkness is below this threshold. */
|
|
19
|
+
altitude: number;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
const RAD = Math.PI / 180;
|
|
23
|
+
const TAU = 2 * Math.PI;
|
|
24
|
+
// Sub-millimeter tolerance on Earth; also covers Julian-day rounding at equinox.
|
|
25
|
+
const POLE_EPSILON = 1e-10;
|
|
26
|
+
|
|
27
|
+
/** Spherical geometric day/night or twilight boundary, without atmospheric refraction. */
|
|
28
|
+
export function getSunTerminator(
|
|
29
|
+
timestamp: number | Date,
|
|
30
|
+
{altitude = 0, resolution = 360}: SunTerminatorOptions = {}
|
|
31
|
+
): SunTerminator {
|
|
32
|
+
const time = timestamp instanceof Date ? timestamp.getTime() : timestamp;
|
|
33
|
+
if (!Number.isFinite(time) || !Number.isFinite(new Date(time).getTime())) {
|
|
34
|
+
throw new RangeError('Timestamp must be a valid finite date');
|
|
35
|
+
}
|
|
36
|
+
if (!Number.isFinite(altitude) || altitude < -18 || altitude > 0) {
|
|
37
|
+
throw new RangeError('Altitude must be between -18 and 0 degrees');
|
|
38
|
+
}
|
|
39
|
+
if (!Number.isSafeInteger(resolution) || resolution < 8) {
|
|
40
|
+
throw new RangeError('Resolution must be an integer >= 8');
|
|
41
|
+
}
|
|
42
|
+
const days = toDays(time);
|
|
43
|
+
const {declination, rightAscension} = getSunCoords(days);
|
|
44
|
+
const longitude = rightAscension - getSiderealTime(days, 0);
|
|
45
|
+
const sunDirection: [number, number, number] = [
|
|
46
|
+
Math.cos(declination) * Math.cos(longitude),
|
|
47
|
+
Math.cos(declination) * Math.sin(longitude),
|
|
48
|
+
Math.sin(declination)
|
|
49
|
+
];
|
|
50
|
+
const [sx, sy, sz] = sunDirection;
|
|
51
|
+
const horizontal = Math.hypot(sx, sy);
|
|
52
|
+
const u = [-sy / horizontal, sx / horizontal, 0];
|
|
53
|
+
const v = [-sz * u[1], sz * u[0], horizontal];
|
|
54
|
+
const offset = Math.sin(altitude * RAD);
|
|
55
|
+
const radius = Math.cos(altitude * RAD);
|
|
56
|
+
const point = (angle: number): number[] =>
|
|
57
|
+
sunDirection.map(
|
|
58
|
+
(component, i) =>
|
|
59
|
+
offset * component + radius * (Math.cos(angle) * u[i] + Math.sin(angle) * v[i])
|
|
60
|
+
);
|
|
61
|
+
|
|
62
|
+
// Solve y(theta)=0 analytically and split only on the negative-X half plane.
|
|
63
|
+
// This inserts exact boundary points rather than interpolating in lon/lat.
|
|
64
|
+
const cuts = [0, TAU];
|
|
65
|
+
const a = radius * u[1];
|
|
66
|
+
const b = radius * v[1];
|
|
67
|
+
const amplitude = Math.hypot(a, b);
|
|
68
|
+
const ratio = (-offset * sy) / amplitude;
|
|
69
|
+
if (amplitude > 1e-14 && Math.abs(ratio) <= 1 + 1e-14) {
|
|
70
|
+
const phase = Math.atan2(b, a);
|
|
71
|
+
const angle = Math.acos(Math.max(-1, Math.min(1, ratio)));
|
|
72
|
+
for (const candidate of [phase - angle, phase + angle]) {
|
|
73
|
+
const t = ((candidate % TAU) + TAU) % TAU;
|
|
74
|
+
if (point(t)[0] < 1e-12) cuts.push(t);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
// A circle through a pole has two different limiting longitudes there.
|
|
78
|
+
for (const t of [Math.PI / 2, (3 * Math.PI) / 2]) {
|
|
79
|
+
const p = point(t);
|
|
80
|
+
if (Math.hypot(p[0], p[1]) < POLE_EPSILON) cuts.push(t);
|
|
81
|
+
}
|
|
82
|
+
const sorted = cuts.sort((x, y) => x - y).filter((t, i, all) => !i || t - all[i - 1] > 1e-12);
|
|
83
|
+
const coordinates: [number, number][][] = [];
|
|
84
|
+
for (let i = 1; i < sorted.length; i++) {
|
|
85
|
+
const start = sorted[i - 1];
|
|
86
|
+
const end = sorted[i];
|
|
87
|
+
const angles = [start];
|
|
88
|
+
for (let j = Math.floor((start / TAU) * resolution) + 1; j < resolution; j++) {
|
|
89
|
+
const t = (j / resolution) * TAU;
|
|
90
|
+
if (t >= end - 1e-12) break;
|
|
91
|
+
angles.push(t);
|
|
92
|
+
}
|
|
93
|
+
angles.push(end);
|
|
94
|
+
coordinates.push(
|
|
95
|
+
angles.map((t, j): [number, number] => {
|
|
96
|
+
const p = point(t);
|
|
97
|
+
const nearby = point(t + (j === 0 ? 1 : -1) * Math.min(1e-7, (end - start) / 4));
|
|
98
|
+
const polar = Math.hypot(p[0], p[1]) < POLE_EPSILON;
|
|
99
|
+
let longitude = Math.atan2(polar ? nearby[1] : p[1], polar ? nearby[0] : p[0]) / RAD;
|
|
100
|
+
if (!polar && p[0] < 0 && Math.abs(p[1]) < 1e-12) {
|
|
101
|
+
longitude = nearby[1] >= 0 ? 180 : -180;
|
|
102
|
+
}
|
|
103
|
+
return [longitude, Math.atan2(p[2], Math.hypot(p[0], p[1])) / RAD];
|
|
104
|
+
})
|
|
105
|
+
);
|
|
106
|
+
}
|
|
107
|
+
return {
|
|
108
|
+
geometry: {type: 'MultiLineString', coordinates},
|
|
109
|
+
sunDirection,
|
|
110
|
+
altitude
|
|
111
|
+
};
|
|
112
|
+
}
|
package/src/timezone/index.ts
CHANGED
|
@@ -7,3 +7,8 @@ export {lookupTimezoneAsync} from './lookup-async';
|
|
|
7
7
|
export {getLocalDateTime} from './local-date-time';
|
|
8
8
|
export {getTimezoneLabel, isTimezoneSupported} from './timezone-label';
|
|
9
9
|
export type {LocalDateTime} from './types';
|
|
10
|
+
|
|
11
|
+
// Public named exports. Implementations remain in independently tree-shakable files.
|
|
12
|
+
export {lookupTimezone} from './lookup';
|
|
13
|
+
export {getStartOfDay, localDateTimeToInstant, getTimezoneTransitions} from './temporal';
|
|
14
|
+
export type {LocalDateTimeInput, LocalDateTimeOptions, TimezoneTransition} from './temporal';
|