Skip to content

Win32DPIUtils:pointToPixel shouldn't have residual #2364

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

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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 @@ -205,7 +205,8 @@ public static Point pointToPixel(Point point, int zoom) {
float scaleFactor = DPIUtil.getScalingFactor(zoom);
float scaledX = fPoint.getX() * scaleFactor;
float scaledY = fPoint.getY() * scaleFactor;
return new Point.OfFloat(scaledX, scaledY);
Point scaledPoint = new Point.OfFloat(scaledX, scaledY);
return new Point.OfFloat(scaledPoint.x, scaledPoint.y);
}

public static Point pointToPixel(Drawable drawable, Point point, int zoom) {
Expand All @@ -228,7 +229,8 @@ public static Rectangle pointToPixel(Rectangle rect, int zoom) {
}

private static Rectangle pointToPixel(Rectangle.OfFloat rect, int zoom) {
return scaleBounds(rect, zoom, 100);
Rectangle scaledRectangle = scaleBounds(rect, zoom, 100);
return new Rectangle.OfFloat(scaledRectangle.x, scaledRectangle.y, scaledRectangle.width, scaledRectangle.height);
}

public static Rectangle pointToPixel(Drawable drawable, Rectangle rect, int zoom) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,15 +222,27 @@ public void scaleUpRectangle() {

@Test
public void scaleDownscaleUpRectangleInvertible() {
int[] zooms = new int[] {25, 50, 75, 100, 125, 150, 175, 200, 225, 250, 275, 300, 325, 350, 375, 400};
for (int zoom : zooms) {
for (int i = 1; i <= 10000; i++) {
Rectangle rect = new Rectangle.OfFloat(0, 0, i, i);
Rectangle scaleDown = Win32DPIUtils.pixelToPoint(rect, zoom);
Rectangle scaleUp = Win32DPIUtils.pointToPixel(scaleDown, zoom);
assertEquals(rect.width, scaleUp.width);
assertEquals(rect.height, scaleUp.height);
}
}
}

@Test
public void scaleBoundsRectangleInvertible() {
int[] zooms = new int[] {25, 50, 75, 100, 125, 150, 175, 200, 225, 250, 275, 300, 325, 350, 375, 400};
for (int zoom1 : zooms) {
for (int zoom2 : zooms) {
for (int i = 1; i <= 10000; i++) {
Rectangle rect = new Rectangle.OfFloat(0, 0, i, i);
Rectangle scaleDown = Win32DPIUtils.pixelToPoint(rect, zoom1);
Rectangle scaleUp = Win32DPIUtils.pointToPixel(scaleDown, zoom2);
scaleDown = Win32DPIUtils.pixelToPoint(scaleUp, zoom2);
scaleUp = Win32DPIUtils.pointToPixel(scaleDown, zoom1);
Rectangle scaleDown = Win32DPIUtils.scaleBounds(rect, zoom1, zoom2);
Rectangle scaleUp = Win32DPIUtils.scaleBounds(scaleDown, zoom2, zoom1);
assertEquals(rect.width, scaleUp.width);
assertEquals(rect.height, scaleUp.height);
}
Expand All @@ -240,18 +252,14 @@ public void scaleDownscaleUpRectangleInvertible() {

@Test
public void scaleDownscaleUpPointInvertible() {
int[] zooms = new int[] {25, 50, 75, 100, 125, 150, 175, 200, 225, 250, 275, 300, 325, 350, 375, 400};
for (int zoom1 : zooms) {
for (int zoom2 : zooms) {
for (int i = 1; i <= 10000; i++) {
Point pt = new Point(i, i);
Point scaleDown = Win32DPIUtils.pixelToPoint(pt, zoom1);
Point scaleUp = Win32DPIUtils.pointToPixel(scaleDown, zoom2);
scaleDown = Win32DPIUtils.pixelToPoint(scaleUp, zoom2);
scaleUp = Win32DPIUtils.pointToPixel(scaleDown, zoom1);
assertEquals(pt.x, scaleUp.x);
assertEquals(pt.y, scaleUp.y);
}
int[] zooms = new int[] {100, 125, 150, 175, 200, 225, 250, 275, 300, 325, 350, 375, 400};
for (int zoom : zooms) {
for (int i = 1; i <= 10000; i++) {
Point pt = new Point(i, i);
Point scaleDown = Win32DPIUtils.pixelToPoint(pt, zoom);
Point scaleUp = Win32DPIUtils.pointToPixel(scaleDown, zoom);
assertEquals(pt.x, scaleUp.x);
assertEquals(pt.y, scaleUp.y);
}
}
}
Expand Down
Loading