Пример #1
0
  // Helper function to test any rectangle
  private static void testMove(Rectangle r) {
    Point ll = r.lowerLeft();
    Point ur = r.upperRight();
    Point c = r.center();
    double wd = r.width();
    double ht = r.height();

    r.move(0., 0.); // Nothing should change
    assertTrue(r.lowerLeft().equals(ll));
    assertTrue(r.upperRight().equals(ur));
    assertTrue(r.center().equals(c));
    assertTrue(r.width() == wd);
    assertTrue(r.height() == ht);

    double dx = 10.0; // how much to move.
    double dy = -10.0;
    r.move(dx, dy);
    Point newll = new Point(ll.getX() + dx, ll.getY() + dy);
    Point newur = new Point(ur.getX() + dx, ur.getY() + dy);
    Point newc = new Point(c.getX() + dx, c.getY() + dy);
    assertTrue(r.lowerLeft().equals(newll));
    assertTrue(r.upperRight().equals(newur));
    assertTrue(r.center().equals(newc));
    assertTrue(r.width() == wd); // no change in size
    assertTrue(r.height() == ht);
  }
Пример #2
0
 // Helper function to test any non-empty rectangle
 private static void testInterior(Rectangle r) {
   assertTrue(r.interior(r.center()));
   assertFalse(r.interior(r.lowerRight()));
   assertFalse(r.interior(r.upperLeft()));
   assertFalse(r.interior(r.upperLeft().offset(0, 1)));
   assertFalse(r.interior(r.lowerLeft().offset(0, -1)));
   assertFalse(r.interior(r.upperRight().offset(1, 0)));
   assertFalse(r.interior(r.lowerRight().offset(1, 1)));
   assertTrue(r.interior(r.lowerLeft().offset(r.width() / 4, r.height() / 10)));
 }
Пример #3
0
  // Helper function for any rectangle.
  // Expects the lower left coordinates (llx,lly)
  //   and upper-right coordinates (urx, ury),
  //   even if that's not how the rectangle is
  //   internally represented.
  private static void testGeometry(Rectangle r, double llx, double lly, double urx, double ury) {
    // Sanity-check the inputs
    assertTrue(llx <= urx);
    assertTrue(lly <= ury);

    // Check the corners
    assertTrue(r.lowerLeft().getX() == llx);
    assertTrue(r.lowerLeft().getY() == lly);
    assertTrue(r.upperRight().getX() == urx);
    assertTrue(r.upperRight().getY() == ury);
    assertTrue(r.lowerRight().getX() == urx);
    assertTrue(r.lowerRight().getY() == lly);
    assertTrue(r.upperLeft().getX() == llx);
    assertTrue(r.upperLeft().getY() == ury);

    // Check the center
    assertTrue(r.center().getX() == (llx + urx) / 2.0);
    assertTrue(r.center().getY() == (lly + ury) / 2.0);

    // Check the width
    assertTrue(r.width() == (urx - llx));
    assertTrue(r.height() == (ury - lly));
  }