/** * Returns an estimation about whatever the specified transform swaps <var>x</var> and * <var>y</var> axis. This method assumes that the specified affine transform is built from * arbitrary translations, scales or rotations, but no shear. It returns {@code +1} if the * (<var>x</var>, <var>y</var>) axis order seems to be preserved, {@code -1} if the transform * seems to swap axis to the (<var>y</var>, <var>x</var>) axis order, or {@code 0} if this * method can not make a decision. */ public static int getSwapXY(final AffineTransform tr) { final int flip = getFlip(tr); if (flip != 0) { final double scaleX = getScaleX0(tr); final double scaleY = getScaleY0(tr) * flip; final double y = Math.abs(tr.getShearY() / scaleY - tr.getShearX() / scaleX); final double x = Math.abs(tr.getScaleY() / scaleY + tr.getScaleX() / scaleX); if (x > y) return +1; if (x < y) return -1; // At this point, we may have (x == y) or some NaN value. } return 0; }
/** * Returns an estimation of the rotation angle in radians. This method assumes that the * specified affine transform is built from arbitrary translations, scales or rotations, but no * shear. If a flip has been applied, then this method assumes that the flipped axis is the * <var>y</var> one in <cite>source CRS</cite> space. For a <cite>grid to world CRS</cite> * transform, this is the row number in grid coordinates. * * @param tr The affine transform to inspect. * @return An estimation of the rotation angle in radians, or {@link Double#NaN NaN} if the * angle can not be estimated. */ public static double getRotation(final AffineTransform tr) { final int flip = getFlip(tr); if (flip != 0) { final double scaleX = getScaleX0(tr); final double scaleY = getScaleY0(tr) * flip; return Math.atan2( tr.getShearY() / scaleY - tr.getShearX() / scaleX, tr.getScaleY() / scaleY + tr.getScaleX() / scaleX); } return Double.NaN; }
final int flip = XAffineTransform.getFlip(gridToWorldTransform); final CoordinateReferenceSystem crs2D = ((GridCoverage2D) coverage).getCoordinateReferenceSystem2D();
assertEquals(0, XAffineTransform.getRotation(tr), EPS); assertEquals(1, XAffineTransform.getSwapXY(tr)); assertEquals(f, XAffineTransform.getFlip(tr)); assertEquals(f, getFlipFromType(tr)); assertEquals(r, XAffineTransform.getRotation(tr), EPS); assertEquals(1, XAffineTransform.getSwapXY(tr)); assertEquals(f, XAffineTransform.getFlip(tr)); assertEquals(f, getFlipFromType(tr)); assertEquals(r, XAffineTransform.getRotation(tr), EPS); assertEquals(-1, XAffineTransform.getSwapXY(tr)); assertEquals(f, XAffineTransform.getFlip(tr)); assertEquals(f, getFlipFromType(tr)); assertEquals(0, XAffineTransform.getRotation(tr), EPS); assertEquals(1, XAffineTransform.getSwapXY(tr)); assertEquals(f, XAffineTransform.getFlip(tr)); assertEquals(f, getFlipFromType(tr)); assertEquals(r, XAffineTransform.getRotation(tr), EPS); assertEquals(-1, XAffineTransform.getSwapXY(tr)); assertEquals(f, XAffineTransform.getFlip(tr)); assertEquals(1, getFlipFromType(tr)); // Always unflipped according Java 1.5.0_09... assertEquals(r, XAffineTransform.getRotation(tr), EPS); assertEquals(-1, XAffineTransform.getSwapXY(tr)); assertEquals(-f, XAffineTransform.getFlip(tr)); assertEquals(-f, getFlipFromType(tr));
final int flip = XAffineTransform.getFlip(gridToWorldTransform); final CoordinateReferenceSystem crs2D = ((GridCoverage2D) coverage) .getCoordinateReferenceSystem2D();
final int flip = XAffineTransform.getFlip(gridToWorldTransform); final CoordinateReferenceSystem crs2D = ((GridCoverage2D) coverage) .getCoordinateReferenceSystem2D();