Skip to content

Commit

Permalink
finish rust
Browse files Browse the repository at this point in the history
  • Loading branch information
jacob-pro committed May 28, 2023
1 parent f7b1fae commit 2bc22e4
Show file tree
Hide file tree
Showing 19 changed files with 2,103 additions and 1,409 deletions.
18 changes: 6 additions & 12 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ on: [push, pull_request]

env:
CARGO_TERM_COLOR: always
IMAGE_NAME: mdbook-bibfile-referencing

jobs:

Expand All @@ -19,12 +18,11 @@ jobs:

- name: Cargo Test
run: cargo test -- --nocapture
working-directory: ./rust-bindings
working-directory: ./rust

- name: no_std
if: ${{ matrix.os != 'macos-latest' }}
run: cargo build --no-default-features
working-directory: ./rust-bindings
- name: Cargo Clippy Check
run: cargo clippy --all-features --workspace -- -D warnings
working-directory: ./rust

check_style:
runs-on: ubuntu-latest
Expand All @@ -33,12 +31,8 @@ jobs:

- name: Cargo Format Check
run: cargo fmt -- --check
working-directory: ./rust-bindings
working-directory: ./rust

- name: Cargo Sort Check
run: cargo install cargo-sort && cargo-sort --check
working-directory: ./rust-bindings

- name: Cargo Clippy Check
run: cargo clippy --all-features --workspace -- -D warnings
working-directory: ./rust-bindings
working-directory: ./rust
42 changes: 2 additions & 40 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,42 +1,4 @@
# Sunrise Sunset Calculator

[![Build status](https://github.com/jacob-pro/sunrise-sunset-calculator/actions/workflows/cmake.yml/badge.svg)](https://github.com/jacob-pro/sunrise-sunset-calculator/actions/workflows/cmake.yml)
[![Rust status](https://github.com/jacob-pro/sunrise-sunset-calculator/actions/workflows/rust.yml/badge.svg)](https://github.com/jacob-pro/sunrise-sunset-calculator/actions/workflows/rust.yml)

A C99 library for computing sunrise and sunset times. Builds are tested on Linux/GCC, Windows/MSVC and MacOS/Clang,
and there is also support for nostdlib environments.

Rust bindings are also [available](https://github.com/jacob-pro/sunrise-sunset-calculator/tree/master/rust-bindings).

## Usage

This library uses Unix time for input and output, on nearly all platforms (including Linux/Unix/Windows) this is
equivalent to `time_t` so you can just use the C time functions to work with dates. (If not consider looking at the
[musl](http://git.musl-libc.org/cgit/musl/tree/src/time) implementation of these functions)

```
#include "ssc.h"
...
SunriseSunsetParameters params;
SunriseSunsetResult result;
SunriseSunsetParameters_init(&params, UNIX_TIMESTAMP, LATITUDE, LONGITUDE);
assert(sunrise_sunset_calculate(&input, &result) == SpaStatus_Success);
printf("Visible: %s, Sunset: %lld, Sunrise: %lld", result.visible ? "true" : "false", result.set, result.rise);
```

The input timestamp is guaranteed to be between the output sunset and sunrise.

## Implementation Details

Internally this uses a stripped down version of [NREL's Solar Position Algorithm (SPA)](https://midcdmz.nrel.gov/spa/)
to compute the solar elevation / altitude at a given time. Dates between -2000 and 6000 are accepted.

We use the NOAA definition of sunrise/sunset as being at the point which the center of the sun is 0.8333° below
the horizon. We then use interval bisection to find the point at which the sun's elevation crosses this boundary.

It will work at all latitudes on Earth, although the step size option controls the shortest day/night lengths that
will be detected, which is configured with a reasonable default based on the input latitude.

## License

All my code is LGPL, but the NREL algorithm this bundles has its own separate license, so take this into account.
- [C Implementation](c)
- [Rust Implementation](rust)
1 change: 0 additions & 1 deletion c/README.md

This file was deleted.

39 changes: 39 additions & 0 deletions c/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Sunrise Sunset Calculator

[![Build status](https://github.com/jacob-pro/sunrise-sunset-calculator/actions/workflows/cmake.yml/badge.svg)](https://github.com/jacob-pro/sunrise-sunset-calculator/actions/workflows/cmake.yml)

A C99 library for computing sunrise and sunset times. Builds are tested on Linux/GCC, Windows/MSVC and MacOS/Clang,
and there is also support for nostdlib environments.

## Usage

This library uses Unix time for input and output, on nearly all platforms (including Linux/Unix/Windows) this is
equivalent to `time_t` so you can just use the C time functions to work with dates. (If not consider looking at the
[musl](http://git.musl-libc.org/cgit/musl/tree/src/time) implementation of these functions)

```
#include "ssc.h"
...
SunriseSunsetParameters params;
SunriseSunsetResult result;
SunriseSunsetParameters_init(&params, UNIX_TIMESTAMP, LATITUDE, LONGITUDE);
assert(sunrise_sunset_calculate(&input, &result) == SpaStatus_Success);
printf("Visible: %s, Sunset: %lld, Sunrise: %lld", result.visible ? "true" : "false", result.set, result.rise);
```

The input timestamp is guaranteed to be between the output sunset and sunrise.

## Implementation Details

Internally this uses a stripped down version of [NREL's Solar Position Algorithm (SPA)](https://midcdmz.nrel.gov/spa/)
to compute the solar elevation / altitude at a given time. Dates between -2000 and 6000 are accepted.

We use the NOAA definition of sunrise/sunset as being at the point which the center of the sun is 0.8333° below
the horizon. We then use interval bisection to find the point at which the sun's elevation crosses this boundary.

It will work at all latitudes on Earth, although the step size option controls the shortest day/night lengths that
will be detected, which is configured with a reasonable default based on the input latitude.

## License

All my code is LGPL, but the NREL algorithm this bundles has its own separate license, so take this into account.
2 changes: 0 additions & 2 deletions rust-bindings/.gitignore

This file was deleted.

38 changes: 0 additions & 38 deletions rust-bindings/Cargo.toml

This file was deleted.

41 changes: 0 additions & 41 deletions rust-bindings/README.md

This file was deleted.

17 changes: 0 additions & 17 deletions rust-bindings/bindings.rs

This file was deleted.

7 changes: 0 additions & 7 deletions rust-bindings/build.rs

This file was deleted.

Loading

0 comments on commit 2bc22e4

Please sign in to comment.