sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1424364 - in /sis/branches/JDK7/sis-referencing/src: main/java/org/apache/sis/geometry/ test/java/org/apache/sis/geometry/
Date Thu, 20 Dec 2012 08:25:36 GMT
Author: desruisseaux
Date: Thu Dec 20 08:25:36 2012
New Revision: 1424364

URL: http://svn.apache.org/viewvc?rev=1424364&view=rev
Log:
Lower/UpperCorner of GeneralEnvelope are now read/write views.

Modified:
    sis/branches/JDK7/sis-referencing/src/main/java/org/apache/sis/geometry/AbstractEnvelope.java
    sis/branches/JDK7/sis-referencing/src/main/java/org/apache/sis/geometry/Envelope2D.java
    sis/branches/JDK7/sis-referencing/src/main/java/org/apache/sis/geometry/GeneralEnvelope.java
    sis/branches/JDK7/sis-referencing/src/test/java/org/apache/sis/geometry/GeneralEnvelopeTest.java

Modified: sis/branches/JDK7/sis-referencing/src/main/java/org/apache/sis/geometry/AbstractEnvelope.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-referencing/src/main/java/org/apache/sis/geometry/AbstractEnvelope.java?rev=1424364&r1=1424363&r2=1424364&view=diff
==============================================================================
--- sis/branches/JDK7/sis-referencing/src/main/java/org/apache/sis/geometry/AbstractEnvelope.java
(original)
+++ sis/branches/JDK7/sis-referencing/src/main/java/org/apache/sis/geometry/AbstractEnvelope.java
Thu Dec 20 08:25:36 2012
@@ -28,6 +28,7 @@ import org.opengis.geometry.Envelope;
 import org.opengis.geometry.DirectPosition;
 import org.opengis.geometry.MismatchedDimensionException;
 import org.opengis.geometry.MismatchedReferenceSystemException;
+import org.opengis.geometry.UnmodifiableGeometryException;
 import org.opengis.referencing.crs.CoordinateReferenceSystem;
 import org.opengis.referencing.cs.CoordinateSystemAxis;
 import org.opengis.referencing.cs.CoordinateSystem;
