From 681f1ff00e20029913104b412165d309af1f9afb Mon Sep 17 00:00:00 2001 From: Florian Gebhardt Date: Wed, 27 Mar 2024 15:49:50 +0100 Subject: [PATCH] fix: shift values had wrong sign (#24) --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/image_util.rs | 5 +++-- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index cb4d061..61d8e0f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -968,7 +968,7 @@ dependencies = [ [[package]] name = "spritter" -version = "0.5.0" +version = "0.5.1" dependencies = [ "clap", "env_logger", diff --git a/Cargo.toml b/Cargo.toml index 6d4a6ec..a95124d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "spritter" -version = "0.5.0" +version = "0.5.1" edition = "2021" authors = ["fgardt "] description = "Spritesheet generator for factorio" diff --git a/src/image_util.rs b/src/image_util.rs index e460420..8ab5836 100644 --- a/src/image_util.rs +++ b/src/image_util.rs @@ -145,6 +145,7 @@ pub fn crop_images(images: &mut Vec) -> ImgUtilResult<(f64, f64)> { let cropped_height = max_y - min_y + 1; debug!("cropping from {raw_width}x{raw_height} to {cropped_width}x{cropped_height}"); + trace!("min_x: {min_x}, min_y: {min_y}, max_x: {max_x}, max_y: {max_y}"); // crop images for image in images { @@ -155,8 +156,8 @@ pub fn crop_images(images: &mut Vec) -> ImgUtilResult<(f64, f64)> { } // calculate how the center point shifted relative to the original image - let shift_x = (f64::from(raw_width - cropped_width) / 2.0) - f64::from(min_x); - let shift_y = (f64::from(raw_height - cropped_height) / 2.0) - f64::from(min_y); + let shift_x = -((f64::from(raw_width - cropped_width) / 2.0) - f64::from(min_x)); + let shift_y = -((f64::from(raw_height - cropped_height) / 2.0) - f64::from(min_y)); trace!("shifted by ({shift_x}, {shift_y})");