1 | 'use strict';
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 | exports.Sunrise = undefined;
|
7 |
|
8 | var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); |
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 | var _base = require('./base');
|
20 |
|
21 | var _base2 = _interopRequireDefault(_base);
|
22 |
|
23 | var _eqtime = require('./eqtime');
|
24 |
|
25 | var _eqtime2 = _interopRequireDefault(_eqtime);
|
26 |
|
27 | var _sexagesimal = require('./sexagesimal');
|
28 |
|
29 | var _sexagesimal2 = _interopRequireDefault(_sexagesimal);
|
30 |
|
31 | var _solar = require('./solar');
|
32 |
|
33 | var _solar2 = _interopRequireDefault(_solar);
|
34 |
|
35 | var _julian = require('./julian');
|
36 |
|
37 | var _julian2 = _interopRequireDefault(_julian);
|
38 |
|
39 | var _rise = require('./rise');
|
40 |
|
41 | var _rise2 = _interopRequireDefault(_rise);
|
42 |
|
43 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
44 |
|
45 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
46 |
|
47 | var stdh0 = {
|
48 | sunrise: new _sexagesimal2.default.Angle(true, 0, 50, 0).rad(),
|
49 | sunriseEnd: new _sexagesimal2.default.Angle(true, 0, 18, 0).rad(),
|
50 | twilight: new _sexagesimal2.default.Angle(true, 6, 0, 0).rad(),
|
51 | nauticalTwilight: new _sexagesimal2.default.Angle(true, 12, 0, 0).rad(),
|
52 | night: new _sexagesimal2.default.Angle(true, 18, 0, 0).rad(),
|
53 | goldenHour: new _sexagesimal2.default.Angle(false, 6, 0, 0).rad()
|
54 | };
|
55 |
|
56 | var stdh0Sunrise = function stdh0Sunrise(refraction) {
|
57 | return _rise2.default.refraction(stdh0.sunrise, refraction);
|
58 | };
|
59 | var stdh0SunriseEnd = function stdh0SunriseEnd(refraction) {
|
60 | return _rise2.default.refraction(stdh0.sunriseEnd, refraction);
|
61 | };
|
62 | var stdh0Twilight = function stdh0Twilight(refraction) {
|
63 | return _rise2.default.refraction(stdh0.twilight, refraction);
|
64 | };
|
65 | var stdh0NauticalTwilight = function stdh0NauticalTwilight(refraction) {
|
66 | return _rise2.default.refraction(stdh0.nauticalTwilight, refraction);
|
67 | };
|
68 | var stdh0Night = function stdh0Night(refraction) {
|
69 | return _rise2.default.refraction(stdh0.night, refraction);
|
70 | };
|
71 | var stdh0GoldenHour = function stdh0GoldenHour(refraction) {
|
72 | return _rise2.default.refraction(stdh0.goldenHour, refraction);
|
73 | };
|
74 |
|
75 | var Sunrise = exports.Sunrise = function () {
|
76 | |
77 |
|
78 |
|
79 |
|
80 |
|
81 |
|
82 |
|
83 |
|
84 | function Sunrise(date, lat, lon, refraction) {
|
85 | _classCallCheck(this, Sunrise);
|
86 |
|
87 | this.date = date;
|
88 | this.jde = date.midnight().toJDE();
|
89 | this.lat = _sexagesimal2.default.angleFromDeg(lat);
|
90 | this.lon = _sexagesimal2.default.angleFromDeg(lon);
|
91 | this.refraction = refraction;
|
92 | }
|
93 |
|
94 | _createClass(Sunrise, [{
|
95 | key: '_calcNoon',
|
96 | value: function _calcNoon(jde) {
|
97 | var etime = _sexagesimal2.default.secFromHourAngle(_eqtime2.default.eSmart(jde));
|
98 | var delta = _sexagesimal2.default.secFromHourAngle(this.lon);
|
99 | var time = 43200 + delta - etime;
|
100 | return _base2.default.pmod(time / 86400, 86400);
|
101 | }
|
102 | }, {
|
103 | key: '_calcRiseOrSet',
|
104 | value: function _calcRiseOrSet(jde, h0, isSet) {
|
105 | var etime = _sexagesimal2.default.secFromHourAngle(_eqtime2.default.eSmart(jde));
|
106 | var solarDec = _solar2.default.apparentEquatorial(jde).dec;
|
107 | var ha = _rise2.default.hourAngle(this.lat, h0, solarDec);
|
108 | if (isSet) ha = -ha;
|
109 | var delta = _sexagesimal2.default.secFromHourAngle(ha - this.lon);
|
110 | var time = 43200 - delta - etime;
|
111 | return time / 86400;
|
112 | }
|
113 | }, {
|
114 | key: '_calcPolarDayNight',
|
115 | value: function _calcPolarDayNight(h0, isSet, step) {
|
116 | var jde = this.jde;
|
117 | var t = void 0;
|
118 | var failCnt = 0;
|
119 | while (failCnt < 190) {
|
120 |
|
121 | jde += step;
|
122 | try {
|
123 | t = this._calcRiseOrSet(jde, h0, isSet);
|
124 | t = this._calcRiseOrSet(jde + t, h0, isSet);
|
125 | break;
|
126 | } catch (e) {
|
127 | t = undefined;
|
128 | failCnt++;
|
129 | }
|
130 | }
|
131 | if (t === undefined) {
|
132 | return;
|
133 | }
|
134 | return new _julian2.default.Calendar().fromJDE(jde + t);
|
135 | }
|
136 | }, {
|
137 | key: '_calc',
|
138 | value: function _calc(h0, isSet) {
|
139 | var t = void 0;
|
140 | var jde = this.jde;
|
141 |
|
142 | try {
|
143 | t = this._calcRiseOrSet(jde, h0, isSet);
|
144 | t = this._calcRiseOrSet(jde + t, h0, isSet);
|
145 | return new _julian2.default.Calendar().fromJDE(jde + t);
|
146 | } catch (e) {
|
147 | var step = isSet ? -1 : 1;
|
148 | var doy = this.date.dayOfYear();
|
149 | if (
|
150 | this.lat > 0 && doy > 76 && doy < 267 ||
|
151 | this.lat < 0 && (doy < 83 || doy > 262)
|
152 | ) {
|
153 | step = -step;
|
154 | }
|
155 | return this._calcPolarDayNight(h0, isSet, step);
|
156 | }
|
157 | }
|
158 |
|
159 | |
160 |
|
161 |
|
162 |
|
163 |
|
164 | }, {
|
165 | key: 'noon',
|
166 | value: function noon() {
|
167 | var jde = this.jde;
|
168 |
|
169 | var t = this._calcNoon(jde + this.lon / (2 * Math.PI));
|
170 | t = this._calcNoon(jde + t);
|
171 | return new _julian2.default.Calendar().fromJDE(jde + t);
|
172 | }
|
173 |
|
174 | |
175 |
|
176 |
|
177 |
|
178 |
|
179 | }, {
|
180 | key: 'rise',
|
181 | value: function rise() {
|
182 | return this._calc(stdh0Sunrise(this.refraction), false);
|
183 | }
|
184 |
|
185 | |
186 |
|
187 |
|
188 |
|
189 |
|
190 | }, {
|
191 | key: 'set',
|
192 | value: function set() {
|
193 | return this._calc(stdh0Sunrise(this.refraction), true);
|
194 | }
|
195 |
|
196 | |
197 |
|
198 |
|
199 |
|
200 |
|
201 | }, {
|
202 | key: 'riseEnd',
|
203 | value: function riseEnd() {
|
204 | return this._calc(stdh0SunriseEnd(this.refraction), false);
|
205 | }
|
206 |
|
207 | |
208 |
|
209 |
|
210 |
|
211 |
|
212 | }, {
|
213 | key: 'setStart',
|
214 | value: function setStart() {
|
215 | return this._calc(stdh0SunriseEnd(this.refraction), true);
|
216 | }
|
217 |
|
218 | |
219 |
|
220 |
|
221 |
|
222 |
|
223 | }, {
|
224 | key: 'dawn',
|
225 | value: function dawn() {
|
226 | return this._calc(stdh0Twilight(this.refraction), false);
|
227 | }
|
228 |
|
229 | |
230 |
|
231 |
|
232 |
|
233 |
|
234 |
|
235 | }, {
|
236 | key: 'dusk',
|
237 | value: function dusk() {
|
238 | return this._calc(stdh0Twilight(this.refraction), true);
|
239 | }
|
240 |
|
241 | |
242 |
|
243 |
|
244 |
|
245 |
|
246 | }, {
|
247 | key: 'nauticalDawn',
|
248 | value: function nauticalDawn() {
|
249 | return this._calc(stdh0NauticalTwilight(this.refraction), false);
|
250 | }
|
251 |
|
252 | |
253 |
|
254 |
|
255 |
|
256 |
|
257 | }, {
|
258 | key: 'nauticalDusk',
|
259 | value: function nauticalDusk() {
|
260 | return this._calc(stdh0NauticalTwilight(this.refraction), true);
|
261 | }
|
262 |
|
263 | |
264 |
|
265 |
|
266 |
|
267 |
|
268 |
|
269 | }, {
|
270 | key: 'nightStart',
|
271 | value: function nightStart() {
|
272 | return this._calc(stdh0Night(this.refraction), true);
|
273 | }
|
274 |
|
275 | |
276 |
|
277 |
|
278 |
|
279 |
|
280 |
|
281 | }, {
|
282 | key: 'nightEnd',
|
283 | value: function nightEnd() {
|
284 | return this._calc(stdh0Night(this.refraction), false);
|
285 | }
|
286 |
|
287 | |
288 |
|
289 |
|
290 |
|
291 |
|
292 | }, {
|
293 | key: 'goldenHourStart',
|
294 | value: function goldenHourStart() {
|
295 | return this._calc(stdh0GoldenHour(this.refraction), true);
|
296 | }
|
297 |
|
298 | |
299 |
|
300 |
|
301 |
|
302 |
|
303 | }, {
|
304 | key: 'goldenHourEnd',
|
305 | value: function goldenHourEnd() {
|
306 | return this._calc(stdh0GoldenHour(this.refraction), false);
|
307 | }
|
308 | }]);
|
309 |
|
310 | return Sunrise;
|
311 | }();
|
312 |
|
313 | exports.default = {
|
314 | Sunrise: Sunrise
|
315 | }; |
\ | No newline at end of file |