@math.gl/sun 3.5.6 → 3.6.0-alpha.2

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.
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/index.js"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA","sourcesContent":["export {getSunPosition, getSunDirection} from './suncalc';\n"],"file":"index.js"}
1
+ {"version":3,"sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA","sourcesContent":["export {getSunPosition, getSunDirection} from './suncalc';\n"],"file":"index.js"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/suncalc.js"],"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":";;;;;;;AAEA,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;;AAEO,SAASC,cAAT,CAAwBC,SAAxB,EAAmCC,QAAnC,EAA6CC,SAA7C,EAAwD;AAC7D,MAAMC,sBAAsB,GAAGf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B;AAEL9B,IAAAA,cAAc,EAAEW,iBAAiB,CAACmB,CAAD,EAAI,CAAJ;AAF5B,GAAP;AAID","sourcesContent":["// sun position calculations are based on http://aa.quae.nl/en/reken/zonpositie.html formulas\n// and inspired by https://github.com/mourner/suncalc/blob/master/suncalc.js\nconst 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\nexport function getSunPosition(timestamp, latitude, longitude) {\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 // https://www.aa.quae.nl/en/reken/zonpositie.html\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 return {\n azimuth: getAzimuth(H, phi, c.declination),\n altitude: getAltitude(H, phi, c.declination)\n };\n}\n\nexport function getSunDirection(timestamp, latitude, longitude) {\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) {\n return timestamp / DAY_IN_MS - 0.5 + JD1970;\n}\n\nfunction toDays(timestamp) {\n return toJulianDay(timestamp) - JD2000;\n}\n\nfunction getRightAscension(eclipticLongitude, b) {\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, b) {\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, latitudeInRadians, declination) {\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, latitudeInRadians, declination) {\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, longitudeWestInRadians) {\n return DEGREES_TO_RADIANS * (THETA0 + THETA1 * dates) - longitudeWestInRadians;\n}\n\nfunction getSolarMeanAnomaly(days) {\n return DEGREES_TO_RADIANS * (M0 + M1 * days);\n}\n\nfunction getEclipticLongitude(meanAnomaly) {\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) {\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"}
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,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,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D;AACtD,SAAOf,kBAAkB,IAAIS,MAAM,GAAGC,MAAM,GAAGmC,KAAtB,CAAlB,GAAiD9B,sBAAxD;AACD;;AAED,SAAS+B,mBAAT,CAA6BC,IAA7B,EAAmC;AACjC,SAAO/C,kBAAkB,IAAIO,EAAE,GAAGC,EAAE,GAAGuC,IAAd,CAAzB;AACD;;AAED,SAASC,oBAAT,CAA8BC,WAA9B,EAA2C;AACzC,MAAMC,CAAC,GAAGD,WAAV;AAEA,MAAME,CAAC,GACLnD,kBAAkB,IAAI,SAASC,IAAI,CAAC8B,GAAL,CAASmB,CAAT,CAAT,GAAuB,OAAOjD,IAAI,CAAC8B,GAAL,CAAS,IAAImB,CAAb,CAA9B,GAAgD,SAASjD,IAAI,CAAC8B,GAAL,CAAS,IAAImB,CAAb,CAA7D,CADpB;AAGA,MAAME,CAAC,GAAGpD,kBAAkB,GAAG,QAA/B;AAEA,SAAOkD,CAAC,GAAGC,CAAJ,GAAQC,CAAR,GAAYnD,IAAI,CAACC,EAAxB;AACD;;AAED,SAASkB,YAAT,CAAsByB,KAAtB,EAA6B;AAC3B,MAAMK,CAAC,GAAGJ,mBAAmB,CAACD,KAAD,CAA7B;AACA,MAAMQ,CAAC,GAAGL,oBAAoB,CAACE,CAAD,CAA9B;AAEA,SAAO;AACLxB,IAAAA,WAAW,EAAEc,cAAc,CAACa,CAAD,EAAI,CAAJ,CADtB;AAEL9B,IAAAA,cAAc,EAAEW,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) {\n return timestamp / DAY_IN_MS - 0.5 + JD1970;\n}\n\nfunction toDays(timestamp) {\n return toJulianDay(timestamp) - JD2000;\n}\n\nfunction getRightAscension(eclipticLongitude, b) {\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, b) {\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, latitudeInRadians, declination) {\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, latitudeInRadians, declination) {\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, longitudeWestInRadians) {\n return DEGREES_TO_RADIANS * (THETA0 + THETA1 * dates) - longitudeWestInRadians;\n}\n\nfunction getSolarMeanAnomaly(days) {\n return DEGREES_TO_RADIANS * (M0 + M1 * days);\n}\n\nfunction getEclipticLongitude(meanAnomaly) {\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) {\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"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/index.js"],"names":["getSunPosition","getSunDirection"],"mappings":"AAAA,SAAQA,cAAR,EAAwBC,eAAxB,QAA8C,WAA9C","sourcesContent":["export {getSunPosition, getSunDirection} from './suncalc';\n"],"file":"index.js"}
1
+ {"version":3,"sources":["../../src/index.ts"],"names":["getSunPosition","getSunDirection"],"mappings":"AAAA,SAAQA,cAAR,EAAwBC,eAAxB,QAA8C,WAA9C","sourcesContent":["export {getSunPosition, getSunDirection} from './suncalc';\n"],"file":"index.js"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/suncalc.js"],"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":"AAEA,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;AAEA,OAAO,SAASC,cAAT,CAAwBC,SAAxB,EAAmCC,QAAnC,EAA6CC,SAA7C,EAAwD;AAC7D,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,cA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AT,CAA9E,CAAP;AACD;;AAID,SAASC,eAAT,CAAyBuB,KAAzB,EAAgC9B,sBAAhC,EAAwD;AACtD,SAAOf,kBAAkB,IAAIS,MAAM,GAAGC,MAAM,GAAGmC,KAAtB,CAAlB,GAAiD9B,sBAAxD;AACD;;AAED,SAAS+B,mBAAT,CAA6BC,IAA7B,EAAmC;AACjC,SAAO/C,kBAAkB,IAAIO,EAAE,GAAGC,EAAE,GAAGuC,IAAd,CAAzB;AACD;;AAED,SAASC,oBAAT,CAA8BC,WAA9B,EAA2C;AACzC,QAAMC,CAAC,GAAGD,WAAV;AAEA,QAAME,CAAC,GACLnD,kBAAkB,IAAI,SAASC,IAAI,CAAC8B,GAAL,CAASmB,CAAT,CAAT,GAAuB,OAAOjD,IAAI,CAAC8B,GAAL,CAAS,IAAImB,CAAb,CAA9B,GAAgD,SAASjD,IAAI,CAAC8B,GAAL,CAAS,IAAImB,CAAb,CAA7D,CADpB;AAGA,QAAME,CAAC,GAAGpD,kBAAkB,GAAG,QAA/B;AAEA,SAAOkD,CAAC,GAAGC,CAAJ,GAAQC,CAAR,GAAYnD,IAAI,CAACC,EAAxB;AACD;;AAED,SAASkB,YAAT,CAAsByB,KAAtB,EAA6B;AAC3B,QAAMK,CAAC,GAAGJ,mBAAmB,CAACD,KAAD,CAA7B;AACA,QAAMQ,CAAC,GAAGL,oBAAoB,CAACE,CAAD,CAA9B;AAEA,SAAO;AACLxB,IAAAA,WAAW,EAAEc,cAAc,CAACa,CAAD,EAAI,CAAJ,CADtB;AAEL9B,IAAAA,cAAc,EAAEW,iBAAiB,CAACmB,CAAD,EAAI,CAAJ;AAF5B,GAAP;AAID","sourcesContent":["// sun position calculations are based on http://aa.quae.nl/en/reken/zonpositie.html formulas\n// and inspired by https://github.com/mourner/suncalc/blob/master/suncalc.js\nconst 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\nexport function getSunPosition(timestamp, latitude, longitude) {\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 // https://www.aa.quae.nl/en/reken/zonpositie.html\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 return {\n azimuth: getAzimuth(H, phi, c.declination),\n altitude: getAltitude(H, phi, c.declination)\n };\n}\n\nexport function getSunDirection(timestamp, latitude, longitude) {\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) {\n return timestamp / DAY_IN_MS - 0.5 + JD1970;\n}\n\nfunction toDays(timestamp) {\n return toJulianDay(timestamp) - JD2000;\n}\n\nfunction getRightAscension(eclipticLongitude, b) {\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, b) {\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, latitudeInRadians, declination) {\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, latitudeInRadians, declination) {\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, longitudeWestInRadians) {\n return DEGREES_TO_RADIANS * (THETA0 + THETA1 * dates) - longitudeWestInRadians;\n}\n\nfunction getSolarMeanAnomaly(days) {\n return DEGREES_TO_RADIANS * (M0 + M1 * days);\n}\n\nfunction getEclipticLongitude(meanAnomaly) {\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) {\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"}
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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,kBAAkB,IAAI,SAASC,IAAI,CAAC8B,GAAL,CAASmB,CAAT,CAAT,GAAuB,OAAOjD,IAAI,CAAC8B,GAAL,CAAS,IAAImB,CAAb,CAA9B,GAAgD,SAASjD,IAAI,CAAC8B,GAAL,CAAS,IAAImB,CAAb,CAA7D,CADpB;AAGA,QAAME,CAAC,GAAGpD,kBAAkB,GAAG,QAA/B;AAEA,SAAOkD,CAAC,GAAGC,CAAJ,GAAQC,CAAR,GAAYnD,IAAI,CAACC,EAAxB;AACD;;AAED,SAASkB,YAAT,CAAsByB,KAAtB,EAA6B;AAC3B,QAAMK,CAAC,GAAGJ,mBAAmB,CAACD,KAAD,CAA7B;AACA,QAAMQ,CAAC,GAAGL,oBAAoB,CAACE,CAAD,CAA9B;AAEA,SAAO;AACLxB,IAAAA,WAAW,EAAEc,cAAc,CAACa,CAAD,EAAI,CAAJ,CADtB;AAEL9B,IAAAA,cAAc,EAAEW,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) {\n return timestamp / DAY_IN_MS - 0.5 + JD1970;\n}\n\nfunction toDays(timestamp) {\n return toJulianDay(timestamp) - JD2000;\n}\n\nfunction getRightAscension(eclipticLongitude, b) {\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, b) {\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, latitudeInRadians, declination) {\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, latitudeInRadians, declination) {\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, longitudeWestInRadians) {\n return DEGREES_TO_RADIANS * (THETA0 + THETA1 * dates) - longitudeWestInRadians;\n}\n\nfunction getSolarMeanAnomaly(days) {\n return DEGREES_TO_RADIANS * (M0 + M1 * days);\n}\n\nfunction getEclipticLongitude(meanAnomaly) {\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) {\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"}
@@ -0,0 +1,2 @@
1
+ export { getSunPosition, getSunDirection } from './suncalc';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,cAAc,EAAE,eAAe,EAAC,MAAM,WAAW,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1 @@
1
+ export { getSunPosition, getSunDirection } from './suncalc';
@@ -0,0 +1,18 @@
1
+ /**
2
+ * A position in the sky defined by two angles
3
+ * The altitude is 0° at the horizon, +90° in the zenith (straight over your head), and −90° in the nadir (straight down).
4
+ * The azimuth is the direction along the horizon, which we measure from south to west.
5
+ * South has azimuth 0°, west +90°, north +180°, and east +270° (or −90°, that's the same thing).
6
+ */
7
+ export declare type CelestialPosition = {
8
+ azimuth: number;
9
+ altitude: number;
10
+ };
11
+ /**
12
+ * Calculate sun position
13
+ * based on https://www.aa.quae.nl/en/reken/zonpositie.html
14
+ * inspired by https://github.com/mourner/suncalc/blob/master/suncalc.js
15
+ */
16
+ export declare function getSunPosition(timestamp: number | Date, latitude: number, longitude: number): CelestialPosition;
17
+ export declare function getSunDirection(timestamp: number | Date, latitude: number, longitude: number): number[];
18
+ //# sourceMappingURL=suncalc.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"suncalc.d.ts","sourceRoot":"","sources":["../src/suncalc.ts"],"names":[],"mappings":"AAiBA;;;;;GAKG;AACH,oBAAY,iBAAiB,GAAG;IAC9B,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF;;;;GAIG;AACH,wBAAgB,cAAc,CAC5B,SAAS,EAAE,MAAM,GAAG,IAAI,EACxB,QAAQ,EAAE,MAAM,EAChB,SAAS,EAAE,MAAM,GAChB,iBAAiB,CAanB;AAED,wBAAgB,eAAe,CAC7B,SAAS,EAAE,MAAM,GAAG,IAAI,EACxB,QAAQ,EAAE,MAAM,EAChB,SAAS,EAAE,MAAM,GAChB,MAAM,EAAE,CAOV"}
@@ -0,0 +1,86 @@
1
+ const DEGREES_TO_RADIANS = Math.PI / 180;
2
+ const DAY_IN_MS = 1000 * 60 * 60 * 24;
3
+ const JD1970 = 2440588; // Julian Day year 1970
4
+ const JD2000 = 2451545; // Julian Day year 2000
5
+ // This angle ε [epsilon] is called the obliquity of the ecliptic and its value at the beginning of 2000 was 23.4397°
6
+ const e = DEGREES_TO_RADIANS * 23.4397; // obliquity of the Earth
7
+ // Refer https://www.aa.quae.nl/en/reken/zonpositie.html
8
+ // "The Mean Anomaly" section for explanation
9
+ const M0 = 357.5291; // Earth mean anomaly on start day
10
+ const M1 = 0.98560028; // Earth angle traverses on average per day seen from the sun
11
+ const THETA0 = 280.147; // The sidereal time (in degrees) at longitude 0° at the instant defined by JD2000
12
+ const THETA1 = 360.9856235; // The rate of change of the sidereal time, in degrees per day.
13
+ /**
14
+ * Calculate sun position
15
+ * based on https://www.aa.quae.nl/en/reken/zonpositie.html
16
+ * inspired by https://github.com/mourner/suncalc/blob/master/suncalc.js
17
+ */
18
+ export function getSunPosition(timestamp, latitude, longitude) {
19
+ const longitudeWestInRadians = DEGREES_TO_RADIANS * -longitude;
20
+ const phi = DEGREES_TO_RADIANS * latitude;
21
+ const d = toDays(timestamp);
22
+ const c = getSunCoords(d);
23
+ // hour angle
24
+ const H = getSiderealTime(d, longitudeWestInRadians) - c.rightAscension;
25
+ return {
26
+ azimuth: getAzimuth(H, phi, c.declination),
27
+ altitude: getAltitude(H, phi, c.declination)
28
+ };
29
+ }
30
+ export function getSunDirection(timestamp, latitude, longitude) {
31
+ const { azimuth, altitude } = getSunPosition(timestamp, latitude, longitude);
32
+ // convert azimuth from 0 at south to be 0 at north
33
+ const azimuthN = azimuth + Math.PI;
34
+ // solar position to light direction
35
+ return [-Math.sin(azimuthN), Math.cos(azimuthN), -Math.sin(altitude)];
36
+ }
37
+ function toJulianDay(timestamp) {
38
+ return timestamp / DAY_IN_MS - 0.5 + JD1970;
39
+ }
40
+ function toDays(timestamp) {
41
+ return toJulianDay(timestamp) - JD2000;
42
+ }
43
+ function getRightAscension(eclipticLongitude, b) {
44
+ const lambda = eclipticLongitude;
45
+ return Math.atan2(Math.sin(lambda) * Math.cos(e) - Math.tan(b) * Math.sin(e), Math.cos(lambda));
46
+ }
47
+ function getDeclination(eclipticLongitude, b) {
48
+ const lambda = eclipticLongitude;
49
+ return Math.asin(Math.sin(b) * Math.cos(e) + Math.cos(b) * Math.sin(e) * Math.sin(lambda));
50
+ }
51
+ function getAzimuth(hourAngle, latitudeInRadians, declination) {
52
+ const H = hourAngle;
53
+ const phi = latitudeInRadians;
54
+ const delta = declination;
55
+ return Math.atan2(Math.sin(H), Math.cos(H) * Math.sin(phi) - Math.tan(delta) * Math.cos(phi));
56
+ }
57
+ function getAltitude(hourAngle, latitudeInRadians, declination) {
58
+ const H = hourAngle;
59
+ const phi = latitudeInRadians;
60
+ const delta = declination;
61
+ return Math.asin(Math.sin(phi) * Math.sin(delta) + Math.cos(phi) * Math.cos(delta) * Math.cos(H));
62
+ }
63
+ // https://www.aa.quae.nl/en/reken/zonpositie.html
64
+ // "The Observer section"
65
+ function getSiderealTime(dates, longitudeWestInRadians) {
66
+ return DEGREES_TO_RADIANS * (THETA0 + THETA1 * dates) - longitudeWestInRadians;
67
+ }
68
+ function getSolarMeanAnomaly(days) {
69
+ return DEGREES_TO_RADIANS * (M0 + M1 * days);
70
+ }
71
+ function getEclipticLongitude(meanAnomaly) {
72
+ const M = meanAnomaly;
73
+ // equation of center
74
+ const C = DEGREES_TO_RADIANS * (1.9148 * Math.sin(M) + 0.02 * Math.sin(2 * M) + 0.0003 * Math.sin(3 * M));
75
+ // perihelion of the Earth
76
+ const P = DEGREES_TO_RADIANS * 102.9372;
77
+ return M + C + P + Math.PI;
78
+ }
79
+ function getSunCoords(dates) {
80
+ const M = getSolarMeanAnomaly(dates);
81
+ const L = getEclipticLongitude(M);
82
+ return {
83
+ declination: getDeclination(L, 0),
84
+ rightAscension: getRightAscension(L, 0)
85
+ };
86
+ }
package/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "publishConfig": {
6
6
  "access": "public"
7
7
  },
8
- "version": "3.5.6",
8
+ "version": "3.6.0-alpha.2",
9
9
  "keywords": [
10
10
  "javascript",
11
11
  "math",
@@ -18,7 +18,7 @@
18
18
  "type": "git",
19
19
  "url": "https://github.com/uber-web/math.gl.git"
20
20
  },
21
- "types": "src/index.d.ts",
21
+ "types": "dist/index.d.ts",
22
22
  "main": "dist/es5/index.js",
23
23
  "module": "dist/esm/index.js",
24
24
  "files": [
@@ -28,5 +28,5 @@
28
28
  "dependencies": {
29
29
  "@babel/runtime": "^7.12.0"
30
30
  },
31
- "gitHead": "0e69c70ff2e6373fed84d303cbf8198a6972944f"
31
+ "gitHead": "ea7dc265c98b68af56218302d1d42b7d65f74ccb"
32
32
  }
File without changes
@@ -1,5 +1,3 @@
1
- // sun position calculations are based on http://aa.quae.nl/en/reken/zonpositie.html formulas
2
- // and inspired by https://github.com/mourner/suncalc/blob/master/suncalc.js
3
1
  const DEGREES_TO_RADIANS = Math.PI / 180;
4
2
 
5
3
  const DAY_IN_MS = 1000 * 60 * 60 * 24;
@@ -17,7 +15,27 @@ const M1 = 0.98560028; // Earth angle traverses on average per day seen from the
17
15
  const THETA0 = 280.147; // The sidereal time (in degrees) at longitude 0° at the instant defined by JD2000
18
16
  const THETA1 = 360.9856235; // The rate of change of the sidereal time, in degrees per day.
19
17
 
20
- export function getSunPosition(timestamp, latitude, longitude) {
18
+ /**
19
+ * A position in the sky defined by two angles
20
+ * The altitude is 0° at the horizon, +90° in the zenith (straight over your head), and −90° in the nadir (straight down).
21
+ * The azimuth is the direction along the horizon, which we measure from south to west.
22
+ * South has azimuth 0°, west +90°, north +180°, and east +270° (or −90°, that's the same thing).
23
+ */
24
+ export type CelestialPosition = {
25
+ azimuth: number;
26
+ altitude: number;
27
+ };
28
+
29
+ /**
30
+ * Calculate sun position
31
+ * based on https://www.aa.quae.nl/en/reken/zonpositie.html
32
+ * inspired by https://github.com/mourner/suncalc/blob/master/suncalc.js
33
+ */
34
+ export function getSunPosition(
35
+ timestamp: number | Date,
36
+ latitude: number,
37
+ longitude: number
38
+ ): CelestialPosition {
21
39
  const longitudeWestInRadians = DEGREES_TO_RADIANS * -longitude;
22
40
  const phi = DEGREES_TO_RADIANS * latitude;
23
41
  const d = toDays(timestamp);
@@ -26,17 +44,17 @@ export function getSunPosition(timestamp, latitude, longitude) {
26
44
  // hour angle
27
45
  const H = getSiderealTime(d, longitudeWestInRadians) - c.rightAscension;
28
46
 
29
- // https://www.aa.quae.nl/en/reken/zonpositie.html
30
- // The altitude is 0° at the horizon, +90° in the zenith (straight over your head), and −90° in the nadir (straight down).
31
- // The azimuth is the direction along the horizon, which we measure from south to west.
32
- // South has azimuth 0°, west +90°, north +180°, and east +270° (or −90°, that's the same thing).
33
47
  return {
34
48
  azimuth: getAzimuth(H, phi, c.declination),
35
49
  altitude: getAltitude(H, phi, c.declination)
36
50
  };
37
51
  }
38
52
 
39
- export function getSunDirection(timestamp, latitude, longitude) {
53
+ export function getSunDirection(
54
+ timestamp: number | Date,
55
+ latitude: number,
56
+ longitude: number
57
+ ): number[] {
40
58
  const {azimuth, altitude} = getSunPosition(timestamp, latitude, longitude);
41
59
  // convert azimuth from 0 at south to be 0 at north
42
60
  const azimuthN = azimuth + Math.PI;
@@ -1,20 +0,0 @@
1
- type CelestialPosition = {
2
- azimuth: number;
3
- altitude: number;
4
- };
5
-
6
- // https://www.aa.quae.nl/en/reken/zonpositie.html
7
- // The altitude is 0° at the horizon, +90° in the zenith (straight over your head), and −90° in the nadir (straight down).
8
- // The azimuth is the direction along the horizon, which we measure from south to west.
9
- // South has azimuth 0°, west +90°, north +180°, and east +270° (or −90°, that's the same thing).
10
- export function getSunPosition(
11
- timestamp: number | Date,
12
- latitude: number,
13
- longitude: number
14
- ): CelestialPosition;
15
-
16
- export function getSunDirection(
17
- timestamp: number | Date,
18
- latitude: number,
19
- longitude: number
20
- ): number[];
@@ -1 +0,0 @@
1
- export {getSunPosition, getSunDirection} from './suncalc';
@@ -1,20 +0,0 @@
1
- type CelestialPosition = {
2
- azimuth: number;
3
- altitude: number;
4
- };
5
-
6
- // https://www.aa.quae.nl/en/reken/zonpositie.html
7
- // The altitude is 0° at the horizon, +90° in the zenith (straight over your head), and −90° in the nadir (straight down).
8
- // The azimuth is the direction along the horizon, which we measure from south to west.
9
- // South has azimuth 0°, west +90°, north +180°, and east +270° (or −90°, that's the same thing).
10
- export function getSunPosition(
11
- timestamp: number | Date,
12
- latitude: number,
13
- longitude: number
14
- ): CelestialPosition;
15
-
16
- export function getSunDirection(
17
- timestamp: number | Date,
18
- latitude: number,
19
- longitude: number
20
- ): number[];
package/src/index.d.ts DELETED
@@ -1 +0,0 @@
1
- export {getSunPosition, getSunDirection} from './suncalc';
package/src/index.js DELETED
@@ -1 +0,0 @@
1
- export {getSunPosition, getSunDirection} from './suncalc';
package/src/suncalc.d.ts DELETED
@@ -1,20 +0,0 @@
1
- type CelestialPosition = {
2
- azimuth: number;
3
- altitude: number;
4
- };
5
-
6
- // https://www.aa.quae.nl/en/reken/zonpositie.html
7
- // The altitude is 0° at the horizon, +90° in the zenith (straight over your head), and −90° in the nadir (straight down).
8
- // The azimuth is the direction along the horizon, which we measure from south to west.
9
- // South has azimuth 0°, west +90°, north +180°, and east +270° (or −90°, that's the same thing).
10
- export function getSunPosition(
11
- timestamp: number | Date,
12
- latitude: number,
13
- longitude: number
14
- ): CelestialPosition;
15
-
16
- export function getSunDirection(
17
- timestamp: number | Date,
18
- latitude: number,
19
- longitude: number
20
- ): number[];