14
14
package org .eclipse .swt .widgets ;
15
15
16
16
import static org .junit .jupiter .api .Assertions .assertEquals ;
17
+ import static org .junit .jupiter .api .Assertions .assertTrue ;
17
18
18
19
import java .util .function .*;
19
20
import java .util .stream .*;
@@ -39,62 +40,104 @@ private Monitor createMonitor(CoordinateSystemMapper mapper, Rectangle boundsInP
39
40
return monitor ;
40
41
}
41
42
42
- void setupMonitors (CoordinateSystemMapper mapper ) {
43
+ private void setupMonitors (CoordinateSystemMapper mapper ) {
43
44
Rectangle boundsInPixelsForLeftMonitor = new Rectangle (0 , 0 , 2000 , 2000 );
44
45
Rectangle boundsInPixelsForRightMonitor = new Rectangle (2000 , 0 , 2000 , 2000 );
45
46
monitors = new Monitor [] { createMonitor (mapper , boundsInPixelsForLeftMonitor , 200 ),
46
47
createMonitor (mapper , boundsInPixelsForRightMonitor , 100 ) };
47
48
}
48
49
49
- Stream <CoordinateSystemMapper > provideCoordinateSystemMappers () {
50
- return Stream .of (new MultiZoomCoordinateSystemMapper (null , () -> monitors ),
51
- new SingleZoomCoordinateSystemMapper (null ));
50
+ private Stream <CoordinateSystemMapper > provideCoordinateSystemMappers () {
51
+ return Stream .of (getMultiZoomCoordinateSystemMapper (), getSingleZoomCoordinateSystemMapper ());
52
+ }
53
+
54
+ private MultiZoomCoordinateSystemMapper getMultiZoomCoordinateSystemMapper () {
55
+ return new MultiZoomCoordinateSystemMapper (null , () -> monitors );
56
+ }
57
+
58
+ private SingleZoomCoordinateSystemMapper getSingleZoomCoordinateSystemMapper () {
59
+ return new SingleZoomCoordinateSystemMapper (null );
52
60
}
53
61
54
62
@ ParameterizedTest
55
63
@ MethodSource ("provideCoordinateSystemMappers" )
56
64
void translatePointInNoMonitorBackAndForthShouldBeTheSame (CoordinateSystemMapper mapper ) {
57
65
setupMonitors (mapper );
58
- Point pt = new Point ( 5000 , -400 );
66
+ Point pt = createExpectedPoint ( mapper , 5000 , -400 , monitors [ 0 ] );
59
67
Point px = mapper .translateToDisplayCoordinates (pt , monitors [0 ].getZoom ());
60
68
assertEquals (pt , mapper .translateFromDisplayCoordinates (px , monitors [0 ].getZoom ()));
61
69
}
62
70
63
- @ ParameterizedTest
64
- @ MethodSource ("provideCoordinateSystemMappers" )
65
- @ Disabled ("Disabled due to current limitations of MultiZoomCoordinateSystemMapper" )
66
- void translatePointInGapBackAndForthShouldBeTheSame (CoordinateSystemMapper mapper ) {
71
+ @ Test
72
+ void translatePointInGapBackAndForthInSingleZoomShouldBeTheSame () {
73
+ SingleZoomCoordinateSystemMapper mapper = getSingleZoomCoordinateSystemMapper ();
67
74
setupMonitors (mapper );
68
75
Point pt = new Point (1900 , 400 );
69
76
Point px = mapper .translateToDisplayCoordinates (pt , monitors [0 ].getZoom ());
70
77
assertEquals (pt , mapper .translateFromDisplayCoordinates (px , monitors [0 ].getZoom ()));
71
78
}
72
79
80
+ @ Test
81
+ void translatePointInGapBackAndForthInMultiZoomShouldEndInsideTheSameMonitor () {
82
+ MultiZoomCoordinateSystemMapper mapper = getMultiZoomCoordinateSystemMapper ();
83
+ setupMonitors (mapper );
84
+ Point pt = new Point (1900 , 400 );
85
+ Point px = mapper .translateToDisplayCoordinates (pt , monitors [0 ].getZoom ());
86
+ Point translatedPt = mapper .translateFromDisplayCoordinates (px , monitors [0 ].getZoom ());
87
+ Point translatedPx = mapper .translateToDisplayCoordinates (translatedPt , monitors [0 ].getZoom ());
88
+ assertEquals (new Point (translatedPt .x , translatedPt .y ), translatedPx );
89
+ assertEquals (translatedPx , px );
90
+ }
91
+
73
92
@ ParameterizedTest
74
93
@ MethodSource ("provideCoordinateSystemMappers" )
75
94
void translateRectangleInNoMonitorBackAndForthShouldBeTheSame (CoordinateSystemMapper mapper ) {
76
95
setupMonitors (mapper );
77
- Rectangle rectInPts = new Rectangle ( 5000 , -400 , 200 , 200 );
96
+ Rectangle rectInPts = createExpectedRectangle ( mapper , 5000 , -400 , 200 , 200 , monitors [ 0 ] );
78
97
Rectangle rectInPxs = mapper .translateToDisplayCoordinates (rectInPts , monitors [0 ].getZoom ());
79
98
assertEquals (rectInPts , mapper .translateFromDisplayCoordinates (rectInPxs , monitors [0 ].getZoom ()));
80
99
}
81
100
82
- @ ParameterizedTest
83
- @ MethodSource ("provideCoordinateSystemMappers" )
84
- @ Disabled ("Disabled due to current limitations of MultiZoomCoordinateSystemMapper" )
85
- void translateRectangleInGapBackAndForthShouldBeTheSame (CoordinateSystemMapper mapper ) {
101
+ @ Test
102
+ void translateRectangleInGapBackAndForthInSingleZoomShouldBeTheSame () {
103
+ SingleZoomCoordinateSystemMapper mapper = getSingleZoomCoordinateSystemMapper ();
86
104
setupMonitors (mapper );
87
105
Rectangle rectInPts = new Rectangle (1800 , 400 , 100 , 100 );
88
106
Rectangle rectInPxs = mapper .translateToDisplayCoordinates (rectInPts , monitors [0 ].getZoom ());
89
107
assertEquals (rectInPts , mapper .translateFromDisplayCoordinates (rectInPxs , monitors [0 ].getZoom ()));
90
108
}
91
109
92
- @ ParameterizedTest
93
- @ MethodSource ("provideCoordinateSystemMappers" )
94
- @ Disabled ("Disabled due to current limitations of MultiZoomCoordinateSystemMapper" )
95
- void translateRectangleInGapPartiallyInRightBackAndForthShouldBeTheSame (CoordinateSystemMapper mapper ) {
110
+ @ Test
111
+ void translateRectangleInGapBackAndForthInMultiZoomShouldBeInMonitorBounds () {
112
+ MultiZoomCoordinateSystemMapper mapper = getMultiZoomCoordinateSystemMapper ();
113
+ setupMonitors (mapper );
114
+ Rectangle rectInPts = new Rectangle (1800 , 400 , 100 , 100 );
115
+ Rectangle rectInPxs = mapper .translateToDisplayCoordinates (rectInPts , monitors [0 ].getZoom ());
116
+ Rectangle rectInPtsTranslated = mapper .translateFromDisplayCoordinates (rectInPxs , monitors [0 ].getZoom ());
117
+ boolean isInsideMonitor = false ;
118
+ for (Monitor monitor : monitors ) {
119
+ if (monitor .getClientArea ().intersects (rectInPtsTranslated )) {
120
+ isInsideMonitor = true ;
121
+ break ;
122
+ }
123
+ }
124
+ assertTrue (isInsideMonitor , "The translated rectangle in points is inside the monitor bounds in points" );
125
+ }
126
+
127
+ @ Test
128
+ void translateRectangleInGapPartiallyInRightBackAndForthInSingleZoomShouldBeTheSame () {
129
+ SingleZoomCoordinateSystemMapper mapper = getSingleZoomCoordinateSystemMapper ();
96
130
setupMonitors (mapper );
97
- Rectangle rectInPts = new Rectangle (1950 , 400 , 100 , 100 );
131
+ Rectangle rectInPts = new Rectangle (1950 , 400 , 150 , 100 );
132
+ Rectangle rectInPxs = mapper .translateToDisplayCoordinates (rectInPts , monitors [0 ].getZoom ());
133
+ assertEquals (rectInPts , mapper .translateFromDisplayCoordinates (rectInPxs , monitors [0 ].getZoom ()));
134
+ }
135
+
136
+ @ Test
137
+ void translateRectangleInGapPartiallyInRightBackAndForthInMultiZoomShouldBeInside () {
138
+ MultiZoomCoordinateSystemMapper mapper = getMultiZoomCoordinateSystemMapper ();
139
+ setupMonitors (mapper );
140
+ Rectangle rectInPts = new MonitorAwareRectangle (1950 , 400 , 150 , 100 , monitors [1 ]);
98
141
Rectangle rectInPxs = mapper .translateToDisplayCoordinates (rectInPts , monitors [0 ].getZoom ());
99
142
assertEquals (rectInPts , mapper .translateFromDisplayCoordinates (rectInPxs , monitors [0 ].getZoom ()));
100
143
}
@@ -103,24 +146,35 @@ void translateRectangleInGapPartiallyInRightBackAndForthShouldBeTheSame(Coordina
103
146
@ MethodSource ("provideCoordinateSystemMappers" )
104
147
void translateRectangleInGapPartiallyInLeftBackAndForthShouldBeTheSame (CoordinateSystemMapper mapper ) {
105
148
setupMonitors (mapper );
106
- Rectangle rectInPts = new Rectangle ( 750 , 400 , 100 , 100 );
149
+ Rectangle rectInPts = createExpectedRectangle ( mapper , 750 , 400 , 100 , 100 , monitors [ 0 ] );
107
150
Rectangle rectInPxs = mapper .translateToDisplayCoordinates (rectInPts , monitors [0 ].getZoom ());
108
151
assertEquals (rectInPts , mapper .translateFromDisplayCoordinates (rectInPxs , monitors [0 ].getZoom ()));
109
152
}
110
153
111
- @ ParameterizedTest
112
- @ MethodSource ( "provideCoordinateSystemMappers" )
113
- void translateRectangleInPointsInBothMonitorsPartiallyBackAndForthShouldBeTheSame ( CoordinateSystemMapper mapper ) {
154
+ @ Test
155
+ void translateRectangleInPointsInBothMonitorsPartiallyBackAndForthInSingleZoomShouldBeTheSame () {
156
+ SingleZoomCoordinateSystemMapper mapper = getSingleZoomCoordinateSystemMapper ();
114
157
setupMonitors (mapper );
115
158
Rectangle rectInPts = new Rectangle (950 , 400 , 1500 , 100 );
116
159
Rectangle rectInPxs = mapper .translateToDisplayCoordinates (rectInPts , monitors [0 ].getZoom ());
117
160
assertEquals (rectInPts , mapper .translateFromDisplayCoordinates (rectInPxs , monitors [0 ].getZoom ()));
118
161
}
119
162
120
163
@ Test
121
- @ Disabled ("Disabled due to current limitations of MultiZoomCoordinateSystemMapper" )
164
+ void translateRectangleInPointsInBothMonitorsPartiallyBackAndForthInMultiZoomShouldNotEndUpInGap () {
165
+ MultiZoomCoordinateSystemMapper mapper = getMultiZoomCoordinateSystemMapper ();
166
+ setupMonitors (mapper );
167
+ Rectangle rectInPts = new Rectangle (950 , 400 , 1500 , 100 );
168
+ Rectangle rectInPxs = mapper .translateToDisplayCoordinates (rectInPts , monitors [0 ].getZoom ());
169
+ Rectangle rectInPtsTranslated = mapper .translateFromDisplayCoordinates (rectInPxs , monitors [0 ].getZoom ());
170
+ Rectangle rectInPxsTranslated = mapper .translateToDisplayCoordinates (rectInPtsTranslated ,
171
+ monitors [0 ].getZoom ());
172
+ assertEquals (rectInPxs , rectInPxsTranslated );
173
+ }
174
+
175
+ @ Test
122
176
void moveRectangleInPixelsInRightMonitorsPartiallyBackAndForthShouldBeTheSame () {
123
- CoordinateSystemMapper mapper = provideCoordinateSystemMappers (). findFirst (). get ();
177
+ MultiZoomCoordinateSystemMapper mapper = getMultiZoomCoordinateSystemMapper ();
124
178
setupMonitors (mapper );
125
179
Rectangle rectInPxs = new Rectangle (1990 , -10 , 2000 , 2000 );
126
180
Rectangle expectedSmallRectInPxs = new Rectangle (0 , 0 , 0 , monitors [0 ].getZoom ());
@@ -140,10 +194,9 @@ void moveRectangleInPixelsInRightMonitorsPartiallyBackAndForthShouldBeTheSame()
140
194
141
195
@ ParameterizedTest
142
196
@ MethodSource ("provideCoordinateSystemMappers" )
143
- @ Disabled ("Disabled due to current limitations of MultiZoomCoordinateSystemMapper" )
144
197
void translateRectangleInPixelsOutisdeMonitorsBackAndForthShouldBeTheSame (CoordinateSystemMapper mapper ) {
145
198
setupMonitors (mapper );
146
- Rectangle rectInPxs = new Rectangle (4400 , 400 , 1000 , 1000 );
199
+ Rectangle rectInPxs = new Rectangle (400 , 2400 , 1000 , 1000 );
147
200
Rectangle rectInPts = mapper .translateFromDisplayCoordinates (rectInPxs , monitors [0 ].getZoom ());
148
201
assertEquals (rectInPxs , mapper .translateToDisplayCoordinates (rectInPts , monitors [0 ].getZoom ()));
149
202
}
@@ -157,4 +210,20 @@ void translateRectangleInPixelsInBothMonitorsBackAndForthShouldBeTheSame(Coordin
157
210
assertEquals (rectInPxs , mapper .translateToDisplayCoordinates (rectInPts , monitors [0 ].getZoom ()));
158
211
}
159
212
213
+ private Point createExpectedPoint (CoordinateSystemMapper mapper , int x , int y , Monitor monitor ) {
214
+ if (mapper instanceof SingleZoomCoordinateSystemMapper ) {
215
+ return new Point (x , y );
216
+ } else {
217
+ return new MonitorAwarePoint (x , y , monitor );
218
+ }
219
+ }
220
+
221
+ private Rectangle createExpectedRectangle (CoordinateSystemMapper mapper , int x , int y , int width , int height , Monitor monitor ) {
222
+ if (mapper instanceof SingleZoomCoordinateSystemMapper ) {
223
+ return new Rectangle (x , y , width , height );
224
+ } else {
225
+ return new MonitorAwareRectangle (x , y , width , height , monitor );
226
+ }
227
+ }
228
+
160
229
}
0 commit comments