|
| 1 | +package org.eclipse.swt.widgets; |
| 2 | + |
| 3 | +import static org.junit.jupiter.api.Assertions.assertEquals; |
| 4 | + |
| 5 | +import java.util.function.*; |
| 6 | + |
| 7 | +import org.eclipse.swt.graphics.*; |
| 8 | +import org.junit.jupiter.api.*; |
| 9 | + |
| 10 | +public class CoordinateSystemMapperTests { |
| 11 | + |
| 12 | + Supplier<Monitor[]> getMonitorConsumer; |
| 13 | + MultiZoomCoordinateSystemMapper multiZoomCoordinateSystemMapper; |
| 14 | + |
| 15 | + private Monitor getMonitorLeft200() { |
| 16 | + Monitor monitor = new Monitor(); |
| 17 | + monitor.x = 0; |
| 18 | + monitor.y = 0; |
| 19 | + monitor.width = 1000; |
| 20 | + monitor.height = 1000; |
| 21 | + monitor.clientHeight = 1000; |
| 22 | + monitor.clientWidth = 1000; |
| 23 | + monitor.clientX = 0; |
| 24 | + monitor.clientY = 0; |
| 25 | + monitor.zoom = 200; |
| 26 | + monitor.handle = 1; |
| 27 | + return monitor; |
| 28 | + } |
| 29 | + |
| 30 | + private Monitor getMonitorRight100() { |
| 31 | + Monitor monitor = new Monitor(); |
| 32 | + monitor.x = 2000; |
| 33 | + monitor.y = 0; |
| 34 | + monitor.width = 2000; |
| 35 | + monitor.height = 2000; |
| 36 | + monitor.clientHeight = 2000; |
| 37 | + monitor.clientWidth = 2000; |
| 38 | + monitor.clientX = 2000; |
| 39 | + monitor.clientY = 0; |
| 40 | + monitor.zoom = 100; |
| 41 | + monitor.handle = 2; |
| 42 | + return monitor; |
| 43 | + } |
| 44 | + |
| 45 | + @BeforeEach |
| 46 | + void setup() { |
| 47 | + Monitor [] monitors = new Monitor [] {getMonitorLeft200(), getMonitorRight100()}; |
| 48 | + getMonitorConsumer = () -> monitors; |
| 49 | + multiZoomCoordinateSystemMapper = new MultiZoomCoordinateSystemMapper(null, getMonitorConsumer); |
| 50 | + } |
| 51 | + |
| 52 | + @Test |
| 53 | + void translatePointInNoMonitorBackAndForthShouldBeTheSame() { |
| 54 | + Point pt = new Point(5000, -400); |
| 55 | + Point px = multiZoomCoordinateSystemMapper.translateToDisplayCoordinates(pt, 0); |
| 56 | + assertEquals(pt, multiZoomCoordinateSystemMapper.translateFromDisplayCoordinates(px, 0)); |
| 57 | + } |
| 58 | + |
| 59 | + @Test |
| 60 | + @Disabled("Disabled due to current limitations of MultiZoomCoordinateSystemMapper") |
| 61 | + void translatePointInGapBackAndForthShouldBeTheSame() { |
| 62 | + Point pt = new Point(1900, 400); |
| 63 | + Point px = multiZoomCoordinateSystemMapper.translateToDisplayCoordinates(pt, 0); |
| 64 | + assertEquals(pt, multiZoomCoordinateSystemMapper.translateFromDisplayCoordinates(px, 0)); |
| 65 | + } |
| 66 | + |
| 67 | + @Test |
| 68 | + void translateRectangleInNoMonitorBackAndForthShouldBeTheSame() { |
| 69 | + Rectangle rectInPts = new Rectangle(5000, -400, 200, 200); |
| 70 | + Rectangle rectInPxs = multiZoomCoordinateSystemMapper.translateToDisplayCoordinates(rectInPts, 0); |
| 71 | + assertEquals(rectInPts, multiZoomCoordinateSystemMapper.translateFromDisplayCoordinates(rectInPxs, 0)); |
| 72 | + } |
| 73 | + |
| 74 | + @Test |
| 75 | + @Disabled("Disabled due to current limitations of MultiZoomCoordinateSystemMapper") |
| 76 | + void translateRectangleInGapBackAndForthShouldBeTheSame() { |
| 77 | + Rectangle rectInPts = new Rectangle(1800, 400, 100, 100); |
| 78 | + Rectangle rectInPxs = multiZoomCoordinateSystemMapper.translateToDisplayCoordinates(rectInPts, 0); |
| 79 | + assertEquals(rectInPts, multiZoomCoordinateSystemMapper.translateFromDisplayCoordinates(rectInPxs, 0)); |
| 80 | + } |
| 81 | + |
| 82 | + @Test |
| 83 | + @Disabled("Disabled due to current limitations of MultiZoomCoordinateSystemMapper") |
| 84 | + void translateRectangleInGapPartiallyInRightBackAndForthShouldBeTheSame() { |
| 85 | + Rectangle rectInPts = new Rectangle(1950, 400, 100, 100); |
| 86 | + Rectangle rectInPxs = multiZoomCoordinateSystemMapper.translateToDisplayCoordinates(rectInPts, 0); |
| 87 | + assertEquals(rectInPts, multiZoomCoordinateSystemMapper.translateFromDisplayCoordinates(rectInPxs, 0)); |
| 88 | + } |
| 89 | + |
| 90 | + @Test |
| 91 | + void translateRectangleInGapPartiallyInLeftBackAndForthShouldBeTheSame() { |
| 92 | + Rectangle rectInPts = new Rectangle(750, 400, 100, 100); |
| 93 | + Rectangle rectInPxs = multiZoomCoordinateSystemMapper.translateToDisplayCoordinates(rectInPts, 0); |
| 94 | + assertEquals(rectInPts, multiZoomCoordinateSystemMapper.translateFromDisplayCoordinates(rectInPxs, 0)); |
| 95 | + } |
| 96 | + |
| 97 | + @Test |
| 98 | + void translateRectangleInPointsInBothMonitorsPartiallyBackAndForthShouldBeTheSame() { |
| 99 | + Rectangle rectInPts = new Rectangle(950, 400, 1500, 100); |
| 100 | + Rectangle rectInPxs = multiZoomCoordinateSystemMapper.translateToDisplayCoordinates(rectInPts, 0); |
| 101 | + assertEquals(rectInPts, multiZoomCoordinateSystemMapper.translateFromDisplayCoordinates(rectInPxs, 0)); |
| 102 | + } |
| 103 | + |
| 104 | + @Test |
| 105 | + @Disabled("Disabled due to current limitations of MultiZoomCoordinateSystemMapper") |
| 106 | + void moveRectangleInPixelsInRightMonitorsPartiallyBackAndForthShouldBeTheSame() { |
| 107 | + Rectangle rectInPxs = new Rectangle(1990, -10, 2000, 2000); |
| 108 | + Rectangle expectedSmallRectInPxs = new Rectangle(0, 0, 0, 0); |
| 109 | + expectedSmallRectInPxs.x = rectInPxs.x + (rectInPxs.width/2) - 200; |
| 110 | + expectedSmallRectInPxs.y = rectInPxs.y + (rectInPxs.height/2) - 200; |
| 111 | + expectedSmallRectInPxs.width = 400; |
| 112 | + expectedSmallRectInPxs.height = 400; |
| 113 | + Rectangle rectInPts = multiZoomCoordinateSystemMapper.translateFromDisplayCoordinates(rectInPxs, 0); |
| 114 | + Rectangle smallRectInPts = new Rectangle(0, 0, 0, 0); |
| 115 | + smallRectInPts.x = rectInPts.x + (rectInPts.width/2) - 200; |
| 116 | + smallRectInPts.y = rectInPts.y + (rectInPts.height/2) - 200; |
| 117 | + smallRectInPts.width = 400; |
| 118 | + smallRectInPts.height = 400; |
| 119 | + Rectangle smallRectInPxs = multiZoomCoordinateSystemMapper.translateToDisplayCoordinates(smallRectInPts, 0); |
| 120 | + assertEquals(expectedSmallRectInPxs, smallRectInPxs); |
| 121 | + } |
| 122 | + |
| 123 | + @Test |
| 124 | + @Disabled("Disabled due to current limitations of MultiZoomCoordinateSystemMapper") |
| 125 | + void translateRectangleInPixelsOutisdeMonitorsBackAndForthShouldBeTheSame() { |
| 126 | + Rectangle rectInPxs = new Rectangle(4400, 400, 1000, 1000); |
| 127 | + Rectangle rectInPts = multiZoomCoordinateSystemMapper.translateFromDisplayCoordinates(rectInPxs, 0); |
| 128 | + assertEquals(rectInPxs, multiZoomCoordinateSystemMapper.translateToDisplayCoordinates(rectInPts, 0)); |
| 129 | + } |
| 130 | + |
| 131 | + @Test |
| 132 | + void translateRectangleInPixelsInBothMonitorsBackAndForthShouldBeTheSame() { |
| 133 | + Rectangle rectInPxs = new Rectangle(1500, 400, 502, 500); |
| 134 | + Rectangle rectInPts = multiZoomCoordinateSystemMapper.translateFromDisplayCoordinates(rectInPxs, 0); |
| 135 | + assertEquals(rectInPxs, multiZoomCoordinateSystemMapper.translateToDisplayCoordinates(rectInPts, 0)); |
| 136 | + } |
| 137 | + |
| 138 | +} |
0 commit comments