-
Notifications
You must be signed in to change notification settings - Fork 182
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -225,7 +225,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) { | ||
|
@@ -248,7 +249,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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do you need to create yet another copy? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just thinking if we could somehow reset the residual values. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, I see. Tricky to do without exposing too much about the internal workings of I would be OK with doing this: Rectangle scaledRectangle = scaleBounds(rect, zoom, 100);
scaledRectangle.setX(Math.round(scaledRectangle.getX());
scaledRectangle.setY(Math.round(scaledRectangle.getY()); It's not perfectly encapsulated (exposes the fact that you use If you don't want to expose that detail then you should add yet another method to void round() {
setX(Math.round(getX());
setY(Math.round(getY());
} Your call. |
||
} | ||
|
||
public static Rectangle pointToPixel(Drawable drawable, Rectangle rect, int zoom) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to instantiate twice, do either:
or even better, simply declare
scaledX
andscaledY
asint
sThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(int) will not round it properly. We will need to use Math.round instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See https://github.com/eclipse-platform/eclipse.platform.swt/pull/2364/files/ca6ef3a35062a41e9e47b39d9e3b071fabbc3811#r2379074441 since you are probably trying to do the same here and you have to preserve the other information (
monitor
) here too.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't the point of this code to ensure that we have a consistent way of rounding (by delegating the responsibility to
Point.OfFloat
), which would break with replicating the actual rounding implementation (via Math.round) here?