X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2Fjalview%2Frenderer%2FContactGeometry.java;fp=src%2Fjalview%2Frenderer%2FContactGeometry.java;h=9fd4de6cd02c2502ca94cfb106c4ab2c2d5059d4;hb=92031091141338165383a81aa2f6ba2207603337;hp=4aef1d81ae9bdd95fa86234cedf12025ad323020;hpb=b9293410486a5a6f9bc505e66b04b912a559cdd5;p=jalview.git diff --git a/src/jalview/renderer/ContactGeometry.java b/src/jalview/renderer/ContactGeometry.java index 4aef1d8..9fd4de6 100644 --- a/src/jalview/renderer/ContactGeometry.java +++ b/src/jalview/renderer/ContactGeometry.java @@ -2,10 +2,23 @@ package jalview.renderer; import java.util.Iterator; +import jalview.datamodel.ColumnSelection; import jalview.datamodel.ContactListI; - +import jalview.datamodel.HiddenColumns; +import jalview.renderer.ContactGeometry.contactInterval; + +/** + * encapsulate logic for mapping between positions in a ContactList and their + * rendered representation in a given number of pixels. + * + * @author jprocter + * + */ public class ContactGeometry { + + final ContactListI contacts; + final int pixels_step; final double contacts_per_pixel; @@ -14,8 +27,9 @@ public class ContactGeometry final int graphHeight; - public ContactGeometry(ContactListI contacts, int graphHeight) + public ContactGeometry(final ContactListI contacts, int graphHeight) { + this.contacts = contacts; this.graphHeight = graphHeight; contact_height = contacts.getContactHeight(); // fractional number of contacts covering each pixel @@ -54,6 +68,56 @@ public class ContactGeometry public final int pStart; public final int pEnd; + + } + + /** + * + * @param columnSelection + * @param ci + * @param visibleOnly + * - when true, only test intersection of visible columns given + * matrix range + * @return true if the range on the matrix specified by ci intersects with + * selected columns in the ContactListI's reference frame. + */ + + boolean intersects(contactInterval ci, ColumnSelection columnSelection, + HiddenColumns hiddenColumns, boolean visibleOnly) + { + boolean rowsel = false; + final int[] mappedRange = contacts.getMappedPositionsFor(ci.cStart, + ci.cEnd); + if (mappedRange == null) + { + return false; + } + for (int p = 0; p < mappedRange.length && !rowsel; p += 2) + { + boolean containsHidden = false; + if (visibleOnly && hiddenColumns != null + && hiddenColumns.hasHiddenColumns()) + { + // TODO: turn into function on hiddenColumns and create test !! + Iterator viscont = hiddenColumns.getVisContigsIterator( + mappedRange[p], mappedRange[p + 1], false); + containsHidden = !viscont.hasNext(); + if (!containsHidden) + { + for (int[] interval = viscont.next(); viscont + .hasNext(); rowsel |= columnSelection + .intersects(interval[p], interval[p + 1])) + ; + } + } + else + { + rowsel = columnSelection.intersects(mappedRange[p], + mappedRange[p + 1]); + } + } + return rowsel; + } /**