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 ccc3336c9e95e5dea074cac36c69ae4ff38a4e8e
Author: Martin Desruisseaux <[email protected]>
AuthorDate: Mon Dec 8 13:19:20 2025 +0100

    Move the `GridCoverage2D.BIDIMENSIONAL` constant for more sharing.
    Minor documentation updates and code formatting.
---
 .../org/apache/sis/coverage/grid/ClippedGridCoverage.java |  8 ++++----
 .../apache/sis/coverage/grid/DimensionalityReduction.java | 12 ++++++------
 .../main/org/apache/sis/coverage/grid/GridCoverage.java   |  6 ++++++
 .../main/org/apache/sis/coverage/grid/GridCoverage2D.java |  6 ------
 .../apache/sis/coverage/grid/GridCoverageProcessor.java   |  2 +-
 .../main/org/apache/sis/coverage/grid/GridExtent.java     |  6 +++---
 .../main/org/apache/sis/coverage/grid/ImageRenderer.java  | 15 ++++++++-------
 .../org/apache/sis/coverage/grid/ReducedGridCoverage.java | 10 +++++-----
 .../apache/sis/coverage/grid/ResampledGridCoverage.java   |  5 -----
 .../main/org/apache/sis/coverage/grid/SliceGeometry.java  |  2 +-
 .../main/org/apache/sis/geometry/CoordinateFormat.java    | 11 ++++++++---
 .../referencing/internal/shared/IntervalRectangle.java    |  8 ++++----
 12 files changed, 46 insertions(+), 45 deletions(-)

diff --git 
a/endorsed/src/org.apache.sis.feature/main/org/apache/sis/coverage/grid/ClippedGridCoverage.java
 
