Skip to content

Commit

Permalink
fix: shift values had wrong sign (#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
fgardt authored Mar 27, 2024
1 parent 4de7ebe commit 681f1ff
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "spritter"
version = "0.5.0"
version = "0.5.1"
edition = "2021"
authors = ["fgardt <[email protected]>"]
description = "Spritesheet generator for factorio"
Expand Down
5 changes: 3 additions & 2 deletions src/image_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ pub fn crop_images(images: &mut Vec<RgbaImage>) -> 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 {
Expand All @@ -155,8 +156,8 @@ pub fn crop_images(images: &mut Vec<RgbaImage>) -> 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})");

Expand Down

0 comments on commit 681f1ff

Please sign in to comment.