Create the array that describes how junctions overlap
195307
def calculate_overlap(self):
      """"""
      overs = []
      if not self.tx_obj1.range.overlaps(self.tx_obj2.range): return [] # if they dont overlap wont find anything
      for i in range(0,len(self.j1)):
        for j in range(0,len(self.j2)):
          if self.j1[i].overlaps(self.j2[j],tolerance=self.tolerance):
            overs.append([i,j])
      return overs
449886
private void intersectionMatrix(int[][] res, ArrayList<int[]> partsx, ArrayList<int[]> partsy, int gridsize) {
    for(int x = 0; x < gridsize; x++) {
      final int[] px = partsx.get(x);
      final int[] rowx = res[x];
      for(int y = 0; y < gridsize; y++) {
        int[] py = partsy.get(y);
        rowx[y] = intersectionSize(px, py);
      }
    }
  }
107756
function findLineIntersections(line, crossCheckLines) {
        return util.toArray(crossCheckLines).reduce(function(res, crossCheckLine) {
            var intersection = line.intersection(crossCheckLine);
            if (intersection) {
                res.push(intersection);
            }
            return res;
        }, []);
    }
709381
function () {
    var data = this.data;
    var i;
    var objectEls;

    // Push meshes onto list of objects to intersect.
    if (data.objects) {
      objectEls = this.el.sceneEl.querySelectorAll(data.objects);
      this.objects = [];
      for (i = 0; i < objectEls.length; i++) {
        this.objects.push(objectEls[i].object3D);
      }
      return;
    }

    // If objects not defined, intersect with everything.
    this.objects = this.el.sceneEl.object3D.children;
  }
393067
def get_intersectionsbysubsets(df,cols_fracby2vals,cols_subset,col_ids):
    
    for col_fracby in cols_fracby2vals:
        val=cols_fracby2vals[col_fracby]
        ids=df.loc[(df[col_fracby]==val),col_ids].dropna().unique()
        for col_subset in cols_subset:
            for subset in dropna(df[col_subset].unique()):
                ids_subset=df.loc[(df[col_subset]==subset),col_ids].dropna().unique()
                df.loc[(df[col_subset]==subset),f'P {col_fracby} {col_subset}']=len(set(ids_subset).intersection(ids))/len(ids_subset)
    return df
283498
def overlap(ival0, ival1):
    '''
    

    '''
    min0, max0 = ival0
    min1, max1 = ival1
    return max(0, min(max0, max1) - max(min0, min1)) > 0
1350790
def calculate_overlap(self1):
      """"""
      overs = []
      if not self1.tx_obj1.range.overlaps(self1.tx_obj2.range): return # if they dont overlap wont find anything
      for i in range(0,len(self1.tx_obj1.exons)):
        for j in range(0,len(self1.tx_obj2.exons)):
          osize = self1.tx_obj1.exons[i].range.overlap_size(self1.tx_obj2.exons[j].range)
          ofrac = 0
          if osize > 0:
            ofrac = min(float(osize)/float(self1.tx_obj1.exons[i].range.length)\
                       ,float(osize)/float(self1.tx_obj2.exons[j].range.length))

          if self1.tx_obj1.get_exon_count() == 1 or self1.tx_obj2.get_exon_count() == 1:
            # use single exon rules
            if osize >= self1.single_minover and ofrac >= self1.single_frac:
              #print 'single exon match'
              overs.append([i,j])
          else: # for multi exons
            if i == 0 or j == 0 or i == len(self1.tx_obj1.exons)-1 or j == len(self1.tx_obj2.exons)-1:
              #its on an end
              if osize >= self1.multi_minover and ofrac >= self1.multi_endfrac:
                #print 'end exon match'
                overs.append([i,j])
            #else its a middle
            elif osize >= self1.multi_minover and ofrac >= self1.multi_midfrac:
              #print 'mid exon match'
              overs.append([i,j])
      #print overs
      self1.overs = overs
387719
def junctions(self):
    """"""
    if len(self.exons) < 2: return []
    junctions = []
    for i in range(1,len(self.exons)):
      junctions.append(Junction(self.exons[i-1],self.exons[i]))
    return junctions
54473
function calculateDiff() {
    // we need to take 2 pointers
    // and travel progressively between them ...
    var newFirst = [
      [].concat(array1Extract[0]),
      [].concat(array1Extract[1])
    ];
    var newSecond = [
      [].concat(array2Extract[0]),
      [].concat(array2Extract[1])
    ];
    var array1Length = array1Extract[0] ? array1Extract[0].length : 0;
    var array2Length = array2Extract[0] ? array2Extract[0].length : 0;

    var pos1 = 0;
    var pos2 = 0;
    var previous2 = 0;
    while (pos1 < array1Length) {
      var diff = newFirst[0][pos1] - array2Extract[0][pos2];
      if (Math.abs(diff) < widthBottom) { // there is some overlap
        var overlap;
        if (options.trapezoid) {
          overlap = getOverlapTrapezoid(newFirst[0][pos1], newFirst[1][pos1], newSecond[0][pos2], newSecond[1][pos2], widthTop, widthBottom);
        } else {
          overlap = getOverlap(newFirst[0][pos1], newFirst[1][pos1], newSecond[0][pos2], newSecond[1][pos2], widthTop, widthBottom);
        }
        newFirst[1][pos1] -= overlap;
        newSecond[1][pos2] -= overlap;
        if (pos2 < (array2Length - 1)) {
          pos2++;
        } else {
          pos1++;
          pos2 = previous2;
        }
      } else {
        if (diff > 0 && pos2 < (array2Length - 1)) {
          pos2++;
          previous2 = pos2;
        } else {
          pos1++;
          pos2 = previous2;
        }
      }
    }
    return newSecond;
  }
