Author: desruisseaux
Date: Mon Dec 17 08:01:00 2012
New Revision: 1422782
URL: http://svn.apache.org/viewvc?rev=1422782&view=rev
Log:
Ported some (not all) of GeneralEnvelopeTest.
Some tests are disabled for now because we need a CRS:84 instance to run them.
Added:
sis/branches/JDK7/sis-referencing/src/test/java/org/apache/sis/geometry/GeneralEnvelopeTest.java
(with props)
Modified:
sis/branches/JDK7/sis-referencing/src/main/java/org/apache/sis/geometry/ArrayEnvelope.java
sis/branches/JDK7/sis-referencing/src/main/java/org/apache/sis/geometry/ImmutableEnvelope.java
sis/branches/JDK7/sis-referencing/src/test/java/org/apache/sis/geometry/AbstractEnvelopeTest.java
Modified: sis/branches/JDK7/sis-referencing/src/main/java/org/apache/sis/geometry/ArrayEnvelope.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-referencing/src/main/java/org/apache/sis/geometry/ArrayEnvelope.java?rev=1422782&r1=1422781&r2=1422782&view=diff
==============================================================================
--- sis/branches/JDK7/sis-referencing/src/main/java/org/apache/sis/geometry/ArrayEnvelope.java
(original)
+++ sis/branches/JDK7/sis-referencing/src/main/java/org/apache/sis/geometry/ArrayEnvelope.java
Mon Dec 17 08:01:00 2012
@@ -210,7 +210,7 @@ class ArrayEnvelope extends AbstractEnve
double[] maximum = new double[dimLimit];
int dimension = 0;
int c;
-scan: for (int i=CharSequences.skipLeadingWhitespaces(wkt, 0, length); i<length; c+=Character.charCount(c))
{
+scan: for (int i=CharSequences.skipLeadingWhitespaces(wkt, 0, length); i<length; i+=Character.charCount(c))
{
c = Character.codePointAt(wkt, i);
if (Character.isUnicodeIdentifierStart(c)) {
do {
Modified: sis/branches/JDK7/sis-referencing/src/main/java/org/apache/sis/geometry/ImmutableEnvelope.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-referencing/src/main/java/org/apache/sis/geometry/ImmutableEnvelope.java?rev=1422782&r1=1422781&r2=1422782&view=diff
==============================================================================
--- sis/branches/JDK7/sis-referencing/src/main/java/org/apache/sis/geometry/ImmutableEnvelope.java
(original)
+++ sis/branches/JDK7/sis-referencing/src/main/java/org/apache/sis/geometry/ImmutableEnvelope.java
Mon Dec 17 08:01:00 2012
@@ -65,6 +65,23 @@ public final class ImmutableEnvelope ext
}
/**
+ * Constructs an envelope defined by two sequences of ordinate values.
+ *
+ * @param lowerCorner Lower ordinate values.
+ * @param upperCorner Upper ordinate values.
+ * @param crs The CRS to assign to this envelope, or {@code null}.
+ * @throws MismatchedDimensionException If the two sequences do not have the same length,
or
+ * if the dimension of the given CRS is not equals to the dimension of the given
corners.
+ */
+ public ImmutableEnvelope(final double[] lowerCorner, final double[] upperCorner,
+ final CoordinateReferenceSystem crs) throws MismatchedDimensionException
+ {
+ super(lowerCorner, upperCorner);
+ this.crs = crs;
+ AbstractDirectPosition.ensureDimensionMatch(crs, getDimension());
+ }
+
+ /**
* Constructs a new envelope with the same data than the specified geographic bounding
box.
* The coordinate reference system is set to {@code "CRS:84"}.
*
@@ -97,8 +114,8 @@ public final class ImmutableEnvelope ext
* <p>The main purpose of this method is to assign a non-null CRS when the envelope
to
* copy has a null CRS.</p>
*
- * @param envelope The envelope from which to copy ordinate values.
- * @param crs The CRS to assign to this envelope, or {@code null}.
+ * @param envelope The envelope from which to copy ordinate values.
+ * @param crs The CRS to assign to this envelope, or {@code null}.
* @throws MismatchedDimensionException If the dimension of the given CRS is not equals
* to the dimension of the given envelope.
*/
Modified: sis/branches/JDK7/sis-referencing/src/test/java/org/apache/sis/geometry/AbstractEnvelopeTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-referencing/src/test/java/org/apache/sis/geometry/AbstractEnvelopeTest.java?rev=1422782&r1=1422781&r2=1422782&view=diff
==============================================================================
--- sis/branches/JDK7/sis-referencing/src/test/java/org/apache/sis/geometry/AbstractEnvelopeTest.java
(original)
+++ sis/branches/JDK7/sis-referencing/src/test/java/org/apache/sis/geometry/AbstractEnvelopeTest.java
Mon Dec 17 08:01:00 2012
@@ -66,7 +66,7 @@ public final strictfp class AbstractEnve
return envelope;
}
case IMMUTABLE: {
- // TODO return new ImmutableEnvelope(xmin, xmax, ymin, ymax, null);
+ return new ImmutableEnvelope(new double[] {xmin, ymin}, new double[] {xmax,
ymax}, null);
}
case RECTANGLE: {
return new Envelope2D(xmin, ymin, xmax - xmin, ymax - ymin, null);
Added: 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=1422782&view=auto
==============================================================================
--- sis/branches/JDK7/sis-referencing/src/test/java/org/apache/sis/geometry/GeneralEnvelopeTest.java
(added)
+++ sis/branches/JDK7/sis-referencing/src/test/java/org/apache/sis/geometry/GeneralEnvelopeTest.java
Mon Dec 17 08:01:00 2012
@@ -0,0 +1,489 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sis.geometry;
+
+import org.opengis.geometry.Envelope;
+import org.opengis.geometry.DirectPosition;
+import org.apache.sis.test.DependsOn;
+import org.apache.sis.test.TestCase;
+import org.junit.Ignore;
+import org.junit.Test;
+
+import static java.lang.Double.NaN;
+import static org.apache.sis.referencing.Assert.*;
+import static org.apache.sis.math.MathFunctions.isNegative;
+
+
+/**
+ * Tests the {@link GeneralEnvelope} class. The {@link Envelope2D} class will also be tested
as a
+ * side effect, because it is used for comparison purpose. Note that {@link AbstractEnvelopeTest}
+ * already tested {@code contains} and {@code intersects} methods, so this test file will
focus on
+ * other methods.
+ *
+ * @author Martin Desruisseaux (IRD, Geomatys)
+ * @author Johann Sorel (Geomatys)
+ * @since 0.3 (derived from geotk-2.4)
+ * @version 0.3
+ * @module
+ */
+@DependsOn(AbstractEnvelopeTest.class)
+public final strictfp class GeneralEnvelopeTest extends TestCase {
+ /**
+ * The comparison threshold for strict comparisons.
+ */
+ private static final double STRICT = 0;
+
+ /**
+ * Tolerance threshold for floating point comparisons.
+ */
+ private static final double EPS = 1E-4;
+
+ /**
+ * Creates a new geographic envelope for the given ordinate values.
+ */
+ private static GeneralEnvelope create(final double xmin, final double ymin, final double
xmax, final double ymax) {
+ final GeneralEnvelope envelope = new GeneralEnvelope(2);
+ envelope.setEnvelope(xmin, ymin, xmax, ymax);
+ return envelope;
+ }
+
+ /**
+ * Asserts that the given two-dimensional envelope is equals to the given rectangle.
+ * The {@code xLower} and {@code xUpper} arguments are the <var>x</var> ordinate
values
+ * for the lower and upper corners respectively. The actual {@code xmin} and {@code ymin}
+ * values will be inferred from those corners.
+ *
+ * <p>This method assumes that only the <var>x</var> axis may be a
wraparound axis.</p>
+ *
+ * @param test The actual envelope to verify.
+ * @param xLower The expected first <var>x</var> ordinate value. May be
greater than {@code xUpper}.
+ * @param xUpper The expected last <var>x</var> ordinate value. May be
less than {@code xLower}.
+ * @param ymin The expected minimal <var>y</var> ordinate value. Must be
less than {@code ymax}.
+ * @param ymax The expected maximal <var>y</var> ordinate value. Must be
greater than {@code ymax}.
+ */
+ private static void assertEnvelopeEquals(final Envelope test,
+ final double xLower, final double ymin, final double xUpper, final double ymax)
+ {
+ final double xmin, xmax;
+ if (isNegative(xUpper - xLower)) { // Check for anti-meridian spanning.
+ xmin = -180;
+ xmax = +180;
+ } else {
+ xmin = xLower;
+ xmax = xUpper;
+ }
+ final DirectPosition lower = test.getLowerCorner();
+ final DirectPosition upper = test.getUpperCorner();
+ assertEquals("lower", xLower, lower.getOrdinate(0), STRICT);
+ assertEquals("upper", xUpper, upper.getOrdinate(0), STRICT);
+ assertEquals("xmin", xmin, test .getMinimum (0), STRICT);
+ assertEquals("xmax", xmax, test .getMaximum (0), STRICT);
+ assertEquals("ymin", ymin, test .getMinimum (1), STRICT);
+ assertEquals("ymax", ymax, test .getMaximum (1), STRICT);
+ assertEquals("ymin", ymin, lower.getOrdinate(1), STRICT);
+ assertEquals("ymax", ymax, upper.getOrdinate(1), STRICT);
+ if (test instanceof Envelope2D) {
+ final Envelope2D ri = (Envelope2D) test;
+ assertEquals("xmin", xmin, ri.getMinX(), STRICT);
+ assertEquals("xmax", xmax, ri.getMaxX(), STRICT);
+ assertEquals("ymin", ymin, ri.getMinY(), STRICT);
+ assertEquals("ymax", ymax, ri.getMaxY(), STRICT);
+ }
+ }
+
+ /**
+ * Asserts that the intersection of the two following envelopes is equals to the given
rectangle.
+ * First, this method tests using the {@link Envelope2D} implementation. Then, it tests
using the
+ * {@link GeneralEnvelope} implementation.
+ */
+ private static void assertIntersectEquals(final GeneralEnvelope e1, final GeneralEnvelope
e2,
+ final double xmin, final double ymin, final double xmax, final double ymax)
+ {
+ final boolean isEmpty = !(((xmax - xmin) * (ymax - ymin)) != 0); // Use ! for catching
NaN.
+ final Envelope2D r1 = new Envelope2D(e1);
+ final Envelope2D r2 = new Envelope2D(e2);
+ final Envelope2D ri = r1.createIntersection(r2);
+ assertEquals("isEmpty", isEmpty, r1.isEmpty());
+ assertEnvelopeEquals(ri, xmin, ymin, xmax, ymax);
+ assertEquals("Interchanged arguments.", ri, r2.createIntersection(r1));
+
+ // Compares with GeneralEnvelope.
+ final GeneralEnvelope ei = new GeneralEnvelope(e1);
+ ei.intersect(e2);
+ assertEquals("isEmpty", isEmpty, e1.isEmpty());
+ assertEnvelopeEquals(ei, xmin, ymin, xmax, ymax);
+ assertTrue("Using GeneralEnvelope.", ei.equals(ri, STRICT, false));
+
+ // Interchanges arguments.
+ ei.setEnvelope(e2);
+ ei.intersect(e1);
+ assertEquals("isEmpty", isEmpty, e1.isEmpty());
+ assertEnvelopeEquals(ei, xmin, ymin, xmax, ymax);
+ assertTrue("Using GeneralEnvelope.", ei.equals(ri, STRICT, false));
+ }
+
+ /**
+ * Asserts that the union of the two following envelopes is equals to the given rectangle.
+ * First, this method tests using the {@link Envelope2D} implementation. Then, it tests
+ * using the {@link GeneralEnvelope} implementation.
+ *
+ * @param inf {@code true} if the range after union is infinite. The handling of such
case
+ * is different for {@link GeneralEnvelope} than for {@link Envelope2D} because
we
+ * can not store infinite values in a reliable way in a {@link Rectangle2D} object,
+ * so we use NaN instead.
+ * @param exactlyOneAntiMeridianSpan {@code true} if one envelope spans the anti-meridian
+ * and the other does not.
+ */
+ private static void assertUnionEquals(final GeneralEnvelope e1, final GeneralEnvelope
e2,
+ final double xmin, final double ymin, final double xmax, final double ymax,
+ final boolean inf, final boolean exactlyOneAntiMeridianSpan)
+ {
+ final Envelope2D r1 = new Envelope2D(e1);
+ final Envelope2D r2 = new Envelope2D(e2);
+ final Envelope2D ri = r1.createUnion(r2);
+ assertEnvelopeEquals(ri, inf ? NaN : xmin, ymin, inf ? NaN : xmax, ymax);
+ assertEquals("Interchanged arguments.", ri, r2.createUnion(r1));
+
+ // Compares with GeneralEnvelope.
+ final GeneralEnvelope ei = new GeneralEnvelope(e1);
+ ei.add(e2);
+ assertEnvelopeEquals(ei, xmin, ymin, xmax, ymax);
+ if (!inf) {
+ assertTrue("Using GeneralEnvelope.", ei.equals(ri, STRICT, false));
+ }
+
+ // Interchanges arguments.
+ ei.setEnvelope(e2);
+ ei.add(e1);
+ if (inf && exactlyOneAntiMeridianSpan) {
+ assertEnvelopeEquals(ei, Double.NEGATIVE_INFINITY, ymin, Double.POSITIVE_INFINITY,
ymax);
+ } else {
+ assertEnvelopeEquals(ei, xmin, ymin, xmax, ymax);
+ }
+ if (!inf) {
+ assertTrue("Using GeneralEnvelope.", ei.equals(ri, STRICT, false));
+ }
+ }
+
+ /**
+ * Asserts that adding the given point to the given envelope produces the given result.
+ * First, this method tests using the {@link Envelope2D} implementation. Then, it tests
+ * using the {@link GeneralEnvelope} implementation.
+ */
+ private static void assertAddEquals(final GeneralEnvelope e, final DirectPosition2D p,
+ final double xmin, final double ymin, final double xmax, final double ymax)
+ {
+ final Envelope2D r = new Envelope2D(e);
+ r.add(p);
+ assertEnvelopeEquals(r, xmin, ymin, xmax, ymax);
+
+ // Compares with GeneralEnvelope.
+ final GeneralEnvelope ec = new GeneralEnvelope(e);
+ ec.add(p);
+ assertEnvelopeEquals(ec, xmin, ymin, xmax, ymax);
+ assertTrue("Using GeneralEnvelope.", ec.equals(r, STRICT, false));
+ }
+
+ /**
+ * Tests the {@link GeneralEnvelope#intersect(Envelope)} and
+ * {@link Envelope2D#createIntersection(Rectangle2D)} methods.
+ */
+ @Test
+ @Ignore("The tested envelope needs to be associated to CRS:84")
+ public void testIntersection() {
+ // âââââââââââââââ
+ // â âââââââââ â
+ // â âââââââââ â
+ // âââââââââââââââ
+ final GeneralEnvelope e1 = create(20, -20, 80, 10);
+ final GeneralEnvelope e2 = create(40, -10, 62, 8);
+ assertIntersectEquals(e1, e2, 40, -10, 62, 8);
+ // ââââââââââââ
+ // â âââââââââ¼âââ
+ // â âââââââââ¼âââ
+ // ââââââââââââ
+ e1.setEnvelope(20, -20, 80, 12);
+ e2.setEnvelope(40, -10, 100, 30);
+ final double ymin=-10, ymax=12; // Will not change anymore
+ assertIntersectEquals(e1, e2, 40, ymin, 80, ymax);
+ // âââââ âââââ
+ // âââ â â âââ
+ // âââ â â âââ
+ // âââââ âââââ
+ e1.setRange(0, 80, 20);
+ e2.setRange(0, 100, 18);
+ assertIntersectEquals(e1, e2, 100, ymin, 18, ymax);
+ // âââââ âââââ
+ // âââââ¼âââ¼ââââ
+ // âââââ¼âââ¼ââââ
+ // âââââ âââââ
+ e2.setRange(0, 100, 90);
+ assertIntersectEquals(e1, e2, 100, ymin, 20, ymax);
+ // ââââââ ââââââ
+ // âââ¼âââââ â
+ // âââ¼âââââ â
+ // ââââââ ââââââ
+ e2.setRange(0, 10, 30);
+ assertIntersectEquals(e1, e2, 10, ymin, 20, ymax);
+ // âââââââââââ ââââââ
+ // ââââââ â â
+ // ââââââ â â
+ // âââââââââââ ââââââ
+ e2.setRange(0, 10, 16);
+ assertIntersectEquals(e1, e2, 10, ymin, 16, ymax);
+ // ââââââ ââââââ
+ // â âââ â
+ // â âââ â
+ // ââââââ ââââââ
+ e2.setRange(0, 40, 60);
+ assertIntersectEquals(e1, e2, NaN, ymin, NaN, ymax);
+ // ââââââ ââââââ
+ // âââ¼ââââââ¼ââ
+ // âââ¼ââââââ¼ââ
+ // ââââââ ââââââ
+ e2.setRange(0, 10, 90);
+ assertIntersectEquals(e1, e2, NaN, ymin, NaN, ymax);
+ }
+
+ /**
+ * Tests the {@link GeneralEnvelope#add(Envelope)} and
+ * {@link Envelope2D#createUnion(Rectangle2D)} methods.
+ */
+ @Test
+ @Ignore("The tested envelope needs to be associated to CRS:84")
+ public void testUnion() {
+ // âââââââââââââââ
+ // â âââââââââ â
+ // â âââââââââ â
+ // âââââââââââââââ
+ final GeneralEnvelope e1 = create(20, -20, 80, 10);
+ final GeneralEnvelope e2 = create(40, -10, 62, 8);
+ assertUnionEquals(e1, e2, 20, -20, 80, 10, false, false);
+ // ââââââââââââ
+ // â âââââââââ¼âââ
+ // â âââââââââ¼âââ
+ // ââââââââââââ
+ e1.setEnvelope(20, -20, 80, 12);
+ e2.setEnvelope(40, -10, 100, 30);
+ final double ymin=-20, ymax=30; // Will not change anymore
+ assertUnionEquals(e1, e2, 20, ymin, 100, ymax, false, false);
+ // âââââ âââââ
+ // âââ â â âââ
+ // âââ â â âââ
+ // âââââ âââââ
+ e1.setRange(0, 80, 20);
+ e2.setRange(0, 100, 18);
+ assertUnionEquals(e1, e2, 80, ymin, 20, ymax, false, false);
+ // âââââ âââââ
+ // âââââ¼âââ¼ââââ
+ // âââââ¼âââ¼ââââ
+ // âââââ âââââ
+ e2.setRange(0, 100, 90);
+ assertUnionEquals(e1, e2, +0.0, ymin, -0.0, ymax, true, false);
+ // ââââââ ââââââ
+ // âââ¼âââââ â
+ // âââ¼âââââ â
+ // ââââââ ââââââ
+ e2.setRange(0, 10, 30);
+ assertUnionEquals(e1, e2, 80, ymin, 30, ymax, false, true);
+ // âââââââââââ ââââââ
+ // ââââââ â â
+ // ââââââ â â
+ // âââââââââââ ââââââ
+ e2.setRange(0, 10, 16);
+ assertUnionEquals(e1, e2, 80, ymin, 20, ymax, false, true);
+ // ââââââ ââââââ
+ // â âââ â
+ // â âââ â
+ // ââââââ ââââââ
+ e2.setRange(0, 41, 60);
+ assertUnionEquals(e1, e2, 41, ymin, 20, ymax, false, true);
+ // ââââââ ââââââ
+ // âââ¼ââââââ¼ââ
+ // âââ¼ââââââ¼ââ
+ // ââââââ ââââââ
+ e2.setRange(0, 10, 90);
+ assertUnionEquals(e1, e2, +0.0, ymin, -0.0, ymax, true, true);
+ }
+
+ /**
+ * Tests the {@link GeneralEnvelope#add(DirectPosition)} and
+ * {@link Envelope2D#add(Point2D)} methods.
+ */
+ @Test
+ @Ignore("The tested envelope needs to be associated to CRS:84")
+ public void testAddPoint() {
+ final double ymin=-20, ymax=30; // Will not change anymore
+ final GeneralEnvelope e = create(20, ymin, 80, ymax);
+ final DirectPosition2D p = new DirectPosition2D(40, 15);
+ assertAddEquals(e, p, 20, ymin, 80, ymax);
+
+ p.x = 100; // Add on the right side.
+ assertAddEquals(e, p, 20, ymin, 100, ymax);
+
+ p.x = -10; // Add on the left side.
+ assertAddEquals(e, p, -10, ymin, 80, ymax);
+
+ e.setRange(0, 80, 20);
+ p.x = 100; // No change expected.
+ assertAddEquals(e, p, 80, ymin, 20, ymax);
+
+ p.x = 70; // Add on the right side.
+ assertAddEquals(e, p, 70, ymin, 20, ymax);
+
+ p.x = 30; // Add on the left side.
+ assertAddEquals(e, p, 80, ymin, 30, ymax);
+ }
+
+ /**
+ * Tests the {@link GeneralEnvelope#GeneralEnvelope(String)} constructor.
+ */
+ @Test
+ public void testWktParsing() {
+ GeneralEnvelope envelope = new GeneralEnvelope("BOX(-180 -90,180 90)");
+ assertEquals(2, envelope.getDimension());
+ assertEquals(-180, envelope.getLower(0), STRICT);
+ assertEquals( 180, envelope.getUpper(0), STRICT);
+ assertEquals( -90, envelope.getLower(1), STRICT);
+ assertEquals( 90, envelope.getUpper(1), STRICT);
+
+ envelope = new GeneralEnvelope("BOX3D(-180 -90 10, 180 90 30)");
+ assertEquals(3, envelope.getDimension());
+ assertEquals(-180, envelope.getLower(0), STRICT);
+ assertEquals( 180, envelope.getUpper(0), STRICT);
+ assertEquals( -90, envelope.getLower(1), STRICT);
+ assertEquals( 90, envelope.getUpper(1), STRICT);
+ assertEquals( 10, envelope.getLower(2), STRICT);
+ assertEquals( 30, envelope.getUpper(2), STRICT);
+
+ envelope = new GeneralEnvelope("POLYGON((-80 -30,-100 40,80 40,100 -40,-80 -30))");
+ assertEquals(-100, envelope.getLower(0), STRICT);
+ assertEquals( 100, envelope.getUpper(0), STRICT);
+ assertEquals( -40, envelope.getLower(1), STRICT);
+ assertEquals( 40, envelope.getUpper(1), STRICT);
+
+ assertEquals("BOX2D(6 10, 6 10)", new GeneralEnvelope("POINT(6 10)").toString());
+ assertEquals("BOX3D(6 10 3, 6 10 3)", new GeneralEnvelope("POINT M [ 6 10 3 ] ").toString());
+ assertEquals("BOX2D(3 4, 20 50)", new GeneralEnvelope("LINESTRING(3 4,10 50,20
25)").toString());
+ assertEquals("BOX2D(1 1, 6 5)", new GeneralEnvelope(
+ "MULTIPOLYGON(((1 1,5 1,5 5,1 5,1 1),(2 2, 3 2, 3 3, 2 3,2 2)),((3 3,6 2,6
4,3 3)))").toString());
+ assertEquals("BOX2D(3 6, 7 10)", new GeneralEnvelope("GEOMETRYCOLLECTION(POINT(4
6),LINESTRING(3 8,7 10))").toString());
+ assertEquals(0, new GeneralEnvelope("BOX()").getDimension());
+
+ try {
+ new GeneralEnvelope("BOX2D(3 4");
+ fail("Parsing should fails because of missing parenthesis.");
+ } catch (IllegalArgumentException e) {
+ // This is the expected exception.
+ assertTrue(e.getMessage().contains("BOX2D"));
+ }
+ try {
+ new GeneralEnvelope("LINESTRING(3 4,10 50),20 25)");
+ fail("Parsing should fails because of missing parenthesis.");
+ } catch (IllegalArgumentException e) {
+ // This is the expected exception.
+ assertTrue(e.getMessage().contains("LINESTRING"));
+ }
+ }
+
+ /**
+ * Tests the {@link GeneralEnvelope#equals} method.
+ */
+ @Test
+ public void testEquals() {
+ /*
+ * Initializes an empty envelope. The new envelope is empty
+ * but not null because initialized to 0, not NaN.
+ */
+ final GeneralEnvelope e1 = new GeneralEnvelope(4);
+ assertTrue (e1.isEmpty());
+ assertFalse (e1.isNull());
+ assertEquals(e1.getLowerCorner(), e1.getUpperCorner());
+ /*
+ * Initializes with arbitrary coordinate values.
+ * Should not be empty anymore.
+ */
+ for (int i=e1.getDimension(); --i>=0;) {
+ e1.setRange(i, i*5 + 2, i*6 + 5);
+ }
+ assertFalse(e1.isNull ());
+ assertFalse(e1.isEmpty());
+ assertFalse(e1.getLowerCorner().equals(e1.getUpperCorner()));
+ /*
+ * Creates a new envelope initialized with the same
+ * coordinate values. The two envelope should be equals.
+ */
+ final GeneralEnvelope e2 = new GeneralEnvelope(e1);
+ assertPositionEquals(e1.getLowerCorner(), e2.getLowerCorner());
+ assertPositionEquals(e1.getUpperCorner(), e2.getUpperCorner());
+ assertTrue (e1.contains(e2, true ));
+ assertFalse (e1.contains(e2, false));
+ assertNotSame(e1, e2);
+ assertEquals (e1, e2);
+ assertTrue (e1.equals(e2, EPS, true ));
+ assertTrue (e1.equals(e2, EPS, false));
+ assertEquals (e1.hashCode(), e2.hashCode());
+ /*
+ * Offset slightly some coordinate value. Should not be equals anymore,
+ * except when comparing with a tolerance value.
+ */
+ e2.setRange(2, e2.getLower(2) + 3E-5, e2.getUpper(2) - 3E-5);
+ assertTrue (e1.contains(e2, true ));
+ assertFalse(e1.contains(e2, false));
+ assertFalse(e1.equals (e2));
+ assertTrue (e1.equals (e2, EPS, true ));
+ assertTrue (e1.equals (e2, EPS, false));
+ assertFalse(e1.hashCode() == e2.hashCode());
+ /*
+ * Applies a greater offset. Should not be equal,
+ * even when comparing with a tolerance value.
+ */
+ e2.setRange(1, e2.getLower(1) + 1.5, e2.getUpper(1) - 1.5);
+ assertTrue (e1.contains(e2, true ));
+ assertFalse(e1.contains(e2, false));
+ assertFalse(e1.equals (e2));
+ assertFalse(e1.equals (e2, EPS, true ));
+ assertFalse(e1.equals (e2, EPS, false));
+ assertFalse(e1.hashCode() == e2.hashCode());
+ }
+
+ /**
+ * Compares the specified corners.
+ */
+ private static void assertPositionEquals(final DirectPosition p1, final DirectPosition
p2) {
+ assertNotSame(p1, p2);
+ assertEquals (p1, p2);
+ assertEquals (p1.hashCode(), p2.hashCode());
+ }
+
+ /**
+ * Tests the {@link GeneralEnvelope#clone()} method.
+ */
+ @Test
+ public void testClone() {
+ final GeneralEnvelope e1 = new GeneralEnvelope(2);
+ e1.setRange(0, -40, +60);
+ e1.setRange(1, -20, +30);
+ final GeneralEnvelope e2 = e1.clone();
+ assertNotSame("Expected a new instance.", e1, e2);
+ assertEquals ("The two instances should be equal.", e1, e2);
+ e1.setRange(0, -40, +61);
+ assertFalse("Ordinates array should have been cloned.", e1.equals(e2));
+ e2.setRange(0, -40, +61);
+ assertEquals(e1, e2);
+ }
+}
Propchange: sis/branches/JDK7/sis-referencing/src/test/java/org/apache/sis/geometry/GeneralEnvelopeTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: sis/branches/JDK7/sis-referencing/src/test/java/org/apache/sis/geometry/GeneralEnvelopeTest.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
|