Chore: cleanup

test/generate-svg-logo
Dorian Zedler 2023-03-11 21:51:26 +01:00
parent cb29aaf7f7
commit 65401700c0
Signed by: dozedler
GPG Key ID: 989DE36109AFA354
3 changed files with 18 additions and 11 deletions

View File

@ -66,7 +66,7 @@ pub fn draw_polygon(
num_sides: i32,
context: &Context,
dark_mode: bool,
) {
) -> Result<(), cairo::Error> {
let mut rng = rand::thread_rng();
let c1 = generate_color(&mut rng, dark_mode, None);
set_color_i8(c1, context);
@ -79,7 +79,9 @@ pub fn draw_polygon(
}
context.close_path();
context.fill().unwrap();
context.fill()?;
Ok(())
}
pub fn draw_segmented_polygon(
@ -88,7 +90,7 @@ pub fn draw_segmented_polygon(
num_sides: i32,
context: &Context,
dark_mode: bool,
) {
) -> Result<(), cairo::Error> {
let mut rng = rand::thread_rng();
let c1 = generate_color(&mut rng, dark_mode, None);
set_color_i8(c1, context);
@ -108,7 +110,7 @@ pub fn draw_segmented_polygon(
}
context.close_path();
context.fill().unwrap();
context.fill()?;
let c2 = generate_color(&mut rng, dark_mode, Some(c1));
set_color_i8(c2, context);
@ -120,7 +122,9 @@ pub fn draw_segmented_polygon(
}
context.close_path();
context.fill().unwrap();
context.fill()?;
Ok(())
}
pub fn draw_polygon_of_segmented_polygons(
@ -129,11 +133,12 @@ pub fn draw_polygon_of_segmented_polygons(
num_sides: i32,
context: &Context,
dark_mode: bool,
) {
) -> Result<(), cairo::Error> {
let corners = calculate_polygon_corners(center, num_sides, side_length, 0.0);
for corner in corners {
draw_segmented_polygon(corner, side_length * 0.4, num_sides, &context, dark_mode);
draw_segmented_polygon(corner, side_length * 0.4, num_sides, &context, dark_mode)?;
}
Ok(())
}
pub fn draw_polygon_of_polygons(
@ -142,9 +147,10 @@ pub fn draw_polygon_of_polygons(
num_sides: i32,
context: &Context,
dark_mode: bool,
) {
) -> Result<(), cairo::Error> {
let corners = calculate_polygon_corners(center, num_sides, side_length, 0.0);
for corner in corners {
draw_polygon(corner, side_length * 0.4, num_sides, &context, dark_mode);
draw_polygon(corner, side_length * 0.4, num_sides, &context, dark_mode)?;
}
Ok(())
}

View File

@ -10,7 +10,7 @@ async fn handler() -> impl axum::response::IntoResponse {
context.set_source_rgba(0.0, 0.0, 0.0, 0.0);
context.fill().unwrap();
polygon::draw_polygon_of_polygons((50.0, 50.0), 65.0, 6, &context, false);
polygon::draw_polygon_of_polygons((50.0, 50.0), 65.0, 6, &context, false).unwrap();
let mut data: Vec<u8> = Vec::new();
surface.write_to_png(&mut data).unwrap();

View File

@ -32,7 +32,8 @@ async fn handler(Query(properties): Query<ImageProperties>) -> impl axum::respon
6,
&context,
properties.dark_mode,
);
)
.unwrap();
let mut data: Vec<u8> = Vec::new();
surface.write_to_png(&mut data).unwrap();