Skip to content

Instantly share code, notes, and snippets.

@jfcarr
Created November 25, 2024 00:43
Show Gist options
  • Save jfcarr/f41803782d4b17c34acf42ca9b4bbe86 to your computer and use it in GitHub Desktop.
Save jfcarr/f41803782d4b17c34acf42ca9b4bbe86 to your computer and use it in GitHub Desktop.
Reproduce Bug from Practical Astronomy - Rust, issue # 6
// https://github.com/jfcarr/practical-astronomy-rust/issues/6
use practical_astronomy_rust::moon as M;
struct MoonRiseSetInfo {
mr_lt_hour: f64,
mr_lt_min: f64,
mr_local_date_day: f64,
mr_local_date_month: u32,
mr_local_date_year: u32,
mr_azimuth_deg: f64,
ms_lt_hour: f64,
ms_lt_min: f64,
ms_local_date_day: f64,
ms_local_date_month: u32,
ms_local_date_year: u32,
ms_azimuth_deg: f64,
}
fn get_moon_rise_set_info(
local_date_day: f64,
local_date_month: u32,
local_date_year: u32,
is_daylight_saving: bool,
zone_correction_hours: i32,
geog_longitude_deg: f64,
geog_latitude_deg: f64,
) -> MoonRiseSetInfo {
let (
mr_lt_hour,
mr_lt_min,
mr_local_date_day,
mr_local_date_month,
mr_local_date_year,
mr_azimuth_deg,
ms_lt_hour,
ms_lt_min,
ms_local_date_day,
ms_local_date_month,
ms_local_date_year,
ms_azimuth_deg,
) = M::moonrise_and_moonset(
local_date_day,
local_date_month,
local_date_year,
is_daylight_saving,
zone_correction_hours,
geog_longitude_deg,
geog_latitude_deg,
);
let return_value = MoonRiseSetInfo {
mr_lt_hour,
mr_lt_min,
mr_local_date_day,
mr_local_date_month,
mr_local_date_year,
mr_azimuth_deg,
ms_lt_hour,
ms_lt_min,
ms_local_date_day,
ms_local_date_month,
ms_local_date_year,
ms_azimuth_deg,
};
return return_value;
}
fn main() {
let local_date_day: f64 = 24.0;
let local_date_month: u32 = 11;
let local_date_year: u32 = 2024;
let is_daylight_saving: bool = false;
let zone_correction_hours: i32 = 1;
let geog_longitude_deg: f64 = 9.44041;
let geog_latitude_deg: f64 = 49.17738;
let mut result = get_moon_rise_set_info(
local_date_day,
local_date_month,
local_date_year,
is_daylight_saving,
zone_correction_hours,
geog_longitude_deg,
geog_latitude_deg,
);
// Did we actually get the result for the next day, instead of the day we requested?
if result.mr_local_date_day == local_date_day + 1.0 {
// If so, get the result again, but for the requested day - 1:
result = get_moon_rise_set_info(
local_date_day - 1.0,
local_date_month,
local_date_year,
is_daylight_saving,
zone_correction_hours,
geog_longitude_deg,
geog_latitude_deg,
);
}
println!(
"Moonrise and Moonset: [Local Date] {}/{}/{} [DST?] {} [Zone Correction] {} hours [Geographical Longitude/Latitude] {} degrees / {} degrees = [Moonrise] [Local Time] {}:{} [Local Date] {}/{}/{} [Azimuth] {} degrees [Moonset] [Local Time] {}:{} [Local Date] {}/{}/{} [Azimuth] {} degrees",
local_date_month,
local_date_day,
local_date_year,
is_daylight_saving,
zone_correction_hours,
geog_longitude_deg,
geog_latitude_deg,
result.mr_lt_hour,
result.mr_lt_min,
result.mr_local_date_month,
result.mr_local_date_day,
result.mr_local_date_year,
result.mr_azimuth_deg,
result.ms_lt_hour,
result.ms_lt_min,
result.ms_local_date_month,
result.ms_local_date_day,
result.ms_local_date_year,
result.ms_azimuth_deg
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment