Search in sources :

Example 1 with AffineTransformation

use of com.revolsys.geometry.model.util.AffineTransformation in project com.revolsys.open by revolsys.

the class AffineTransformationTest method testCompose2.

public void testCompose2() {
    final AffineTransformation t0 = AffineTransformation.reflectionInstance(0, 0, 1, 0);
    t0.reflect(0, 0, 0, -1);
    final AffineTransformation t1 = AffineTransformation.rotationInstance(Math.PI);
    checkTransformation(t0, t1);
}
Also used : AffineTransformation(com.revolsys.geometry.model.util.AffineTransformation)

Example 2 with AffineTransformation

use of com.revolsys.geometry.model.util.AffineTransformation in project com.revolsys.open by revolsys.

the class AffineTransformationTest method testCompose3.

public void testCompose3() {
    final AffineTransformation t0 = AffineTransformation.reflectionInstance(0, 10, 10, 0);
    t0.translate(-10, -10);
    final AffineTransformation t1 = AffineTransformation.reflectionInstance(0, 0, -1, 1);
    checkTransformation(t0, t1);
}
Also used : AffineTransformation(com.revolsys.geometry.model.util.AffineTransformation)

Example 3 with AffineTransformation

use of com.revolsys.geometry.model.util.AffineTransformation in project com.revolsys.open by revolsys.

the class AffineTransformationTest method checkTransformation.

/**
 * 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(final double x, final double y, final AffineTransformation trans, final double xp, final double yp) {
    final Point p = new PointDoubleXY(x, y);
    final Point p2 = trans.transform(p);
    assertEquals(xp, p2.getX(), .00005);
    assertEquals(yp, p2.getY(), .00005);
    // if the transformation is invertible, test the inverse
    try {
        final AffineTransformation invTrans = trans.getInverse();
        final Point pInv = invTrans.transform(p2);
        assertEquals(x, pInv.getX(), .00005);
        assertEquals(y, pInv.getY(), .00005);
        final double det = trans.getDeterminant();
        final double detInv = invTrans.getDeterminant();
        assertEquals(det, 1.0 / detInv, .00005);
    } catch (final NoninvertibleTransformationException ex) {
    }
}
Also used : NoninvertibleTransformationException(com.revolsys.geometry.model.util.NoninvertibleTransformationException) AffineTransformation(com.revolsys.geometry.model.util.AffineTransformation) Point(com.revolsys.geometry.model.Point) PointDoubleXY(com.revolsys.geometry.model.impl.PointDoubleXY)

Example 4 with AffineTransformation

use of com.revolsys.geometry.model.util.AffineTransformation in project com.revolsys.open by revolsys.

the class AffineTransformationTest method testReflectXYXY1.

public void testReflectXYXY1() throws IOException, ParseException {
    final 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);
}
Also used : AffineTransformation(com.revolsys.geometry.model.util.AffineTransformation)

Example 5 with AffineTransformation

use of com.revolsys.geometry.model.util.AffineTransformation in project com.revolsys.open by revolsys.

the class AffineTransformationTest method checkTransformation.

void checkTransformation(final String geomStr) throws IOException, ParseException, NoninvertibleTransformationException {
    final Geometry geom = geometryFactory.geometry(geomStr);
    final AffineTransformation trans = AffineTransformation.rotationInstance(Math.PI / 2);
    final AffineTransformation inv = trans.getInverse();
    final Geometry transGeom = trans.transform(geom);
    final Geometry invGeom = inv.transform(transGeom);
    // check if transformed geometry is equal to original
    final boolean isEqual = geom.equalsExact(invGeom, 0.0005);
    assertTrue(isEqual);
}
Also used : Geometry(com.revolsys.geometry.model.Geometry) AffineTransformation(com.revolsys.geometry.model.util.AffineTransformation)

Aggregations

AffineTransformation (com.revolsys.geometry.model.util.AffineTransformation)29 Point (com.revolsys.geometry.model.Point)13 PointDoubleXY (com.revolsys.geometry.model.impl.PointDoubleXY)4 AffineTransformationBuilder (com.revolsys.geometry.model.util.AffineTransformationBuilder)3 Geometry (com.revolsys.geometry.model.Geometry)2 BoundingBox (com.revolsys.geometry.model.BoundingBox)1 NoninvertibleTransformationException (com.revolsys.geometry.model.util.NoninvertibleTransformationException)1