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 a9b8b051004b0207b8e4b67046b2d0618006181b
Author: Martin Desruisseaux <martin.desruisseaux@geomatys.com>
AuthorDate: Mon Sep 14 16:27:53 2020 +0200
Move `MathTransformsOrFactory` in an internal package where it can be shared with classes
in different packages.
---
.../apache/sis/coverage/grid/SliceGeometry.java | 17 +++-------
.../referencing}/MathTransformsOrFactory.java | 38 ++++++++++++++--------
.../operation/transform/PassThroughTransform.java | 1 +
.../operation/transform/TransformSeparator.java | 1 +
4 files changed, 31 insertions(+), 26 deletions(-)
diff --git a/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/SliceGeometry.java
b/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/SliceGeometry.java
index fdb017d..4c03da2 100644
--- a/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/SliceGeometry.java
+++ b/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/SliceGeometry.java
@@ -32,6 +32,7 @@ import org.apache.sis.referencing.CRS;
import org.apache.sis.geometry.GeneralEnvelope;
import org.apache.sis.geometry.ImmutableEnvelope;
import org.apache.sis.internal.referencing.DirectPositionView;
+import org.apache.sis.internal.referencing.MathTransformsOrFactory;
import org.apache.sis.internal.util.Numerics;
import org.apache.sis.util.ComparisonMode;
import org.apache.sis.util.ArraysExt;
@@ -239,8 +240,9 @@ final class SliceGeometry implements Function<RenderedImage, GridGeometry>
{
offset[i] = extent.getLow(gridDimensions[i]);
}
final LinearTransform translation = MathTransforms.translation(offset);
- gridToCRS = concatenate(translation, gridToCRS);
- cornerToCRS = concatenate(translation, cornerToCRS);
+ final MathTransformsOrFactory f = MathTransformsOrFactory.wrap(factory);
+ gridToCRS = f.concatenate(translation, gridToCRS);
+ cornerToCRS = f.concatenate(translation, cornerToCRS);
}
extent = relativeExtent;
}
@@ -355,17 +357,6 @@ final class SliceGeometry implements Function<RenderedImage, GridGeometry>
{
}
/**
- * Returns the concatenation of given transforms.
- */
- private MathTransform concatenate(final MathTransform tr1, final MathTransform tr2) throws
FactoryException {
- if (factory != null) {
- return factory.createConcatenatedTransform(tr1, tr2);
- } else {
- return MathTransforms.concatenate(tr1, tr2);
- }
- }
-
- /**
* Invoked if an error occurred while computing the {@link ImageRenderer#getImageGeometry(int)}
value.
* This exception should never occur actually, unless a custom factory implementation
is used
* (instead of the Apache SIS default) and there is a problem with that factory.
diff --git a/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/MathTransformsOrFactory.java
b/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/MathTransformsOrFactory.java
similarity index 71%
rename from core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/MathTransformsOrFactory.java
rename to core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/MathTransformsOrFactory.java
index e5e3082..1514a0e 100644
--- a/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/MathTransformsOrFactory.java
+++ b/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/MathTransformsOrFactory.java
@@ -14,12 +14,14 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.sis.referencing.operation.transform;
+package org.apache.sis.internal.referencing;
+import org.opengis.util.FactoryException;
+import org.opengis.referencing.operation.Matrix;
import org.opengis.referencing.operation.MathTransform;
import org.opengis.referencing.operation.MathTransformFactory;
-import org.opengis.referencing.operation.Matrix;
-import org.opengis.util.FactoryException;
+import org.apache.sis.referencing.operation.transform.MathTransforms;
+import org.apache.sis.referencing.operation.transform.PassThroughTransform;
/**
@@ -29,11 +31,11 @@ import org.opengis.util.FactoryException;
* all methods.
*
* @author Martin Desruisseaux (Geomatys)
- * @version 1.0
+ * @version 1.1
* @since 1.0
* @module
*/
-class MathTransformsOrFactory {
+public class MathTransformsOrFactory {
/**
* The unique instance to use when no {@link MathTransformFactory} is specified.
*/
@@ -49,8 +51,9 @@ class MathTransformsOrFactory {
* Returns the instance to use for the given factory.
*
* @param factory the factory, which may be {@code null}.
+ * @return the instance to use.
*/
- static MathTransformsOrFactory wrap(final MathTransformFactory factory) {
+ public static MathTransformsOrFactory wrap(final MathTransformFactory factory) {
return (factory != null) ? new Specified(factory) : INSTANCE;
}
@@ -59,8 +62,9 @@ class MathTransformsOrFactory {
*
* @param matrix the matrix used to define the linear transform.
* @return the linear (usually affine) transform.
+ * @throws FactoryException if a factory is wrapped and can not perform the operation.
*/
- MathTransform linear(Matrix matrix) throws FactoryException {
+ public MathTransform linear(final Matrix matrix) throws FactoryException {
return MathTransforms.linear(matrix);
}
@@ -71,8 +75,9 @@ class MathTransformsOrFactory {
* @param subTransform the sub-transform to apply on modified coordinates.
* @param numTrailingCoordinates number of trailing coordinates to pass through.
* @return a pass-through transform, potentially as a {@link PassThroughTransform} instance
but not necessarily.
+ * @throws FactoryException if a factory is wrapped and can not perform the operation.
*/
- MathTransform passThrough(int firstAffectedCoordinate, MathTransform subTransform, int
numTrailingCoordinates) throws FactoryException {
+ public MathTransform passThrough(int firstAffectedCoordinate, MathTransform subTransform,
int numTrailingCoordinates) throws FactoryException {
return MathTransforms.passThrough(firstAffectedCoordinate, subTransform, numTrailingCoordinates);
}
@@ -82,15 +87,22 @@ class MathTransformsOrFactory {
* @param tr1 the first math transform.
* @param tr2 the second math transform.
* @return the concatenated transform.
+ * @throws FactoryException if a factory is wrapped and can not perform the operation.
*/
- MathTransform concatenate(MathTransform tr1, MathTransform tr2) throws FactoryException
{
+ public MathTransform concatenate(MathTransform tr1, MathTransform tr2) throws FactoryException
{
return MathTransforms.concatenate(tr1, tr2);
}
/**
* Concatenates the two given transforms, switching their order if {@code applyOtherFirst}
is {@code true}.
+ *
+ * @param tr the first math transform.
+ * @param other the second math transform.
+ * @param applyOtherFirst whether {@code other} should be first in the concatenation
chain.
+ * @return the concatenated transform.
+ * @throws FactoryException if a factory is wrapped and can not perform the operation.
*/
- final MathTransform concatenate(boolean applyOtherFirst, MathTransform tr, MathTransform
other) throws FactoryException {
+ public final MathTransform concatenate(boolean applyOtherFirst, MathTransform tr, MathTransform
other) throws FactoryException {
if (applyOtherFirst) {
return concatenate(other, tr);
} else {
@@ -112,17 +124,17 @@ class MathTransformsOrFactory {
}
/** Delegate to {@link MathTransformFactory#createAffineTransform(Matrix)}. */
- @Override MathTransform linear(Matrix matrix) throws FactoryException {
+ @Override public MathTransform linear(Matrix matrix) throws FactoryException {
return factory.createAffineTransform(matrix);
}
/** Delegate to {@link MathTransformFactory#createPassThroughTransform(int, MathTransform,
int)}. */
- @Override MathTransform passThrough(int firstAffectedCoordinate, MathTransform subTransform,
int numTrailingCoordinates) throws FactoryException {
+ @Override public MathTransform passThrough(int firstAffectedCoordinate, MathTransform
subTransform, int numTrailingCoordinates) throws FactoryException {
return factory.createPassThroughTransform(firstAffectedCoordinate, subTransform,
numTrailingCoordinates);
}
/** Delegate to {@link MathTransformFactory#createConcatenatedTransform(MathTransform,
MathTransform)}. */
- @Override MathTransform concatenate(MathTransform tr, MathTransform other) throws
FactoryException {
+ @Override public MathTransform concatenate(MathTransform tr, MathTransform other)
throws FactoryException {
return factory.createConcatenatedTransform(tr, other);
}
}
diff --git a/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/PassThroughTransform.java
b/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/PassThroughTransform.java
index 42a144e..0ee050b 100644
--- a/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/PassThroughTransform.java
+++ b/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/PassThroughTransform.java
@@ -28,6 +28,7 @@ import org.opengis.referencing.operation.TransformException;
import org.opengis.referencing.operation.NoninvertibleTransformException;
import org.apache.sis.referencing.operation.matrix.Matrices;
import org.apache.sis.referencing.operation.matrix.MatrixSIS;
+import org.apache.sis.internal.referencing.MathTransformsOrFactory;
import org.apache.sis.internal.referencing.DirectPositionView;
import org.apache.sis.internal.referencing.WKTKeywords;
import org.apache.sis.internal.util.Numerics;
diff --git a/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/TransformSeparator.java
b/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/TransformSeparator.java
index 72e38f8..4f20cff 100644
--- a/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/TransformSeparator.java
+++ b/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/TransformSeparator.java
@@ -23,6 +23,7 @@ import org.opengis.referencing.operation.MathTransform;
import org.opengis.referencing.operation.MathTransformFactory;
import org.apache.sis.referencing.operation.matrix.MatrixSIS;
import org.apache.sis.referencing.operation.matrix.Matrices;
+import org.apache.sis.internal.referencing.MathTransformsOrFactory;
import org.apache.sis.internal.referencing.Resources;
import org.apache.sis.internal.util.Strings;
import org.apache.sis.util.resources.Errors;
|