Helper method to calculate the span of the sub-interval. Simply returns
the cieling of ((limit - start) / segments) and accounts for invalid
start and limit combinations.
548278
static long calcInterval(int segments, int start, int limit) {

        long range = limit - start;

        if (range < 0) {
            return 0;
        }

        int partSegment = (range % segments) == 0 ? 0
                                                  : 1;

        return (range / segments) + partSegment;
    }
942247
def intersection(self, other: "Interval") -> Optional["Interval"]:
        
        if not self.contiguous(other):
            return None
        return Interval(
            max(self.start, other.start),
            min(self.end, other.end)
        )
1128455
def get_overlaps(self) -> "IntervalList":
        
        overlaps = IntervalList()
        for i in range(len(self.intervals)):
            for j in range(i + 1, len(self.intervals)):
                first = self.intervals[i]
                second = self.intervals[j]
                ol = first.intersection(second)
                if ol is not None:
                    overlaps.add(ol)
        return overlaps
1190957
def span(self):
        
        other = VersionRange(None)
        bound = _Bound(self.bounds[0].lower, self.bounds[-1].upper)
        other.bounds = [bound]
        return other
1040028
def coverage(self):
        
        if self._targetLength == 0:
            return 0.0

        coverage = 0
        for (intervalType, (start, end)) in self.walk():
            if intervalType == self.FULL:
                # Adjust start and end to ignore areas where the read falls
                # outside the target.
                coverage += (min(end, self._targetLength) - max(0, start))
        return float(coverage) / self._targetLength
1254680
def is_eligible(self, segment):
        
        if not segment or not segment.sampled:
            return False

        return segment.get_total_subsegments_size() > self.streaming_threshold
29843
function(t, opt) {

            var segments = this.segments;
            var numSegments = segments.length;
            if (numSegments === 0) return 0; // if segments is an empty array

            var segmentIndex = t.segmentIndex;
            if (segmentIndex < 0) return 0; // regardless of t.value

            var tValue = t.value;
            if (segmentIndex >= numSegments) {
                segmentIndex = numSegments - 1;
                tValue = 1;
            }
            else if (tValue < 0) tValue = 0;
            else if (tValue > 1) tValue = 1;

            opt = opt || {};
            var precision = (opt.precision === undefined) ? this.PRECISION : opt.precision;
            var segmentSubdivisions = (opt.segmentSubdivisions === undefined) ? this.getSegmentSubdivisions({ precision: precision }) : opt.segmentSubdivisions;
            // not using localOpt

            var subdivisions;
            var length = 0;
            for (var i = 0; i < segmentIndex; i++) {

                var segment = segments[i];
                subdivisions = segmentSubdivisions[i];
                length += segment.length({ precisison: precision, subdivisions: subdivisions });
            }

            segment = segments[segmentIndex];
            subdivisions = segmentSubdivisions[segmentIndex];
            length += segment.lengthAtT(tValue, { precisison: precision, subdivisions: subdivisions });

            return length;
        }
51220
def distance_to_interval(self, start, end):
        
        if self.start > end:
            # interval is before this exon
            return self.start - end
        elif self.end < start:
            # exon is before the interval
            return start - self.end
        else:
            return 0
1316204
def finite_datetimes(self, finite_start, finite_stop):
        
        # Validate that the minutes_interval can divide 60 and it is greater than 0 and lesser than 60
        if not (0 < self.minutes_interval < 60):
            raise ParameterException('minutes-interval must be within 0..60')
        if (60 / self.minutes_interval) * self.minutes_interval != 60:
            raise ParameterException('minutes-interval does not evenly divide 60')
        # start of a complete interval, e.g. 20:13 and the interval is 5 -> 20:10
        start_minute = int(finite_start.minute/self.minutes_interval)*self.minutes_interval
        datehour_start = datetime(
            year=finite_start.year,
            month=finite_start.month,
            day=finite_start.day,
            hour=finite_start.hour,
            minute=start_minute)
        datehours = []
        for i in itertools.count():
            t = datehour_start + timedelta(minutes=i*self.minutes_interval)
            if t >= finite_stop:
                return datehours
            if t >= finite_start:
                datehours.append(t)
