Dodge overlapping interval

        Assumes that each set has the same horizontal position.
431921
def strategy(data, params):
        
        width = params['width']
        with suppress(TypeError):
            iter(width)
            width = np.asarray(width)
            width = width[data.index]

        udata_group = data['group'].drop_duplicates()

        n = params.get('n', None)
        if n is None:
            n = len(udata_group)
        if n == 1:
            return data

        if not all([col in data.columns for col in ['xmin', 'xmax']]):
            data['xmin'] = data['x']
            data['xmax'] = data['x']

        d_width = np.max(data['xmax'] - data['xmin'])

        # Have a new group index from 1 to number of groups.
        # This might be needed if the group numbers in this set don't
        # include all of 1:n
        udata_group = udata_group.sort_values()
        groupidx = match(data['group'], udata_group)
        groupidx = np.asarray(groupidx) + 1

        # Find the center for each group, then use that to
        # calculate xmin and xmax
        data['x'] = data['x'] + width * ((groupidx - 0.5) / n - 0.5)
        data['xmin'] = data['x'] - (d_width / n) / 2
        data['xmax'] = data['x'] + (d_width / n) / 2

        return data
1118958
protected boolean overlap(Pair<Integer, Integer> expected,
            Pair<Integer, Integer> actual) {
        // // a1 then a2
        // if (a2.getBegin() - a1.getEnd() > 0)
        // return Position.before;
        //
        // // a2 then a1
        // if (a1.getBegin() - a2.getEnd() > 0)
        // return Position.after;
        //
        // // overlap
        // return Position.overlap;
        //

        if (actual.getKey() >= expected.getKey()
                && actual.getValue() <= expected.getValue()) {
            return true;
        }
        return false;

        // full overlap is too lenient
        // if (expected.getKey() < actual.getValue()
        // && actual.getKey() < expected.getValue()) {
        // return true;
        // }
        // return false;

    }
272121
function sameMove(a, b) {
    return Position.hasSameXY(a.from, b.from) && Position.hasSameXY(a.to, b.to);
}
1136903
private static IntervalTreeNodeData<String> createPositionHit(Match m,
      ComponentGroup group) {
    Integer start = null;
    Integer end = null;
    if (group.hitInside != null || group.hitInsideLeft != null
        || group.hitInsideRight != null) {
      start = m.startPosition;
      end = m.endPosition - 1;
    } else {
      start = null;
      end = null;
    }
    if (group.hitLeft != null) {
      start = m.startPosition;
      end = Math.max(m.startPosition + group.hitLeft.length - 1,
          m.endPosition - 1);
    }
    if (group.hitRight != null) {
      start = Math.min(m.endPosition - group.hitRight.length, m.startPosition);
      end = end == null ? (m.endPosition - 1)
          : Math.max(end, (m.endPosition - 1));
    }
    if (group.left != null) {
      start = start == null ? m.startPosition - group.left.length
          : Math.min(m.startPosition - group.left.length, start);
      end = end == null ? m.startPosition - 1
          : Math.max(m.startPosition - 1, end);
    }
    if (group.right != null) {
      start = start == null ? m.endPosition : Math.min(m.endPosition, start);
      end = end == null ? m.endPosition + group.right.length - 1
          : Math.max(m.endPosition + group.right.length - 1, end);
    }
    return new IntervalTreeNodeData<>(start, end, m.startPosition,
        m.endPosition - 1);
  }
777843
def overlapping(start1, end1, start2, end2):
    
    return not ((start1 <= start2 and start1 <= end2 and end1 <= end2 and end1 <= start2) or
                (start1 >= start2 and start1 >= end2 and end1 >= end2 and end1 >= start2))
563959
def overlap(self, other: 'Span'):
        """"""
        return not (
            # if one rectangle is left of other
            other.column_end <= self.column_start
            or self.column_end <= other.column_start
            # if one rectangle is above other
            or other.row_end <= self.row_start
            or self.row_end <= other.row_start
        )
1333520
function _same_set(set1, set2){
	var h1 = {};
	var h2 = {};
	for( var h1i = 0; h1i < set1.length; h1i++ ){ h1[set1[h1i]] = 1; }
	for( var h2i = 0; h2i < set2.length; h2i++ ){ h2[set2[h2i]] = 1; }
	return _same_hash(h1, h2);
    }
1374559
def get_1D_overlap(eclusters, depth=1):
    
    overlap_set = set()
    active = set()

    ends = []
    for i, (chr, left, right) in enumerate(eclusters):
        ends.append((chr, left, 0, i))  # 0/1 for left/right-ness
        ends.append((chr, right, 1, i))
    ends.sort()

    chr_last = ""
    for chr, pos, left_right, i in ends:
        if chr != chr_last:
            active.clear()
        if left_right == 0:
            active.add(i)
        else:
            active.remove(i)

        if len(active) > depth:
            overlap_set.add(tuple(sorted(active)))

        chr_last = chr

    return overlap_set