@@ -233,9 +234,12 @@ public abstract class AbstractEnvelope i
     }
 
     /**
-     * A coordinate position consisting of all the {@linkplain #getLower(int) lower ordinates}.
-     * The default implementation returns a unmodifiable direct position backed by this envelope,
+     * A coordinate position consisting of all the lower ordinate values.
+     * The default implementation returns a view over the {@link #getLower(int)} method,
      * so changes in this envelope will be immediately reflected in the returned direct position.
+     * If the particular case of the {@code GeneralEnvelope} subclass, the returned position
+     * supports also {@linkplain DirectPosition#setOrdinate(int, double) write operations},
+     * so changes in the position are reflected back in the envelope.
      *
      * {@note The <cite>Web Coverage Service</cite> (WCS) 1.1 specification uses
an extended
      * interpretation of the bounding box definition. In a WCS 1.1 data structure, the lower
@@ -245,7 +249,7 @@ public abstract class AbstractEnvelope i
      * longitude greater than the upper corner longitude. Such extended interpretation applies
      * mostly to axes having <code>WRAPAROUND</code> range meaning.}
      *
-     * @return The lower corner, typically (but not necessarily) containing minimal ordinate
values.
+     * @return A view over the lower corner, typically (but not necessarily) containing minimal
ordinate values.
      */
     @Override
     public DirectPosition getLowerCorner() {
@@ -255,9 +259,12 @@ public abstract class AbstractEnvelope i
     }
 
     /**
-     * A coordinate position consisting of all the {@linkplain #getUpper(int) upper ordinates}.
-     * The default implementation returns a unmodifiable direct position backed by this envelope,
+     * A coordinate position consisting of all the upper ordinate values.
+     * The default implementation returns a view over the {@link #getUpper(int)} method,
      * so changes in this envelope will be immediately reflected in the returned direct position.
+     * If the particular case of the {@code GeneralEnvelope} subclass, the returned position
+     * supports also {@linkplain DirectPosition#setOrdinate(int, double) write operations},
+     * so changes in the position are reflected back in the envelope.
      *
      * {@note The <cite>Web Coverage Service</cite> (WCS) 1.1 specification uses
an extended
      * interpretation of the bounding box definition. In a WCS 1.1 data structure, the upper
@@ -267,7 +274,7 @@ public abstract class AbstractEnvelope i
      * longitude less than the lower corner longitude. Such extended interpretation applies
      * mostly to axes having <code>WRAPAROUND</code> range meaning.}
      *
-     * @return The upper corner, typically (but not necessarily) containing maximal ordinate
values.
+     * @return A view over the upper corner, typically (but not necessarily) containing maximal
ordinate values.
      */
     @Override
     public DirectPosition getUpperCorner() {
@@ -277,8 +284,8 @@ public abstract class AbstractEnvelope i
     }
 
     /**
-     * A coordinate position consisting of all the {@linkplain #getMedian(int) middle ordinates}.
-     * The default implementation returns a unmodifiable direct position backed by this envelope,
+     * A coordinate position consisting of all the median ordinate values.
+     * The default implementation returns a view over the {@link #getMedian(int)} method,
      * so changes in this envelope will be immediately reflected in the returned direct position.
      *
      * @return The median coordinates.
@@ -979,11 +986,6 @@ public abstract class AbstractEnvelope i
         @Override public final int getDimension() {
             return AbstractEnvelope.this.getDimension();
         }
-
-        /** Sets the ordinate value along the specified dimension. */
-        @Override public final void setOrdinate(int dimension, double value) {
-            throw new UnsupportedOperationException();
-        }
     }
 
     /**
@@ -995,6 +997,11 @@ public abstract class AbstractEnvelope i
         @Override public double getOrdinate(final int dimension) throws IndexOutOfBoundsException
{
             return getLower(dimension);
         }
+
+        /** Sets the ordinate value along the specified dimension. */
+        @Override public void setOrdinate(final int dimension, final double value) {
+            setRange(dimension, value, getUpper(dimension));
+        }
     }
 
     /**
@@ -1006,6 +1013,11 @@ public abstract class AbstractEnvelope i
         @Override public double getOrdinate(final int dimension) throws IndexOutOfBoundsException
{
             return getUpper(dimension);
         }
+
+        /** Sets the ordinate value along the specified dimension. */
+        @Override public void setOrdinate(final int dimension, final double value) {
+            setRange(dimension, getLower(dimension), value);
+        }
     }
 
     /**
@@ -1017,5 +1029,30 @@ public abstract class AbstractEnvelope i
         @Override public double getOrdinate(final int dimension) throws IndexOutOfBoundsException
{
             return getMedian(dimension);
         }
+
+        /** Unsupported operation. */
+        @Override public void setOrdinate(int dimension, double value) {
+            throw new UnmodifiableGeometryException(Errors.format(Errors.Keys.UnmodifiableObject_1,
getClass()));
+        }
+    }
+
+    /**
+     * Invoked by {@link LowerCorner} and {@link UpperCorner} when a coordinate is modified.
+     * The default implementation throws an {@link UnmodifiableGeometryException} in every
cases.
+     * This method is overridden and made public by {@link GeneralGeometry}.
+     *
+     * <p>The declaration in this {@code AbstractEnvelope} class is not public on purpose,
+     * since this class intentionally have no public setter methods. This is necessary for
+     * preserving the immutable aspect of {@link ImmutableEnvelope} subclass among others.</p>
+     *
+     * @param  dimension The dimension to set.
+     * @param  lower     The limit in the direction of decreasing ordinate values.
+     * @param  upper     The limit in the direction of increasing ordinate values.
+     * @throws IndexOutOfBoundsException If the given index is out of bounds.
+     */
+    void setRange(final int dimension, final double lower, final double upper)
+            throws IndexOutOfBoundsException
+    {
+        throw new UnmodifiableGeometryException(Errors.format(Errors.Keys.UnmodifiableObject_1,
getClass()));
     }
 }

