JAL-3858 fix off-by-one in matrix visualisation and interactive tooltip
[jalview.git] / src / jalview / datamodel / ContactListImpl.java
index 6eb4cdb..bb31c5d 100644 (file)
@@ -1,5 +1,9 @@
 package jalview.datamodel;
 
+import java.awt.Color;
+
+import jalview.renderer.ContactGeometry.contactInterval;
+
 /**
  * helper class to compute min/max/mean for a range on a contact list
  * 
@@ -10,7 +14,6 @@ public class ContactListImpl implements ContactListI
 {
   ContactListProviderI clist;
 
-
   public static ContactListI newContactList(ContactListProviderI list)
   {
     return new ContactListImpl(list);
@@ -22,6 +25,12 @@ public class ContactListImpl implements ContactListI
   }
 
   @Override
+  public int getPosition()
+  {
+    return clist.getPosition();
+  }
+
+  @Override
   public double getContactAt(int column)
   {
     return clist.getContactAt(column);
@@ -36,6 +45,7 @@ public class ContactListImpl implements ContactListI
   @Override
   public ContactRange getRangeFor(int from_column, int to_column)
   {
+    // TODO: consider caching ContactRange for a particular call ?
     if (clist instanceof ContactListI)
     {
       // clist may implement getRangeFor in a more efficient way, so use theirs
@@ -45,15 +55,15 @@ public class ContactListImpl implements ContactListI
     {
       from_column = 0;
     }
-    if (to_column > getContactHeight())
+    if (to_column >= getContactHeight())
     {
-      to_column = getContactHeight();
+      to_column = getContactHeight()-1;
     }
     ContactRange cr = new ContactRange();
     cr.setFrom_column(from_column);
     cr.setTo_column(to_column);
     double tot = 0;
-    for (int i = from_column; i < to_column; i++)
+    for (int i = from_column; i <= to_column; i++)
     {
       double contact = getContactAt(i);
       tot += contact;
@@ -80,7 +90,7 @@ public class ContactListImpl implements ContactListI
     }
     if (tot > 0)
     {
-      cr.setMean(tot / (to_column - from_column));
+      cr.setMean(tot / (1 + to_column - from_column));
     }
     else
     {
@@ -89,4 +99,15 @@ public class ContactListImpl implements ContactListI
     return cr;
   }
 
+  @Override
+  public int[] getMappedPositionsFor(int cStart, int cEnd)
+  {
+    return clist.getMappedPositionsFor(cStart, cEnd);
+  }
+
+  @Override
+  public Color getColourForGroup()
+  {
+    return clist.getColourForGroup();
+  }
 }