sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1535134 - in /sis/branches/JDK7/core: sis-metadata/src/main/java/org/apache/sis/metadata/iso/extent/ sis-metadata/src/test/java/org/apache/sis/metadata/iso/extent/ sis-referencing/src/main/java/org/apache/sis/referencing/datum/
Date Wed, 23 Oct 2013 19:43:25 GMT
Author: desruisseaux
Date: Wed Oct 23 19:43:25 2013
New Revision: 1535134

URL: http://svn.apache.org/r1535134
Log:
Added a null-safe Extents.intersection(GeographicBoundingBox, GeographicBoundingBox) convenience
method.

Modified:
    sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/extent/DefaultGeographicBoundingBox.java
    sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/extent/Extents.java
    sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/extent/package-info.java
    sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/extent/ExtentsTest.java
    sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultEllipsoid.java

Modified: sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/extent/DefaultGeographicBoundingBox.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/extent/DefaultGeographicBoundingBox.java?rev=1535134&r1=1535133&r2=1535134&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/extent/DefaultGeographicBoundingBox.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/extent/DefaultGeographicBoundingBox.java
[UTF-8] Wed Oct 23 19:43:25 2013
@@ -432,8 +432,11 @@ public class DefaultGeographicBoundingBo
      * The {@linkplain #getInclusion() inclusion} status must be the same for both boxes.
      *
      * @param box The geographic bounding box to intersect with this box.
+     * @throws IllegalArgumentException If the inclusion status is not the same for both
boxes.
+     *
+     * @see Extents#intersection(GeographicBoundingBox, GeographicBoundingBox)
      */
-    public void intersect(final GeographicBoundingBox box) {
+    public void intersect(final GeographicBoundingBox box) throws IllegalArgumentException
{
         checkWritePermission();
         if (MetadataUtilities.getInclusion(    getInclusion()) !=
             MetadataUtilities.getInclusion(box.getInclusion()))

Modified: sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/extent/Extents.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/extent/Extents.java?rev=1535134&r1=1535133&r2=1535134&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/extent/Extents.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/extent/Extents.java
[UTF-8] Wed Oct 23 19:43:25 2013
@@ -112,11 +112,35 @@ public final class Extents extends Stati
     }
 
     /**
+     * Returns the intersection of the given geographic bounding boxes. If any of the arguments
is {@code null},
+     * then this method returns the other argument. If both argument are non-null, then this
method returns a
+     * new box which is the intersection of the two given boxes.
+     *
+     * @param  b1 The first bounding box, or {@code null}.
+     * @param  b2 The second bounding box, or {@code null}.
+     * @return The intersection (may be any of the {@code b1} or {@code b2} argument if unchanged),
+     *         or {@code null} if the two given boxes are null.
+     * @throws IllegalArgumentException If the {@linkplain DefaultGeographicBoundingBox#getInclusion()
inclusion status}
+     *         is not the same for both boxes.
+     *
+     * @see DefaultGeographicBoundingBox#intersect(GeographicBoundingBox)
+     *
+     * @since 0.4
+     */
+    public static GeographicBoundingBox intersection(final GeographicBoundingBox b1, final
GeographicBoundingBox b2) {
+        if (b1 == null) return b2;
+        if (b2 == null) return b1;
+        final DefaultGeographicBoundingBox box = new DefaultGeographicBoundingBox(b1);
+        box.intersect(b2);
+        return box;
+    }
+
+    /**
      * Returns an <em>estimation</em> of the area (in square metres) of the given
bounding box.
      * Since {@code GeographicBoundingBox} provides only approximative information (for example
-     * they do not specify the datum), the value returned by this method is also approximative.
+     * it does not specify the datum), the value returned by this method is also approximative.
      *
-     * <p>The current implementation assumes the
+     * <p>The current implementation performs its computation on the
      * {@linkplain org.apache.sis.referencing.GeodeticObjects#SPHERE GRS 1980 Authalic Sphere}.
      * However this may change in any future SIS version.</p>
      *

Modified: sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/extent/package-info.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/extent/package-info.java?rev=1535134&r1=1535133&r2=1535134&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/extent/package-info.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/extent/package-info.java
[UTF-8] Wed Oct 23 19:43:25 2013
@@ -57,6 +57,16 @@
  *       getGeographicBoundingBox(Extent)}
  *       for extracting a global geographic bounding box.</li>
  *     </ul>
+ *     <ul>
+ *       <li>{@link org.apache.sis.metadata.iso.extent.Extents#intersection
+ *       intersection(GeographicBoundingBox, GeographicBoundingBox)}
+ *       for computing the intersection of two geographic bounding boxes, which may be null.</li>
+ *     </ul>
+ *     <ul>
+ *       <li>{@link org.apache.sis.metadata.iso.extent.Extents#area
+ *       area(GeographicBoundingBox)}
+ *       for estimating the area of a geographic bounding box.</li>
+ *     </ul>
  *   </li>
  *   <li>{@link org.apache.sis.metadata.iso.extent.DefaultGeographicBoundingBox}
  *     <ul>

Modified: sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/extent/ExtentsTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/extent/ExtentsTest.java?rev=1535134&r1=1535133&r2=1535134&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/extent/ExtentsTest.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/extent/ExtentsTest.java
[UTF-8] Wed Oct 23 19:43:25 2013
@@ -39,13 +39,27 @@ public final strictfp class ExtentsTest 
     private static final double MINUTE = 1./60;
 
     /**
+     * Tests {@link Extents#intersection(GeographicBoundingBox, GeographicBoundingBox)}.
+     */
+    @Test
+    public void testIntersection() {
+        final GeographicBoundingBox b1 = new DefaultGeographicBoundingBox(10, 20, 30, 40);
+        final GeographicBoundingBox b2 = new DefaultGeographicBoundingBox(15, 25, 26, 32);
+        assertEquals(new DefaultGeographicBoundingBox(15, 20, 30, 32), Extents.intersection(b1,
b2));
+        assertSame(b1, Extents.intersection(b1,   null));
+        assertSame(b2, Extents.intersection(null, b2));
+        assertNull(    Extents.intersection(null, null));
+    }
+
+    /**
      * Tests {@link Extents#area(GeographicBoundingBox)}.
      */
     @Test
-    public void testGetArea() {
+    public void testArea() {
         /*
-         * The nautical mile is equals to the length of 1 second of arc along meridians or
parallels at the equator.
-         * Since we are using the GRS80 authalic sphere instead than WGS84, we have a slight
empirical shift.
+         * The nautical mile is equals to the length of 1 second of arc along a meridian
or parallel at the equator.
+         * Since we are using the GRS80 authalic sphere instead than WGS84, and since the
nautical mile definition
+         * itself is a little bit approximative, we add a slight empirical shift.
          */
         final DefaultGeographicBoundingBox box = new DefaultGeographicBoundingBox(10, 10+MINUTE,
2.9685, 2.9685+MINUTE);
         assertEquals(NAUTICAL_MILE * NAUTICAL_MILE, Extents.area(box), 0.1);

Modified: sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultEllipsoid.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultEllipsoid.java?rev=1535134&r1=1535133&r2=1535134&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultEllipsoid.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/datum/DefaultEllipsoid.java
[UTF-8] Wed Oct 23 19:43:25 2013
@@ -386,6 +386,8 @@ public class DefaultEllipsoid extends Ab
      * The radius is expressed in {@linkplain #getAxisUnit() axis linear unit}.
      *
      * @return The radius of a sphere having the same surface than this ellipsoid.
+     *
+     * @see org.apache.sis.referencing.GeodeticObjects#SPHERE
      */
     public double getAuthalicRadius() {
         return Formulas.getAuthalicRadius(getSemiMajorAxis(), getSemiMinorAxis());



Mime
View raw message