Skip to content

Conversation

amartya4256
Copy link
Contributor

This commit contributes to scaling points and rectangles from point to pixels while making sure they do not have any residuals since the OS doesn't support sub-pixel drawing.

contributes to #62

Copy link
Contributor

github-actions bot commented Jul 31, 2025

Test Results

  118 files  ±0    118 suites  ±0   9m 52s ⏱️ -24s
4 441 tests +1  4 422 ✅ +2  17 💤 ±0  2 ❌  - 1 
  299 runs  +1    293 ✅ +2   4 💤 ±0  2 ❌  - 1 

For more details on these failures, see this check.

Results for commit 341a86b. ± Comparison against base commit 810cbcc.

♻️ This comment has been updated with latest results.

@amartya4256 amartya4256 marked this pull request as ready for review September 23, 2025 08:09
Comment on lines +208 to +229
Point scaledPoint = new Point.OfFloat(scaledX, scaledY);
return new Point.OfFloat(scaledPoint.x, scaledPoint.y);
Copy link
Contributor

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:

// Cast to int so that there are no residuals
return new Point.OfFloat((int) scaledX, (int) scaledY);

or even better, simply declare scaledX and scaledY as ints

// Use ints so that there are no residuals
int scaledX = ...;
int scaledY = ...;
return new Point.OfFloat(scaledX, scaledY);

Copy link
Contributor Author

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.

Copy link
Contributor

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.

Copy link
Contributor

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?

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);
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do you need to create yet another copy? scaleBounds(...) already returns a shallow copy. In fact, in doing so, you might loose information about the monitor since you're not using clone, you're using a constructor.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just thinking if we could somehow reset the residual values.

Copy link
Contributor

Choose a reason for hiding this comment

The 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 OfFloat.

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 Math.round(...) instead of just casting to int) but at least it preserves the monitor (if it's there).

If you don't want to expose that detail then you should add yet another method to Rectangle.OfFloat that does the rounding and looses the residuals. Something like:

void round() {
   setX(Math.round(getX());
   setY(Math.round(getY());
}

Your call.

This commit contributes to scaling points and rectangles from point to
pixels while making sure they do not have any residuals since the OS doesn't
support sub-pixel drawing.

contributes to eclipse-platform#62
@fedejeanne fedejeanne force-pushed the amartya4256/point_to_pixel_offloat branch from ca6ef3a to 341a86b Compare September 25, 2025 13:25
@fedejeanne
Copy link
Contributor

@amartya4256 I rebased on master, please pull.

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.

Analyze: Using integer value in pointToPixel for OfFloat
3 participants