JAL-2611 Added overview dimensions test for position in box
[jalview.git] / test / jalview / viewmodel / OverviewDimensionsHideHiddenTest.java
index 2bd9c47..0c751e2 100644 (file)
@@ -21,6 +21,8 @@
 package jalview.viewmodel;
 
 import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertTrue;
 
 import jalview.analysis.AlignmentGenerator;
 import jalview.datamodel.Alignment;
@@ -56,7 +58,7 @@ public class OverviewDimensionsHideHiddenTest
 
   ViewportRanges vpranges;
 
-  Hashtable<SequenceI, SequenceCollectionI> hiddenRepSequences = new Hashtable<SequenceI, SequenceCollectionI>();
+  Hashtable<SequenceI, SequenceCollectionI> hiddenRepSequences = new Hashtable<>();
 
   HiddenColumns hiddenCols = new HiddenColumns();
 
@@ -79,10 +81,8 @@ public class OverviewDimensionsHideHiddenTest
     hiddenCols.revealAllHiddenColumns(colsel);
     
     vpranges = new ViewportRanges(al);
-    vpranges.setStartRes(0);
-    vpranges.setEndRes(62);
-    vpranges.setStartSeq(0);
-    vpranges.setEndSeq(17);
+    vpranges.setViewportStartAndHeight(0, 18);
+    vpranges.setViewportStartAndWidth(0, 63);
 
     viewHeight = vpranges.getEndSeq() - vpranges.getStartSeq() + 1;
     viewWidth = vpranges.getEndRes() - vpranges.getStartRes() + 1;
@@ -204,26 +204,26 @@ public class OverviewDimensionsHideHiddenTest
     assertEquals(od.getBoxX(), 0);
     assertEquals(od.getBoxY(), 0);
     assertEquals(od.getBoxWidth(), boxWidth);
-    assertEquals(od.getScrollCol(), 0);
-    assertEquals(od.getScrollRow(), 0);
+    assertEquals(vpranges.getStartRes(), 0);
+    assertEquals(vpranges.getStartSeq(), 0);
 
     // negative boxX value reset to 0
     mouseClick(od, -5, 10);
     assertEquals(od.getBoxX(), 0);
     assertEquals(od.getBoxWidth(), boxWidth);
     assertEquals(od.getBoxHeight(), boxHeight);
