1414package org .eclipse .swt .widgets ;
1515
1616import static org .junit .jupiter .api .Assertions .assertEquals ;
17+ import static org .junit .jupiter .api .Assertions .assertTrue ;
1718
1819import java .util .function .*;
1920import java .util .stream .*;
@@ -39,16 +40,23 @@ 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 (), getSingleZoomCoordinateSystemMapper ());
52+ }
53+
54+ private MultiZoomCoordinateSystemMapper getMultiZoomCoordinateSystemMapper () {
55+ return new MultiZoomCoordinateSystemMapper (null , () -> monitors );
56+ }
57+
58+ private SingleZoomCoordinateSystemMapper getSingleZoomCoordinateSystemMapper () {
59+ return new SingleZoomCoordinateSystemMapper (null );
5260 }
5361
5462 @ ParameterizedTest
@@ -60,16 +68,27 @@ void translatePointInNoMonitorBackAndForthShouldBeTheSame(CoordinateSystemMapper
6068 assertEquals (pt , mapper .translateFromDisplayCoordinates (px , monitors [0 ].getZoom ()));
6169 }
6270
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 ();
6774 setupMonitors (mapper );
6875 Point pt = new Point (1900 , 400 );
6976 Point px = mapper .translateToDisplayCoordinates (pt , monitors [0 ].getZoom ());
7077 assertEquals (pt , mapper .translateFromDisplayCoordinates (px , monitors [0 ].getZoom ()));
7178 }
7279
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 (translatedPt , translatedPx );
89+ assertEquals (translatedPx , px );
90+ }
91+
7392 @ ParameterizedTest
7493 @ MethodSource ("provideCoordinateSystemMappers" )
7594 void translateRectangleInNoMonitorBackAndForthShouldBeTheSame (CoordinateSystemMapper mapper ) {
@@ -79,22 +98,46 @@ void translateRectangleInNoMonitorBackAndForthShouldBeTheSame(CoordinateSystemMa
7998 assertEquals (rectInPts , mapper .translateFromDisplayCoordinates (rectInPxs , monitors [0 ].getZoom ()));
8099 }
81100
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 ();
86104 setupMonitors (mapper );
87105 Rectangle rectInPts = new Rectangle (1800 , 400 , 100 , 100 );
88106 Rectangle rectInPxs = mapper .translateToDisplayCoordinates (rectInPts , monitors [0 ].getZoom ());
89107 assertEquals (rectInPts , mapper .translateFromDisplayCoordinates (rectInPxs , monitors [0 ].getZoom ()));
90108 }
91109
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 ();
130+ setupMonitors (mapper );
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 ();
96139 setupMonitors (mapper );
97- Rectangle rectInPts = new Rectangle (1950 , 400 , 100 , 100 );
140+ Rectangle rectInPts = new MonitorAwareRectangle (1950 , 400 , 150 , 100 , monitors [ 1 ] );
98141 Rectangle rectInPxs = mapper .translateToDisplayCoordinates (rectInPts , monitors [0 ].getZoom ());
99142 assertEquals (rectInPts , mapper .translateFromDisplayCoordinates (rectInPxs , monitors [0 ].getZoom ()));
100143 }
@@ -108,19 +151,30 @@ void translateRectangleInGapPartiallyInLeftBackAndForthShouldBeTheSame(Coordinat
108151 assertEquals (rectInPts , mapper .translateFromDisplayCoordinates (rectInPxs , monitors [0 ].getZoom ()));
109152 }
110153
111- @ ParameterizedTest
112- @ MethodSource ( "provideCoordinateSystemMappers" )
113- void translateRectangleInPointsInBothMonitorsPartiallyBackAndForthShouldBeTheSame ( CoordinateSystemMapper mapper ) {
154+ @ Test
155+ void translateRectangleInPointsInBothMonitorsPartiallyBackAndForthInSingleZoomShouldBeTheSame () {
156+ SingleZoomCoordinateSystemMapper mapper = getSingleZoomCoordinateSystemMapper ();
114157 setupMonitors (mapper );
115158 Rectangle rectInPts = new Rectangle (950 , 400 , 1500 , 100 );
116159 Rectangle rectInPxs = mapper .translateToDisplayCoordinates (rectInPts , monitors [0 ].getZoom ());
117160 assertEquals (rectInPts , mapper .translateFromDisplayCoordinates (rectInPxs , monitors [0 ].getZoom ()));
118161 }
119162
120163 @ 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
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 ());
@@ -140,10 +194,9 @@ void moveRectangleInPixelsInRightMonitorsPartiallyBackAndForthShouldBeTheSame()
140194
141195 @ ParameterizedTest
142196 @ MethodSource ("provideCoordinateSystemMappers" )
143- @ Disabled ("Disabled due to current limitations of MultiZoomCoordinateSystemMapper" )
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