1290929
function(positions, rows_left) {
        var lasts_in_row = [];
        var n_overlaps = 0;

        for (var i = 0; i < positions.length; i++) {
            var pos_info = positions[i];
            var overlaps = [];

            // See if we can add item to an existing row without
            // overlapping the previous item in that row
            delete pos_info.row;

            for (var j = 0; j < lasts_in_row.length; j++) {
                overlaps.push(lasts_in_row[j].end - pos_info.start);
                if(overlaps[j] <= 0) {
                    pos_info.row = j;
                    lasts_in_row[j] = pos_info;
                    break;
                }
            }

            // If we couldn't add to an existing row without overlap...
            if (typeof(pos_info.row) == 'undefined') {
                if (rows_left === null) {
                    // Make a new row
                    pos_info.row = lasts_in_row.length;
                    lasts_in_row.push(pos_info);
                } else if (rows_left > 0) {
                    // Make a new row
                    pos_info.row = lasts_in_row.length;
                    lasts_in_row.push(pos_info);
                    rows_left--;
                } else {
                    // Add to existing row with minimum overlap.
                    var min_overlap = Math.min.apply(null, overlaps);
                    var idx = overlaps.indexOf(min_overlap);
                    pos_info.row = idx;
                    if (pos_info.end > lasts_in_row[idx].end) {
                        lasts_in_row[idx] = pos_info;
                    }
                    n_overlaps++;
                }
            }
        }

        return {n_rows: lasts_in_row.length, n_overlaps: n_overlaps};
    }
779686
def intersection(self, *others):
        
        return self.copy(super(NGram, self).intersection(*others))
857713
def multi_polygons_data(element):
    
    paths = element.split(datatype='array', dimensions=element.kdims)
    xs, ys = ([path[:, idx] for path in paths] for idx in (0, 1))
    holes = element.holes()
    xsh, ysh = [], []
    for x, y, multi_hole in zip(xs, ys, holes):
        xhs = [[h[:, 0] for h in hole] for hole in multi_hole]
        yhs = [[h[:, 1] for h in hole] for hole in multi_hole]
        array = np.column_stack([x, y])
        splits = np.where(np.isnan(array[:, :2].astype('float')).sum(axis=1))[0]
        arrays = np.split(array, splits+1) if len(splits) else [array]
        multi_xs, multi_ys = [], []
        for i, (path, hx, hy) in enumerate(zip(arrays, xhs, yhs)):
            if i != (len(arrays)-1):
                path = path[:-1]
            multi_xs.append([path[:, 0]]+hx)
            multi_ys.append([path[:, 1]]+hy)
        xsh.append(multi_xs)
        ysh.append(multi_ys)
    return xsh, ysh
165784
def overlap(listA, listB):
    
    if (listA is None) or (listB is None):
        return []
    else:
        return list(set(listA) & set(listB))
264194
function(p1, p2, check_walls, check_items) {
        var minres = false;
        
        // collide with walls
        if(check_walls) {
          for(var i=0,n=this.walls.length;i<n;i++) {
            var wall = this.walls[i];
            var res = line_intersect(p1, p2, wall.p1, wall.p2);
            if(res) {
              res.type = 0; // 0 is wall
              if(!minres) { minres=res; }
              else {
                // check if its closer
                if(res.ua < minres.ua) {
                  // if yes replace it
                  minres = res;
                }
              }
            }
          }
        }
        
        // collide with items
        if(check_items) {
          for(var i=0,n=this.items.length;i<n;i++) {
            var it = this.items[i];
            var res = line_point_intersect(p1, p2, it.p, it.rad);
            if(res) {
              res.type = it.type; // store type of item
              if(!minres) { minres=res; }
              else { if(res.ua < minres.ua) { minres = res; }
              }
            }
          }
        }
        
        return minres;
      }
416990
def overlaps(self, begin, end=None):
        
        if end is not None:
            return self.overlaps_range(begin, end)
        elif isinstance(begin, Number):
            return self.overlaps_point(begin)
        else:
            return self.overlaps_range(begin.begin, begin.end)
1108002
def overlaps(self, contig, start, end, strand=None):
        
        return (
            self.can_overlap(contig, strand) and
            self.distance_to_interval(start, end) == 0)
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