[Refactor] Convert hour_name_font_size to a constant

This commit is contained in:
Gergely Polonkai 2022-05-22 06:01:54 +02:00
parent eaf111f216
commit dcde43831b
No known key found for this signature in database
GPG Key ID: 2D2885533B869ED4
1 changed files with 5 additions and 7 deletions

View File

@ -26,6 +26,7 @@ const HOUR_NAMES: [&str; 24] = [
"Mushroom", "Thunder", "Frost", "Lantern",
];
const IMAGE_WIDTH: u32 = 700;
const HOUR_NAME_FONT_SIZE: f32 = IMAGE_WIDTH as f32 * 0.019109;
enum Season {
Spring,
@ -95,7 +96,6 @@ fn hour_marker(
is_current_hour: bool,
outer_r: f32,
ring_width: f32,
hour_name_font_size: f32,
utc_hour_font_size: f32,
) -> Group {
let season = match hour {
@ -142,7 +142,7 @@ fn hour_marker(
let hour_name_text = Text::new()
.set("text-anchor", "middle")
.set("dominant-baseline", "mathematical")
.set("font-size", hour_name_font_size)
.set("font-size", HOUR_NAME_FONT_SIZE)
.add(hour_name_text_path);
let utc_hour_text = Text::new()
@ -268,10 +268,9 @@ fn gen_svg(config: &Option<Config>) -> Document {
let moon_phase = moon_illumination.phase * 28.0;
let local_hour_font_size = IMAGE_WIDTH as f32 * 0.02357;
let hour_name_font_size = IMAGE_WIDTH as f32 * 0.019109;
let utc_hour_font_size = IMAGE_WIDTH as f32 * 0.021462;
let outer_r = (IMAGE_WIDTH as f32) / 2.0 - 3.0 * hour_name_font_size;
let ring_width = hour_name_font_size * 3.0;
let outer_r = (IMAGE_WIDTH as f32) / 2.0 - 3.0 * HOUR_NAME_FONT_SIZE;
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;
@ -351,7 +350,6 @@ fn gen_svg(config: &Option<Config>) -> Document {
hour == utc_hour as i32,
outer_r,
ring_width,
hour_name_font_size,
utc_hour_font_size,
));
}
@ -530,7 +528,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;