Skip to content

Use Float Aware Geometry for Scaling #62 #2200

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

amartya4256
Copy link
Contributor

This PR introduces FloatAwareRectangle and FloatAwarePoint as an extension of Rectangle and Point respectively to improve scaling precision in the DPIUtil by using residuals obtained from rounding.

Contributes to
#62 and #128

This commit introduces FloatAwareRectangle and FloatAwarePoint as an
extension of Rectangle and Point respectively to improve scaling
precision in the DPIUtil by using residuals obtained from rounding.

Contributes to
eclipse-platform#62 and
eclipse-platform#128
Copy link
Contributor

github-actions bot commented Jun 5, 2025

Test Results

104 files   -    441  104 suites   - 441   8s ⏱️ - 32m 36s
 66 tests  -  4 333   65 ✅  -  4 316  0 💤  -  18  1 ❌ +1 
213 runs   - 16 510  212 ✅  - 16 370  0 💤  - 141  1 ❌ +1 

For more details on these failures, see this check.

Results for commit ff5192d. ± Comparison against base commit e40ad29.

This pull request removes 4333 tests.
AllGTKTests org.eclipse.swt.tests.gtk.Test_GtkConverter ‑ test_HeuristicASCII_dollarSign
AllGTKTests org.eclipse.swt.tests.gtk.Test_GtkConverter ‑ test_HeuristicASCII_emptyString
AllGTKTests org.eclipse.swt.tests.gtk.Test_GtkConverter ‑ test_HeuristicASCII_letterA
AllGTKTests org.eclipse.swt.tests.gtk.Test_GtkConverter ‑ test_HeuristicASCII_letters
AllGTKTests org.eclipse.swt.tests.gtk.Test_GtkConverter ‑ test_HeuristicUTF16LE_null
AllGTKTests org.eclipse.swt.tests.gtk.Test_GtkConverter ‑ test_HeuristicUTF16_AsciiLetters
AllGTKTests org.eclipse.swt.tests.gtk.Test_GtkConverter ‑ test_HeuristicUTF16_Asciiletter
AllGTKTests org.eclipse.swt.tests.gtk.Test_GtkConverter ‑ test_HeuristicUTF16_LotsOfLetters
AllGTKTests org.eclipse.swt.tests.gtk.Test_GtkConverter ‑ test_HeuristicUTF16_letter
AllGTKTests org.eclipse.swt.tests.gtk.Test_GtkConverter ‑ test_HeuristicUTF16_letters
…

@laeubi
Copy link
Contributor

laeubi commented Jun 5, 2025

I must confess that this XyzAware things sound strange from an object oriented point of view. one would always question e.g. if the fields are synchronized with the integer variants.

Is there any reason to not have proper getter/setter instead of public modifiable fields? The e.g. a setX(double) can always update the integer fields as well.

Also one might look at how AWT is doing it here: https://docs.oracle.com/javase/8/docs/api/java/awt/geom/Rectangle2D.html

So the have

@HeikoKlare
Copy link
Contributor

I must confess that this XyzAware things sound strange from an object oriented point of view. one would always question e.g. if the fields are synchronized with the integer variants.

Is there any reason to not have proper getter/setter instead of public modifiable fields? The e.g. a setX(double) can always update the integer fields as well.

Also one might look at how AWT is doing it here: https://docs.oracle.com/javase/8/docs/api/java/awt/geom/Rectangle2D.html

I don't see a good reason to not have proper getter/setters for the newly added fields. One issue from OO perspective is that we have the public fields in the existing Rectangle/Points classes which are accessed directly everywhere and makes it difficult to properly extend the classes. But for the additional classes with higher precision, which are only supposed to be used inside SWT at least for now anyway, it definitely makes sense to apply proper encapsulation.

I also agree that that names sound strange, at least the float version (for MonitorAware* it makes more sense to me).
Thank you for the reference to the AWT classes. I was not aware of them. Having the specializations realized as inner classes, so that you can have a Rectangle.Float (and maybe then also a Rectangle.WithMonitor or the like) sounds like a reasonable approach that we could also apply here.

for (int zoom1 : zooms) {
for (int zoom2 : zooms) {
for (int i = 1; i <= 10000; i++) {
Rectangle rect = new Rectangle(0, 0, i, i);
Copy link
Contributor

@arunjose696 arunjose696 Jun 5, 2025

Choose a reason for hiding this comment

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

shouldnt the tests be testing FloatAwareRectangle too?

Copy link
Contributor Author

@amartya4256 amartya4256 Jun 6, 2025

Choose a reason for hiding this comment

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

DPIUtil is responsible for creating the FloatAwareRectangle from Rectangle internally. Hence, this test is already testing FloatAwareRectangle internally.

@laeubi
Copy link
Contributor

laeubi commented Jun 5, 2025

But for the additional classes with higher precision, which are only supposed to be used inside SWT at least for now anyway,

I'm not sure if we should design such "supposed to be internal" API here. Actually one big drawback of SWT compared to eg. Graphics2D is its inability to use floating point arithmetic in most places. One can prevent this by constructing a Path (that supports at least float), so I see an opportunity enable such advanced use cases with using "Double/Float" variants of rectangle, point and so on ... especially if transforms / scaling comes into play now it seems to limited to only allow integer / pixel drawing.

@HeikoKlare
Copy link
Contributor

I'm not sure if we should design such "supposed to be internal" API here.

I think this is a misunderstanding. I did not want to propose to design an API that is supposed to only be internal. I just wanted to say that these classes are only supposed to be used internally for now, so still having the chance for redesign before they are eventually made public API. We should first adapt the code inside SWT to properly handle higher-precision coordinates (for the reasons you also mentioned) and see where/whether we run into problems there and what needs to be done to adapt all consumers of Point/Rectangle to properly handle the higher-precision versions of them. Afterwards, once we know how to properly do it and once everything is implemented, we can make it API public. If we would do it now, strange things would happen as a consumer could pass a point with floating-point precision to consumers inside SWT without them being adapted to properly consider the higher-precision value. So there is quite some need to adaptation before we might do that.

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.

4 participants