/* * GeoTools - The Open Source Java GIS Toolkit * http://geotools.org * * (C) 2005-2008, Open Source Geospatial Foundation (OSGeo) * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; * version 2.1 of the License. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. */ package org.geotools.referencing.operation.matrix; import java.awt.geom.AffineTransform; import org.opengis.referencing.operation.Matrix; import org.geotools.resources.i18n.Errors; import org.geotools.resources.i18n.ErrorKeys; import org.geotools.util.Utilities; /** * An affine matrix of fixed {@value #SIZE}×{@value #SIZE} size. Here, the term "affine" * means a matrix with the last row fixed to {@code [0,0,1]} values. Such matrices are used for * affine transformations in a 2D space. *
* This class both extends the Java2D {@link AffineTransform} class and implements * the {@link Matrix} interface. It allows interoperbility for code that need to pass the same * matrix to both Java2D API and more generic API working with coordinates of * arbitrary dimension. *
* This class do not implements the {@link XMatrix} interface because the inherited {@code invert()}
* method (new in J2SE 1.6) declares a checked exception, {@code setZero()} would be an unsupported
* operation (because it is not possible to change the value at {@code (2,2)}), {@code transpose()}
* would fails in most cases, and {@code isAffine()} would be useless.
*
* @since 2.3
*
*
* @source $URL$
* @version $Id$
* @author Martin Desruisseaux (IRD)
*/
public class AffineTransform2D extends AffineTransform implements Matrix {
/**
* Serial number for interoperability with different versions.
*/
private static final long serialVersionUID = -9104194268576601386L;
/**
* The matrix size, which is {@value}.
*/
public static final int SIZE = 3;
/**
* Creates a new identity matrix.
*/
public AffineTransform2D() {
}
/**
* Constructs a 3×3 matrix from the specified affine transform.
*/
public AffineTransform2D(final AffineTransform transform) {
super(transform);
}
/**
* Creates a new matrix initialized to the same value than the specified one.
* The specified matrix size must be {@value #SIZE}×{@value #SIZE}.
*/
public AffineTransform2D(final Matrix matrix) {
if (matrix.getNumRow()!=SIZE || matrix.getNumCol()!=SIZE) {
throw new IllegalArgumentException(Errors.format(ErrorKeys.ILLEGAL_MATRIX_SIZE));
}
for (int i=0; i