-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSunLight.cpp
146 lines (125 loc) · 3.79 KB
/
SunLight.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <sys/time.h>
#include "SunLight.h"
SunLight::SunLight(Date date, double latitude, double longitude)
{
_date = date;
_latitude = latitude;
_longitude = longitude;
_sun = new SunCalc(date, latitude, longitude);
}
/// \brief When the upper edge of the Sun appears over the eastern horizon in the morning (0.833 degrees)
time_t SunLight::sunrise()
{
return _sun->timeAtAngle(SunCalc::sunrise, true);
}
/// \brief When the upper edge of the Sun disappears below the horizon
time_t SunLight::sunset()
{
return _sun->timeAtAngle(SunCalc::sunrise, false);
}
/// \brief
time_t SunLight::sunriseEnd()
{
return _sun->timeAtAngle(SunCalc::sunriseEnd, true);
}
/// \brief
time_t SunLight::sunsetStart()
{
return _sun->timeAtAngle(SunCalc::sunriseEnd, false);
}
/// \brief Aka civild Dawn.
time_t SunLight::dawn()
{
return civilDawn();
}
/// \brief Aka civild dusk.
time_t SunLight::dusk()
{
return civilDusk();
}
/// \brief When there is enough light for objects to be distinguishable. This occurs when the sun is 6 degrees below the horizon in the morning
time_t SunLight::civilDawn()
{
return _sun->timeAtAngle(SunCalc::twilight, true);
}
/// \brief When the sun is 6 degrees below the horizon in the evening. At this time objects are distinguishable and some stars and planets are
/// visible to the naked eye.
time_t SunLight::civilDusk()
{
return _sun->timeAtAngle(SunCalc::twilight, false);
}
/// \brief When there is enough sunlight for the horizon and some objects to be distinguishable. This occurs when the Sun is 12 degrees below
// the horizon in the morning
time_t SunLight::nauticalDawn()
{
return _sun->timeAtAngle(SunCalc::nauticalTwilight, true);
}
/// \brief When the sun is 12 degrees below the horizon in the evening. At this time, objects are no longer distinguishable, and the horizon is
/// no longer visible to the naked eye
time_t SunLight::nauticalDusk()
{
return _sun->timeAtAngle(SunCalc::nauticalTwilight, false);
}
/// \brief Astronomical dusk is the moment when the geometric center of the Sun is 18 degrees below the horizon in the evening.
time_t SunLight::astronomicalDusk()
{
return _sun->timeAtAngle(SunCalc::night, false);
}
/// \brief When the sky is no longer completely dark. This occurs when the Sun is 18 degrees below the horizon in the morning
time_t SunLight::astronomicalDawn()
{
return _sun->timeAtAngle(SunCalc::night, true);
}
/// \brief When the Sun is close to the horizon on a sunny day, its light appears warmer and softer.
time_t SunLight::goldenHourStart()
{
return _sun->timeAtAngle(SunCalc::goldenHour, false);
}
/// \brief When the Sun is close to the horizon on a sunny day, its light appears warmer and softer.
time_t SunLight::goldenHourEnd()
{
return _sun->timeAtAngle(SunCalc::goldenHour, true);
}
/*
int main(int argc, char *argv[])
{
tzset();
Date d;
d.year = 2015;
d.month = 3;
d.day = 8;
SunLight s(d, 35.78L, -78.649999L);
time_t expt = 1425814530;
time_t x = s.sunrise();
if( x != expt )
{
std::cout << "Failed" << std::endl;
}
struct tm *ptm2 = gmtime(&x);
char buf[1024];
memset(buf, 0, sizeof(buf));
strftime(buf, sizeof(buf), "%Y %m %d %H:%M:%SZ", ptm2);
std::cout << buf << std::endl;
expt = 1425856548;
x = s.sunset();
if( x != expt )
{
std::cout << "Failed" << std::endl;
}
// London
SunLight london(d, 51.508530L, -0.076132L);
expt = 1425796261;
x = london.sunrise();
if( x != expt )
{
std::cout << "Failed" << std::endl;
}
ptm2 = gmtime(&x);
memset(buf, 0, sizeof(buf));
strftime(buf, sizeof(buf), "%Y %m %d %H:%M:%SZ", ptm2);
std::cout << buf << std::endl;
return 0;
}*/