private void computeIntersections(SegmentIntersector si) {
    nOverlaps = 0;
    prepareEvents();

    for (int i = 0; i < events.size(); i++) {
      SweepLineEvent ev = (SweepLineEvent) events.get(i);
      if (ev.isInsert()) {
        processOverlaps(i, ev.getDeleteEventIndex(), ev, si);
      }
    }
  }
 private void processOverlaps(int start, int end, SweepLineEvent ev0, SegmentIntersector si) {
   SweepLineSegment ss0 = (SweepLineSegment) ev0.getObject();
   /**
    * Since we might need to test for self-intersections, include current insert event object in
    * list of event objects to test. Last index can be skipped, because it must be a Delete event.
    */
   for (int i = start; i < end; i++) {
     SweepLineEvent ev1 = (SweepLineEvent) events.get(i);
     if (ev1.isInsert()) {
       SweepLineSegment ss1 = (SweepLineSegment) ev1.getObject();
       if (ev0.edgeSet == null || (ev0.edgeSet != ev1.edgeSet)) {
         ss0.computeIntersections(ss1, si);
         nOverlaps++;
       }
     }
   }
 }