Skip to content

Conversation

amartya4256
Copy link
Contributor

@amartya4256 amartya4256 commented Sep 26, 2025

When converting pixels to point there can be- depending on the zoom level - a fractional result. Currently, in all cases the result is converted into an integer using Math.round() that will make values +/-0.5 resulting in small values to be rounded towards a smaller value.
While it is maybe valid for a location, when using points to express a dimension this is not okay as it will result in the reported (integer) value to be to small leading to errors when the SWT API is then used after performing additional computations maybe.
See

This PR also resolves the issue #2166

@amartya4256 amartya4256 linked an issue Sep 26, 2025 that may be closed by this pull request
Copy link
Contributor

github-actions bot commented Sep 26, 2025

Test Results

  118 files  ±0    118 suites  ±0   10m 37s ⏱️ +15s
4 581 tests ±0  4 561 ✅ +3  17 💤 ±0  3 ❌  - 3 
  330 runs  ±0    323 ✅ +3   4 💤 ±0  3 ❌  - 3 

For more details on these failures, see this check.

Results for commit 67a7758. ± Comparison against base commit ff6bf58.

♻️ This comment has been updated with latest results.

@ShahzaibIbrahim ShahzaibIbrahim force-pushed the round_size_up branch 2 times, most recently from 59b68e6 to a479282 Compare September 26, 2025 14:41
@ShahzaibIbrahim
Copy link
Contributor

I cannot un draft it as this PR was not created by me. I also have tested the original issue after my changes: #2166. Also tested runtime workspace if something is broken.

The commit message is needed to adapted and also some API check failures need to be fixed, but feel free to review/test it.

@HeikoKlare @akoch-yatta

@ShahzaibIbrahim ShahzaibIbrahim force-pushed the round_size_up branch 5 times, most recently from 1926a71 to 9bdfef4 Compare September 29, 2025 08:33
private static final long serialVersionUID = -1862062276431597053L;

public float residualX, residualY;
public RoundingMode roundingMode;
Copy link
Contributor

Choose a reason for hiding this comment

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

@akoch-yatta this field was added as public while it is only used in this class internally. Was there a reason for that? Why not simply have it private?

Copy link
Contributor

Choose a reason for hiding this comment

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

Probably because it was work in progress. If it can be private, make it private

Copy link
Contributor

Choose a reason for hiding this comment

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

it should at least be final ... on the other hand residualX/y are public modifiable as well... I think one best make both private.

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.

Checking all changed calls in this PR, they look semantically correct, regarding the different rounding for sizes and locations

Copy link
Contributor

@laeubi laeubi left a comment

Choose a reason for hiding this comment

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

@amartya4256 thanks for taking over this and working on this, it looks all sane for me.

private static final long serialVersionUID = -1862062276431597053L;

public float residualX, residualY;
public RoundingMode roundingMode;
Copy link
Contributor

Choose a reason for hiding this comment

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

it should at least be final ... on the other hand residualX/y are public modifiable as well... I think one best make both private.

@ShahzaibIbrahim ShahzaibIbrahim force-pushed the round_size_up branch 3 times, most recently from bdeebd9 to 147e135 Compare September 29, 2025 15:12
When converting pixels to point there can be depending on the zoom level
be a fractional result.
Currently in all cases these result is converted into an integer using
`Math.round()` that will make values `+/-0.5` resulting in small values
to be round towards a smaller value.

While it is maybe valid for a _location_, when using points to express a
_dimension_ this is not okay as it will result in the reported (integer)
value to be to small leading to errors when the SWT API is then used
after performing additional computations maybe.

See
- eclipse-platform#2381
- eclipse-platform#2166
@ShahzaibIbrahim
Copy link
Contributor

Changing residualX, residualY to private will be done in another PR and test failures are unrelated: #2516.

From my side this PR is ready to be merge if no other objections.

@akoch-yatta akoch-yatta marked this pull request as ready for review September 29, 2025 15:40
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.

I tested it with different zooms like 125%, 150% and 175% and didn't not see a regression caused by this. As I already had a look into the code this PR is good to go from my side.

@akoch-yatta
Copy link
Contributor

Test are still failing after rebuild, but unrelated #2516

@akoch-yatta akoch-yatta merged commit f51bb3b into eclipse-platform:master Sep 29, 2025
23 of 27 checks passed
@akoch-yatta akoch-yatta deleted the round_size_up branch September 29, 2025 16:39
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.

Improve Rounding behavior for Locations and Dimensions Labels are cut off by autoscaling
4 participants