[Refactor] Move the get_range_path function to the svg_clock module

This commit is contained in:
Gergely Polonkai 2022-05-23 17:51:05 +02:00
parent 4c15ffa826
commit af637bcd10
No known key found for this signature in database
GPG Key ID: 2D2885533B869ED4
2 changed files with 32 additions and 32 deletions

View File

@ -18,8 +18,8 @@ use svg::Document;
mod svg_clock;
use svg_clock::{
cache_hour_name_paths, hour_marker, seconds_to_degrees, svg_to_usvg, HOUR_NAMES,
HOUR_NAME_FONT_SIZE, IMAGE_WIDTH, OUTER_R, RING_WIDTH, UTC_HOUR_FONT_SIZE,
cache_hour_name_paths, get_range_path, hour_marker, seconds_to_degrees, svg_to_usvg,
HOUR_NAMES, HOUR_NAME_FONT_SIZE, IMAGE_WIDTH, OUTER_R, RING_WIDTH, UTC_HOUR_FONT_SIZE,
};
sctk::default_environment!(SeasonalClock, desktop);
@ -36,36 +36,6 @@ struct CompleteConfig {
seasonal_clock: Config,
}
fn get_range_path(radius: f32, range_name: &str, start_time: i32, end_time: i32) -> Path {
let start_deg = seconds_to_degrees(start_time);
let end_deg = seconds_to_degrees(end_time);
let deg_diff = end_deg - start_deg;
let start_delta_x = radius * start_deg.to_radians().sin();
let start_delta_y = radius * (1.0 - start_deg.to_radians().cos());
let end_delta_x = radius * end_deg.to_radians().sin();
let end_delta_y = radius * (1.0 - end_deg.to_radians().cos());
let path_data = PathData::new()
.move_to((IMAGE_WIDTH / 2, IMAGE_WIDTH / 2))
.line_to((
IMAGE_WIDTH as f32 / 2.0 - start_delta_x,
IMAGE_WIDTH as f32 / 2.0 + radius - start_delta_y,
))
.elliptical_arc_to((
radius,
radius,
deg_diff,
((start_deg < end_deg) ^ (deg_diff.abs() >= 180.0)) as u8,
0,
IMAGE_WIDTH as f32 / 2.0 - end_delta_x,
IMAGE_WIDTH as f32 / 2.0 + radius - end_delta_y,
))
.close();
Path::new().set("class", range_name).set("d", path_data)
}
fn get_moon_path(radius: f32, moon_phase: f64) -> Path {
let handle_x_pos = radius as f64 * 1.34;
let handle_y_pos = radius * 0.88;

View File

@ -256,3 +256,33 @@ pub fn hour_marker(
.add(hour_name_path)
.add(utc_hour_path)
}
pub fn get_range_path(radius: f32, range_name: &str, start_time: i32, end_time: i32) -> Path {
let start_deg = seconds_to_degrees(start_time);
let end_deg = seconds_to_degrees(end_time);
let deg_diff = end_deg - start_deg;
let start_delta_x = radius * start_deg.to_radians().sin();
let start_delta_y = radius * (1.0 - start_deg.to_radians().cos());
let end_delta_x = radius * end_deg.to_radians().sin();
let end_delta_y = radius * (1.0 - end_deg.to_radians().cos());
let path_data = PathData::new()
.move_to((IMAGE_WIDTH / 2, IMAGE_WIDTH / 2))
.line_to((
IMAGE_WIDTH as f32 / 2.0 - start_delta_x,
IMAGE_WIDTH as f32 / 2.0 + radius - start_delta_y,
))
.elliptical_arc_to((
radius,
radius,
deg_diff,
((start_deg < end_deg) ^ (deg_diff.abs() >= 180.0)) as u8,
0,
IMAGE_WIDTH as f32 / 2.0 - end_delta_x,
IMAGE_WIDTH as f32 / 2.0 + radius - end_delta_y,
))
.close();
Path::new().set("class", range_name).set("d", path_data)
}