52581fb10eeb9e62396185faeff6909b49e793fd
[jalview.git] / src / jalview / renderer / ContactGeometry.java
1 package jalview.renderer;
2
3 import java.util.Iterator;
4
5 import jalview.datamodel.ContactListI;
6
7 public class ContactGeometry
8 {
9   final int pixels_step;
10
11   final double contacts_per_pixel;
12
13   final int contact_height;
14
15   public ContactGeometry(ContactListI contacts, int graphHeight)
16   {
17     contact_height = contacts.getContactHeight();
18     // fractional number of contacts covering each pixel
19     contacts_per_pixel = (graphHeight < 1) ? contact_height
20             : ((double) contact_height) / ((double) graphHeight);
21
22     if (contacts_per_pixel >= 1)
23     {
24       // many contacts rendered per pixel
25       pixels_step = 1;
26     }
27     else
28     {
29       // pixel height for each contact
30       pixels_step = (int) Math
31               .ceil(((double) graphHeight) / (double) contact_height);
32     }
33   }
34
35   public class contactInterval
36   {
37     public contactInterval(int cStart, int cEnd, int pStart, int pEnd)
38     {
39       this.cStart = cStart;
40       this.cEnd = cEnd;
41       this.pStart = pStart;
42       this.pEnd = pEnd;
43     }
44
45     // range on contact list
46     public final int cStart;
47
48     public final int cEnd;
49
50     // range in pixels
51     public final int pStart;
52
53     public final int pEnd;
54   }
55
56   /**
57    * 
58    * @param pStart
59    * @param pEnd
60    * @return range for
61    */
62   public contactInterval mapFor(int pStart, int pEnd)
63   {
64     int cStart = (int) Math.floor(pStart * contacts_per_pixel);
65     contactInterval ci = new contactInterval(cStart,
66             (int) Math.min(contact_height,
67                     Math.ceil(
68                             cStart + (pEnd - pStart) * contacts_per_pixel)),
69             pStart, pEnd);
70
71     return ci;
72   }
73
74   public Iterator<contactInterval> iterateOverContactIntervals(
75           int graphHeight)
76   {
77     // NOT YET IMPLEMENTED
78     return null;
79     // int cstart = 0, cend;
80     //
81     // for (int ht = y2,
82     // eht = y2 - graphHeight; ht >= eht; ht -= pixels_step)
83     // {
84     // cstart = (int) Math.floor(((double) y2 - ht) * contacts_per_pixel);
85     // cend = (int) Math.min(contact_height,
86     // Math.ceil(cstart + contacts_per_pixel * pixels_step));
87     //
88     // return new Iterator<contactIntervals>() {
89     //
90     // @Override
91     // public boolean hasNext()
92     // {
93     // // TODO Auto-generated method stub
94     // return false;
95     // }
96     //
97     // @Override
98     // public contactIntervals next()
99     // {
100     // // TODO Auto-generated method stub
101     // return null;
102     // }
103     //
104     // }
105   }
106 }