1264353
def calculate_intervals(chunk_sizes):
        
        start_indexes = [sum(chunk_sizes[:i]) for i in range(0, len(chunk_sizes))]
        end_indexes = [sum(chunk_sizes[:i+1]) for i in range(0, len(chunk_sizes))]
        return tuple(zip(start_indexes, end_indexes))
1038257
def get_elapsed(self, restart=True):
        '''
        
        '''
        end = time.time()
        span = end - self.__start
        if restart:
            self.__start = end
        return span
586681
public static Collection<TimeSlot> calculateTimeSots( Day day, int intervalSeconds, Time startTime, Time endTime)
   {
      if(intervalSeconds <1)
      {
         throw new IllegalArgumentException("interval seconds cannot be less than one");
      }
      
      int count = 1*60*60*24/intervalSeconds;
      
      ArrayList<TimeSlot> slots = new ArrayList<TimeSlot>(count);   
      
      TimeSlot startSlot = TimeSlot.firstSlot(day,startTime, intervalSeconds);
      TimeSlot slot = startSlot;
      
      while(slot != null)
      {
         slots.add(slot);
         slot = slot.nextTimeSlot(intervalSeconds,endTime);
      }          
      
      return slots;
   }
1202303
def range(start, stop):
    

    length = stop - start

    out = list(length=length)

    index = 0

    orig_start = start

    while start < stop:
        val = index + orig_start
        out[index] = val
        index = index + 1
        start = orig_start + index

    return out
749079
function(length, opt) {

            var segments = this.segments;
            var numSegments = segments.length;
            if (numSegments === 0) return null; // if segments is an empty array

            var fromStart = true;
            if (length < 0) {
                fromStart = false; // negative lengths mean start calculation from end point
                length = -length; // absolute value
            }

            opt = opt || {};
            var precision = (opt.precision === undefined) ? this.PRECISION : opt.precision;
            var segmentSubdivisions = (opt.segmentSubdivisions === undefined) ? this.getSegmentSubdivisions({ precision: precision }) : opt.segmentSubdivisions;
            // not using localOpt

            var lastVisibleSegmentIndex = null;
            var l = 0; // length so far
            for (var i = (fromStart ? 0 : (numSegments - 1)); (fromStart ? (i < numSegments) : (i >= 0)); (fromStart ? (i++) : (i--))) {

                var segment = segments[i];
                var subdivisions = segmentSubdivisions[i];
                var d = segment.length({ precision: precision, subdivisions: subdivisions });

                if (segment.isVisible) {
                    if (length <= (l + d)) return i;
                    lastVisibleSegmentIndex = i;
                }

                l += d;
            }

            // if length requested is higher than the length of the path, return last visible segment index
            // if no visible segment, return null
            return lastVisibleSegmentIndex;
        }
25715
def _find_intervals(bundles, duration, step):
    """"""
    segments = []
    for bund in bundles:
        beg, end = bund['times'][0][0], bund['times'][-1][1]

        if end - beg >= duration:
            new_begs = arange(beg, end - duration, step)

            for t in new_begs:
                seg = bund.copy()
                seg['times'] = [(t, t + duration)]
                segments.append(seg)

    return segments
985339
def pt_within(self, pt, subject):
        """"""
        try:
            if pt >= int(subject[0]) and pt <= int(subject[1]):
                return True
        except ValueError:
            raise ValueError('Interval start and stop has to be integers. %s' % str(subject))

        return False
