- int cStart = (int) Math.floor(pStart * contacts_per_pixel);
- contactInterval ci = new contactInterval(cStart,
- (int) Math.min(contact_height,
- Math.ceil(
- cStart + (pEnd - pStart) * contacts_per_pixel)),
- pStart, pEnd);
-
- return ci;
+ if (pStart < 0)
+ {
+ pStart = 0;
+ }
+ if (pEnd < pStart)
+ {
+ pEnd = pStart;
+ }
+ if (pEnd >= graphHeight)
+ {
+ pEnd = graphHeight - 1;
+ }
+ if (pStart >= graphHeight)
+ {
+ pStart = graphHeight - pixels_step;
+ }
+ int step = Math.floorDiv(pStart, pixels_step);
+ return findStep(step);
+ }
+
+ /**
+ *
+ * @param step
+ * [0..) n steps covering height and contactHeight
+ * @return contactInterval for step, or null if out of bounds
+ */
+ contactInterval findStep(int step)
+ {
+ if (step < 0 || step > lastStep)
+ {
+ return null;
+ }
+ return new contactInterval((int) Math.floor(contacts_step * step),
+ -1 + (int) Math.min(contact_height,
+ Math.floor(contacts_step * (step + 1))),
+ pixels_step * step,
+ Math.min(graphHeight, (step + 1) * pixels_step) - 1);