JAL-2349 (still buggy) interactive selection - time to write tests!
authorJim Procter <j.procter@dundee.ac.uk>
Thu, 20 Oct 2022 10:23:36 +0000 (11:23 +0100)
committerJim Procter <j.procter@dundee.ac.uk>
Thu, 20 Oct 2022 10:23:36 +0000 (11:23 +0100)
src/jalview/gui/AnnotationPanel.java

index 7f606c8..4f5b7d0 100755 (executable)
@@ -852,7 +852,11 @@ public class AnnotationPanel extends JPanel implements AwtRenderPanelI,
      */
     int fromY = Math.min(firstDragY, evt.getY());
     int toY = Math.max(firstDragY, evt.getY());
+    int fromX = Math.min(firstDragX, evt.getX());
+    int toX = Math.max(firstDragX, evt.getX());
+
     int deltaY = toY - fromY;
+    int deltaX = toX - fromX;
 
     int[] rowIndex = getRowIndexAndOffset(fromY,
             av.getAlignment().getAlignmentAnnotation());
@@ -873,20 +877,20 @@ public class AnnotationPanel extends JPanel implements AwtRenderPanelI,
     AlignmentAnnotation cma = av.getAlignment()
             .getAlignmentAnnotation()[rowIndex[0]];
 
-    int fromXp = Math.min(firstDragX, evt.getX());
-    int toXp = Math.max(firstDragX, evt.getX());
-    int lastX = getColumnForXPos(fromXp);
-    int currentX = getColumnForXPos(toXp);
-    ContactListI forLastX = av.getContactList(cma, lastX);
-    ContactListI forCurrentX = av.getContactList(cma, currentX);
-    if (forLastX != null && forCurrentX != null)
+    int lastX = getColumnForXPos(fromX);
+    int currentX = getColumnForXPos(toX);
+    int fromXc = Math.min(lastX, currentX);
+    int toXc = Math.max(lastX, currentX);
+    ContactListI forFromX = av.getContactList(cma, fromXc);
+    ContactListI forToX = av.getContactList(cma, toXc);
+
+    if (forFromX != null && forToX != null)
     {
-      ContactGeometry lastXcgeom = new ContactGeometry(forLastX,
+      ContactGeometry lastXcgeom = new ContactGeometry(forFromX,
               cma.graphHeight);
-      ContactGeometry.contactInterval lastXci = lastXcgeom.mapFor(
-              rowIndex[1],
-              rowIndex[1] + ((fromY == firstDragY) ? -deltaY : deltaY));
-      ContactGeometry cXcgeom = new ContactGeometry(forCurrentX,
+      ContactGeometry.contactInterval lastXci = lastXcgeom
+              .mapFor(rowIndex[1], rowIndex[1] + deltaY);
+      ContactGeometry cXcgeom = new ContactGeometry(forToX,
               cma.graphHeight);
       ContactGeometry.contactInterval cXci = cXcgeom.mapFor(rowIndex[1],
               rowIndex[1] + deltaY);