JAL-2388 Fixed inherited&new out-by-one errors; further unit tests
[jalview.git] / src / jalview / viewmodel / OverviewDimensions.java
index 1f18a10..4a2dd29 100644 (file)
@@ -138,7 +138,7 @@ public class OverviewDimensions
     {
       x = 0;
     }
-    else if (x >= alwidth)
+    else if (x >= width)
     {
       x = alwidth - 1;
     }
@@ -147,7 +147,7 @@ public class OverviewDimensions
     {
       y = 0;
     }
-    else if (y >= alheight)
+    else if (y >= sequencesHeight)
     {
       y = alheight - 1;
     }
@@ -174,7 +174,8 @@ public class OverviewDimensions
             .findColumnPosition(xAsRes));
 
     // get where end res should be by adding the viewport width on
-    int endRes = xAsRes + vpwidth;
+    // subtract 1 because the width includes endRes
+    int endRes = xAsRes + vpwidth - 1;
 
     // check in case we went off the edge of the alignment
     if (endRes > alwidth)
@@ -182,7 +183,8 @@ public class OverviewDimensions
       // went past the end of the alignment, adjust backwards
       endRes = alwidth;
       // recalc xAsRes backwards from endRes
-      xAsRes = endRes - vpwidth;
+      // add 1 because width includes xAsRes
+      xAsRes = endRes - vpwidth + 1;
     }
 
     //
@@ -193,6 +195,7 @@ public class OverviewDimensions
     int yAsSeq = Math.round((float) y * alheight / sequencesHeight);
 
     // get viewport height in sequences
+    // add 1 because height includes both endSeq and startSeq
     int vpheight = props.getEndSeq() - props.getStartSeq() + 1;
 
     // get where y should be when accounting for hidden rows
@@ -203,7 +206,7 @@ public class OverviewDimensions
             .findIndexWithoutHiddenSeqs(yAsSeq));
 
     // get where end seq should be by adding the viewport height on
-    int endSeq = yAsSeq + vpheight;
+    int endSeq = yAsSeq + vpheight - 1;
 
     // check in case we went off the edge of the alignment
     if (endSeq > alheight)
@@ -250,9 +253,13 @@ public class OverviewDimensions
     boxY = Math.round((float) startSeq * sequencesHeight / alheight);
 
     // boxWidth is the width in residues translated to pixels
+    // since the box includes both the start and end residues, add 1 to the
+    // difference
     boxWidth = Math
             .round((float) (endRes - startRes + 1) * width / alwidth);
     // boxHeight is the height in sequences translated to pixels
+    // since the box includes both the start and end sequences, add 1 to the
+    // difference
     boxHeight = Math.round((float) (endSeq - startSeq + 1)
             * sequencesHeight
             / alheight);