Skip to content

Conversation

@HeikoKlare
Copy link
Contributor

For the float-aware Point class, a rounding mode has been introduced to store in which way the Point needs to be rounded when necessary. For rectangles, this has not been implemented yet and is added by this change. It also correct the way in which rectangle values are rounded by considering the top-left and bottom-right corner instead of top-left corner and width/height, also done in the Win32DPIUtils. So it streamlines the rounding behavior in Win32DPIUtils and the Rectangle class to uniformly scale the upper left and bottom right corner of a rectangle.

The changes also makes proper use of the floating-precision coordinates in the point/pixel conversions for rectangles in the Win32DPIUtils.

@github-actions
Copy link
Contributor

github-actions bot commented Oct 30, 2025

Test Results

  118 files  ±0    118 suites  ±0   16m 54s ⏱️ + 2m 11s
4 650 tests ±0  4 633 ✅ ±0  17 💤 ±0  0 ❌ ±0 
  330 runs  ±0    326 ✅ ±0   4 💤 ±0  0 ❌ ±0 

Results for commit 03ec9bc. ± Comparison against base commit 704dc92.

♻️ This comment has been updated with latest results.

@HeikoKlare HeikoKlare marked this pull request as ready for review October 30, 2025 18:45
@HeikoKlare HeikoKlare force-pushed the rectangle-rounding-mode branch from 43f1a89 to c23483c Compare October 31, 2025 08:50
@amartya4256
Copy link
Contributor

@HeikoKlare I see that only RoundingMode.ROUND is used in the code for now for rectangles. Could you please explain what RoundingMode is intended to be used in which case?

@HeikoKlare
Copy link
Contributor Author

With the current changes, we will revert to ROUND everywhere (except for the conservative calculations in computeSize()), as everything else broke behavior at one place or the other. But properly introducing the rounding mode everywhere allows to better test changes to the rounding mode at the different places.


public void setWidth(float width) {
this.width = Math.round(width);
this.width = sizeRounding.round(width + getX()) - x;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I remember there were cases in the past where some places would have different results when you would scale the rectangle using scaleBounds or scaleUp because they both used different approach to scaling. One had height and width calculated using the difference between top left and bottom right and the other as just the width and height values in the object. Are we sure that this approach would not break that behavior for certain consumers? Visually I cannot see anything in the IDE but I just wanted to pick this out just to be careful. I am going to consider that since there's no test failing, this might not be the case anymore?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there is no way to be 100% sure that we to not break any behavior for existing consumers. With all the back-and-forth of the kinds of rounding we have implemented, this will probably also have effects that we currently do not see (either positive or negative).
Regarding the different scaling methods that you mention: they are still in place. We still have Win32DPIUtils#scaleBounds() which implement the "other" way of scaling (used for things related to image). The modified way of scaling only applies to what is passed to Win32DPIUtils#pointToPixel()/pixelToPoint(). And there the only removed case distinction is that when a Rectangle.OfFloat was passed, no forwarding to scaleBounds() happens anymore.

Copy link
Contributor

@amartya4256 amartya4256 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changes look fine and introduce the rounding mode while scaling the rectangle. I do not see any visual difference in the runtime (as it should be). Hence, with the introduction of rounding mode now the rectangles scale consistently as implemented in OfFloat and WinDPIUtils. Since we have a public constructor to initialize a rectangle with a specific rounding, are there any possibilities where we will be using any other rounding mode in future? If not can we hide it for the time being?

@HeikoKlare HeikoKlare force-pushed the rectangle-rounding-mode branch from c23483c to dc68e98 Compare October 31, 2025 15:26
@HeikoKlare
Copy link
Contributor Author

Since we have a public constructor to initialize a rectangle with a specific rounding, are there any possibilities where we will be using any other rounding mode in future? If not can we hide it for the time being?

Sure, I've made it private for now. The class and all its methods are @noreference anyway (so effectively no API), but since the constructor is not used yet, it's definititely better to not make it public at all.

For the float-aware Point class, a rounding mode has been introduced to
store in which way the Point needs to be rounded when necessary. For
rectangles, this has not been implemented yet and is added by this
change. It also correct the way in which rectangle values are rounded by
considering the top-left and bottom-right corner instead of top-left
corner and width/height, also done in the Win32DPIUtils. So it
streamlines the rounding behavior in Win32DPIUtils and the
Rectangle class to uniformly scale the upper left and bottom right
corner of a rectangle.

The changes also makes proper use of the floating-precision coordinates
in the point/pixel conversions for rectangles in the Win32DPIUtils.
@akoch-yatta akoch-yatta force-pushed the rectangle-rounding-mode branch from dc68e98 to 03ec9bc Compare October 31, 2025 15:38
Copy link
Contributor

@akoch-yatta akoch-yatta left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code looks fine. Although there is no obvious visible improvement, I'll follow the argument with consistency and would merge this. I did not find a regression when testing around with different zoom values

@akoch-yatta akoch-yatta merged commit 910f5cd into eclipse-platform:master Oct 31, 2025
17 checks passed
@akoch-yatta akoch-yatta deleted the rectangle-rounding-mode branch October 31, 2025 15:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Inconsistent rounding implementation for Rectangles

3 participants