b/endorsed/src/org.apache.sis.feature/main/org/apache/sis/coverage/grid/ClippedGridCoverage.java
index 65cba86440..fe62d0d81b 100644
--- 
a/endorsed/src/org.apache.sis.feature/main/org/apache/sis/coverage/grid/ClippedGridCoverage.java
+++ 
b/endorsed/src/org.apache.sis.feature/main/org/apache/sis/coverage/grid/ClippedGridCoverage.java
@@ -35,7 +35,7 @@ final class ClippedGridCoverage extends DerivedGridCoverage {
      *
      * @see #evaluator()
      */
-    private final Map<Integer,Long> defaultSlice;
+    private final Map<Integer, Long> defaultSlice;
 
     /**
      * Constructs a new grid coverage which will delegate the rendering 
operation to the given source.
@@ -46,7 +46,7 @@ final class ClippedGridCoverage extends DerivedGridCoverage {
      */
     private ClippedGridCoverage(final GridCoverage source, final GridGeometry 
domain) {
         super(source, domain);
-        final Map<Integer,Long> c = domain.getExtent().getSliceCoordinates();
+        final Map<Integer, Long> c = domain.getExtent().getSliceCoordinates();
         if 
(c.equals(source.getGridGeometry().getExtent().getSliceCoordinates())) {
             defaultSlice = null;
         } else {
@@ -129,7 +129,7 @@ final class ClippedGridCoverage extends DerivedGridCoverage 
{
                 if (property instanceof int[]) {
                     gridDimensions = (int[]) property;
                 } else {
-                    gridDimensions = 
clipped.getSubspaceDimensions(GridCoverage2D.BIDIMENSIONAL);
+                    gridDimensions = 
clipped.getSubspaceDimensions(BIDIMENSIONAL);
                 }
                 final var t = new ReshapedImage(image, 
translation[gridDimensions[0]], translation[gridDimensions[1]]);
                 return t.isIdentity() ? t.source : t;
@@ -186,7 +186,7 @@ final class ClippedGridCoverage extends DerivedGridCoverage 
{
          * @throws IllegalArgumentException if the map contains an illegal 
dimension or grid coordinate value.
          */
         @Override
-        public void setDefaultSlice(final Map<Integer,Long> slice) {
+        public void setDefaultSlice(final Map<Integer, Long> slice) {
             super.setDefaultSlice(slice != null ? slice : defaultSlice);
         }
     }
diff --git 
a/endorsed/src/org.apache.sis.feature/main/org/apache/sis/coverage/grid/DimensionalityReduction.java
 
b/endorsed/src/org.apache.sis.feature/main/org/apache/sis/coverage/grid/DimensionalityReduction.java
index 01fc2cc3e0..f89da839af 100644
--- 
a/endorsed/src/org.apache.sis.feature/main/org/apache/sis/coverage/grid/DimensionalityReduction.java
+++ 
b/endorsed/src/org.apache.sis.feature/main/org/apache/sis/coverage/grid/DimensionalityReduction.java
@@ -136,7 +136,7 @@ public class DimensionalityReduction implements 
UnaryOperator<GridCoverage>, Ser
      * @see #getSliceCoordinates()
      */
     @SuppressWarnings("serial")                                 // Map.of(…) 
are serializable.
-    private final Map<Integer,Long> sliceCoordinates;
+    private final Map<Integer, Long> sliceCoordinates;
 
     /**
      * A cache of {@link #gridAxesToPass} for all combinations of axes to 
retain in the first four dimensions.
@@ -280,7 +280,7 @@ public class DimensionalityReduction implements 
UnaryOperator<GridCoverage>, Ser
      * @param  source  the dimensionality reduction to copy.
      * @param  slice   coordinates of the slice in removed dimensions.
      */
-    private DimensionalityReduction(final DimensionalityReduction source, 
final Map<Integer,Long> slice) {
+    private DimensionalityReduction(final DimensionalityReduction source, 
final Map<Integer, Long> slice) {
         sourceGeometry     = source.sourceGeometry;
         reducedGeometry    = source.reducedGeometry;
         gridAxesToPass     = source.gridAxesToPass;
@@ -548,7 +548,7 @@ public class DimensionalityReduction implements 
UnaryOperator<GridCoverage>, Ser
      * @see GridCoverage.Evaluator#setDefaultSlice(Map)
      */
     @SuppressWarnings("ReturnOfCollectionOrArrayField")     // Map is 
immutable.
-    public Map<Integer,Long> getSliceCoordinates() {
+    public Map<Integer, Long> getSliceCoordinates() {
         return sliceCoordinates;
     }
 
@@ -941,7 +941,7 @@ public class DimensionalityReduction implements 
UnaryOperator<GridCoverage>, Ser
         final GridExtent extent = sourceGeometry.getExtent();
         final int sourceDim = extent.getDimension();
         ArgumentChecks.ensureDimensionMatches("slicePoint", sourceDim, extent);
-        final Map<Integer,Long> slices = new HashMap<>();
+        final Map<Integer, Long> slices = new HashMap<>();
         for (int dim=0; dim < sourceDim; dim++) {
             final long low   = extent.getLow (dim);
             final long high  = extent.getHigh(dim);
@@ -951,7 +951,7 @@ public class DimensionalityReduction implements 
UnaryOperator<GridCoverage>, Ser
                 b = b.substring(1, b.length() - 1);   // Remove brackets.
                 throw new PointOutsideCoverageException(Resources.format(
                         Resources.Keys.GridCoordinateOutsideCoverage_4,
-                        extent.getAxisIdentification(dim,dim), low, high, b));
+                        extent.getAxisIdentification(dim, dim), low, high, b));
             }
             if (low != high && toReducedDimension(dim) < 0) {
                 slices.put(dim, value);
@@ -980,7 +980,7 @@ public class DimensionalityReduction implements 
UnaryOperator<GridCoverage>, Ser
         ArgumentChecks.ensureBetween("ratio", 0, 1, ratio);
         final GridExtent extent = sourceGeometry.getExtent();
         final int sourceDim = extent.getDimension();
-        final Map<Integer,Long> slices = new HashMap<>();
+        final Map<Integer, Long> slices = new HashMap<>();
         for (int dim=0; dim < sourceDim; dim++) {
             if (toReducedDimension(dim) < 0 && extent.getLow(dim) != 
extent.getHigh(dim)) {
                 slices.put(dim, extent.getRelative(dim, ratio));
diff --git 
a/endorsed/src/org.apache.sis.feature/main/org/apache/sis/coverage/grid/GridCoverage.java
 
b/endorsed/src/org.apache.sis.feature/main/org/apache/sis/coverage/grid/GridCoverage.java
index e428365373..d58dd22075 100644
--- 
a/endorsed/src/org.apache.sis.feature/main/org/apache/sis/coverage/grid/GridCoverage.java
+++ 
b/endorsed/src/org.apache.sis.feature/main/org/apache/sis/coverage/grid/GridCoverage.java
@@ -61,6 +61,12 @@ import org.opengis.coverage.CannotEvaluateException;
  * @since   1.0
  */
 public abstract class GridCoverage extends BandedCoverage {
+    /**
+     * A constant for making easier to identify codes working on two 
dimensional data.
+     * This is the minimal number of dimension required for {@link 
GridCoverage2D}.
+     */
+    static final int BIDIMENSIONAL = 2;
+
     /**
      * The processor to use in calls to {@link #convert(RenderedImage, 
DataType, MathTransform1D[], ImageProcessor)}.
      * Wrapped in a class for lazy instantiation.
diff --git 
a/endorsed/src/org.apache.sis.feature/main/org/apache/sis/coverage/grid/GridCoverage2D.java
 
b/endorsed/src/org.apache.sis.feature/main/org/apache/sis/coverage/grid/GridCoverage2D.java
index 14bf66550a..5e4188a2f1 100644
--- 
a/endorsed/src/org.apache.sis.feature/main/org/apache/sis/coverage/grid/GridCoverage2D.java
+++ 
b/endorsed/src/org.apache.sis.feature/main/org/apache/sis/coverage/grid/GridCoverage2D.java
@@ -95,12 +95,6 @@ import org.opengis.coverage.PointOutsideCoverageException;
  * @since   1.1
  */
 public class GridCoverage2D extends GridCoverage {
-    /**
-     * A constant for identifying code that relying on having 2 dimensions.
-     * This is the minimal number of dimension required for this coverage.
-     */
-    static final int BIDIMENSIONAL = 2;
-
     /**
      * The sample values stored as a {@code RenderedImage}.
      */
diff --git 
a/endorsed/src/org.apache.sis.feature/main/org/apache/sis/coverage/grid/GridCoverageProcessor.java
 
b/endorsed/src/org.apache.sis.feature/main/org/apache/sis/coverage/grid/GridCoverageProcessor.java
index b4b2f9a674..aa0ea843ee 100644
--- 
a/endorsed/src/org.apache.sis.feature/main/org/apache/sis/coverage/grid/GridCoverageProcessor.java
+++ 
b/endorsed/src/org.apache.sis.feature/main/org/apache/sis/coverage/grid/GridCoverageProcessor.java
@@ -346,7 +346,7 @@ public class GridCoverageProcessor implements Cloneable {
         if (value instanceof GridGeometry) {
             return (GridGeometry) value;
         }
-        return new ImageRenderer(coverage, 
null).getImageGeometry(GridCoverage2D.BIDIMENSIONAL);
+        return new ImageRenderer(coverage, 
null).getImageGeometry(GridCoverage.BIDIMENSIONAL);
     }
 
     /**
diff --git 
a/endorsed/src/org.apache.sis.feature/main/org/apache/sis/coverage/grid/GridExtent.java
 
b/endorsed/src/org.apache.sis.feature/main/org/apache/sis/coverage/grid/GridExtent.java
index e680141015..defb8b2b51 100644
--- 
a/endorsed/src/org.apache.sis.feature/main/org/apache/sis/coverage/grid/GridExtent.java
+++ 
b/endorsed/src/org.apache.sis.feature/main/org/apache/sis/coverage/grid/GridExtent.java
@@ -983,8 +983,8 @@ public class GridExtent implements GridEnvelope, 
LenientComparable, Serializable
      *
      * @since 1.3
      */
-    public SortedMap<Integer,Long> getSliceCoordinates() {
-        final var slice = new TreeMap<Integer,Long>();
+    public SortedMap<Integer, Long> getSliceCoordinates() {
+        final var slice = new TreeMap<Integer, Long>();
         final int dimension = getDimension();
         for (int i=0; i<dimension; i++) {
             final long value = coordinates[i];
@@ -1176,7 +1176,7 @@ public class GridExtent implements GridEnvelope, 
LenientComparable, Serializable
 
     /**
      * Returns the {@link #types} array or a default array of arbitrary length 
if {@link #types} is null.
-     * This method returns directly the arrays without cloning; do not modify.
+     * This method returns directly the arrays without cloning, <strong>do not 
modify</strong>.
      */
     final DimensionNameType[] getAxisTypes() {
         return (types != null) ? types : DEFAULT_TYPES;
diff --git 
a/endorsed/src/org.apache.sis.feature/main/org/apache/sis/coverage/grid/ImageRenderer.java
 
b/endorsed/src/org.apache.sis.feature/main/org/apache/sis/coverage/grid/ImageRenderer.java
index 8d293236cd..401c404991 100644
--- 
a/endorsed/src/org.apache.sis.feature/main/org/apache/sis/coverage/grid/ImageRenderer.java
+++ 
b/endorsed/src/org.apache.sis.feature/main/org/apache/sis/coverage/grid/ImageRenderer.java
@@ -60,6 +60,7 @@ import org.apache.sis.math.Vector;
 import static org.apache.sis.image.PlanarImage.XY_DIMENSIONS_KEY;
 import static org.apache.sis.image.PlanarImage.GRID_GEOMETRY_KEY;
 import static org.apache.sis.image.PlanarImage.SAMPLE_DIMENSIONS_KEY;
+import static org.apache.sis.coverage.grid.GridCoverage.BIDIMENSIONAL;
 
 // Specific to the geoapi-4.0 branch:
 import org.opengis.coordinate.MismatchedDimensionException;
@@ -123,7 +124,7 @@ public class ImageRenderer {
 
     /**
      * The dimensions to select in the grid coverage for producing an image. 
This is an array of length
-     * {@value GridCoverage2D#BIDIMENSIONAL} obtained by {@link 
GridExtent#getSubspaceDimensions(int)}.
+     * {@value GridCoverage#BIDIMENSIONAL} obtained by {@link 
GridExtent#getSubspaceDimensions(int)}.
      * The array content is almost always {0,1}, but this class should work 
with other dimensions too.
      *
      * @see #getXYDimensions()
@@ -318,7 +319,7 @@ public class ImageRenderer {
         } else {
             sliceExtent = source;
         }
-        gridDimensions  = 
sliceExtent.getSubspaceDimensions(GridCoverage2D.BIDIMENSIONAL);
+        gridDimensions  = sliceExtent.getSubspaceDimensions(BIDIMENSIONAL);
         final int  xd   = gridDimensions[0];
         final int  yd   = gridDimensions[1];
         final long xcov = source.getLow(xd);
@@ -451,7 +452,7 @@ public class ImageRenderer {
      */
     public GridGeometry getImageGeometry(final int dimCRS) {
         GridGeometry ig = imageGeometry;
-        if (ig == null || dimCRS != GridCoverage2D.BIDIMENSIONAL) {
+        if (ig == null || dimCRS != BIDIMENSIONAL) {
             if (imageUseSameGeometry(dimCRS)) {
                 ig = geometry;
             } else try {
@@ -460,7 +461,7 @@ public class ImageRenderer {
             } catch (FactoryException e) {
                 throw SliceGeometry.canNotCompute(e);
             }
-            if (dimCRS == GridCoverage2D.BIDIMENSIONAL) {
+            if (dimCRS == BIDIMENSIONAL) {
                 imageGeometry = ig;
             }
         }
@@ -486,7 +487,7 @@ public class ImageRenderer {
     public Object getProperty(final String key) {
         switch (key) {
             case XY_DIMENSIONS_KEY:     return getXYDimensions();
-            case GRID_GEOMETRY_KEY:     return 
getImageGeometry(GridCoverage2D.BIDIMENSIONAL);
+            case GRID_GEOMETRY_KEY:     return getImageGeometry(BIDIMENSIONAL);
             case SAMPLE_DIMENSIONS_KEY: return bands.clone();
         }
         return (properties != null) ? properties.get(key) : null;
@@ -529,7 +530,7 @@ public class ImageRenderer {
      */
     private boolean imageUseSameGeometry(final int dimCRS) {
         final int tgtDim = geometry.getTargetDimension();
-        ArgumentChecks.ensureBetween("dimCRS", GridCoverage2D.BIDIMENSIONAL, 
tgtDim, dimCRS);
+        ArgumentChecks.ensureBetween("dimCRS", BIDIMENSIONAL, tgtDim, dimCRS);
         if (tgtDim == dimCRS && geometry.getDimension() == 
gridDimensions.length) {
             final GridExtent extent = geometry.extent;
             if (sliceExtent == null) {
@@ -773,7 +774,7 @@ public class ImageRenderer {
         }
         SliceGeometry supplier = null;
         if (imageGeometry == null) {
-            if (imageUseSameGeometry(GridCoverage2D.BIDIMENSIONAL)) {
+            if (imageUseSameGeometry(BIDIMENSIONAL)) {
                 imageGeometry = geometry;
             } else {
                 supplier = new SliceGeometry(geometry, sliceExtent, 
gridDimensions, mtFactory);
diff --git 
a/endorsed/src/org.apache.sis.feature/main/org/apache/sis/coverage/grid/ReducedGridCoverage.java
 
b/endorsed/src/org.apache.sis.feature/main/org/apache/sis/coverage/grid/ReducedGridCoverage.java
index 61fbe9a64d..d9f7e32376 100644
--- 
a/endorsed/src/org.apache.sis.feature/main/org/apache/sis/coverage/grid/ReducedGridCoverage.java
+++ 
b/endorsed/src/org.apache.sis.feature/main/org/apache/sis/coverage/grid/ReducedGridCoverage.java
@@ -96,7 +96,7 @@ final class ReducedGridCoverage extends DerivedGridCoverage {
          * The slice where to perform evaluation, or {@code null} if not yet 
computed.
          * This is the cached value of {@link #getDefaultSlice()}.
          */
-        private Map<Integer,Long> slice;
+        private Map<Integer, Long> slice;
 
         /**
          * Creates a new evaluator wrapping the given source coverage 
evaluator.
@@ -123,9 +123,9 @@ final class ReducedGridCoverage extends DerivedGridCoverage 
{
          */
         @Override
         @SuppressWarnings("ReturnOfCollectionOrArrayField")     // Because the 
map is unmodifiable.
-        public Map<Integer,Long> getDefaultSlice() {
+        public Map<Integer, Long> getDefaultSlice() {
             if (slice == null) {
-                final var copy = new TreeMap<Integer,Long>();
+                final var copy = new TreeMap<Integer, Long>();
                 super.getDefaultSlice().forEach((dim, coord) -> {
                     dim = reduction.toReducedDimension(dim);
                     if (dim >= 0) copy.put(dim, coord);
@@ -141,12 +141,12 @@ final class ReducedGridCoverage extends 
DerivedGridCoverage {
          * @throws IllegalArgumentException if the map contains an illegal 
dimension or grid coordinate value.
          */
         @Override
-        public void setDefaultSlice(Map<Integer,Long> slice) {
+        public void setDefaultSlice(Map<Integer, Long> slice) {
             if (slice == null) {
                 GridGeometry origin = 
ReducedGridCoverage.this.source.getGridGeometry();
                 slice = origin.getExtent().getSliceCoordinates();
             } else {
-                final var copy = new TreeMap<Integer,Long>();
+                final var copy = new TreeMap<Integer, Long>();
                 slice.forEach((dim, coord) -> 
copy.put(reduction.toSourceDimension(dim), coord));
                 slice = copy;
             }
diff --git 
a/endorsed/src/org.apache.sis.feature/main/org/apache/sis/coverage/grid/ResampledGridCoverage.java
 
b/endorsed/src/org.apache.sis.feature/main/org/apache/sis/coverage/grid/ResampledGridCoverage.java
index 0ec7f0a33f..c387deaeb0 100644
--- 
a/endorsed/src/org.apache.sis.feature/main/org/apache/sis/coverage/grid/ResampledGridCoverage.java
+++ 
b/endorsed/src/org.apache.sis.feature/main/org/apache/sis/coverage/grid/ResampledGridCoverage.java
@@ -54,11 +54,6 @@ import org.opengis.coverage.CannotEvaluateException;
  * @author  Johann Sorel (Geomatys)
  */
 final class ResampledGridCoverage extends DerivedGridCoverage {
-    /**
-     * The {@value} constant for identifying code specific to the 
two-dimensional case.
-     */
-    private static final int BIDIMENSIONAL = 2;
-
     /**
      * The transform from cell coordinates in this coverage to cell 
coordinates in {@linkplain #source source} coverage.
      * Note that an offset may exist between cell coordinates and pixel 
coordinates, so some translations may need
diff --git 
a/endorsed/src/org.apache.sis.feature/main/org/apache/sis/coverage/grid/SliceGeometry.java
 
b/endorsed/src/org.apache.sis.feature/main/org/apache/sis/coverage/grid/SliceGeometry.java
index d57182f506..340382b850 100644
--- 
a/endorsed/src/org.apache.sis.feature/main/org/apache/sis/coverage/grid/SliceGeometry.java
+++ 
b/endorsed/src/org.apache.sis.feature/main/org/apache/sis/coverage/grid/SliceGeometry.java
@@ -108,7 +108,7 @@ final class SliceGeometry implements 
Function<RenderedImage, GridGeometry> {
     public GridGeometry apply(final RenderedImage image) {
         try {
             final GridExtent extent = new GridExtent(image.getMinX(), 
image.getMinY(), image.getWidth(), image.getHeight());
-            return reduce(extent, GridCoverage2D.BIDIMENSIONAL);
+            return reduce(extent, GridCoverage.BIDIMENSIONAL);
         } catch (FactoryException e) {
             throw canNotCompute(e);
         }
diff --git 
a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/geometry/CoordinateFormat.java
 
b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/geometry/CoordinateFormat.java
index 38f7b0de0f..1611183b07 100644
--- 
a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/geometry/CoordinateFormat.java
+++ 
b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/geometry/CoordinateFormat.java
@@ -544,9 +544,14 @@ public class CoordinateFormat extends 
CompoundFormat<DirectPosition> {
          *    - case 3: grid direction  — use NumberFormat configured for 
integers.
          *    - case 4: all other unit  — use NumberFormat + UnitFormat + 
[axis direction]
          */
-        final int      dimension = cs.getDimension();
-        final byte[]   types     = new byte  [dimension];
-        final Format[] formats   = new Format[dimension];
+        final int dimension = cs.getDimension();
+
+        @SuppressWarnings("LocalVariableHidesMemberVariable")
+        final var types = new byte[dimension];
+
+        @SuppressWarnings("LocalVariableHidesMemberVariable")
+        final var formats = new Format[dimension];
+
         for (int i=0; i<dimension; i++) {
             final CoordinateSystemAxis axis = cs.getAxis(i);
             if (axis == null) {                                               
// Paranoiac check.
diff --git 
a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/internal/shared/IntervalRectangle.java
 
b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/internal/shared/IntervalRectangle.java
index 3b7139e03c..29b3c415c8 100644
--- 
a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/internal/shared/IntervalRectangle.java
+++ 
b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/internal/shared/IntervalRectangle.java
@@ -527,10 +527,10 @@ public class IntervalRectangle extends Rectangle2D 
implements Serializable {
      * original rectangle and the specified point.
      *
      * <p>After adding a point, a call to {@code contains} with the added 
point as an argument
-     * does not necessarily return {@code true}. The {@code contains} method 
does not return
-     * {@code true} for points on the right or bottom edges of a rectangle. 
Therefore, if the
-     * added point falls on the left or bottom edge of the enlarged rectangle, 
{@code contains}
-     * returns {@code false} for that point.</p>
+     * does not necessarily return {@code true}. As per Java2D specification, 
the {@code contains}
+     * method does not consider as included the points on the right or bottom 
edges of a rectangle.
+     * Therefore, if the added point falls on the right or bottom edge of the 
enlarged rectangle,
+     * {@code contains} returns {@code false} for that point.</p>
      *
      * @param  x  x coordinate value of the point to add.
      * @param  y  y coordinate value of the point to add.

Reply via email to