diff --git a/src/main.rs b/src/main.rs index 5f46a99..5c573fc 100644 --- a/src/main.rs +++ b/src/main.rs @@ -20,7 +20,9 @@ use svg::Document; mod svg_clock; -use svg_clock::{svg_to_usvg, HOUR_NAMES, HOUR_NAME_FONT_SIZE, IMAGE_WIDTH, OUTER_R, RING_WIDTH}; +use svg_clock::{ + hour_name_path, svg_to_usvg, HOUR_NAMES, HOUR_NAME_FONT_SIZE, IMAGE_WIDTH, OUTER_R, RING_WIDTH, +}; sctk::default_environment!(SeasonalClock, desktop); @@ -67,26 +69,6 @@ fn time_to_degrees(timestamp: i32, // should be time/timestamp seconds_to_degrees(timestamp) } -fn hour_name_path() -> Path { - let radius = OUTER_R - RING_WIDTH / 2.0; - let delta_x = radius * (15.0_f32.to_radians() / 2.0).sin(); - let delta_y = radius * (1.0 - (15.0_f32.to_radians() / 2.0).cos()); - let x1 = (IMAGE_WIDTH as f32) / 2.0 - delta_x; - let y1 = ((IMAGE_WIDTH as f32) / 2.0 - radius) + delta_y; - - let path_data = PathData::new().move_to((x1, y1)).elliptical_arc_by(( - radius, - radius, - 15, - 0, - 1, - 2.0 * delta_x, - 0, - )); - - Path::new().set("id", "hour-name-path").set("d", path_data) -} - fn hour_marker(hour: i32, is_current_hour: bool, utc_hour_font_size: f32) -> Group { let season = match hour { 0..=5 => Season::Winter, diff --git a/src/svg_clock.rs b/src/svg_clock.rs index dea569e..c6f5a81 100644 --- a/src/svg_clock.rs +++ b/src/svg_clock.rs @@ -1,4 +1,7 @@ -use svg::Document; +use svg::{ + node::element::{path::Data as PathData, Path}, + Document, +}; use usvg::Tree; pub const HOUR_NAMES: [&str; 24] = [ @@ -20,3 +23,23 @@ pub fn svg_to_usvg(document: Document) -> Tree { Tree::from_str(&doc_str, &opt.to_ref()).unwrap() } + +pub fn hour_name_path() -> Path { + let radius = OUTER_R - RING_WIDTH / 2.0; + let delta_x = radius * (15.0_f32.to_radians() / 2.0).sin(); + let delta_y = radius * (1.0 - (15.0_f32.to_radians() / 2.0).cos()); + let x1 = (IMAGE_WIDTH as f32) / 2.0 - delta_x; + let y1 = ((IMAGE_WIDTH as f32) / 2.0 - radius) + delta_y; + + let path_data = PathData::new().move_to((x1, y1)).elliptical_arc_by(( + radius, + radius, + 15, + 0, + 1, + 2.0 * delta_x, + 0, + )); + + Path::new().set("id", "hour-name-path").set("d", path_data) +}