From c526a787880d475c11bbc9124052fd5b7d120405 Mon Sep 17 00:00:00 2001 From: kiramt Date: Fri, 3 Nov 2017 10:50:03 +0000 Subject: [PATCH] JAL-2778 Reduced calculation load for overview box --- src/jalview/viewmodel/OverviewDimensions.java | 4 ++++ src/jalview/viewmodel/OverviewDimensionsHideHidden.java | 15 +++++++++------ src/jalview/viewmodel/OverviewDimensionsShowHidden.java | 15 +++++++++------ 3 files changed, 22 insertions(+), 12 deletions(-) diff --git a/src/jalview/viewmodel/OverviewDimensions.java b/src/jalview/viewmodel/OverviewDimensions.java index 170f4e9..d7f2e61 100644 --- a/src/jalview/viewmodel/OverviewDimensions.java +++ b/src/jalview/viewmodel/OverviewDimensions.java @@ -58,6 +58,10 @@ public abstract class OverviewDimensions protected int alheight; + protected float widthRatio; + + protected float heightRatio; + /** * Create an OverviewDimensions object * diff --git a/src/jalview/viewmodel/OverviewDimensionsHideHidden.java b/src/jalview/viewmodel/OverviewDimensionsHideHidden.java index c158ce7..1cc42bb 100644 --- a/src/jalview/viewmodel/OverviewDimensionsHideHidden.java +++ b/src/jalview/viewmodel/OverviewDimensionsHideHidden.java @@ -64,8 +64,8 @@ public class OverviewDimensionsHideHidden extends OverviewDimensions // calculate translation in pixel terms: // get mouse location in viewport coords, add translation in viewport // coords, and update viewport as usual - int vpx = Math.round((float) mousex * alwidth / width); - int vpy = Math.round((float) mousey * alheight / sequencesHeight); + int vpx = Math.round(mousex * widthRatio); + int vpy = Math.round(mousey * heightRatio); updateViewportFromTopLeft(vpx + xdiff, vpy + ydiff, hiddenSeqs, hiddenCols); @@ -162,19 +162,22 @@ public class OverviewDimensionsHideHidden extends OverviewDimensions { alwidth = ranges.getVisibleAlignmentWidth(); alheight = ranges.getVisibleAlignmentHeight(); + + 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 vpx - ranges.getViewportWidth() / 2; } @Override protected int getTopYFromCentreY(int mousey, HiddenSequences hidden) { - int vpy = Math.round((float) mousey * alheight / sequencesHeight); + int vpy = Math.round(mousey * heightRatio); return vpy - ranges.getViewportHeight() / 2; } @@ -184,8 +187,8 @@ public class OverviewDimensionsHideHidden 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() - vpx; ydiff = ranges.getStartSeq() - vpy; diff --git a/src/jalview/viewmodel/OverviewDimensionsShowHidden.java b/src/jalview/viewmodel/OverviewDimensionsShowHidden.java index 9dde16e..ec2efa2 100644 --- a/src/jalview/viewmodel/OverviewDimensionsShowHidden.java +++ b/src/jalview/viewmodel/OverviewDimensionsShowHidden.java @@ -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() -- 1.7.10.2