@math.gl/sun 3.6.0-alpha.5 → 3.6.0-alpha.6
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/dist/es5/suncalc.js +2 -1
- package/dist/es5/suncalc.js.map +1 -1
- package/dist/esm/suncalc.js +2 -1
- package/dist/esm/suncalc.js.map +1 -1
- package/dist/suncalc.js +2 -1
- package/package.json +2 -2
- package/src/suncalc.ts +15 -11
package/dist/es5/suncalc.js
CHANGED
|
@@ -37,7 +37,8 @@ function getSunDirection(timestamp, latitude, longitude) {
|
|
|
37
37
|
}
|
|
38
38
|
|
|
39
39
|
function toJulianDay(timestamp) {
|
|
40
|
-
|
|
40
|
+
var ts = typeof timestamp === 'number' ? timestamp : timestamp.getTime();
|
|
41
|
+
return ts / DAY_IN_MS - 0.5 + JD1970;
|
|
41
42
|
}
|
|
42
43
|
|
|
43
44
|
function toDays(timestamp) {
|
package/dist/es5/suncalc.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/suncalc.ts"],"names":["DEGREES_TO_RADIANS","Math","PI","DAY_IN_MS","JD1970","JD2000","e","M0","M1","THETA0","THETA1","getSunPosition","timestamp","latitude","longitude","longitudeWestInRadians","phi","d","toDays","c","getSunCoords","H","getSiderealTime","rightAscension","azimuth","getAzimuth","declination","altitude","getAltitude","getSunDirection","azimuthN","sin","cos","toJulianDay","getRightAscension","eclipticLongitude","b","lambda","atan2","tan","getDeclination","asin","hourAngle","latitudeInRadians","delta","dates","getSolarMeanAnomaly","days","getEclipticLongitude","meanAnomaly","M","C","P","L"],"mappings":";;;;;;;AAAA,IAAMA,kBAAkB,GAAGC,IAAI,CAACC,EAAL,GAAU,GAArC;AAEA,IAAMC,SAAS,GAAG,OAAO,EAAP,GAAY,EAAZ,GAAiB,EAAnC;AACA,IAAMC,MAAM,GAAG,OAAf;AACA,IAAMC,MAAM,GAAG,OAAf;AAGA,IAAMC,CAAC,GAAG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"],"names":["DEGREES_TO_RADIANS","Math","PI","DAY_IN_MS","JD1970","JD2000","e","M0","M1","THETA0","THETA1","getSunPosition","timestamp","latitude","longitude","longitudeWestInRadians","phi","d","toDays","c","getSunCoords","H","getSiderealTime","rightAscension","azimuth","getAzimuth","declination","altitude","getAltitude","getSunDirection","azimuthN","sin","cos","toJulianDay","ts","getTime","getRightAscension","eclipticLongitude","b","lambda","atan2","tan","getDeclination","asin","hourAngle","latitudeInRadians","delta","dates","getSolarMeanAnomaly","days","getEclipticLongitude","meanAnomaly","M","C","P","L"],"mappings":";;;;;;;AAAA,IAAMA,kBAAkB,GAAGC,IAAI,CAACC,EAAL,GAAU,GAArC;AAEA,IAAMC,SAAS,GAAG,OAAO,EAAP,GAAY,EAAZ,GAAiB,EAAnC;AACA,IAAMC,MAAM,GAAG,OAAf;AACA,IAAMC,MAAM,GAAG,OAAf;AAGA,IAAMC,CAAC,GAAGN,kBAAkB,GAAG,OAA/B;AAIA,IAAMO,EAAE,GAAG,QAAX;AACA,IAAMC,EAAE,GAAG,UAAX;AAEA,IAAMC,MAAM,GAAG,OAAf;AACA,IAAMC,MAAM,GAAG,WAAf;;AAkBO,SAASC,cAAT,CACLC,SADK,EAELC,QAFK,EAGLC,SAHK,EAIc;AACnB,MAAMC,sBAAsB,GAAGf,kBAAkB,GAAG,CAACc,SAArD;AACA,MAAME,GAAG,GAAGhB,kBAAkB,GAAGa,QAAjC;AACA,MAAMI,CAAC,GAAGC,MAAM,CAACN,SAAD,CAAhB;AAEA,MAAMO,CAAC,GAAGC,YAAY,CAACH,CAAD,CAAtB;AAEA,MAAMI,CAAC,GAAGC,eAAe,CAACL,CAAD,EAAIF,sBAAJ,CAAf,GAA6CI,CAAC,CAACI,cAAzD;AAEA,SAAO;AACLC,IAAAA,OAAO,EAAEC,UAAU,CAACJ,CAAD,EAAIL,GAAJ,EAASG,CAAC,CAACO,WAAX,CADd;AAELC,IAAAA,QAAQ,EAAEC,WAAW,CAACP,CAAD,EAAIL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AyByB,KAAzB,EAAwChC,sBAAxC,EAAgF;AAC9E,SAAOf,kBAAkB,IAAIS,MAAM,GAAGC,MAAM,GAAGqC,KAAtB,CAAlB,GAAiDhC,sBAAxD;AACD;;AAED,SAASiC,mBAAT,CAA6BC,IAA7B,EAAmD;AACjD,SAAOjD,kBAAkB,IAAIO,EAAE,GAAGC,EAAE,GAAGyC,IAAd,CAAzB;AACD;;AAED,SAASC,oBAAT,CAA8BC,WAA9B,EAA2D;AACzD,MAAMC,CAAC,GAAGD,WAAV;AAEA,MAAME,CAAC,GACLrD,kBAAkB,IAAI,SAASC,IAAI,CAAC8B,GAAL,CAASqB,CAAT,CAAT,GAAuB,OAAOnD,IAAI,CAAC8B,GAAL,CAAS,IAAIqB,CAAb,CAA9B,GAAgD,SAASnD,IAAI,CAAC8B,GAAL,CAAS,IAAIqB,CAAb,CAA7D,CADpB;AAGA,MAAME,CAAC,GAAGtD,kBAAkB,GAAG,QAA/B;AAEA,SAAOoD,CAAC,GAAGC,CAAJ,GAAQC,CAAR,GAAYrD,IAAI,CAACC,EAAxB;AACD;;AAED,SAASkB,YAAT,CAAsB2B,KAAtB,EAGE;AACA,MAAMK,CAAC,GAAGJ,mBAAmB,CAACD,KAAD,CAA7B;AACA,MAAMQ,CAAC,GAAGL,oBAAoB,CAACE,CAAD,CAA9B;AAEA,SAAO;AACL1B,IAAAA,WAAW,EAAEgB,cAAc,CAACa,CAAD,EAAI,CAAJ,CADtB;AAELhC,IAAAA,cAAc,EAAEa,iBAAiB,CAACmB,CAAD,EAAI,CAAJ;AAF5B,GAAP;AAID","sourcesContent":["const DEGREES_TO_RADIANS = Math.PI / 180;\n\nconst DAY_IN_MS = 1000 * 60 * 60 * 24;\nconst JD1970 = 2440588; // Julian Day year 1970\nconst JD2000 = 2451545; // Julian Day year 2000\n\n// This angle ε [epsilon] is called the obliquity of the ecliptic and its value at the beginning of 2000 was 23.4397°\nconst e = DEGREES_TO_RADIANS * 23.4397; // obliquity of the Earth\n\n// Refer https://www.aa.quae.nl/en/reken/zonpositie.html\n// \"The Mean Anomaly\" section for explanation\nconst M0 = 357.5291; // Earth mean anomaly on start day\nconst M1 = 0.98560028; // Earth angle traverses on average per day seen from the sun\n\nconst THETA0 = 280.147; // The sidereal time (in degrees) at longitude 0° at the instant defined by JD2000\nconst THETA1 = 360.9856235; // The rate of change of the sidereal time, in degrees per day.\n\n/**\n * A position in the sky defined by two angles\n * The altitude is 0° at the horizon, +90° in the zenith (straight over your head), and −90° in the nadir (straight down).\n * The azimuth is the direction along the horizon, which we measure from south to west.\n * South has azimuth 0°, west +90°, north +180°, and east +270° (or −90°, that's the same thing).\n */\nexport type CelestialPosition = {\n azimuth: number;\n altitude: number;\n};\n\n/**\n * Calculate sun position\n * based on https://www.aa.quae.nl/en/reken/zonpositie.html\n * inspired by https://github.com/mourner/suncalc/blob/master/suncalc.js\n */\nexport function getSunPosition(\n timestamp: number | Date,\n latitude: number,\n longitude: number\n): CelestialPosition {\n const longitudeWestInRadians = DEGREES_TO_RADIANS * -longitude;\n const phi = DEGREES_TO_RADIANS * latitude;\n const d = toDays(timestamp);\n\n const c = getSunCoords(d);\n // hour angle\n const H = getSiderealTime(d, longitudeWestInRadians) - c.rightAscension;\n\n return {\n azimuth: getAzimuth(H, phi, c.declination),\n altitude: getAltitude(H, phi, c.declination)\n };\n}\n\nexport function getSunDirection(\n timestamp: number | Date,\n latitude: number,\n longitude: number\n): number[] {\n const {azimuth, altitude} = getSunPosition(timestamp, latitude, longitude);\n // convert azimuth from 0 at south to be 0 at north\n const azimuthN = azimuth + Math.PI;\n\n // solar position to light direction\n return [-Math.sin(azimuthN), Math.cos(azimuthN), -Math.sin(altitude)];\n}\n\nfunction toJulianDay(timestamp: number | Date): number {\n const ts = typeof timestamp === 'number' ? timestamp : timestamp.getTime();\n return ts / DAY_IN_MS - 0.5 + JD1970;\n}\n\nfunction toDays(timestamp: number | Date): number {\n return toJulianDay(timestamp) - JD2000;\n}\n\nfunction getRightAscension(eclipticLongitude: number, b: number): number {\n const lambda = eclipticLongitude;\n return Math.atan2(Math.sin(lambda) * Math.cos(e) - Math.tan(b) * Math.sin(e), Math.cos(lambda));\n}\n\nfunction getDeclination(eclipticLongitude: number, b: number): number {\n const lambda = eclipticLongitude;\n return Math.asin(Math.sin(b) * Math.cos(e) + Math.cos(b) * Math.sin(e) * Math.sin(lambda));\n}\n\nfunction getAzimuth(hourAngle: number, latitudeInRadians: number, declination: number): number {\n const H = hourAngle;\n const phi = latitudeInRadians;\n const delta = declination;\n return Math.atan2(Math.sin(H), Math.cos(H) * Math.sin(phi) - Math.tan(delta) * Math.cos(phi));\n}\n\nfunction getAltitude(hourAngle: number, latitudeInRadians: number, declination: number): number {\n const H = hourAngle;\n const phi = latitudeInRadians;\n const delta = declination;\n return Math.asin(Math.sin(phi) * Math.sin(delta) + Math.cos(phi) * Math.cos(delta) * Math.cos(H));\n}\n\n// https://www.aa.quae.nl/en/reken/zonpositie.html\n// \"The Observer section\"\nfunction getSiderealTime(dates: number, longitudeWestInRadians: number): number {\n return DEGREES_TO_RADIANS * (THETA0 + THETA1 * dates) - longitudeWestInRadians;\n}\n\nfunction getSolarMeanAnomaly(days: number): number {\n return DEGREES_TO_RADIANS * (M0 + M1 * days);\n}\n\nfunction getEclipticLongitude(meanAnomaly: number): number {\n const M = meanAnomaly;\n // equation of center\n const C =\n DEGREES_TO_RADIANS * (1.9148 * Math.sin(M) + 0.02 * Math.sin(2 * M) + 0.0003 * Math.sin(3 * M));\n // perihelion of the Earth\n const P = DEGREES_TO_RADIANS * 102.9372;\n\n return M + C + P + Math.PI;\n}\n\nfunction getSunCoords(dates: number): {\n declination: number;\n rightAscension: number;\n} {\n const M = getSolarMeanAnomaly(dates);\n const L = getEclipticLongitude(M);\n\n return {\n declination: getDeclination(L, 0),\n rightAscension: getRightAscension(L, 0)\n };\n}\n"],"file":"suncalc.js"}
|
package/dist/esm/suncalc.js
CHANGED
|
@@ -28,7 +28,8 @@ export function getSunDirection(timestamp, latitude, longitude) {
|
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
function toJulianDay(timestamp) {
|
|
31
|
-
|
|
31
|
+
const ts = typeof timestamp === 'number' ? timestamp : timestamp.getTime();
|
|
32
|
+
return ts / DAY_IN_MS - 0.5 + JD1970;
|
|
32
33
|
}
|
|
33
34
|
|
|
34
35
|
function toDays(timestamp) {
|
package/dist/esm/suncalc.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/suncalc.ts"],"names":["DEGREES_TO_RADIANS","Math","PI","DAY_IN_MS","JD1970","JD2000","e","M0","M1","THETA0","THETA1","getSunPosition","timestamp","latitude","longitude","longitudeWestInRadians","phi","d","toDays","c","getSunCoords","H","getSiderealTime","rightAscension","azimuth","getAzimuth","declination","altitude","getAltitude","getSunDirection","azimuthN","sin","cos","toJulianDay","getRightAscension","eclipticLongitude","b","lambda","atan2","tan","getDeclination","asin","hourAngle","latitudeInRadians","delta","dates","getSolarMeanAnomaly","days","getEclipticLongitude","meanAnomaly","M","C","P","L"],"mappings":"AAAA,MAAMA,kBAAkB,GAAGC,IAAI,CAACC,EAAL,GAAU,GAArC;AAEA,MAAMC,SAAS,GAAG,OAAO,EAAP,GAAY,EAAZ,GAAiB,EAAnC;AACA,MAAMC,MAAM,GAAG,OAAf;AACA,MAAMC,MAAM,GAAG,OAAf;AAGA,MAAMC,CAAC,GAAGN,kBAAkB,GAAG,OAA/B;AAIA,MAAMO,EAAE,GAAG,QAAX;AACA,MAAMC,EAAE,GAAG,UAAX;AAEA,MAAMC,MAAM,GAAG,OAAf;AACA,MAAMC,MAAM,GAAG,WAAf;AAkBA,OAAO,SAASC,cAAT,CACLC,SADK,EAELC,QAFK,EAGLC,SAHK,EAIc;AACnB,QAAMC,sBAAsB,GAAGf,kBAAkB,GAAG,CAACc,SAArD;AACA,QAAME,GAAG,GAAGhB,kBAAkB,GAAGa,QAAjC;AACA,QAAMI,CAAC,GAAGC,MAAM,CAACN,SAAD,CAAhB;AAEA,QAAMO,CAAC,GAAGC,YAAY,CAACH,CAAD,CAAtB;AAEA,QAAMI,CAAC,GAAGC,eAAe,CAACL,CAAD,EAAIF,sBAAJ,CAAf,GAA6CI,CAAC,CAACI,cAAzD;AAEA,SAAO;AACLC,IAAAA,OAAO,EAAEC,UAAU,CAACJ,CAAD,EAAIL,GAAJ,EAASG,CAAC,CAACO,WAAX,CADd;AAELC,IAAAA,QAAQ,EAAEC,WAAW,CAACP,CAAD,EAAIL,GAAJ,EAASG,CAAC,CAACO,WAAX;AAFhB,GAAP;AAID;AAED,OAAO,SAASG,eAAT,CACLjB,SADK,EAELC,QAFK,EAGLC,SAHK,EAIK;AACV,QAAM;AAACU,IAAAA,OAAD;AAAUG,IAAAA;AAAV,MAAsBhB,cAAc,CAACC,SAAD,EAAYC,QAAZ,EAAsBC,SAAtB,CAA1C;AAEA,QAAMgB,QAAQ,GAAGN,OAAO,GAAGvB,IAAI,CAACC,EAAhC;AAGA,SAAO,CAAC,CAACD,IAAI,CAAC8B,GAAL,CAASD,QAAT,CAAF,EAAsB7B,IAAI,CAAC+B,GAAL,CAASF,QAAT,CAAtB,EAA0C,CAAC7B,IAAI,CAAC8B,GAAL,CAASJ,QAAT,CAA3C,CAAP;AACD;;AAED,SAASM,WAAT,CAAqBrB,SAArB,
|
|
1
|
+
{"version":3,"sources":["../../src/suncalc.ts"],"names":["DEGREES_TO_RADIANS","Math","PI","DAY_IN_MS","JD1970","JD2000","e","M0","M1","THETA0","THETA1","getSunPosition","timestamp","latitude","longitude","longitudeWestInRadians","phi","d","toDays","c","getSunCoords","H","getSiderealTime","rightAscension","azimuth","getAzimuth","declination","altitude","getAltitude","getSunDirection","azimuthN","sin","cos","toJulianDay","ts","getTime","getRightAscension","eclipticLongitude","b","lambda","atan2","tan","getDeclination","asin","hourAngle","latitudeInRadians","delta","dates","getSolarMeanAnomaly","days","getEclipticLongitude","meanAnomaly","M","C","P","L"],"mappings":"AAAA,MAAMA,kBAAkB,GA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,CAAT,GAAuB,OAAOnD,IAAI,CAAC8B,GAAL,CAAS,IAAIqB,CAAb,CAA9B,GAAgD,SAASnD,IAAI,CAAC8B,GAAL,CAAS,IAAIqB,CAAb,CAA7D,CADpB;AAGA,QAAME,CAAC,GAAGtD,kBAAkB,GAAG,QAA/B;AAEA,SAAOoD,CAAC,GAAGC,CAAJ,GAAQC,CAAR,GAAYrD,IAAI,CAACC,EAAxB;AACD;;AAED,SAASkB,YAAT,CAAsB2B,KAAtB,EAGE;AACA,QAAMK,CAAC,GAAGJ,mBAAmB,CAACD,KAAD,CAA7B;AACA,QAAMQ,CAAC,GAAGL,oBAAoB,CAACE,CAAD,CAA9B;AAEA,SAAO;AACL1B,IAAAA,WAAW,EAAEgB,cAAc,CAACa,CAAD,EAAI,CAAJ,CADtB;AAELhC,IAAAA,cAAc,EAAEa,iBAAiB,CAACmB,CAAD,EAAI,CAAJ;AAF5B,GAAP;AAID","sourcesContent":["const DEGREES_TO_RADIANS = Math.PI / 180;\n\nconst DAY_IN_MS = 1000 * 60 * 60 * 24;\nconst JD1970 = 2440588; // Julian Day year 1970\nconst JD2000 = 2451545; // Julian Day year 2000\n\n// This angle ε [epsilon] is called the obliquity of the ecliptic and its value at the beginning of 2000 was 23.4397°\nconst e = DEGREES_TO_RADIANS * 23.4397; // obliquity of the Earth\n\n// Refer https://www.aa.quae.nl/en/reken/zonpositie.html\n// \"The Mean Anomaly\" section for explanation\nconst M0 = 357.5291; // Earth mean anomaly on start day\nconst M1 = 0.98560028; // Earth angle traverses on average per day seen from the sun\n\nconst THETA0 = 280.147; // The sidereal time (in degrees) at longitude 0° at the instant defined by JD2000\nconst THETA1 = 360.9856235; // The rate of change of the sidereal time, in degrees per day.\n\n/**\n * A position in the sky defined by two angles\n * The altitude is 0° at the horizon, +90° in the zenith (straight over your head), and −90° in the nadir (straight down).\n * The azimuth is the direction along the horizon, which we measure from south to west.\n * South has azimuth 0°, west +90°, north +180°, and east +270° (or −90°, that's the same thing).\n */\nexport type CelestialPosition = {\n azimuth: number;\n altitude: number;\n};\n\n/**\n * Calculate sun position\n * based on https://www.aa.quae.nl/en/reken/zonpositie.html\n * inspired by https://github.com/mourner/suncalc/blob/master/suncalc.js\n */\nexport function getSunPosition(\n timestamp: number | Date,\n latitude: number,\n longitude: number\n): CelestialPosition {\n const longitudeWestInRadians = DEGREES_TO_RADIANS * -longitude;\n const phi = DEGREES_TO_RADIANS * latitude;\n const d = toDays(timestamp);\n\n const c = getSunCoords(d);\n // hour angle\n const H = getSiderealTime(d, longitudeWestInRadians) - c.rightAscension;\n\n return {\n azimuth: getAzimuth(H, phi, c.declination),\n altitude: getAltitude(H, phi, c.declination)\n };\n}\n\nexport function getSunDirection(\n timestamp: number | Date,\n latitude: number,\n longitude: number\n): number[] {\n const {azimuth, altitude} = getSunPosition(timestamp, latitude, longitude);\n // convert azimuth from 0 at south to be 0 at north\n const azimuthN = azimuth + Math.PI;\n\n // solar position to light direction\n return [-Math.sin(azimuthN), Math.cos(azimuthN), -Math.sin(altitude)];\n}\n\nfunction toJulianDay(timestamp: number | Date): number {\n const ts = typeof timestamp === 'number' ? timestamp : timestamp.getTime();\n return ts / DAY_IN_MS - 0.5 + JD1970;\n}\n\nfunction toDays(timestamp: number | Date): number {\n return toJulianDay(timestamp) - JD2000;\n}\n\nfunction getRightAscension(eclipticLongitude: number, b: number): number {\n const lambda = eclipticLongitude;\n return Math.atan2(Math.sin(lambda) * Math.cos(e) - Math.tan(b) * Math.sin(e), Math.cos(lambda));\n}\n\nfunction getDeclination(eclipticLongitude: number, b: number): number {\n const lambda = eclipticLongitude;\n return Math.asin(Math.sin(b) * Math.cos(e) + Math.cos(b) * Math.sin(e) * Math.sin(lambda));\n}\n\nfunction getAzimuth(hourAngle: number, latitudeInRadians: number, declination: number): number {\n const H = hourAngle;\n const phi = latitudeInRadians;\n const delta = declination;\n return Math.atan2(Math.sin(H), Math.cos(H) * Math.sin(phi) - Math.tan(delta) * Math.cos(phi));\n}\n\nfunction getAltitude(hourAngle: number, latitudeInRadians: number, declination: number): number {\n const H = hourAngle;\n const phi = latitudeInRadians;\n const delta = declination;\n return Math.asin(Math.sin(phi) * Math.sin(delta) + Math.cos(phi) * Math.cos(delta) * Math.cos(H));\n}\n\n// https://www.aa.quae.nl/en/reken/zonpositie.html\n// \"The Observer section\"\nfunction getSiderealTime(dates: number, longitudeWestInRadians: number): number {\n return DEGREES_TO_RADIANS * (THETA0 + THETA1 * dates) - longitudeWestInRadians;\n}\n\nfunction getSolarMeanAnomaly(days: number): number {\n return DEGREES_TO_RADIANS * (M0 + M1 * days);\n}\n\nfunction getEclipticLongitude(meanAnomaly: number): number {\n const M = meanAnomaly;\n // equation of center\n const C =\n DEGREES_TO_RADIANS * (1.9148 * Math.sin(M) + 0.02 * Math.sin(2 * M) + 0.0003 * Math.sin(3 * M));\n // perihelion of the Earth\n const P = DEGREES_TO_RADIANS * 102.9372;\n\n return M + C + P + Math.PI;\n}\n\nfunction getSunCoords(dates: number): {\n declination: number;\n rightAscension: number;\n} {\n const M = getSolarMeanAnomaly(dates);\n const L = getEclipticLongitude(M);\n\n return {\n declination: getDeclination(L, 0),\n rightAscension: getRightAscension(L, 0)\n };\n}\n"],"file":"suncalc.js"}
|
package/dist/suncalc.js
CHANGED
|
@@ -35,7 +35,8 @@ export function getSunDirection(timestamp, latitude, longitude) {
|
|
|
35
35
|
return [-Math.sin(azimuthN), Math.cos(azimuthN), -Math.sin(altitude)];
|
|
36
36
|
}
|
|
37
37
|
function toJulianDay(timestamp) {
|
|
38
|
-
|
|
38
|
+
const ts = typeof timestamp === 'number' ? timestamp : timestamp.getTime();
|
|
39
|
+
return ts / DAY_IN_MS - 0.5 + JD1970;
|
|
39
40
|
}
|
|
40
41
|
function toDays(timestamp) {
|
|
41
42
|
return toJulianDay(timestamp) - JD2000;
|
package/package.json
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
7
7
|
},
|
|
8
|
-
"version": "3.6.0-alpha.
|
|
8
|
+
"version": "3.6.0-alpha.6",
|
|
9
9
|
"keywords": [
|
|
10
10
|
"javascript",
|
|
11
11
|
"math",
|
|
@@ -28,5 +28,5 @@
|
|
|
28
28
|
"dependencies": {
|
|
29
29
|
"@babel/runtime": "^7.12.0"
|
|
30
30
|
},
|
|
31
|
-
"gitHead": "
|
|
31
|
+
"gitHead": "3b19564c634dc2c0255708b024425050c7fb2b9f"
|
|
32
32
|
}
|
package/src/suncalc.ts
CHANGED
|
@@ -63,32 +63,33 @@ export function getSunDirection(
|
|
|
63
63
|
return [-Math.sin(azimuthN), Math.cos(azimuthN), -Math.sin(altitude)];
|
|
64
64
|
}
|
|
65
65
|
|
|
66
|
-
function toJulianDay(timestamp) {
|
|
67
|
-
|
|
66
|
+
function toJulianDay(timestamp: number | Date): number {
|
|
67
|
+
const ts = typeof timestamp === 'number' ? timestamp : timestamp.getTime();
|
|
68
|
+
return ts / DAY_IN_MS - 0.5 + JD1970;
|
|
68
69
|
}
|
|
69
70
|
|
|
70
|
-
function toDays(timestamp) {
|
|
71
|
+
function toDays(timestamp: number | Date): number {
|
|
71
72
|
return toJulianDay(timestamp) - JD2000;
|
|
72
73
|
}
|
|
73
74
|
|
|
74
|
-
function getRightAscension(eclipticLongitude, b) {
|
|
75
|
+
function getRightAscension(eclipticLongitude: number, b: number): number {
|
|
75
76
|
const lambda = eclipticLongitude;
|
|
76
77
|
return Math.atan2(Math.sin(lambda) * Math.cos(e) - Math.tan(b) * Math.sin(e), Math.cos(lambda));
|
|
77
78
|
}
|
|
78
79
|
|
|
79
|
-
function getDeclination(eclipticLongitude, b) {
|
|
80
|
+
function getDeclination(eclipticLongitude: number, b: number): number {
|
|
80
81
|
const lambda = eclipticLongitude;
|
|
81
82
|
return Math.asin(Math.sin(b) * Math.cos(e) + Math.cos(b) * Math.sin(e) * Math.sin(lambda));
|
|
82
83
|
}
|
|
83
84
|
|
|
84
|
-
function getAzimuth(hourAngle, latitudeInRadians, declination) {
|
|
85
|
+
function getAzimuth(hourAngle: number, latitudeInRadians: number, declination: number): number {
|
|
85
86
|
const H = hourAngle;
|
|
86
87
|
const phi = latitudeInRadians;
|
|
87
88
|
const delta = declination;
|
|
88
89
|
return Math.atan2(Math.sin(H), Math.cos(H) * Math.sin(phi) - Math.tan(delta) * Math.cos(phi));
|
|
89
90
|
}
|
|
90
91
|
|
|
91
|
-
function getAltitude(hourAngle, latitudeInRadians, declination) {
|
|
92
|
+
function getAltitude(hourAngle: number, latitudeInRadians: number, declination: number): number {
|
|
92
93
|
const H = hourAngle;
|
|
93
94
|
const phi = latitudeInRadians;
|
|
94
95
|
const delta = declination;
|
|
@@ -97,15 +98,15 @@ function getAltitude(hourAngle, latitudeInRadians, declination) {
|
|
|
97
98
|
|
|
98
99
|
// https://www.aa.quae.nl/en/reken/zonpositie.html
|
|
99
100
|
// "The Observer section"
|
|
100
|
-
function getSiderealTime(dates, longitudeWestInRadians) {
|
|
101
|
+
function getSiderealTime(dates: number, longitudeWestInRadians: number): number {
|
|
101
102
|
return DEGREES_TO_RADIANS * (THETA0 + THETA1 * dates) - longitudeWestInRadians;
|
|
102
103
|
}
|
|
103
104
|
|
|
104
|
-
function getSolarMeanAnomaly(days) {
|
|
105
|
+
function getSolarMeanAnomaly(days: number): number {
|
|
105
106
|
return DEGREES_TO_RADIANS * (M0 + M1 * days);
|
|
106
107
|
}
|
|
107
108
|
|
|
108
|
-
function getEclipticLongitude(meanAnomaly) {
|
|
109
|
+
function getEclipticLongitude(meanAnomaly: number): number {
|
|
109
110
|
const M = meanAnomaly;
|
|
110
111
|
// equation of center
|
|
111
112
|
const C =
|
|
@@ -116,7 +117,10 @@ function getEclipticLongitude(meanAnomaly) {
|
|
|
116
117
|
return M + C + P + Math.PI;
|
|
117
118
|
}
|
|
118
119
|
|
|
119
|
-
function getSunCoords(dates) {
|
|
120
|
+
function getSunCoords(dates: number): {
|
|
121
|
+
declination: number;
|
|
122
|
+
rightAscension: number;
|
|
123
|
+
} {
|
|
120
124
|
const M = getSolarMeanAnomaly(dates);
|
|
121
125
|
const L = getEclipticLongitude(M);
|
|
122
126
|
|