917511
public boolean overlaps(Location location) {
         if (location.getBeginPosition()>=getBeginPosition() && location.getBeginPosition() <= getEndPosition()) 
             return true;
         if(location.getBeginPosition() <= getBeginPosition() && location.getEndPosition()>=getBeginPosition()) 
             return true;
        else {
            return false;
        }
    }
98099
def _any_overlap_or_contiguous(self, test_overlap: bool) -> bool:
        
        for i in range(len(self.intervals)):
            for j in range(i + 1, len(self.intervals)):
                first = self.intervals[i]
                second = self.intervals[j]
                if test_overlap:
                    test = first.overlaps(second)
                else:
                    test = first.contiguous(second)
                if test:
                    return True
        return False
1181619
def _gap(src_interval, tar_interval):
        
        assert src_interval.bits == tar_interval.bits, "Number of bits should be same for operands"
        # use the same variable names as in paper
        s = src_interval
        t = tar_interval
        (_, b) = (s.lower_bound, s.upper_bound)
        (c, _) = (t.lower_bound, t.upper_bound)

        w = s.bits
        # case 1
        if (not t._surrounds_member(b)) and (not s._surrounds_member(c)):
            #FIXME: maybe we can do better here and to not fix the stride to 1
            #FIXME: found the first common integer for more precision
            return StridedInterval(lower_bound=c, upper_bound=b, bits=w, stride=1).complement
        # otherwise
        return StridedInterval.empty(w)
834895
def _overlapping(files):
    
    segments = set()
    for path in files:
        seg = file_segment(path)
        for s in segments:
            if seg.intersects(s):
                return True
        segments.add(seg)
    return False
652290
function(){

            var isX
                ,hash
                ,tr1
                ,tr2
                ,bound
                ,list
                ,len
                ,i
                ,j
                ,c
                // determine which axis is the last we need to check
                ,collisionFlag = 1 << (dof.z + 1) << (dof.y + 1) << (dof.x + 1)
                ,encounters = this.encounters
                ,enclen = 0
                ,candidates = this.candidates
                ;

            Physics.util.clearArray( encounters );
            Physics.util.clearArray( candidates );

            for ( var xyz = 0; xyz < maxDof; ++xyz ){

                // is the x coord
                isX = (xyz === 0);
                // get the interval list for this axis
                list = this.intervalLists[ xyz ];

                // for each interval bound
                for ( i = 0, len = list.length; i < len; i++ ){

                    bound = list[ i ];
                    tr1 = bound.tracker;

                    if ( bound.type ){

                        // is a max

                        j = enclen;

                        for ( j = enclen - 1; j >= 0; j-- ){

                            tr2 = encounters[ j ];

                            // if they are the same tracked interval
                            if ( tr2 === tr1 ){

                                // remove the interval from the encounters list
                                // faster than .splice()
                                if ( j < enclen - 1 ) {

                                    encounters[ j ] = encounters.pop();

                                } else {

                                    // encountered a max right after a min... no overlap
                                    encounters.pop();
                                }

                                enclen--;

                            } else {

                                // check if we have flagged this pair before
                                // if it's the x axis, create a pair
                                c = this.getPair( tr1, tr2, isX );

                                if ( c && c.flag < collisionFlag ){

                                    // if it's greater than the axis index, set the flag
                                    // to = 0.
                                    // if not, increment the flag by one.
                                    c.flag = c.flag << (xyz + 1);

                                    // c.flag will equal collisionFlag
                                    // if we've incremented the flag
                                    // enough that all axes are overlapping
                                    if ( c.flag === collisionFlag ){

                                        // overlaps on all axes.
                                        // add it to possible collision
                                        // candidates list for narrow phase

                                        candidates.push( c );
                                    }
                                }
                            }
                        }

                    } else {

                        // is a min
                        // just add this minimum to the encounters list
                        enclen = encounters.push( tr1 );
                    }
                }
            }

            return candidates;
        }
1116573
def difference(self,other):
        
        res = IntervalSet.everything()
        for j in other.ints:
            tmp = []
            for i in self.ints:
                tmp.extend(i._difference(j))
            res = res.intersection(IntervalSet(tmp))
        return res
784001
def axis_overlap(ax1, ax2):
    
    b1, t1 = ax1.get_position().intervaly
    b2, t2 = ax2.get_position().intervaly
    return t1 > b2 and b1 < t2
880810
def can_overlap(self, contig, strand=None):
        
        return (self.on_contig(contig) and
                (strand is None or self.on_strand(strand)))
221741
def intersection(self,other):
        
        res = []
        for i1 in self.ints:
            for i2 in other.ints:
                res.append(i1.intersection(i2))

        return IntervalSet(res)