public void testRangeContaining2() {
   RangeSet<Integer> rangeSet = TreeRangeSet.create();
   rangeSet.add(Range.closed(3, 10));
   rangeSet.remove(Range.open(5, 7));
   assertEquals(Range.closed(3, 5), rangeSet.rangeContaining(5));
   assertTrue(rangeSet.contains(5));
   assertEquals(Range.closed(7, 10), rangeSet.rangeContaining(8));
   assertTrue(rangeSet.contains(8));
   assertNull(rangeSet.rangeContaining(6));
   assertFalse(rangeSet.contains(6));
 }
示例#2
0
  /**
   * Draws segment on screen via graphics attribute gc Helper method for traverse_ssector
   *
   * @param seg whose seen attribute may be set to true
   * @param ox1
   * @param y1
   * @param ox2
   * @param y2
   */
  private void drawrect(Seg seg, int ox1, int y1, int ox2, int y2) {
    // int y11, y12, y21, y22;
    // Log.v("inside drawrect", "hooray");
    int z1 = 0;
    int z2 = 100;

    drawrect_ct++; // debug, counter
    ox1 -= viewx;
    y1 -= viewy;
    z1 -= viewz;
    ox2 -= viewx;
    y2 -= viewy;
    z2 -= viewz;

    int y11, y12, y21, y22;
    y11 = y21 = -z1;
    y12 = y22 = -z2;

    int x1;
    int x2;
    x1 = -viewd_unscale(view_dy * ox1 - view_dx * y1);
    z1 = -viewd_unscale(view_dx * ox1 + view_dy * y1);
    x2 = -viewd_unscale(view_dy * ox2 - view_dx * y2);
    z2 = -viewd_unscale(view_dx * ox2 + view_dy * y2);

    RangePair rp = new RangePair(x1, z1, x2, z2);
    if (!clip3d(rp)) {
      return;
    }

    y11 = y11 * zscale / rp.z1 + (view_height / 2); // constant from here
    y12 = y12 * zscale / rp.z1 + (view_height / 2); // constant from here
    y21 = y21 * zscale / rp.z2 + (view_height / 2); // constant from here
    y22 = y22 * zscale / rp.z2 + (view_height / 2); // constant from here
    x1 = rp.x1 * zscale / rp.z1 + (view_width / 2); // constant from here
    x2 = rp.x2 * zscale / rp.z2 + (view_width / 2); // constant from here
    if (x1 >= x2) {
        /* reject backfaces */
      // Log.v("hatefulthings", "grrr");
      return;
    }
    int x1i = x1;
    int xd = x2 - x1;
    gw.setColor(seg.col);

    boolean drawn = false;
    drawrect_late_ct++; // debug, counter
    // loop variable is x1i, upper limit x2 is fixed
    // Log.v("more things", ""+x1i);
    // Log.v("more more things", ""+x2);
    while (x1i <= x2) {
      // check if there is an intersection,
      // if there is none proceed exit the loop,
      // if there is one, get it as (x1i,x2i)
      int[] p = {x1i, x2};
      if (!rset.intersect(p)) break;
      x1i = p[0];
      int x2i = p[1];
      // let's work on the intersection (x1i,x2i)
      int xps[] = {x1i, x1i, x2i + 1, x2i + 1};
      int yps[] = {
        y11 + (x1i - x1) * (y21 - y11) / xd,
        y12 + (x1i - x1) * (y22 - y12) / xd + 1,
        y22 + (x2i - x2) * (y22 - y12) / xd + 1,
        y21 + (x2i - x2) * (y21 - y11) / xd
      };
      System.out.println("I get to here");
      gw.fillPolygon(xps, yps, 4);
      drawn = true;
      rset.remove(x1i, x2i);
      x1i = x2i + 1;
      drawrect_segment_ct++; // debug, counter
    }
    if (drawn && !seg.seen) {
      udpateSeenCellsForSegment(seg);
    }
  }