Skip to content

Commit 336726b

Browse files
committed
Only use double-precision translation when HighDPI scaling is enabled
When the "draw2d.enableAutoscale" system property is enabled, additional (scalable) layers are injected into the IFigure hierarchy to take the monitor zoom into consideration. As a result of this, translating geometric shapes may cause additional rounding errors, which are the result of translating integer-values with an additional, fractional zoom level. To work around this problem, the "useDoublePrecision()" method was added with 5cfe5b7, which converts the geometric shapes to their precise variants. This conversion is generally not backwards compatible. To make sure clients can fully opt-out of this new behavior, this conversion should only be done when the "draw2d.enableAutoscale" is set to true, meaning only when these new layers are added, that require this extended translation logic.
1 parent 88b83cf commit 336726b

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

org.eclipse.draw2d.tests/src/org/eclipse/draw2d/test/PrecisionTests.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313

1414
package org.eclipse.draw2d.test;
1515

16+
import static org.junit.jupiter.api.Assumptions.assumeTrue;
17+
1618
import org.eclipse.draw2d.Figure;
1719
import org.eclipse.draw2d.FigureUtilities;
1820
import org.eclipse.draw2d.IFigure;
@@ -21,6 +23,7 @@
2123
import org.eclipse.draw2d.geometry.PrecisionPointList;
2224
import org.eclipse.draw2d.geometry.PrecisionRectangle;
2325
import org.eclipse.draw2d.geometry.Rectangle;
26+
import org.eclipse.draw2d.internal.InternalDraw2dUtils;
2427

2528
import org.junit.jupiter.api.BeforeEach;
2629
import org.junit.jupiter.api.Test;
@@ -65,6 +68,7 @@ private static ScalableLayeredPane createLayer(double scale) {
6568

6669
@Test
6770
public void testPreciseTranslateToAbsolute() {
71+
assumeTrue(InternalDraw2dUtils.isAutoScaleEnabled());
6872
Rectangle r1 = new Rectangle(13, 37, 163, 377);
6973
Rectangle r2 = new PrecisionRectangle(13, 37, 163, 377);
7074
fig.translateToAbsolute(r1);
@@ -78,6 +82,7 @@ public void testPreciseTranslateToAbsolute() {
7882

7983
@Test
8084
public void testPreciseTranslateToRelative() {
85+
assumeTrue(InternalDraw2dUtils.isAutoScaleEnabled());
8186
Rectangle r1 = new Rectangle(753, 891, 353, 564);
8287
Rectangle r2 = new PrecisionRectangle(753, 891, 353, 564);
8388
fig.translateToRelative(r1);
@@ -91,6 +96,7 @@ public void testPreciseTranslateToRelative() {
9196

9297
@Test
9398
public void testPreciseTranslateToAbsolute_PointList() {
99+
assumeTrue(InternalDraw2dUtils.isAutoScaleEnabled());
94100
PointList p1 = new PointList(new int[] { 13, 29, 32, 5 });
95101
PointList p2 = new PrecisionPointList(new int[] { 13, 29, 32, 5 });
96102
fig.translateToAbsolute(p1);
@@ -101,6 +107,7 @@ public void testPreciseTranslateToAbsolute_PointList() {
101107

102108
@Test
103109
public void testPreciseTranslateToRelative_PointList() {
110+
assumeTrue(InternalDraw2dUtils.isAutoScaleEnabled());
104111
PointList p1 = new PointList(new int[] { 518, 628, 715, 313 });
105112
PointList p2 = new PrecisionPointList(new int[] { 518, 628, 715, 313 });
106113
fig.translateToRelative(p1);

org.eclipse.draw2d/src/org/eclipse/draw2d/ScalableFreeformLayeredPane.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
import org.eclipse.draw2d.geometry.Rectangle;
1616
import org.eclipse.draw2d.geometry.Translatable;
17+
import org.eclipse.draw2d.internal.InternalDraw2dUtils;
1718

1819
/**
1920
* @author hudsonr
@@ -120,6 +121,6 @@ public void translateFromParent(Translatable t) {
120121
*/
121122
@Override
122123
protected boolean useDoublePrecision() {
123-
return true;
124+
return InternalDraw2dUtils.isAutoScaleEnabled();
124125
}
125126
}

org.eclipse.draw2d/src/org/eclipse/draw2d/ScalableLayeredPane.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import org.eclipse.draw2d.geometry.Dimension;
1616
import org.eclipse.draw2d.geometry.Rectangle;
1717
import org.eclipse.draw2d.geometry.Translatable;
18+
import org.eclipse.draw2d.internal.InternalDraw2dUtils;
1819

1920
/**
2021
* A non-freeform, scalable layered pane.
@@ -133,7 +134,7 @@ public boolean isCoordinateSystem() {
133134
*/
134135
@Override
135136
protected boolean useDoublePrecision() {
136-
return true;
137+
return InternalDraw2dUtils.isAutoScaleEnabled();
137138
}
138139

139140
}

0 commit comments

Comments
 (0)