JAL-2349 JAL-4033 refactored contact matrix geom calc to allow reporting of mapped...
[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 = ((double) contact_height) / ((double) graphHeight);
20
21     if (contacts_per_pixel >= 1)
22     {
23       // many contacts rendered per pixel
24       pixels_step = 1;
25     }
26     else
27     {
28       // pixel height for each contact
29       pixels_step = (int) Math
30               .ceil(((double) graphHeight) / (double) contact_height);
31     }
32   }
33
34   public class contactInterval
35   {
36     public contactInterval(int cStart, int cEnd, int pStart, int pEnd)
37     {
38       this.cStart = cStart;
39       this.cEnd = cEnd;
40       this.pStart = pStart;
41       this.pEnd = pEnd;
42     }
43
44     // range on contact list
45     public final int cStart;
46
47     public final int cEnd;
48
49     // range in pixels
50     public final int pStart;
51
52     public final int pEnd;
53   }
54
55   /**
56    * 
57    * @param pStart
58    * @param pEnd
59    * @return range for
60    */
61   public contactInterval mapFor(int pStart, int pEnd)
62   {
63     int cStart = (int) Math.floor(pStart * contacts_per_pixel);
64     contactInterval ci = new contactInterval(cStart,
65             (int) Math.min(contact_height,
66                     Math.ceil(
67                             cStart + (pEnd - pStart) * contacts_per_pixel)),
68             pStart, pEnd);
69
70     return ci;
71   }
72
73   public Iterator<contactInterval> iterateOverContactIntervals(
74           int graphHeight)
75   {
76     // NOT YET IMPLEMENTED
77     return null;
78     // int cstart = 0, cend;
79     //
80     // for (int ht = y2,
81     // eht = y2 - graphHeight; ht >= eht; ht -= pixels_step)
82     // {
83     // cstart = (int) Math.floor(((double) y2 - ht) * contacts_per_pixel);
84     // cend = (int) Math.min(contact_height,
85     // Math.ceil(cstart + contacts_per_pixel * pixels_step));
86     //
87     // return new Iterator<contactIntervals>() {
88     //
89     // @Override
90     // public boolean hasNext()
91     // {
92     // // TODO Auto-generated method stub
93     // return false;
94     // }
95     //
96     // @Override
97     // public contactIntervals next()
98     // {
99     // // TODO Auto-generated method stub
100     // return null;
101     // }
102     //
103     // }
104   }
105 }