# from_rust_till_dawn

A Rust implementation of the **NREL Solar Position Algorithm (SPA)** — computes topocentric sun position (zenith, azimuth, elevation), surface incidence angle, equation of time, and sunrise/sunset times.

## Usage

```toml
[dependencies]
from_rust_till_dawn = "0.1"
```

### Using `SpaInput` directly (recommended for full control)

```rust
use from_rust_till_dawn::SpaInput;

let out = SpaInput {
    year: 2024, month: 6, day: 21,
    hour: 12, minute: 0,
    latitude: 48.8566,
    longitude: 2.3522,
    elevation: 35.0,
    ..Default::default()
}.calculate()?;

println!("zenith    = {:.4}°", out.zenith);
println!("azimuth   = {:.4}°", out.azimuth);
println!("elevation = {:.4}°", out.elevation);
println!("sunrise   = {:.4} h", out.sunrise);
println!("sunset    = {:.4} h", out.sunset);
```

### Using the convenience function

```rust
use chrono::Utc;
use from_rust_till_dawn::sun_position;

let out = sun_position(&Utc::now(), 48.8566, 2.3522, 35.0, None, 15.0)?;
```

## Outputs

| Field | Description |
|---|---|
| `zenith` | Topocentric zenith angle (°) |
| `azimuth` | Azimuth, N=0° clockwise (°) |
| `azimuth_astro` | Azimuth, astronomers' convention (°) |
| `elevation` | Refraction-corrected elevation above horizon (°) |
| `incidence` | Surface incidence angle (°) |
| `eot` | Equation of time (minutes) |
| `suntransit` | Solar noon in local hours |
| `sunrise` | Sunrise in local hours |
| `sunset` | Sunset in local hours |

## Reference

Reda, I. and Andreas, A. (2004). *Solar Position Algorithm for Solar Radiation Applications*. NREL/TP-560-34302. [https://www.nrel.gov/docs/fy08osti/34302.pdf](https://www.nrel.gov/docs/fy08osti/34302.pdf)

## License

MIT
