From 18b0c645cdfafae15e9f1d8c5a38bfa4ef45dc3c Mon Sep 17 00:00:00 2001 From: kiramt Date: Thu, 13 Jul 2017 16:54:22 +0100 Subject: [PATCH] JAL-2611 Added overview dimensions test for position in box --- src/jalview/viewmodel/OverviewDimensions.java | 15 +++++++++++++++ .../viewmodel/OverviewDimensionsHideHiddenTest.java | 17 ++++++++++++++++- .../viewmodel/OverviewDimensionsShowHiddenTest.java | 17 ++++++++++++++++- 3 files changed, 47 insertions(+), 2 deletions(-) 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. */ -- 1.7.10.2