1313 *******************************************************************************/
1414package org .eclipse .swt .widgets ;
1515
16+ import static org .junit .Assert .assertTrue ;
1617import static org .junit .jupiter .api .Assertions .assertEquals ;
1718
1819import java .util .function .*;
@@ -39,16 +40,24 @@ private Monitor createMonitor(CoordinateSystemMapper mapper, Rectangle boundsInP
3940 return monitor ;
4041 }
4142
42- void setupMonitors (CoordinateSystemMapper mapper ) {
43+ private void setupMonitors (CoordinateSystemMapper mapper ) {
4344 Rectangle boundsInPixelsForLeftMonitor = new Rectangle (0 , 0 , 2000 , 2000 );
4445 Rectangle boundsInPixelsForRightMonitor = new Rectangle (2000 , 0 , 2000 , 2000 );
4546 monitors = new Monitor [] { createMonitor (mapper , boundsInPixelsForLeftMonitor , 200 ),
4647 createMonitor (mapper , boundsInPixelsForRightMonitor , 100 ) };
4748 }
4849
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 (),
52+ getSingleZoomCoordinateSystemMapper ());
53+ }
54+
55+ private MultiZoomCoordinateSystemMapper getMultiZoomCoordinateSystemMapper () {
56+ return new MultiZoomCoordinateSystemMapper (null , () -> monitors );
57+ }
58+
59+ private SingleZoomCoordinateSystemMapper getSingleZoomCoordinateSystemMapper () {
60+ return new SingleZoomCoordinateSystemMapper (null );
5261 }
5362
5463 @ ParameterizedTest
@@ -60,16 +69,27 @@ void translatePointInNoMonitorBackAndForthShouldBeTheSame(CoordinateSystemMapper
6069 assertEquals (pt , mapper .translateFromDisplayCoordinates (px , monitors [0 ].getZoom ()));
6170 }
6271
63- @ ParameterizedTest
64- @ MethodSource ("provideCoordinateSystemMappers" )
65- @ Disabled ("Disabled due to current limitations of MultiZoomCoordinateSystemMapper" )
66- void translatePointInGapBackAndForthShouldBeTheSame (CoordinateSystemMapper mapper ) {
72+ @ Test
73+ void translatePointInGapBackAndForthInSingleZoomShouldBeTheSame () {
74+ SingleZoomCoordinateSystemMapper mapper = getSingleZoomCoordinateSystemMapper ();
6775 setupMonitors (mapper );
6876 Point pt = new Point (1900 , 400 );
6977 Point px = mapper .translateToDisplayCoordinates (pt , monitors [0 ].getZoom ());
7078 assertEquals (pt , mapper .translateFromDisplayCoordinates (px , monitors [0 ].getZoom ()));
7179 }
7280
81+ @ Test
82+ void translatePointInGapBackAndForthInMultiZoomShouldEndInsideTheSameMonitor () {
83+ MultiZoomCoordinateSystemMapper mapper = getMultiZoomCoordinateSystemMapper ();
84+ setupMonitors (mapper );
85+ Point pt = new Point (1900 , 400 );
86+ Point px = mapper .translateToDisplayCoordinates (pt , monitors [0 ].getZoom ());
87+ Point translatedPt = mapper .translateFromDisplayCoordinates (px , monitors [0 ].getZoom ());
88+ Point translatedPx = mapper .translateToDisplayCoordinates (translatedPt , monitors [0 ].getZoom ());
89+ assertEquals (translatedPt , translatedPx );
90+ assertEquals (translatedPx , px );
91+ }
92+
7393 @ ParameterizedTest
7494 @ MethodSource ("provideCoordinateSystemMappers" )
7595 void translateRectangleInNoMonitorBackAndForthShouldBeTheSame (CoordinateSystemMapper mapper ) {
@@ -79,22 +99,46 @@ void translateRectangleInNoMonitorBackAndForthShouldBeTheSame(CoordinateSystemMa
7999 assertEquals (rectInPts , mapper .translateFromDisplayCoordinates (rectInPxs , monitors [0 ].getZoom ()));
80100 }
81101
82- @ ParameterizedTest
83- @ MethodSource ("provideCoordinateSystemMappers" )
84- @ Disabled ("Disabled due to current limitations of MultiZoomCoordinateSystemMapper" )
85- void translateRectangleInGapBackAndForthShouldBeTheSame (CoordinateSystemMapper mapper ) {
102+ @ Test
103+ void translateRectangleInGapBackAndForthInSingleZoomShouldBeTheSame () {
104+ SingleZoomCoordinateSystemMapper mapper = getSingleZoomCoordinateSystemMapper ();
86105 setupMonitors (mapper );
87106 Rectangle rectInPts = new Rectangle (1800 , 400 , 100 , 100 );
88107 Rectangle rectInPxs = mapper .translateToDisplayCoordinates (rectInPts , monitors [0 ].getZoom ());
89108 assertEquals (rectInPts , mapper .translateFromDisplayCoordinates (rectInPxs , monitors [0 ].getZoom ()));
90109 }
91110
92- @ ParameterizedTest
93- @ MethodSource ("provideCoordinateSystemMappers" )
94- @ Disabled ("Disabled due to current limitations of MultiZoomCoordinateSystemMapper" )
95- void translateRectangleInGapPartiallyInRightBackAndForthShouldBeTheSame (CoordinateSystemMapper mapper ) {
111+ @ Test
112+ void translateRectangleInGapBackAndForthInMultiZoomShouldBeInMonitorBounds () {
113+ MultiZoomCoordinateSystemMapper mapper = getMultiZoomCoordinateSystemMapper ();
96114 setupMonitors (mapper );
97- Rectangle rectInPts = new Rectangle (1950 , 400 , 100 , 100 );
115+ Rectangle rectInPts = new Rectangle (1800 , 400 , 100 , 100 );
116+ Rectangle rectInPxs = mapper .translateToDisplayCoordinates (rectInPts , monitors [0 ].getZoom ());
117+ Rectangle rectInPtsTranslated = mapper .translateFromDisplayCoordinates (rectInPxs , monitors [0 ].getZoom ());
118+ boolean isInsideMonitor = false ;
119+ for (Monitor monitor : monitors ) {
120+ if (monitor .getClientArea ().intersects (rectInPtsTranslated )) {
121+ isInsideMonitor = true ;
122+ break ;
123+ }
124+ }
125+ assertTrue ("The translated rectangle in points is inside the monitor bounds in points" , isInsideMonitor );
126+ }
127+
128+ @ Test
129+ void translateRectangleInGapPartiallyInRightBackAndForthInSingleZoomShouldBeTheSame () {
130+ SingleZoomCoordinateSystemMapper mapper = getSingleZoomCoordinateSystemMapper ();
131+ setupMonitors (mapper );
132+ Rectangle rectInPts = new Rectangle (1950 , 400 , 150 , 100 );
133+ Rectangle rectInPxs = mapper .translateToDisplayCoordinates (rectInPts , monitors [0 ].getZoom ());
134+ assertEquals (rectInPts , mapper .translateFromDisplayCoordinates (rectInPxs , monitors [0 ].getZoom ()));
135+ }
136+
137+ @ Test
138+ void translateRectangleInGapPartiallyInRightBackAndForthInMultiZoomShouldBeInside () {
139+ MultiZoomCoordinateSystemMapper mapper = getMultiZoomCoordinateSystemMapper ();
140+ setupMonitors (mapper );
141+ Rectangle rectInPts = new MonitorAwareRectangle (1950 , 400 , 150 , 100 , monitors [1 ]);
98142 Rectangle rectInPxs = mapper .translateToDisplayCoordinates (rectInPts , monitors [0 ].getZoom ());
99143 assertEquals (rectInPts , mapper .translateFromDisplayCoordinates (rectInPxs , monitors [0 ].getZoom ()));
100144 }
@@ -108,19 +152,29 @@ void translateRectangleInGapPartiallyInLeftBackAndForthShouldBeTheSame(Coordinat
108152 assertEquals (rectInPts , mapper .translateFromDisplayCoordinates (rectInPxs , monitors [0 ].getZoom ()));
109153 }
110154
111- @ ParameterizedTest
112- @ MethodSource ( "provideCoordinateSystemMappers" )
113- void translateRectangleInPointsInBothMonitorsPartiallyBackAndForthShouldBeTheSame ( CoordinateSystemMapper mapper ) {
155+ @ Test
156+ void translateRectangleInPointsInBothMonitorsPartiallyBackAndForthInSingleZoomShouldBeTheSame () {
157+ SingleZoomCoordinateSystemMapper mapper = getSingleZoomCoordinateSystemMapper ();
114158 setupMonitors (mapper );
115159 Rectangle rectInPts = new Rectangle (950 , 400 , 1500 , 100 );
116160 Rectangle rectInPxs = mapper .translateToDisplayCoordinates (rectInPts , monitors [0 ].getZoom ());
117161 assertEquals (rectInPts , mapper .translateFromDisplayCoordinates (rectInPxs , monitors [0 ].getZoom ()));
118162 }
119163
120164 @ Test
121- @ Disabled ("Disabled due to current limitations of MultiZoomCoordinateSystemMapper" )
165+ void translateRectangleInPointsInBothMonitorsPartiallyBackAndForthInMultiZoomShouldNotEndUpInGap () {
166+ MultiZoomCoordinateSystemMapper mapper = getMultiZoomCoordinateSystemMapper ();
167+ setupMonitors (mapper );
168+ Rectangle rectInPts = new Rectangle (950 , 400 , 1500 , 100 );
169+ Rectangle rectInPxs = mapper .translateToDisplayCoordinates (rectInPts , monitors [0 ].getZoom ());
170+ Rectangle rectInPtsTranslated = mapper .translateFromDisplayCoordinates (rectInPxs , monitors [0 ].getZoom ());
171+ Rectangle rectInPxsTranslated = mapper .translateToDisplayCoordinates (rectInPtsTranslated , monitors [0 ].getZoom ());
172+ assertEquals (rectInPxs , rectInPxsTranslated );
173+ }
174+
175+ @ Test
122176 void moveRectangleInPixelsInRightMonitorsPartiallyBackAndForthShouldBeTheSame () {
123- CoordinateSystemMapper mapper = provideCoordinateSystemMappers (). findFirst (). get ();
177+ MultiZoomCoordinateSystemMapper mapper = getMultiZoomCoordinateSystemMapper ();
124178 setupMonitors (mapper );
125179 Rectangle rectInPxs = new Rectangle (1990 , -10 , 2000 , 2000 );
126180 Rectangle expectedSmallRectInPxs = new Rectangle (0 , 0 , 0 , monitors [0 ].getZoom ());
@@ -139,11 +193,10 @@ void moveRectangleInPixelsInRightMonitorsPartiallyBackAndForthShouldBeTheSame()
139193 }
140194
141195 @ ParameterizedTest
142- @ MethodSource ("provideCoordinateSystemMappers" )
143- @ Disabled ("Disabled due to current limitations of MultiZoomCoordinateSystemMapper" )
196+ @ MethodSource ("provideCoordinateSystemMappers" )
144197 void translateRectangleInPixelsOutisdeMonitorsBackAndForthShouldBeTheSame (CoordinateSystemMapper mapper ) {
145198 setupMonitors (mapper );
146- Rectangle rectInPxs = new Rectangle (4400 , 400 , 1000 , 1000 );
199+ Rectangle rectInPxs = new Rectangle (400 , 2400 , 1000 , 1000 );
147200 Rectangle rectInPts = mapper .translateFromDisplayCoordinates (rectInPxs , monitors [0 ].getZoom ());
148201 assertEquals (rectInPxs , mapper .translateToDisplayCoordinates (rectInPts , monitors [0 ].getZoom ()));
149202 }
0 commit comments