From 6c92a9f0e1da9bd49d74b707210c851cb06b12cf Mon Sep 17 00:00:00 2001 From: Concedo <39025047+LostRuins@users.noreply.github.com> Date: Sat, 28 Jun 2025 23:10:04 +0800 Subject: [PATCH] fixed resizing --- otherarch/sdcpp/sdtype_adapter.cpp | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/otherarch/sdcpp/sdtype_adapter.cpp b/otherarch/sdcpp/sdtype_adapter.cpp index 4657d38e9..345dd7a27 100644 --- a/otherarch/sdcpp/sdtype_adapter.cpp +++ b/otherarch/sdcpp/sdtype_adapter.cpp @@ -604,22 +604,22 @@ sd_generation_outputs sdtype_generate(const sd_generation_inputs inputs) } if (desiredWidth < minsize || desiredHeight < minsize) { // Enforce minsize only if it won't exceed maxsize - if (aspect_ratio > 1.0f) { // wider than tall - // Try to scale width up to max of (minsize, maxsize) - desiredWidth = std::min(maxsize, std::max(minsize, desiredWidth)); - desiredHeight = static_cast(desiredWidth / aspect_ratio); - if (desiredHeight > maxsize) { // If height now exceeds maxsize, clamp based on height instead + float scale_w = static_cast(minsize) / desiredWidth; + float scale_h = static_cast(minsize) / desiredHeight; + float scale = std::max(scale_w, scale_h); + int newWidth = static_cast(desiredWidth * scale); + int newHeight = static_cast(desiredHeight * scale); + if (newWidth > maxsize || newHeight > maxsize) { + if (aspect_ratio > 1.0f) { + desiredWidth = maxsize; + desiredHeight = static_cast(maxsize / aspect_ratio); + } else { desiredHeight = maxsize; desiredWidth = static_cast(maxsize * aspect_ratio); } } else { - // Taller than wide or square - desiredHeight = std::min(maxsize, std::max(minsize, desiredHeight)); - desiredWidth = static_cast(desiredHeight * aspect_ratio); - if (desiredWidth > maxsize) { - desiredWidth = maxsize; - desiredHeight = static_cast(maxsize / aspect_ratio); - } + desiredWidth = newWidth; + desiredHeight = newHeight; } }