Esempio n. 1
0
 /** Test 2d vs 3d points with 3d elavations at/close to 0 */
 public void testMismatchedEquals() {
   Geodetic2DPoint p1 = makePoint(-81.9916466079043, 29.9420387052815, 5000.1);
   Geodetic2DPoint p2 = makePoint(-81.9916466079043, 29.9420387052815, 0.0);
   if (p1.equals(p2)) fail("different elevation but equals() == true");
   if (p2.equals(p1)) fail("different elevation but equals() == true");
   Geodetic2DPoint p3 = makePoint(-81.9916466079043, 29.9420387052815);
   assertEquals("2d with elev=0 and 3d point same lat/lon", p2, p3);
   assertEquals("2d with elev=0 and 3d point same lat/lon", p3, p2);
   Geodetic2DPoint p4 = makePoint(-81.9916466079043, 29.9420387052815, 1e-6);
   // assertEquals(p3, new Geodetic2DPoint(p4.getLongitude(), p4.getLatitude()));
   assertEquals("3d with elev=1e-4 and 3d point same lat/lon", p2, p4);
   assertEquals("3d with elev=1e-4 and 3d point same lat/lon", p4, p2);
   assertEquals("3d with elev=1e-4 and 3d point same lat/lon", p3, p4);
 }
Esempio n. 2
0
  /** This method performs format conversions with string constructors in degrees and dms */
  public void testRandomEquals() {
    for (int i = 0; i < 1000; i++) {
      Geodetic3DPoint a1 = randomGeoPoint(r);
      Geodetic3DPoint a2 =
          new Geodetic3DPoint(a1.getLongitude(), a1.getLatitude(), a1.getElevation());
      // note by making equals() work in round off errors (such as in this case) using
      // Angle.equals() vs phi1=phi2 && lamb1==lamb2
      // but break contract in hashCode such that a.equals(b) -> true but hashCode(a) may not equal
      // hashCode(b)
      assertEquals(a1, a2);
      assertEquals(a1.hashCode(), a2.hashCode());

      // for symmetric tests to work elevation must be non-zero
      final double elevation = a1.getElevation();
      if (elevation == 0.0 || Math.abs(elevation) < 1e-8) a1.setElevation(1234.5);

      // test symmetric equals tests a.equals(b) -> b.equals(a)
      Geodetic2DPoint pt2 = new Geodetic2DPoint(a1.getLongitude(), a1.getLatitude());
      assertFalse(pt2.equals(a1));
      assertFalse(a1.equals(pt2));
      a1.setElevation(0);
      assertEquals(pt2, a1); // pt2.equals(al) -> a1.equals(pt2)
      assertEquals(a1, pt2);
    }
  }