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


The following commit(s) were added to refs/heads/geoapi-4.0 by this push:
     new 0cae00bc0e Delegate `AxisDirections.opposite(…)` to the GeoAPI method.
0cae00bc0e is described below

commit 0cae00bc0ede50fa44fba49109562af3bcac8021
Author: Martin Desruisseaux <martin.desruisse...@geomatys.com>
AuthorDate: Sun Jun 23 18:14:13 2024 +0200

    Delegate `AxisDirections.opposite(…)` to the GeoAPI method.
---
 .../org/apache/sis/coverage/grid/PixelInCell.java  |  3 ++
 .../sis/referencing/privy/AxisDirections.java      | 38 +++-------------------
 .../sis/referencing/privy/AxisDirectionsTest.java  |  2 +-
 3 files changed, 8 insertions(+), 35 deletions(-)

diff --git 
a/endorsed/src/org.apache.sis.feature/main/org/apache/sis/coverage/grid/PixelInCell.java
 
b/endorsed/src/org.apache.sis.feature/main/org/apache/sis/coverage/grid/PixelInCell.java
index 53a0e836ae..5b2b7a1f8d 100644
--- 
a/endorsed/src/org.apache.sis.feature/main/org/apache/sis/coverage/grid/PixelInCell.java
+++ 
b/endorsed/src/org.apache.sis.feature/main/org/apache/sis/coverage/grid/PixelInCell.java
@@ -115,6 +115,9 @@ public enum PixelInCell implements ControlledVocabulary {
      */
     @Override
     public String[] names() {
+        if (this == CELL_CENTER) {
+            return new String[] {name(), identifier, "cell centre"};
+        }
         return new String[] {name(), identifier};
     }
 
diff --git 
a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/privy/AxisDirections.java
 
b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/privy/AxisDirections.java
index aa443b4110..414d1a7a54 100644
--- 
a/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/privy/AxisDirections.java
+++ 
b/endorsed/src/org.apache.sis.referencing/main/org/apache/sis/referencing/privy/AxisDirections.java
@@ -17,7 +17,6 @@
 package org.apache.sis.referencing.privy;
 
 import java.util.Map;
-import java.util.HashMap;
 import java.util.Objects;
 import javax.measure.Unit;
 import javax.measure.quantity.Angle;
@@ -68,38 +67,6 @@ public final class AxisDirections extends Static {
      */
     private static final int LAST_ORDINAL = UNSPECIFIED.ordinal();
 
-    /**
-     * For each direction, the opposite direction.
-     * This map shall be immutable after construction.
-     */
-    private static final Map<AxisDirection,AxisDirection> OPPOSITES = new 
HashMap<>(24);
-    static {
-        put(UNSPECIFIED,       UNSPECIFIED);
-        put(NORTH,             SOUTH);
-        put(NORTH_NORTH_EAST,  SOUTH_SOUTH_WEST);
-        put(NORTH_EAST,        SOUTH_WEST);
-        put(EAST_NORTH_EAST,   WEST_SOUTH_WEST);
-        put(EAST,              WEST);
-        put(EAST_SOUTH_EAST,   WEST_NORTH_WEST);
-        put(SOUTH_EAST,        NORTH_WEST);
-        put(SOUTH_SOUTH_EAST,  NORTH_NORTH_WEST);
-        put(UP,                DOWN);
-        put(FUTURE,            PAST);
-        put(COLUMN_POSITIVE,   COLUMN_NEGATIVE);
-        put(ROW_POSITIVE,      ROW_NEGATIVE);
-        put(DISPLAY_RIGHT,     DISPLAY_LEFT);
-        put(DISPLAY_UP,        DISPLAY_DOWN);
-        put(COUNTER_CLOCKWISE, CLOCKWISE);
-    }
-
-    /**
-     * Stores the given directions in the {@link #OPPOSITES} array.
-     */
-    private static void put(final AxisDirection dir, final AxisDirection 
opposite) {
-        OPPOSITES.put(dir, opposite);
-        OPPOSITES.put(opposite, dir);
-    }
-
     /**
      * Proposed abbreviations for some axis directions.
      */
@@ -138,6 +105,7 @@ public final class AxisDirections extends Static {
      * <tr><td>{@code DISPLAY_RIGHT},   {@code DISPLAY_LEFT}</td>     
<td>{@code DISPLAY_RIGHT}</td></tr>
      * <tr><td>{@code DISPLAY_UP},      {@code DISPLAY_DOWN}</td>     
<td>{@code DISPLAY_UP}</td></tr>
      * <tr><td>{@code CLOCKWISE},       {@code COUNTERCLOCKWISE}</td> 
<td>{@code COUNTERCLOCKWISE}</td></tr>
+     * <tr><td>{@code AWAY_FROM},       {@code TOWARDS}</td>          
<td>{@code AWAY_FROM}</td></tr>
      * <tr><td>{@code OTHER}</td>                                     
<td>{@code OTHER}</td></tr>
      * </table>
      *
@@ -153,6 +121,8 @@ public final class AxisDirections extends Static {
             // Ordinal values do not have the desired order for this 
particular case.
             if (dir == CLOCKWISE) {
                 dir = COUNTER_CLOCKWISE;
+            } else if (dir == TOWARDS) {
+                dir = AWAY_FROM;
             }
         }
         return dir;
@@ -168,7 +138,7 @@ public final class AxisDirections extends Static {
      * @return the opposite direction, or {@code null} if none or unknown.
      */
     public static AxisDirection opposite(AxisDirection dir) {
-        return OPPOSITES.get(dir);
+        return (dir != null) ? dir.opposite().orElse(null) : null;
     }
 
     /**
diff --git 
a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/privy/AxisDirectionsTest.java
 
b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/privy/AxisDirectionsTest.java
index 8e12595bda..7b16e340ca 100644
--- 
a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/privy/AxisDirectionsTest.java
+++ 
b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/privy/AxisDirectionsTest.java
@@ -97,7 +97,7 @@ public final class AxisDirectionsTest extends TestCase {
         assertEquals(FUTURE,            AxisDirections.opposite(PAST));
         assertEquals(COUNTER_CLOCKWISE, AxisDirections.opposite(CLOCKWISE));
         assertEquals(CLOCKWISE,         
AxisDirections.opposite(COUNTER_CLOCKWISE));
-        assertNull  (                   AxisDirections.opposite(AWAY_FROM));
+        assertEquals(TOWARDS,           AxisDirections.opposite(AWAY_FROM));
     }
 
     /**

Reply via email to