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); }
/** * 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) { } }