Skip to content

Conversation

@HeikoKlare
Copy link
Contributor

@HeikoKlare HeikoKlare commented Mar 27, 2025

The MonitorAwarePoint and MonitorAwareRectangle classes have been introduced as specializations of the existing Point and Rectangle classes solely to support monitor-specific scaling and only used in the context of that feature. They are not supposed to be used outside of SWT but just an internal construct. However, instances of those classes reach consumers of SWT API, e.g., via the Shell class. This broke equality assumptions for consumers, as, e.g., a comparison between a Point and a MonitorAwarePoint (returned by methods of Shell) are never equal, even though the consumers is not supposed to even know that a MonitorAwarePoint can be returned here.

To restore equality, this change aligns equality of the monitor-aware implementations of point and rectangle with their original implementations. In consequence, a Point and a MonitorAwarePoint will be considered equal if their x/y coordinates match. The monitor stored in a MonitorAwarePoint will be ignored. This analogously applies to MonitorAwareRectangle. Since those classes are only used internally, no one may rely on any other kind of equality specification for the monitor-aware implementations of point and rectangle, but existing equality for Points and Rectangles in general is restored.

Note: MonitorAwarePoint/MonitorAwareRectangle are not part of public API and are currently only used when monitor-specific scaling on Windows is active, which is marked as an experimental feature. This is why no one currently relies on specific equality handling of those added types, allowing to correct their equality relation.

See also #1711 (comment) and other comments in that PR.

@HeikoKlare HeikoKlare linked an issue Mar 27, 2025 that may be closed by this pull request
@github-actions
Copy link
Contributor

github-actions bot commented Mar 27, 2025

Test Results

   545 files  ±0     545 suites  ±0   27m 12s ⏱️ - 2m 11s
 4 367 tests ±0   4 355 ✅ ±0   12 💤 ±0  0 ❌ ±0 
16 616 runs  ±0  16 512 ✅ ±0  104 💤 ±0  0 ❌ ±0 

Results for commit ff10047. ± Comparison against base commit 42ed1da.

♻️ This comment has been updated with latest results.

@HeikoKlare HeikoKlare force-pushed the equality-point-rectangle branch from 78f7766 to 364088a Compare March 27, 2025 09:22
@HeikoKlare HeikoKlare marked this pull request as ready for review March 27, 2025 09:41
@HeikoKlare
Copy link
Contributor Author

@amartya4256 please have a look when you have time since you originally introduced those classes

@nedtwigg for your information

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.

Changes look good to me and the explanation makes sense

The MonitorAwarePoint and MonitorAwareRectangle classes have been
introduced as specializations of the existing Point and Rectangle
classes solely to support monitor-specific scaling and only used in the
context of that feature. They are not supposed to be used outside of SWT
but just an internal construct. However, instances of those classes
reach consumers of SWT API, e.g., via the Shell class. This broke
equality assumptions for consumers, as, e.g., a comparison between a
Point and a MonitorAwarePoint (returned by methods of Shell) are never
equal, even though the consumers is not supposed to even know that a
MonitorAwarePoint can be returned here.

To restore equality, this change aligns equality of the monitor-aware
implementations of point and rectangle with their original
implementations. In consequence, a Point and a MonitorAwarePoint will be
considered equal if their x/y coordinates match. The monitor stored in a
MonitorAwarePoint will be ignored. This analogously applies to
MonitorAwareRectangle. Since those classes are only used internally, no
one may rely on any other kind of equality specification for the
monitor-aware implementations of point and rectangle, but existing
equality for Points and Rectangles in general is restored.
@HeikoKlare HeikoKlare force-pushed the equality-point-rectangle branch from 364088a to ff10047 Compare March 31, 2025 08:25
@HeikoKlare HeikoKlare merged commit 72695f8 into eclipse-platform:master Mar 31, 2025
15 checks passed
@HeikoKlare HeikoKlare deleted the equality-point-rectangle branch March 31, 2025 09:26
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.

Broken equality for Point/Rectangle

2 participants