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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
//! # Solar Positioning Library
//!
//! High-accuracy solar positioning algorithms for calculating sun position and sunrise/sunset times.
//!
//! This library provides implementations of two complementary solar positioning algorithms:
//! - **SPA** (Solar Position Algorithm): NREL's authoritative algorithm (±0.0003°, years -2000 to 6000)
//! - **Grena3**: Simplified algorithm (±0.01°, years 2010-2110, ~10x faster)
//!
//! In addition, it provides an estimator for Delta T (ΔT) values based on the work of F. Espenak & J. Meeus.
//!
//! ## Features
//!
//! - Multiple configurations: `std` or `no_std`, with or without `chrono`, math via native or `libm`
//! - Maximum accuracy: Authentic NREL SPA implementation, validated against reference data
//! - Performance optimized: Split functions for bulk calculations (SPA only)
//! - Thread-safe: Stateless, immutable data structures
//!
//! ## Feature Flags
//!
//! - `std` (default): Use standard library for native math functions (usually faster than `libm`)
//! - `chrono` (default): Enable `DateTime<Tz>` based convenience API
//! - `libm`: Use pure Rust math for `no_std` environments
//!
//! **Configuration examples:**
//! ```toml
//! # Default: std + chrono (most convenient)
//! solar-positioning = "0.5"
//!
//! # Minimal std (no chrono, smallest dependency tree)
//! solar-positioning = { version = "0.5", default-features = false, features = ["std"] }
//!
//! # no_std + chrono (embedded with DateTime support)
//! solar-positioning = { version = "0.5", default-features = false, features = ["libm", "chrono"] }
//!
//! # Minimal no_std (pure numeric API)
//! solar-positioning = { version = "0.5", default-features = false, features = ["libm"] }
//! ```
//!
//! ## References
//!
//! - Reda, I.; Andreas, A. (2003). Solar position algorithm for solar radiation applications.
//! Solar Energy, 76(5), 577-589. DOI: <http://dx.doi.org/10.1016/j.solener.2003.12.003>
//! - Grena, R. (2012). Five new algorithms for the computation of sun position from 2010 to 2110.
//! Solar Energy, 86(5), 1323-1337. DOI: <http://dx.doi.org/10.1016/j.solener.2012.01.024>
//!
//! ## Quick Start
//!
//! ### Solar Position (with chrono)
//! ```rust
//! # #[cfg(feature = "chrono")] {
//! use solar_positioning::{spa, RefractionCorrection, time::DeltaT};
//! use chrono::{DateTime, FixedOffset};
//!
//! // Calculate sun position for Vienna at noon
//! let datetime = "2026-06-21T12:00:00+02:00".parse::<DateTime<FixedOffset>>().unwrap();
//! let position = spa::solar_position(
//! datetime,
//! 48.21, // Vienna latitude
//! 16.37, // Vienna longitude
//! 190.0, // elevation (meters)
//! DeltaT::estimate_from_date_like(datetime).unwrap(), // delta T
//! Some(RefractionCorrection::standard())
//! ).unwrap();
//!
//! println!("Azimuth: {:.3}°", position.azimuth());
//! println!("Elevation: {:.3}°", position.elevation_angle());
//! # }
//! ```
//!
//! ### Solar Position (numeric API, no chrono)
//! ```rust
//! use solar_positioning::{spa, time::JulianDate, RefractionCorrection};
//!
//! // Create Julian date from UTC components (2026-06-21 12:00:00 UTC + 69s ΔT)
//! let jd = JulianDate::from_utc(2026, 6, 21, 12, 0, 0.0, 69.0).unwrap();
//!
//! // Calculate sun position (works in both std and no_std)
//! let position = spa::solar_position_from_julian(
//! jd,
//! 48.21, // Vienna latitude
//! 16.37, // Vienna longitude
//! 190.0, // elevation (meters)
//! Some(RefractionCorrection::standard())
//! ).unwrap();
//!
//! println!("Azimuth: {:.3}°", position.azimuth());
//! println!("Elevation: {:.3}°", position.elevation_angle());
//! ```
//!
//! ### Sunrise and Sunset (with chrono)
//! ```rust
//! # #[cfg(feature = "chrono")] {
//! use solar_positioning::{spa, Horizon, time::DeltaT};
//! use chrono::{DateTime, FixedOffset};
//!
//! // Calculate sunrise/sunset for San Francisco
//! let date = "2026-06-21T00:00:00-07:00".parse::<DateTime<FixedOffset>>().unwrap();
//! // Note: returned timestamps are in the same timezone as `date`, but can fall on the
//! // previous/next local calendar date when events occur near midnight.
//! let result = spa::sunrise_sunset_for_horizon(
//! date,
//! 37.7749, // San Francisco latitude
//! -122.4194, // San Francisco longitude
//! DeltaT::estimate_from_date_like(date).unwrap(),
//! Horizon::SunriseSunset
//! ).unwrap();
//!
//! match result {
//! solar_positioning::SunriseResult::RegularDay { sunrise, transit, sunset } => {
//! println!("Sunrise: {}", sunrise);
//! println!("Solar noon: {}", transit);
//! println!("Sunset: {}", sunset);
//! }
//! _ => println!("No sunrise/sunset (polar day/night)"),
//! }
//! # }
//! ```
//!
//! ### Sunrise and Sunset (numeric API, no chrono)
//! ```rust
//! use solar_positioning::{spa, Horizon};
//!
//! // Calculate sunrise/sunset for San Francisco (returns hours since midnight UTC)
//! let result = spa::sunrise_sunset_utc_for_horizon(
//! 2026, 6, 21, // June 21, 2026
//! 37.7749, // San Francisco latitude
//! -122.4194, // San Francisco longitude
//! 69.0, // ΔT (seconds)
//! Horizon::SunriseSunset
//! ).unwrap();
//!
//! match result {
//! solar_positioning::SunriseResult::RegularDay { sunrise, transit, sunset } => {
//! println!("Sunrise: {:.2} hours UTC", sunrise.hours());
//! println!("Solar noon: {:.2} hours UTC", transit.hours());
//! println!("Sunset: {:.2} hours UTC", sunset.hours());
//! }
//! _ => println!("No sunrise/sunset (polar day/night)"),
//! }
//! ```
//!
//! ## Algorithms
//!
//! ### SPA (Solar Position Algorithm)
//!
//! Based on the NREL algorithm by Reda & Andreas (2003). Provides the highest accuracy
//! with uncertainties of ±0.0003 degrees, suitable for applications requiring precise
//! solar positioning over long time periods.
//!
//! ### Grena3
//!
//! A simplified algorithm optimized for years 2010-2110. Approximately 10 times faster
//! than SPA while maintaining good accuracy (maximum error 0.01°).
//!
//! ## Coordinate System
//!
//! - **Azimuth**: 0° = North, measured clockwise (0° to 360°)
//! - **Zenith angle**: 0° = directly overhead (zenith), 90° = horizon (0° to 180°)
//! - **Elevation angle**: 0° = horizon, 90° = directly overhead (-90° to +90°)
// Public API exports - core types only
pub use crate;
pub use crate;
// Algorithm modules
// Supporting modules
// Internal modules