Esempio n. 1
0
 void checkTransformation(AffineTransformation trans0, AffineTransformation trans1) {
   double[] m0 = trans0.getMatrixEntries();
   double[] m1 = trans1.getMatrixEntries();
   for (int i = 0; i < m0.length; i++) {
     assertEquals(m0[i], m1[i], 0.000005);
   }
 }
Esempio n. 2
0
  public void testCompose2() {
    AffineTransformation t0 = AffineTransformation.reflectionInstance(0, 0, 1, 0);
    t0.reflect(0, 0, 0, -1);

    AffineTransformation t1 = AffineTransformation.rotationInstance(Math.PI);

    checkTransformation(t0, t1);
  }
Esempio n. 3
0
  public void testCompose3() {
    AffineTransformation t0 = AffineTransformation.reflectionInstance(0, 10, 10, 0);
    t0.translate(-10, -10);

    AffineTransformation t1 = AffineTransformation.reflectionInstance(0, 0, -1, 1);

    checkTransformation(t0, t1);
  }
Esempio n. 4
0
  public void testComposeRotation1() {
    AffineTransformation t0 = AffineTransformation.rotationInstance(1, 10, 10);

    AffineTransformation t1 = AffineTransformation.translationInstance(-10, -10);
    t1.rotate(1);
    t1.translate(10, 10);

    checkTransformation(t0, t1);
  }
Esempio n. 5
0
 void checkTransformation(String geomStr)
     throws IOException, ParseException, NoninvertibleTransformationException {
   Geometry geom = rdr.read(geomStr);
   AffineTransformation trans = AffineTransformation.rotationInstance(Math.PI / 2);
   AffineTransformation inv = trans.getInverse();
   Geometry transGeom = (Geometry) geom.clone();
   transGeom.apply(trans);
   // System.out.println(transGeom);
   transGeom.apply(inv);
   // check if transformed geometry is equal to original
   boolean isEqual = geom.equalsExact(transGeom, 0.0005);
   assertTrue(isEqual);
 }
Esempio n. 6
0
 public void testReflectXY2() throws IOException, ParseException {
   AffineTransformation t = AffineTransformation.reflectionInstance(1, -1);
   checkTransformation(10, 0, t, 0, -10);
   checkTransformation(0, 10, t, -10, 0);
   checkTransformation(-10, -10, t, 10, 10);
   checkTransformation(-3, -4, t, 4, 3);
 }
Esempio n. 7
0
 public void testRotateAroundPoint1() throws IOException, ParseException {
   AffineTransformation t = AffineTransformation.rotationInstance(Math.PI / 2, 1, 1);
   checkTransformation(1, 1, t, 1, 1);
   checkTransformation(10, 0, t, 2, 10);
   checkTransformation(0, 10, t, -8, 0);
   checkTransformation(-10, -10, t, 12, -10);
 }
Esempio n. 8
0
  public void testCompose1() {
    AffineTransformation t0 = AffineTransformation.translationInstance(10, 0);
    t0.rotate(Math.PI / 2);
    t0.translate(0, -10);

    AffineTransformation t1 = AffineTransformation.translationInstance(0, 0);
    t1.rotate(Math.PI / 2);

    checkTransformation(t0, t1);
  }
Esempio n. 9
0
  /**
   * Checks that a transformation produces the expected result
   *
   * @param x the input pt x
   * @param y the input pt y
   * @param trans the transformation
   * @param xp the expected output x
   * @param yp the expected output y
   */
  void checkTransformation(double x, double y, AffineTransformation trans, double xp, double yp) {
    Coordinate p = new Coordinate(x, y);
    Coordinate p2 = new Coordinate();
    trans.transform(p, p2);
    assertEquals(xp, p2.x, .00005);
    assertEquals(yp, p2.y, .00005);

    // if the transformation is invertible, test the inverse
    try {
      AffineTransformation invTrans = trans.getInverse();
      Coordinate pInv = new Coordinate();
      invTrans.transform(p2, pInv);
      assertEquals(x, pInv.x, .00005);
      assertEquals(y, pInv.y, .00005);

      double det = trans.getDeterminant();
      double detInv = invTrans.getDeterminant();
      assertEquals(det, 1.0 / detInv, .00005);

    } catch (NoninvertibleTransformationException ex) {
    }
  }
Esempio n. 10
0
 public void testTranslateRotate1() throws IOException, ParseException {
   AffineTransformation t = AffineTransformation.translationInstance(3, 3).rotate(Math.PI / 2);
   checkTransformation(10, 0, t, -3, 13);
   checkTransformation(-10, -10, t, 7, -7);
 }
Esempio n. 11
0
 public void testTranslate1() throws IOException, ParseException {
   AffineTransformation t = AffineTransformation.translationInstance(2, 3);
   checkTransformation(1, 0, t, 3, 3);
   checkTransformation(0, 0, t, 2, 3);
   checkTransformation(-10, -5, t, -8, -2);
 }
Esempio n. 12
0
 public void testShear1() throws IOException, ParseException {
   AffineTransformation t = AffineTransformation.shearInstance(2, 3);
   checkTransformation(10, 0, t, 10, 30);
 }
Esempio n. 13
0
 public void testScale1() throws IOException, ParseException {
   AffineTransformation t = AffineTransformation.scaleInstance(2, 3);
   checkTransformation(10, 0, t, 20, 0);
   checkTransformation(0, 10, t, 0, 30);
   checkTransformation(-10, -10, t, -20, -30);
 }
Esempio n. 14
0
 public void testReflectXYXY1() throws IOException, ParseException {
   AffineTransformation t = AffineTransformation.reflectionInstance(0, 5, 5, 0);
   checkTransformation(5, 0, t, 5, 0);
   checkTransformation(0, 0, t, 5, 5);
   checkTransformation(-10, -10, t, 15, 15);
 }
Esempio n. 15
0
 public void testRotate1() throws IOException, ParseException {
   AffineTransformation t = AffineTransformation.rotationInstance(Math.PI / 2);
   checkTransformation(10, 0, t, 0, 10);
   checkTransformation(0, 10, t, -10, 0);
   checkTransformation(-10, -10, t, 10, -10);
 }