Modified: sis/branches/JDK7/sis-referencing/src/main/java/org/apache/sis/geometry/Envelope2D.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-referencing/src/main/java/org/apache/sis/geometry/Envelope2D.java?rev=1424364&r1=1424363&r2=1424364&view=diff
==============================================================================
--- sis/branches/JDK7/sis-referencing/src/main/java/org/apache/sis/geometry/Envelope2D.java
(original)
+++ sis/branches/JDK7/sis-referencing/src/main/java/org/apache/sis/geometry/Envelope2D.java
Thu Dec 20 08:25:36 2012
@@ -287,6 +287,9 @@ public class Envelope2D extends Rectangl
      * This is typically a coordinate position consisting of the minimal ordinates for
      * the two dimensions for all points within the {@code Envelope}.
      *
+     * <p>The object returned by this method is a copy. Change in the returned position
+     * will not affect this envelope, and conversely.</p>
+     *
      * {@note The <cite>Web Coverage Service</cite> (WCS) 1.1 specification uses
an extended
      * interpretation of the bounding box definition. In a WCS 1.1 data structure, the lower
      * corner defines the edges region in the directions of <em>decreasing</em>
coordinate
@@ -295,7 +298,7 @@ public class Envelope2D extends Rectangl
      * longitude greater than the upper corner longitude. Such extended interpretation applies
      * mostly to axes having <code>WRAPAROUND</code> range meaning.}
      *
