JAL-2349 JAL-3855 highlight residues associated with elements under mouse - Jmol...
[jalview.git] / src / jalview / renderer / ContactGeometry.java
index 52581fb..4aef1d8 100644 (file)
@@ -12,8 +12,11 @@ public class ContactGeometry
 
   final int contact_height;
 
+  final int graphHeight;
+
   public ContactGeometry(ContactListI contacts, int graphHeight)
   {
+    this.graphHeight = graphHeight;
     contact_height = contacts.getContactHeight();
     // fractional number of contacts covering each pixel
     contacts_per_pixel = (graphHeight < 1) ? contact_height
@@ -71,6 +74,25 @@ public class ContactGeometry
     return ci;
   }
 
+  /**
+   * return the cell containing given pixel
+   * 
+   * @param pCentre
+   * @return range for pCEntre
+   */
+  public contactInterval mapFor(int pCentre)
+  {
+    int pStart = Math.max(pCentre - pixels_step, 0);
+    int pEnd = Math.min(pStart + pixels_step, graphHeight);
+    int cStart = (int) Math.floor(pStart * contacts_per_pixel);
+    contactInterval ci = new contactInterval(cStart,
+            (int) Math.min(contact_height,
+                    Math.ceil(cStart + (pixels_step) * contacts_per_pixel)),
+            pStart, pEnd);
+
+    return ci;
+  }
+
   public Iterator<contactInterval> iterateOverContactIntervals(
           int graphHeight)
   {