956715
function(length, opt) {

        var numSegments = this.segments.length;
        if (numSegments === 0) return null; // if segments is an empty array

        var fromStart = true;
        if (length < 0) {
            fromStart = false; // negative lengths mean start calculation from end point
            length = -length; // absolute value
        }

        opt = opt || {};
        var precision = (opt.precision === undefined) ? this.PRECISION : opt.precision;
        var segmentSubdivisions = (opt.segmentSubdivisions === undefined) ? this.getSegmentSubdivisions({ precision: precision }) : opt.segmentSubdivisions;
        // not using localOpt

        var i;
        var segment;

        // identify the segment to divide:

        var l = 0; // length so far
        var divided;
        var dividedSegmentIndex;
        var lastValidSegment; // visible AND differentiable
        var lastValidSegmentIndex;
        var t;
        for (i = 0; i < numSegments; i++) {
            var index = (fromStart ? i : (numSegments - 1 - i));

            segment = this.getSegment(index);
            var subdivisions = segmentSubdivisions[index];
            var d = segment.length({ precision: precision, subdivisions: subdivisions });

            if (segment.isDifferentiable()) { // segment is not just a point
                lastValidSegment = segment;
                lastValidSegmentIndex = index;

                if (length <= (l + d)) {
                    dividedSegmentIndex = index;
                    divided = segment.divideAtLength(((fromStart ? 1 : -1) * (length - l)), {
                        precision: precision,
                        subdivisions: subdivisions
                    });
                    break;
                }
            }

            l += d;
        }

        if (!lastValidSegment) { // no valid segment found
            return null;
        }

        // else: the path contains at least one valid segment

        if (!divided) { // the desired length is greater than the length of the path
            dividedSegmentIndex = lastValidSegmentIndex;
            t = (fromStart ? 1 : 0);
            divided = lastValidSegment.divideAtT(t);
        }

        // create a copy of this path and replace the identified segment with its two divided parts:

        var pathCopy = this.clone();
        pathCopy.replaceSegment(dividedSegmentIndex, divided);

        var divisionStartIndex = dividedSegmentIndex;
        var divisionMidIndex = dividedSegmentIndex + 1;
        var divisionEndIndex = dividedSegmentIndex + 2;

        // do not insert the part if it looks like a point
        if (!divided[0].isDifferentiable()) {
            pathCopy.removeSegment(divisionStartIndex);
            divisionMidIndex -= 1;
            divisionEndIndex -= 1;
        }

        // insert a Moveto segment to ensure secondPath will be valid:
        var movetoEnd = pathCopy.getSegment(divisionMidIndex).start;
        pathCopy.insertSegment(divisionMidIndex, g.Path.createSegment('M', movetoEnd));
        divisionEndIndex += 1;

        // do not insert the part if it looks like a point
        if (!divided[1].isDifferentiable()) {
            pathCopy.removeSegment(divisionEndIndex - 1);
            divisionEndIndex -= 1;
        }

        // ensure that Closepath segments in secondPath will be assigned correct subpathStartSegment:

        var secondPathSegmentIndexConversion = divisionEndIndex - divisionStartIndex - 1;
        for (i = divisionEndIndex; i < pathCopy.segments.length; i++) {

            var originalSegment = this.getSegment(i - secondPathSegmentIndexConversion);
            segment = pathCopy.getSegment(i);

            if ((segment.type === 'Z') && !originalSegment.subpathStartSegment.end.equals(segment.subpathStartSegment.end)) {
                // pathCopy segment's subpathStartSegment is different from original segment's one
                // convert this Closepath segment to a Lineto and replace it in pathCopy
                var convertedSegment = g.Path.createSegment('L', originalSegment.end);
                pathCopy.replaceSegment(i, convertedSegment);
            }
        }

        // distribute pathCopy segments into two paths and return those:

        var firstPath = new Path(pathCopy.segments.slice(0, divisionMidIndex));
        var secondPath = new Path(pathCopy.segments.slice(divisionMidIndex));

        return [firstPath, secondPath];
    }