Skip to content

Preserved width/height on scaleUp/Down a Rectangle #2047

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,17 @@ public static Rectangle scaleDown(Rectangle rect, int zoom) {
scaledRect.y = scaledTopLeft.y;
scaledRect.width = scaledBottomRight.x - scaledTopLeft.x;
scaledRect.height = scaledBottomRight.y - scaledTopLeft.y;

int scaledDownWidth = DPIUtil.scaleDown(rect.width, zoom);
int scaledDownHeight = DPIUtil.scaleDown(rect.height, zoom);

// It must be ensured, that a scaled down width or height
// based on Rectangle x or y is not bigger than directly
// scaling down the width or height. Therefore the min
// value is used
scaledRect.width = Math.min(scaledRect.width, scaledDownWidth);
scaledRect.height = Math.min(scaledRect.height, scaledDownHeight);

return scaledRect;
}
/**
Expand Down Expand Up @@ -464,6 +475,16 @@ public static Rectangle scaleUp(Rectangle rect, int zoom) {
scaledRect.y = scaledTopLeft.y;
scaledRect.width = scaledBottomRight.x - scaledTopLeft.x;
scaledRect.height = scaledBottomRight.y - scaledTopLeft.y;

int scaledUpWidth = DPIUtil.scaleUp(rect.width, zoom);
int scaledUpHeight = DPIUtil.scaleUp(rect.height, zoom);

// It must be ensured, that a scaled up width or height
// based on Rectangle x or y is not smaller that directly
// scaling up the width or height. Therefore the max
// value is used
scaledRect.width = Math.max(scaledRect.width, scaledUpWidth);
scaledRect.height = Math.max(scaledRect.height, scaledUpHeight);
return scaledRect;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ public void scaleDownPoint() {
@Test
public void scaleDownRectangle() {
Rectangle valueAt200 = new Rectangle(100, 150, 10, 14);
Rectangle valueAt150 = new Rectangle(75, 113, 7, 10);
Rectangle valueAt150 = new Rectangle(75, 113, 7, 11);
Rectangle valueAt100 = new Rectangle(50, 75, 5, 7);

Rectangle scaledValue = DPIUtil.autoScaleDown(valueAt200);
Expand Down Expand Up @@ -295,7 +295,7 @@ public void scaleUpPoint() {
@Test
public void scaleUpRectangle() {
Rectangle valueAt200 = new Rectangle(100, 150, 10, 14);
Rectangle valueAt150 = new Rectangle(75, 113, 8, 10);
Rectangle valueAt150 = new Rectangle(75, 113, 8, 11);
Rectangle valueAt100 = new Rectangle(50, 75, 5, 7);

Rectangle scaledValue = DPIUtil.autoScaleUp(valueAt100);
Expand Down
Loading