-     * @return The lower corner, typically (but not necessarily) containing minimal ordinate
values.
+     * @return A copy of the lower corner, typically (but not necessarily) containing minimal
ordinate values.
      */
     @Override
     public DirectPosition2D getLowerCorner() {
@@ -307,6 +310,9 @@ public class Envelope2D extends Rectangl
      * This is typically a coordinate position consisting of the maximal ordinates for
      * the two dimensions for all points within the {@code Envelope}.
      *
+     * <p>The object returned by this method is a copy. Change in the returned position
+     * will not affect this envelope, and conversely.</p>
+     *
      * {@note The <cite>Web Coverage Service</cite> (WCS) 1.1 specification uses
an extended
      * interpretation of the bounding box definition. In a WCS 1.1 data structure, the upper
      * corner defines the edges region in the directions of <em>increasing</em>
coordinate
@@ -315,7 +321,7 @@ public class Envelope2D extends Rectangl
      * longitude less than the lower corner longitude. Such extended interpretation applies
      * mostly to axes having <code>WRAPAROUND</code> range meaning.}
      *
-     * @return The upper corner, typically (but not necessarily) containing maximal ordinate
values.
+     * @return A copy of the upper corner, typically (but not necessarily) containing maximal
ordinate values.
      */
     @Override
     public DirectPosition2D getUpperCorner() {
@@ -499,8 +505,6 @@ public class Envelope2D extends Rectangl
      * {@link java.lang.Double#NaN NaN}, then the envelope is considered empty.
      * This is different than the default {@link java.awt.geom.Rectangle2D.Double#isEmpty()}
      * implementation, which doesn't check for {@code NaN} values.
-     *
-     * @since 3.20
      */
     @Override
     public boolean isEmpty() {
@@ -521,8 +525,6 @@ public class Envelope2D extends Rectangl
      * @param  py The second ordinate value of the point to text.
      * @return {@code true} if the specified coordinate is inside the boundary
      *         of this envelope; {@code false} otherwise.
-     *
-     * @since 3.20
      */
     @Override
     public boolean contains(final double px, final double py) {
@@ -549,8 +551,6 @@ public class Envelope2D extends Rectangl
      *
      * @param  rect The rectangle to test for inclusion.
      * @return {@code true} if this envelope completely encloses the specified rectangle.
-     *
-     * @since 3.20
      */
     @Override
     public boolean contains(final Rectangle2D rect) {
@@ -576,8 +576,6 @@ public class Envelope2D extends Rectangl
      * @param  rw The width of the rectangle to test for inclusion. May be negative if the
rectangle spans the anti-meridian.
      * @param  rh The height of the rectangle to test for inclusion. May be negative.
      * @return {@code true} if this envelope completely encloses the specified one.
-     *
-     * @since 3.20
      */
     @Override
     public boolean contains(final double rx, final double ry, final double rw, final double
rh) {
@@ -622,8 +620,6 @@ public class Envelope2D extends Rectangl
      *
      * @param  rect The rectangle to test for intersection.
      * @return {@code true} if this envelope intersects the specified rectangle.
-     *
-     * @since 3.20
      */
     @Override
     public boolean intersects(final Rectangle2D rect) {

Modified: sis/branches/JDK7/sis-referencing/src/main/java/org/apache/sis/geometry/GeneralEnvelope.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-referencing/src/main/java/org/apache/sis/geometry/GeneralEnvelope.java?rev=1424364&r1=1424363&r2=1424364&view=diff
==============================================================================
--- sis/branches/JDK7/sis-referencing/src/main/java/org/apache/sis/geometry/GeneralEnvelope.java
(original)
+++ sis/branches/JDK7/sis-referencing/src/main/java/org/apache/sis/geometry/GeneralEnvelope.java
Thu Dec 20 08:25:36 2012
@@ -263,17 +263,18 @@ public class GeneralEnvelope extends Arr
      * Sets the envelope range along the specified dimension.
      *
      * @param  dimension The dimension to set.
-     * @param  minimum   The minimum value along the specified dimension.
-     * @param  maximum   The maximum value along the specified dimension.
+     * @param  lower     The limit in the direction of decreasing ordinate values.
+     * @param  upper     The limit in the direction of increasing ordinate values.
      * @throws IndexOutOfBoundsException If the given index is out of bounds.
      */
-    public void setRange(final int dimension, final double minimum, final double maximum)
+    @Override
+    public void setRange(final int dimension, final double lower, final double upper)
             throws IndexOutOfBoundsException
     {
         final int d = ordinates.length >>> 1;
         ensureValidIndex(d, dimension);
-        ordinates[dimension + d] = maximum;
-        ordinates[dimension]     = minimum;
+        ordinates[dimension + d] = upper;
+        ordinates[dimension]     = lower;
     }
 
     /**

Modified: sis/branches/JDK7/sis-referencing/src/test/java/org/apache/sis/geometry/GeneralEnvelopeTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-referencing/src/test/java/org/apache/sis/geometry/GeneralEnvelopeTest.java?rev=1424364&r1=1424363&r2=1424364&view=diff
==============================================================================
--- sis/branches/JDK7/sis-referencing/src/test/java/org/apache/sis/geometry/GeneralEnvelopeTest.java
(original)
+++ sis/branches/JDK7/sis-referencing/src/test/java/org/apache/sis/geometry/GeneralEnvelopeTest.java
Thu Dec 20 08:25:36 2012
@@ -356,6 +356,20 @@ public final strictfp class GeneralEnvel
     }
 
     /**
+     * Tests modifying the corner of an envelope.
+     */
+    @Test
+    public void testCornerModifications() {
+        final GeneralEnvelope e = create(2, -2, 3, -3);
+        e.getLowerCorner().setOrdinate(0,  1);
+        e.getUpperCorner().setOrdinate(1, -1);
+        assertEquals( 1.0, e.getLower(0), 0.0);
+        assertEquals(-2.0, e.getLower(1), 0.0);
+        assertEquals( 3.0, e.getUpper(0), 0.0);
+        assertEquals(-1.0, e.getUpper(1), 0.0);
+    }
+
+    /**
      * Tests the {@link GeneralEnvelope#GeneralEnvelope(String)} constructor.
      */
     @Test



Mime
View raw message