1 package jalview.renderer;
3 import java.util.Iterator;
5 import jalview.datamodel.ContactListI;
7 public class ContactGeometry
11 final double contacts_per_pixel;
13 final int contact_height;
15 final int graphHeight;
17 public ContactGeometry(ContactListI contacts, int graphHeight)
19 this.graphHeight = graphHeight;
20 contact_height = contacts.getContactHeight();
21 // fractional number of contacts covering each pixel
22 contacts_per_pixel = (graphHeight < 1) ? contact_height
23 : ((double) contact_height) / ((double) graphHeight);
25 if (contacts_per_pixel >= 1)
27 // many contacts rendered per pixel
32 // pixel height for each contact
33 pixels_step = (int) Math
34 .ceil(((double) graphHeight) / (double) contact_height);
38 public class contactInterval
40 public contactInterval(int cStart, int cEnd, int pStart, int pEnd)
48 // range on contact list
49 public final int cStart;
51 public final int cEnd;
54 public final int pStart;
56 public final int pEnd;
65 public contactInterval mapFor(int pStart, int pEnd)
67 int cStart = (int) Math.floor(pStart * contacts_per_pixel);
68 contactInterval ci = new contactInterval(cStart,
69 (int) Math.min(contact_height,
71 cStart + (pEnd - pStart) * contacts_per_pixel)),
78 * return the cell containing given pixel
81 * @return range for pCEntre
83 public contactInterval mapFor(int pCentre)
85 int pStart = Math.max(pCentre - pixels_step, 0);
86 int pEnd = Math.min(pStart + pixels_step, graphHeight);
87 int cStart = (int) Math.floor(pStart * contacts_per_pixel);
88 contactInterval ci = new contactInterval(cStart,
89 (int) Math.min(contact_height,
90 Math.ceil(cStart + (pixels_step) * contacts_per_pixel)),
96 public Iterator<contactInterval> iterateOverContactIntervals(
99 // NOT YET IMPLEMENTED
101 // int cstart = 0, cend;
104 // eht = y2 - graphHeight; ht >= eht; ht -= pixels_step)
106 // cstart = (int) Math.floor(((double) y2 - ht) * contacts_per_pixel);
107 // cend = (int) Math.min(contact_height,
108 // Math.ceil(cstart + contacts_per_pixel * pixels_step));
110 // return new Iterator<contactIntervals>() {
113 // public boolean hasNext()
115 // // TODO Auto-generated method stub
120 // public contactIntervals next()
122 // // TODO Auto-generated method stub