From: kiramt Date: Thu, 13 Jul 2017 15:54:22 +0000 (+0100) Subject: JAL-2611 Added overview dimensions test for position in box X-Git-Tag: Release_2_10_3b1~132^2~30^2~9 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=18b0c645cdfafae15e9f1d8c5a38bfa4ef45dc3c;p=jalview.git JAL-2611 Added overview dimensions test for position in box --- diff --git a/src/jalview/viewmodel/OverviewDimensions.java b/src/jalview/viewmodel/OverviewDimensions.java index d2912d8..f053a95 100644 --- a/src/jalview/viewmodel/OverviewDimensions.java +++ b/src/jalview/viewmodel/OverviewDimensions.java @@ -240,4 +240,19 @@ public abstract class OverviewDimensions // boxHeight is the height in sequences translated to pixels boxHeight = Math.round((float) vpheight * sequencesHeight / alheight); } + + /** + * Answers if a mouse position is in the overview's red box + * + * @param x + * mouse x position + * @param y + * mouse y position + * @return true if (x,y) is inside the box + */ + protected boolean isPositionInBox(int x, int y) + { + return (x > boxX && y > boxY && boxX + x < boxWidth + && boxY + y < boxHeight); + } } \ No newline at end of file diff --git a/test/jalview/viewmodel/OverviewDimensionsHideHiddenTest.java b/test/jalview/viewmodel/OverviewDimensionsHideHiddenTest.java index 0e931eb..0c751e2 100644 --- a/test/jalview/viewmodel/OverviewDimensionsHideHiddenTest.java +++ b/test/jalview/viewmodel/OverviewDimensionsHideHiddenTest.java @@ -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 hiddenRepSequences = new Hashtable(); + Hashtable hiddenRepSequences = new Hashtable<>(); HiddenColumns hiddenCols = new HiddenColumns(); @@ -908,6 +910,19 @@ 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. */ diff --git a/test/jalview/viewmodel/OverviewDimensionsShowHiddenTest.java b/test/jalview/viewmodel/OverviewDimensionsShowHiddenTest.java index 1bc3bfa..21e3ed3 100644 --- a/test/jalview/viewmodel/OverviewDimensionsShowHiddenTest.java +++ b/test/jalview/viewmodel/OverviewDimensionsShowHiddenTest.java @@ -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; @@ -55,7 +57,7 @@ public class OverviewDimensionsShowHiddenTest ViewportRanges vpranges; - Hashtable hiddenRepSequences = new Hashtable(); + Hashtable hiddenRepSequences = new Hashtable<>(); HiddenColumns hiddenCols = new HiddenColumns(); @@ -951,6 +953,19 @@ public class OverviewDimensionsShowHiddenTest 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. */