[Refactor] Convert ring_width to a constant

This commit is contained in:
Gergely Polonkai 2022-05-22 06:06:36 +02:00
parent fd516083cf
commit cba5372b4d
No known key found for this signature in database
GPG Key ID: 2D2885533B869ED4
1 changed files with 13 additions and 19 deletions

View File

@ -28,6 +28,7 @@ const HOUR_NAMES: [&str; 24] = [
const IMAGE_WIDTH: u32 = 700;
const HOUR_NAME_FONT_SIZE: f32 = IMAGE_WIDTH as f32 * 0.019109;
const OUTER_R: f32 = (IMAGE_WIDTH as f32) / 2.0 - 3.0 * HOUR_NAME_FONT_SIZE;
const RING_WIDTH: f32 = HOUR_NAME_FONT_SIZE * 3.0;
enum Season {
Spring,
@ -72,8 +73,8 @@ fn time_to_degrees(timestamp: i32, // should be time/timestamp
seconds_to_degrees(timestamp)
}
fn hour_name_path(ring_width: f32) -> Path {
let radius = OUTER_R - ring_width / 2.0;
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;
@ -92,12 +93,7 @@ fn hour_name_path(ring_width: f32) -> Path {
Path::new().set("id", "hour-name-path").set("d", path_data)
}
fn hour_marker(
hour: i32,
is_current_hour: bool,
ring_width: f32,
utc_hour_font_size: f32,
) -> Group {
fn hour_marker(hour: i32, is_current_hour: bool, utc_hour_font_size: f32) -> Group {
let season = match hour {
0..=5 => Season::Winter,
6..=11 => Season::Spring,
@ -110,23 +106,23 @@ fn hour_marker(
let delta_x = OUTER_R * (15f32.to_radians() / 2.0).sin();
let delta_y = OUTER_R * (1.0 - (15f32.to_radians() / 2.0).cos());
let s_delta_x = 0.0 - ring_width * (15f32.to_radians() / 2.0).sin();
let s_delta_y = ring_width * (15f32.to_radians() / 2.0).cos();
let s_delta_x = 0.0 - RING_WIDTH * (15f32.to_radians() / 2.0).sin();
let s_delta_y = RING_WIDTH * (15f32.to_radians() / 2.0).cos();
let i_delta_x = -2.0 * (OUTER_R - ring_width) * (15f32.to_radians() / 2.0).sin();
let i_delta_x = -2.0 * (OUTER_R - RING_WIDTH) * (15f32.to_radians() / 2.0).sin();
let x1 = IMAGE_WIDTH as f32 / 2.0 - delta_x;
let y1 = (IMAGE_WIDTH as f32 / 2.0 - OUTER_R) + delta_y;
let utc_hour_y = IMAGE_WIDTH as f32 / 2.0 - OUTER_R + ring_width + utc_hour_font_size;
let utc_hour_y = IMAGE_WIDTH as f32 / 2.0 - OUTER_R + RING_WIDTH + utc_hour_font_size;
let path_data = PathData::new()
.move_to((x1, y1))
.elliptical_arc_by((OUTER_R, OUTER_R, 15, 0, 1, 2.0 * delta_x, 0))
.line_by((s_delta_x, s_delta_y))
.elliptical_arc_by((
OUTER_R - ring_width,
OUTER_R - ring_width,
OUTER_R - RING_WIDTH,
OUTER_R - RING_WIDTH,
15,
0,
0,
@ -269,9 +265,8 @@ fn gen_svg(config: &Option<Config>) -> Document {
let local_hour_font_size = IMAGE_WIDTH as f32 * 0.02357;
let utc_hour_font_size = IMAGE_WIDTH as f32 * 0.021462;
let ring_width = HOUR_NAME_FONT_SIZE * 3.0;
let sun_radius = IMAGE_WIDTH as f32 * 0.0142871;
let marker_radius = OUTER_R - ring_width - 2.0 * utc_hour_font_size;
let marker_radius = OUTER_R - RING_WIDTH - 2.0 * utc_hour_font_size;
let border = Rectangle::new()
.set("x", 0i32)
@ -308,7 +303,7 @@ fn gen_svg(config: &Option<Config>) -> Document {
#current-hour-name {font-weight: bold;}",
);
let definitions = Definitions::new().add(hour_name_path(ring_width));
let definitions = Definitions::new().add(hour_name_path());
let mut local_clock = Group::new().set("id", "local-clock");
for hour in 0i32..24 {
@ -347,7 +342,6 @@ fn gen_svg(config: &Option<Config>) -> Document {
seasonal_clock = seasonal_clock.add(hour_marker(
hour,
hour == utc_hour as i32,
ring_width,
utc_hour_font_size,
));
}
@ -526,7 +520,7 @@ fn gen_svg(config: &Option<Config>) -> Document {
.set("x2", IMAGE_WIDTH / 2)
.set(
"y2",
IMAGE_WIDTH as f32 / 2.0 + OUTER_R - ring_width + HOUR_NAME_FONT_SIZE,
IMAGE_WIDTH as f32 / 2.0 + OUTER_R - RING_WIDTH + HOUR_NAME_FONT_SIZE,
);
let current_box_width = (200f32 / 700f32) * IMAGE_WIDTH as f32;