Transform { public Transform(final Surface ctx) { this(ctx, new Decimal()); } Transform(final Surface ctx);  Transform(final Surface ctx, final Field<Double> field); Point transform(final DblPoint point); Point transform(final XyPoint<Double> point); Point transform(final Vect<Double> point); DblPoint inverse(final Point point);  }
@Test public void transformsDblPoint() { final Double xcoor = Math.random(); final Double ycoor = Math.random(); final DblPoint point = new DblPoint(xcoor, ycoor); final Surface ctx = TransformTest.context(); final Point result = new Transform(ctx).transform(point); final double error = 1.e-6; MatcherAssert.assertThat( result.getX(), Matchers.closeTo( (int) (ctx.width() / 2d + ctx.scale() * xcoor - ctx.center().dblx() * ctx.scale()), error ) ); MatcherAssert.assertThat( result.getY(), Matchers.closeTo( (int) (ctx.height() / 2d - ctx.scale() * ycoor + ctx.center().dbly() * ctx.scale()), error ) ); }
@Test public void transformsXyPoint() { final Double xcoor = Math.random(); final Double ycoor = Math.random(); final XyPoint<Double> point = new DblPoint(xcoor, ycoor); final Surface ctx = TransformTest.context(); final Point result = new Transform(ctx).transform(point); final double error = 1.e-6; MatcherAssert.assertThat( result.getX(), Matchers.closeTo( (int) (ctx.width() / 2d + ctx.scale() * xcoor - ctx.center().dblx() * ctx.scale()), error ) ); MatcherAssert.assertThat( result.getY(), Matchers.closeTo( (int) (ctx.height() / 2d - ctx.scale() * ycoor + ctx.center().dbly() * ctx.scale()), error ) ); }
@Test public void transformsVect() { final Double xcoor = Math.random(); final Double ycoor = Math.random(); final Vect<Double> point = new DblPoint(xcoor, ycoor); final Surface ctx = TransformTest.context(); final Point res = new Transform(ctx, new Decimal()).transform(point); final double error = 1.e-6; MatcherAssert.assertThat( res.getX(), Matchers.closeTo( (int) (ctx.width() / 2d + ctx.scale() * xcoor - ctx.center().dblx() * ctx.scale()), error ) ); MatcherAssert.assertThat( res.getY(), Matchers.closeTo( (int) (ctx.height() / 2d - ctx.scale() * ycoor + ctx.center().dbly() * ctx.scale()), error ) ); }