-    assertEquals(od.getScrollRow(),
+    assertEquals(vpranges.getStartSeq(),
             Math.round((float) 10 * alheight / od.getSequencesHeight()));
-    assertEquals(od.getScrollCol(), 0);
+    assertEquals(vpranges.getStartRes(), 0);
 
     // negative boxY value reset to 0
     mouseClick(od, 6, -2);
     assertEquals(od.getBoxY(), 0);
     assertEquals(od.getBoxWidth(), boxWidth);
     assertEquals(od.getBoxHeight(), boxHeight);
-    assertEquals(od.getScrollCol(),
+    assertEquals(vpranges.getStartRes(),
             Math.round((float) 6 * alwidth / od.getWidth()));
-    assertEquals(od.getScrollRow(), 0);
+    assertEquals(vpranges.getStartSeq(), 0);
 
     // overly large boxX value reset to width-boxWidth
     mouseClick(od, 100, 6);
@@ -231,9 +231,10 @@ public class OverviewDimensionsHideHiddenTest
     assertEquals(od.getBoxY(), 6);
     assertEquals(od.getBoxWidth(), boxWidth);
     assertEquals(od.getBoxHeight(), boxHeight);
-    assertEquals(od.getScrollCol(),
+    assertEquals(vpranges.getStartRes(),
             Math.round((float) od.getBoxX() * alwidth / od.getWidth()));
-    assertEquals(od.getScrollRow(),
+    assertEquals(
+            vpranges.getStartSeq(),
             Math.round((float) od.getBoxY() * alheight
                     / od.getSequencesHeight()));
 
@@ -243,13 +244,14 @@ public class OverviewDimensionsHideHiddenTest
     assertEquals(od.getBoxY(), od.getSequencesHeight() - od.getBoxHeight());
     assertEquals(od.getBoxWidth(), boxWidth);
     assertEquals(od.getBoxHeight(), boxHeight);
-    assertEquals(od.getScrollCol(),
+    assertEquals(vpranges.getStartRes(),
             Math.round((float) od.getBoxX() * alwidth / od.getWidth()));
 
     // here (float) od.getBoxY() * alheight / od.getSequencesHeight() = 507.5
     // and round rounds to 508; however we get 507 working with row values
     // hence the subtraction of 1
-    assertEquals(od.getScrollRow(),
+    assertEquals(
+            vpranges.getStartSeq(),
             Math.round((float) od.getBoxY() * alheight
                     / od.getSequencesHeight()) - 1);
 
@@ -258,9 +260,10 @@ public class OverviewDimensionsHideHiddenTest
     assertEquals(od.getBoxX(), od.getWidth() - od.getBoxWidth());
     assertEquals(od.getBoxWidth(), boxWidth);
     assertEquals(od.getBoxHeight(), boxHeight);
-    assertEquals(od.getScrollCol(),
+    assertEquals(vpranges.getStartRes(),
             Math.round((float) od.getBoxX() * alwidth / od.getWidth()));
-    assertEquals(od.getScrollRow(),
+    assertEquals(
+            vpranges.getStartSeq(),
             Math.round((float) od.getBoxY() * alheight
                     / od.getSequencesHeight()));
 
@@ -274,19 +277,20 @@ public class OverviewDimensionsHideHiddenTest
     assertEquals(od.getBoxX(), oldboxx + 5);
     assertEquals(od.getBoxWidth(), boxWidth);
     assertEquals(od.getBoxHeight(), boxHeight);
-    assertEquals(od.getScrollCol(),
+    assertEquals(vpranges.getStartRes(),
             Math.round((float) od.getBoxX() * alwidth / od.getWidth()));
     assertEquals(od.getBoxY(), oldboxy + 2);
-    assertEquals(od.getScrollRow(),
+    assertEquals(
+            vpranges.getStartSeq(),
             Math.round((float) od.getBoxY() * alheight
                     / od.getSequencesHeight()));
 
     // click at top corner
     mouseClick(od, 0, 0);
     assertEquals(od.getBoxX(), 0);
-    assertEquals(od.getScrollCol(), 0);
+    assertEquals(vpranges.getStartRes(), 0);
     assertEquals(od.getBoxY(), 0);
-    assertEquals(od.getScrollRow(), 0);
+    assertEquals(vpranges.getStartSeq(), 0);
     assertEquals(od.getBoxWidth(), boxWidth);
     assertEquals(od.getBoxHeight(), boxHeight);
   }
@@ -302,8 +306,8 @@ public class OverviewDimensionsHideHiddenTest
     assertEquals(od.getBoxX(), 0);
     assertEquals(od.getBoxY(), 0);
     assertEquals(od.getBoxWidth(), boxWidth);
-    assertEquals(od.getScrollCol(), 0);
-    assertEquals(od.getScrollRow(), 0);
+    assertEquals(vpranges.getStartRes(), 0);
+    assertEquals(vpranges.getStartSeq(), 0);
 
     // hide cols at start and check updated box position is correct
     int lastHiddenCol = 30;
@@ -313,8 +317,8 @@ public class OverviewDimensionsHideHiddenTest
 
     // click to right of hidden columns, box moves to click point
     testBoxIsAtClickPoint(40, 0);
-    assertEquals(od.getScrollRow(), 0);
-    assertEquals(od.getScrollCol(),
+    assertEquals(vpranges.getStartSeq(), 0);
+    assertEquals(vpranges.getStartRes(),
             Math.round((float) 40 * alwidth / od.getWidth()));
 
     // click to right of hidden columns such that box runs over right hand side
@@ -327,9 +331,9 @@ public class OverviewDimensionsHideHiddenTest
     assertEquals(od.getBoxY(), 0);
     assertEquals(od.getBoxWidth(), boxWidth);
     assertEquals(od.getBoxHeight(), boxHeight);
-    assertEquals(od.getScrollCol(),
+    assertEquals(vpranges.getStartRes(),
             Math.round((float) od.getBoxX() * alwidth / od.getWidth()));
-    assertEquals(od.getScrollRow(), 0);
+    assertEquals(vpranges.getStartSeq(), 0);
   }
 
   /**
@@ -344,8 +348,8 @@ public class OverviewDimensionsHideHiddenTest
     assertEquals(od.getBoxX(), 0);
     assertEquals(od.getBoxY(), 0);
     assertEquals(od.getBoxWidth(), boxWidth);
-    assertEquals(od.getScrollCol(), 0);
-    assertEquals(od.getScrollRow(), 0);
+    assertEquals(vpranges.getStartRes(), 0);
+    assertEquals(vpranges.getStartSeq(), 0);
     
     // hide columns 63-73, no change to box position or dimensions
     int firstHidden = 63;
@@ -357,8 +361,8 @@ public class OverviewDimensionsHideHiddenTest
     assertEquals(od.getBoxX(), 0);
     assertEquals(od.getBoxY(), 0);
     assertEquals(od.getBoxWidth(), boxWidth);
-    assertEquals(od.getScrollCol(), 0);
-    assertEquals(od.getScrollRow(), 0);
+    assertEquals(vpranges.getStartRes(), 0);
+    assertEquals(vpranges.getStartSeq(), 0);
 
     // move box so that it overlaps with hidden cols on one side
     // box width, boxX and scrollCol as for unhidden case
@@ -366,35 +370,35 @@ public class OverviewDimensionsHideHiddenTest
                               // between cols 60 and 70
     mouseClick(od, xpos, 0);
     testBoxIsAtClickPoint(xpos, 0);
-    assertEquals(od.getScrollCol(),
+    assertEquals(vpranges.getStartRes(),
             Math.round(xpos * alwidth / od.getWidth()));
-    assertEquals(od.getScrollRow(), 0);
+    assertEquals(vpranges.getStartSeq(), 0);
 
     // move box so that it completely covers hidden cols
     // box width, boxX and scrollCol as for unhidden case
     xpos = 33;
     mouseClick(od, xpos, 0);
     testBoxIsAtClickPoint(xpos, 0);
-    assertEquals(od.getScrollCol(),
+    assertEquals(vpranges.getStartRes(),
             Math.round((float) xpos * alwidth / od.getWidth()));
-    assertEquals(od.getScrollRow(), 0);
+    assertEquals(vpranges.getStartSeq(), 0);
 
     // move box so boxX is in hidden cols, box overhangs at right
     // boxX and scrollCol at left of hidden area, box width unchanged
     xpos = 50;
     mouseClick(od, xpos, 0);
     testBoxIsAtClickPoint(xpos, 0);
-    assertEquals(od.getScrollCol(),
+    assertEquals(vpranges.getStartRes(),
             Math.round((float) xpos * alwidth / od.getWidth()));
-    assertEquals(od.getScrollRow(), 0);
+    assertEquals(vpranges.getStartSeq(), 0);
 
     // move box so boxX is to right of hidden cols, but does not go beyond full
     // width of alignment
     // box width, boxX and scrollCol all as for non-hidden case
     xpos = 75;
     testBoxIsAtClickPoint(xpos, 0);
-    assertEquals(od.getScrollRow(), 0);
-    assertEquals(od.getScrollCol(),
+    assertEquals(vpranges.getStartSeq(), 0);
+    assertEquals(vpranges.getStartRes(),
             Math.round(xpos * alwidth / od.getWidth()));
     
     // move box so it goes beyond full width of alignment
@@ -405,9 +409,9 @@ public class OverviewDimensionsHideHiddenTest
     assertEquals(od.getBoxY(), 0);
     assertEquals(od.getBoxWidth(), boxWidth);
     assertEquals(od.getBoxHeight(), boxHeight);
-    assertEquals(od.getScrollCol(),
+    assertEquals(vpranges.getStartRes(),
             Math.round((float) od.getBoxX() * alwidth / od.getWidth()));
-    assertEquals(od.getScrollRow(), 0);
+    assertEquals(vpranges.getStartSeq(), 0);
 
   }
 
@@ -422,8 +426,8 @@ public class OverviewDimensionsHideHiddenTest
     assertEquals(od.getBoxX(), 0);
     assertEquals(od.getBoxY(), 0);
     assertEquals(od.getBoxWidth(), boxWidth);
-    assertEquals(od.getScrollCol(), 0);
-    assertEquals(od.getScrollRow(), 0);
+    assertEquals(vpranges.getStartRes(), 0);
+    assertEquals(vpranges.getStartSeq(), 0);
 
     // hide columns 140-164, no change to box position or dimensions
     int firstHidden = 140;
@@ -433,15 +437,15 @@ public class OverviewDimensionsHideHiddenTest
     assertEquals(od.getBoxX(), 0);
     assertEquals(od.getBoxY(), 0);
     assertEquals(od.getBoxWidth(), boxWidth);
-    assertEquals(od.getScrollCol(), 0);
-    assertEquals(od.getScrollRow(), 0);
+    assertEquals(vpranges.getStartRes(), 0);
+    assertEquals(vpranges.getStartSeq(), 0);
 
     // click to left of hidden cols, without overlapping
     // boxX, scrollCol and width as normal
     int xpos = 5;
     testBoxIsAtClickPoint(xpos, 0);
-    assertEquals(od.getScrollRow(), 0);
-    assertEquals(od.getScrollCol(),
+    assertEquals(vpranges.getStartSeq(), 0);
+    assertEquals(vpranges.getStartRes(),
             Math.round((float) xpos * alwidth / od.getWidth()));
 
     // click to left of hidden cols, with overlap
@@ -449,9 +453,9 @@ public class OverviewDimensionsHideHiddenTest
     xpos = Math.round((float) 145 * od.getWidth() / alwidth) - boxWidth;
     mouseClick(od, xpos, 0);
     testBoxIsAtClickPoint(xpos, 0);
-    assertEquals(od.getScrollCol(),
+    assertEquals(vpranges.getStartRes(),
             Math.round((float) xpos * alwidth / od.getWidth()));
-    assertEquals(od.getScrollRow(), 0);
+    assertEquals(vpranges.getStartSeq(), 0);
 
     // click off end of alignment
     // boxX and scrollCol adjusted backwards, width normal
@@ -461,9 +465,9 @@ public class OverviewDimensionsHideHiddenTest
     assertEquals(od.getBoxY(), 0);
     assertEquals(od.getBoxWidth(), boxWidth);
     assertEquals(od.getBoxHeight(), boxHeight);
-    assertEquals(od.getScrollCol(),
+    assertEquals(vpranges.getStartRes(),
             Math.round((float) od.getBoxX() * alwidth / od.getWidth()));
-    assertEquals(od.getScrollRow(), 0);
+    assertEquals(vpranges.getStartSeq(), 0);
   }
 
   /**
@@ -750,8 +754,8 @@ public class OverviewDimensionsHideHiddenTest
     assertEquals(od.getBoxY(), 0);
     assertEquals(od.getBoxHeight(), boxHeight);
     assertEquals(od.getBoxWidth(), boxWidth);
-    assertEquals(od.getScrollCol(), 0);
-    assertEquals(od.getScrollRow(), 0);
+    assertEquals(vpranges.getStartRes(), 0);
+    assertEquals(vpranges.getStartSeq(), 0);
 
     // hide rows at start and check updated box position is correct
     int lastHiddenRow = 30;
@@ -795,8 +799,8 @@ public class OverviewDimensionsHideHiddenTest
     assertEquals(od.getBoxY(), 0);
     assertEquals(od.getBoxWidth(), boxWidth);
     assertEquals(od.getBoxHeight(), boxHeight);
-    assertEquals(od.getScrollCol(), 0);
-    assertEquals(od.getScrollRow(), 0);
+    assertEquals(vpranges.getStartRes(), 0);
+    assertEquals(vpranges.getStartSeq(), 0);
 
     // hide rows in middle and check updated box position is correct
     // no changes
@@ -855,8 +859,8 @@ public class OverviewDimensionsHideHiddenTest
     assertEquals(od.getBoxY(), 0);
     assertEquals(od.getBoxWidth(), boxWidth);
     assertEquals(od.getBoxHeight(), boxHeight);
-    assertEquals(od.getScrollCol(), 0);
-    assertEquals(od.getScrollRow(), 0);
+    assertEquals(vpranges.getStartRes(), 0);
+    assertEquals(vpranges.getStartSeq(), 0);
 
     // hide rows at end and check updated box position is correct
     // no changes
@@ -906,13 +910,25 @@ public class OverviewDimensionsHideHiddenTest
     assertEquals(od.getBoxHeight(), boxHeight);
   }
 
+  /**
+   * Test the function to determine if a point is in the overview's box or not
+   */
+  @Test(groups = { "Functional" })
+  public void testPositionInBox()
+  {
+    assertFalse(od.isPositionInBox(0, 0));
+    assertTrue(od.isPositionInBox(10, 9));
+    assertFalse(od.isPositionInBox(0, 9));
+    assertFalse(od.isPositionInBox(9, 0));
+    assertFalse(od.isPositionInBox(75, 20));
+  }
+
   /*
    * Move viewport horizontally: startRes + previous width gives new horizontal extent. Vertical extent stays the same.
    */
   private void moveViewportH(int startRes)
   {
-    vpranges.setStartRes(startRes);
-    vpranges.setEndRes(startRes + viewWidth - 1);
+    vpranges.setViewportStartAndWidth(startRes, viewWidth);
     od.setBoxPosition(al.getHiddenSequences(), hiddenCols);
   }
 
@@ -921,8 +937,7 @@ public class OverviewDimensionsHideHiddenTest
    */
   private void moveViewportV(int startSeq)
   {
-    vpranges.setStartSeq(startSeq);
-    vpranges.setEndSeq(startSeq + viewHeight - 1);
+    vpranges.setViewportStartAndHeight(startSeq, viewHeight);
     od.setBoxPosition(al.getHiddenSequences(), hiddenCols);
   }
 
@@ -931,28 +946,21 @@ public class OverviewDimensionsHideHiddenTest
    */
   private void moveViewport(int startRes, int startSeq)
   {
-    vpranges.setStartRes(startRes);
-    vpranges.setEndRes(startRes + viewWidth - 1);
-    vpranges.setStartSeq(startSeq);
-    vpranges.setEndSeq(startSeq + viewHeight - 1);
+    vpranges.setViewportStartAndWidth(startRes, viewWidth);
+    vpranges.setViewportStartAndHeight(startSeq, viewHeight);
     od.setBoxPosition(al.getHiddenSequences(), hiddenCols);
   }
 
   /*
    * Mouse click as position x,y in overview window
    */
-  private void mouseClick(OverviewDimensionsHideHidden od, int x, int y)
+  private void mouseClick(OverviewDimensions od, int x, int y)
   {
     od.updateViewportFromMouse(x, y, al.getHiddenSequences(), hiddenCols);
 
     // updates require an OverviewPanel to exist which it doesn't here
     // so call setBoxPosition() as it would be called by the AlignmentPanel
     // normally
-
-    vpranges.setStartRes(od.getScrollCol());
-    vpranges.setEndRes(od.getScrollCol() + viewWidth - 1);
-    vpranges.setStartSeq(od.getScrollRow());
-    vpranges.setEndSeq(od.getScrollRow() + viewHeight - 1);
     od.setBoxPosition(al.getHiddenSequences(), hiddenCols);
   }