JAL-2778 Reduced calculation load for overview box
[jalview.git] / src / jalview / viewmodel / OverviewDimensionsShowHidden.java
index 9dde16e..ec2efa2 100644 (file)
@@ -97,10 +97,10 @@ public class OverviewDimensionsShowHidden extends OverviewDimensions
     // get mouse location in viewport coords, add translation in viewport
     // coords,
     // convert back to pixel coords
-    int vpx = Math.round((float) mousex * alwidth / width);
+    int vpx = Math.round(mousex * widthRatio);
     int visXAsRes = hiddenCols.findColumnPosition(vpx) + xdiff;
 
-    int vpy = Math.round((float) mousey * alheight / sequencesHeight);
+    int vpy = Math.round(mousey * heightRatio);
     int visYAsRes = hiddenSeqs.findIndexWithoutHiddenSeqs(vpy) + ydiff;
 
     // update viewport accordingly
@@ -225,12 +225,15 @@ public class OverviewDimensionsShowHidden extends OverviewDimensions
   {
     alwidth = ranges.getAbsoluteAlignmentWidth();
     alheight = ranges.getAbsoluteAlignmentHeight();
+
+    widthRatio = (float) alwidth / width;
+    heightRatio = (float) alheight / sequencesHeight;
   }
 
   @Override
   protected int getLeftXFromCentreX(int mousex, HiddenColumns hidden)
   {
-    int vpx = Math.round((float) mousex * alwidth / width);
+    int vpx = Math.round(mousex * widthRatio);
     return hidden.subtractVisibleColumns(ranges.getViewportWidth() / 2,
             vpx);
   }
@@ -238,7 +241,7 @@ public class OverviewDimensionsShowHidden extends OverviewDimensions
   @Override
   protected int getTopYFromCentreY(int mousey, HiddenSequences hidden)
   {
-    int vpy = Math.round((float) mousey * alheight / sequencesHeight);
+    int vpy = Math.round(mousey * heightRatio);
     return hidden.subtractVisibleRows(ranges.getViewportHeight() / 2, vpy);
   }
 
@@ -248,8 +251,8 @@ public class OverviewDimensionsShowHidden extends OverviewDimensions
   {
     // get alignment position of x and box (can get directly from vpranges) and
     // calculate difference between the positions
-    int vpx = Math.round((float) x * alwidth / width);
-    int vpy = Math.round((float) y * alheight / sequencesHeight);
+    int vpx = Math.round(x * widthRatio);
+    int vpy = Math.round(y * heightRatio);
 
     xdiff = ranges.getStartRes() - hiddenCols.findColumnPosition(vpx);
     ydiff = ranges.getStartSeq()