This is an automated email from the ASF dual-hosted git repository. desruisseaux pushed a commit to branch geoapi-4.0 in repository https://gitbox.apache.org/repos/asf/sis.git
commit 7c107c57eed0a428250c035556917da27fa8f8ff Author: Martin Desruisseaux <martin.desruisse...@geomatys.com> AuthorDate: Wed Sep 6 18:27:50 2023 +0200 Move the check for perpendicular axes in the parent class. This is in anticipation for the addition of experimental coordinate systems such as `MinkowskiCS` in other branches. --- .../org/apache/sis/referencing/cs/AbstractCS.java | 74 +++++++++++++++------- .../sis/referencing/cs/DefaultCartesianCS.java | 26 -------- 2 files changed, 51 insertions(+), 49 deletions(-) diff --git a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/cs/AbstractCS.java b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/cs/AbstractCS.java index 81d87e70ad..df9acffdca 100644 --- a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/cs/AbstractCS.java +++ b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/cs/AbstractCS.java @@ -47,10 +47,11 @@ import org.apache.sis.system.Modules; import org.apache.sis.util.Utilities; import org.apache.sis.util.ComparisonMode; import org.apache.sis.util.internal.Constants; -import org.apache.sis.io.wkt.ElementKind; -import org.apache.sis.io.wkt.Formatter; import org.apache.sis.util.logging.Logging; import org.apache.sis.util.resources.Errors; +import org.apache.sis.io.wkt.ElementKind; +import org.apache.sis.io.wkt.Formatter; +import org.apache.sis.measure.Angle; import static org.apache.sis.util.ArgumentChecks.*; @@ -214,6 +215,54 @@ public class AbstractCS extends AbstractIdentifiedObject implements CoordinateSy } } + /** + * Returns {@link #VALID} if the given argument values are allowed for an axis in this coordinate system, + * or an {@code INVALID_*} error code otherwise. This method is invoked at construction time for checking + * argument validity. The default implementation returns {@code VALID} in all cases. Subclasses override + * this method in order to put more restrictions on allowed axis directions and check for compatibility + * with {@linkplain org.apache.sis.measure.Units#METRE metre} or + * {@linkplain org.apache.sis.measure.Units#DEGREE degree} units. + * + * <p><b>Note for implementers:</b> since this method is invoked at construction time, it shall not depend + * on this object's state. This method is not in public API for that reason.</p> + * + * @param direction the direction to test for compatibility (never {@code null}). + * @param unit the unit to test for compatibility (never {@code null}). + * @return {@link #VALID} if the given direction and unit are compatible with this coordinate system, + * {@link #INVALID_DIRECTION} if the direction is invalid or {@link #INVALID_UNIT} if the unit + * is invalid. + */ + int validateAxis(final AxisDirection direction, final Unit<?> unit) { + return VALID; + } + + /** + * Ensures that all known axes are perpendicular, ignoring unknown axis directions. + * This method can be invoked by the constructors of coordinate systems having this requirement. + * + * @param properties properties given at construction time. + * @throws IllegalArgumentException if an illegal angle is found between two axes. + */ + final void ensurePerpendicularAxis(final Map<String,?> properties) throws IllegalArgumentException { + final int dimension = getDimension(); + for (int i=0; i<dimension; i++) { + final AxisDirection axis0 = getAxis(i).getDirection(); + for (int j=i; ++j<dimension;) { + final AxisDirection axis1 = getAxis(j).getDirection(); + final Angle angle = CoordinateSystems.angle(axis0, axis1); + /* + * The angle may be null for grid directions (COLUMN_POSITIVE, COLUMN_NEGATIVE, + * ROW_POSITIVE, ROW_NEGATIVE). We conservatively accept those directions even if + * they are not really for Cartesian CS because we do not know the grid geometry. + */ + if (angle != null && Math.abs(angle.degrees()) != 90) { + throw new IllegalArgumentException(Resources.forProperties(properties).getString( + Resources.Keys.NonPerpendicularDirections_2, axis0, axis1)); + } + } + } + } + /** * Creates a new coordinate system with the same values than the specified one. * This copy constructor provides a way to convert an arbitrary implementation into a SIS one @@ -277,27 +326,6 @@ public class AbstractCS extends AbstractIdentifiedObject implements CoordinateSy return SubTypes.castOrCopy(object); } - /** - * Returns {@link #VALID} if the given argument values are allowed for an axis in this coordinate system, - * or an {@code INVALID_*} error code otherwise. This method is invoked at construction time for checking - * argument validity. The default implementation returns {@code VALID} in all cases. Subclasses override - * this method in order to put more restrictions on allowed axis directions and check for compatibility - * with {@linkplain org.apache.sis.measure.Units#METRE metre} or - * {@linkplain org.apache.sis.measure.Units#DEGREE degree} units. - * - * <p><b>Note for implementers:</b> since this method is invoked at construction time, it shall not depend - * on this object's state. This method is not in public API for that reason.</p> - * - * @param direction the direction to test for compatibility (never {@code null}). - * @param unit the unit to test for compatibility (never {@code null}). - * @return {@link #VALID} if the given direction and unit are compatible with this coordinate system, - * {@link #INVALID_DIRECTION} if the direction is invalid or {@link #INVALID_UNIT} if the unit - * is invalid. - */ - int validateAxis(final AxisDirection direction, final Unit<?> unit) { - return VALID; - } - /** * Returns the GeoAPI interface implemented by this class. * The default implementation returns {@code CoordinateSystem.class}. diff --git a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/cs/DefaultCartesianCS.java b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/cs/DefaultCartesianCS.java index ee72d04efe..1959440f46 100644 --- a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/cs/DefaultCartesianCS.java +++ b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/cs/DefaultCartesianCS.java @@ -20,10 +20,7 @@ import java.util.Map; import jakarta.xml.bind.annotation.XmlType; import jakarta.xml.bind.annotation.XmlRootElement; import org.opengis.referencing.cs.CartesianCS; -import org.opengis.referencing.cs.AxisDirection; import org.opengis.referencing.cs.CoordinateSystemAxis; -import org.apache.sis.referencing.internal.Resources; -import org.apache.sis.measure.Angle; /** @@ -176,29 +173,6 @@ public class DefaultCartesianCS extends DefaultAffineCS implements CartesianCS { ? (DefaultCartesianCS) object : new DefaultCartesianCS(object); } - /** - * Ensures that all axes are perpendicular. - */ - private void ensurePerpendicularAxis(final Map<String,?> properties) throws IllegalArgumentException { - final int dimension = getDimension(); - for (int i=0; i<dimension; i++) { - final AxisDirection axis0 = getAxis(i).getDirection(); - for (int j=i; ++j<dimension;) { - final AxisDirection axis1 = getAxis(j).getDirection(); - final Angle angle = CoordinateSystems.angle(axis0, axis1); - /* - * The angle may be null for grid directions (COLUMN_POSITIVE, COLUMN_NEGATIVE, - * ROW_POSITIVE, ROW_NEGATIVE). We conservatively accept those directions even if - * they are not really for Cartesian CS because we do not know the grid geometry. - */ - if (angle != null && Math.abs(angle.degrees()) != 90) { - throw new IllegalArgumentException(Resources.forProperties(properties).getString( - Resources.Keys.NonPerpendicularDirections_2, axis0, axis1)); - } - } - } - } - /** * Returns the GeoAPI interface implemented by this class. * The SIS implementation returns {@code CartesianCS.class}.