You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sis.apache.org by de...@apache.org on 2012/12/18 17:07:22 UTC
svn commit: r1423503 - in /sis/branches/JDK7:
sis-referencing/src/main/java/org/apache/sis/geometry/
sis-referencing/src/test/java/org/apache/sis/geometry/
sis-utility/src/main/java/org/apache/sis/math/
sis-utility/src/test/java/org/apache/sis/math/
Author: desruisseaux
Date: Tue Dec 18 16:07:20 2012
New Revision: 1423503
URL: http://svn.apache.org/viewvc?rev=1423503&view=rev
Log:
Moved 'isSimplePrecision' to a package-private method, because it seeems a to heuristic approach for commiting in public API.
Added:
sis/branches/JDK7/sis-referencing/src/test/java/org/apache/sis/geometry/AbstractDirectPositionTest.java (with props)
Modified:
sis/branches/JDK7/sis-referencing/src/main/java/org/apache/sis/geometry/AbstractDirectPosition.java
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/DirectPosition1D.java
sis/branches/JDK7/sis-referencing/src/main/java/org/apache/sis/geometry/DirectPosition2D.java
sis/branches/JDK7/sis-referencing/src/main/java/org/apache/sis/geometry/GeneralDirectPosition.java
sis/branches/JDK7/sis-referencing/src/test/java/org/apache/sis/geometry/GeneralDirectPositionTest.java
sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/math/MathFunctions.java
sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/math/MathFunctionsTest.java
Modified: sis/branches/JDK7/sis-referencing/src/main/java/org/apache/sis/geometry/AbstractDirectPosition.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-referencing/src/main/java/org/apache/sis/geometry/AbstractDirectPosition.java?rev=1423503&r1=1423502&r2=1423503&view=diff
==============================================================================
--- sis/branches/JDK7/sis-referencing/src/main/java/org/apache/sis/geometry/AbstractDirectPosition.java (original)
+++ sis/branches/JDK7/sis-referencing/src/main/java/org/apache/sis/geometry/AbstractDirectPosition.java Tue Dec 18 16:07:20 2012
@@ -161,6 +161,25 @@ public abstract class AbstractDirectPosi
}
/**
+ * Returns {@code true} if every values in the given {@code double} array could be casted
+ * to the {@code float} type without precision lost. This method treats all {@code NaN} values
+ * as equal.
+ *
+ * @param values The value to test for their precision.
+ * @return {@code true} if every values can be casted to the {@code float} type without precision lost.
+ *
+ * @see #toString(DirectPosition, boolean)
+ */
+ static boolean isSimplePrecision(final double... values) {
+ for (final double value : values) {
+ if (Double.doubleToLongBits(value) != Double.doubleToLongBits((float) value)) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ /**
* Formats this position in the <cite>Well Known Text</cite> (WKT) format.
* The returned string is like below, where {@code xâ}, {@code xâ}, {@code xâ}, <i>etc.</i>
* are the ordinate values at index 0, 1, 2, <i>etc.</i>:
@@ -187,6 +206,8 @@ public abstract class AbstractDirectPosi
* @param position The position to format.
* @param isSimplePrecision {@code true} if every ordinate values can be casted to {@code float}.
* @return The point as a {@code POINT} in WKT format.
+ *
+ * @see #isSimplePrecision(double[])
*/
static String toString(final DirectPosition position, final boolean isSimplePrecision) {
final StringBuilder buffer = new StringBuilder(32).append("POINT");
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=1423503&r1=1423502&r2=1423503&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 Tue Dec 18 16:07:20 2012
@@ -38,7 +38,6 @@ import org.apache.sis.referencing.CRS;
import static org.apache.sis.util.Arrays.resize;
import static org.apache.sis.util.ArgumentChecks.*;
import static org.apache.sis.math.MathFunctions.isNegative;
-import static org.apache.sis.math.MathFunctions.isSimplePrecision;
import static org.apache.sis.internal.referencing.Utilities.isPoleToPole;
// Related to JDK7
@@ -481,6 +480,6 @@ scanNumber: while ((i += Character.charC
*/
@Override
public String toString() {
- return toString(this, isSimplePrecision(ordinates));
+ return toString(this, AbstractDirectPosition.isSimplePrecision(ordinates));
}
}
Modified: sis/branches/JDK7/sis-referencing/src/main/java/org/apache/sis/geometry/DirectPosition1D.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-referencing/src/main/java/org/apache/sis/geometry/DirectPosition1D.java?rev=1423503&r1=1423502&r2=1423503&view=diff
==============================================================================
--- sis/branches/JDK7/sis-referencing/src/main/java/org/apache/sis/geometry/DirectPosition1D.java (original)
+++ sis/branches/JDK7/sis-referencing/src/main/java/org/apache/sis/geometry/DirectPosition1D.java Tue Dec 18 16:07:20 2012
@@ -27,8 +27,6 @@ import org.opengis.geometry.DirectPositi
import org.opengis.geometry.MismatchedDimensionException;
import org.apache.sis.util.resources.Errors;
-import static org.apache.sis.math.MathFunctions.isSimplePrecision;
-
/**
* Holds the coordinates for a one-dimensional position within some coordinate reference system.
@@ -219,7 +217,7 @@ public class DirectPosition1D extends Ab
*/
@Override
public String toString() {
- return toString(this, isSimplePrecision(ordinate));
+ return toString(this, ordinate == (float) ordinate);
}
/**
Modified: sis/branches/JDK7/sis-referencing/src/main/java/org/apache/sis/geometry/DirectPosition2D.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-referencing/src/main/java/org/apache/sis/geometry/DirectPosition2D.java?rev=1423503&r1=1423502&r2=1423503&view=diff
==============================================================================
--- sis/branches/JDK7/sis-referencing/src/main/java/org/apache/sis/geometry/DirectPosition2D.java (original)
+++ sis/branches/JDK7/sis-referencing/src/main/java/org/apache/sis/geometry/DirectPosition2D.java Tue Dec 18 16:07:20 2012
@@ -25,7 +25,6 @@ import org.apache.sis.util.resources.Err
import static java.lang.Double.doubleToLongBits;
import static org.apache.sis.util.ArgumentChecks.ensureNonNull;
-import static org.apache.sis.math.MathFunctions.isSimplePrecision;
// Following imports are needed because we can't extend AbstractDirectPosition.
// We want to write this class as if it was an AbstractDirectPosition subclass.
@@ -296,7 +295,7 @@ public class DirectPosition2D extends Po
*/
@Override
public String toString() {
- return AbstractDirectPosition.toString(this, isSimplePrecision(x, y));
+ return AbstractDirectPosition.toString(this, AbstractDirectPosition.isSimplePrecision(x, y));
}
/**
Modified: sis/branches/JDK7/sis-referencing/src/main/java/org/apache/sis/geometry/GeneralDirectPosition.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-referencing/src/main/java/org/apache/sis/geometry/GeneralDirectPosition.java?rev=1423503&r1=1423502&r2=1423503&view=diff
==============================================================================
--- sis/branches/JDK7/sis-referencing/src/main/java/org/apache/sis/geometry/GeneralDirectPosition.java (original)
+++ sis/branches/JDK7/sis-referencing/src/main/java/org/apache/sis/geometry/GeneralDirectPosition.java Tue Dec 18 16:07:20 2012
@@ -28,7 +28,6 @@ import org.opengis.geometry.DirectPositi
import org.opengis.geometry.MismatchedDimensionException;
import org.opengis.referencing.crs.CoordinateReferenceSystem;
import org.apache.sis.util.resources.Errors;
-import org.apache.sis.math.MathFunctions;
// JDK7 related
import java.util.Objects;
@@ -268,7 +267,7 @@ public class GeneralDirectPosition exten
*/
@Override
public String toString() {
- return toString(this, MathFunctions.isSimplePrecision(ordinates));
+ return toString(this, isSimplePrecision(ordinates));
}
/**
Added: sis/branches/JDK7/sis-referencing/src/test/java/org/apache/sis/geometry/AbstractDirectPositionTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-referencing/src/test/java/org/apache/sis/geometry/AbstractDirectPositionTest.java?rev=1423503&view=auto
==============================================================================
--- sis/branches/JDK7/sis-referencing/src/test/java/org/apache/sis/geometry/AbstractDirectPositionTest.java (added)
+++ sis/branches/JDK7/sis-referencing/src/test/java/org/apache/sis/geometry/AbstractDirectPositionTest.java Tue Dec 18 16:07:20 2012
@@ -0,0 +1,42 @@
+/*
+ * 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.junit.Test;
+import org.apache.sis.test.TestCase;
+
+import static org.apache.sis.test.Assert.*;
+
+
+/**
+ * Tests the static methods provided in {@link AbstractDirectPosition}.
+ *
+ * @author Martin Desruisseaux (IRD, Geomatys)
+ * @since 0.3
+ * @version 0.3
+ * @module
+ */
+public final strictfp class AbstractDirectPositionTest extends TestCase {
+ /**
+ * Tests {@link AbstractDirectPosition#isSimplePrecision(double[])}.
+ */
+ @Test
+ public void testIsSimplePrecision() {
+ assertTrue (AbstractDirectPosition.isSimplePrecision(2, 0.5, 0.25, Double.NaN, Double.POSITIVE_INFINITY));
+ assertFalse(AbstractDirectPosition.isSimplePrecision(2, 0.5, 1.0 / 3));
+ }
+}
Propchange: sis/branches/JDK7/sis-referencing/src/test/java/org/apache/sis/geometry/AbstractDirectPositionTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: sis/branches/JDK7/sis-referencing/src/test/java/org/apache/sis/geometry/AbstractDirectPositionTest.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: sis/branches/JDK7/sis-referencing/src/test/java/org/apache/sis/geometry/GeneralDirectPositionTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-referencing/src/test/java/org/apache/sis/geometry/GeneralDirectPositionTest.java?rev=1423503&r1=1423502&r2=1423503&view=diff
==============================================================================
--- sis/branches/JDK7/sis-referencing/src/test/java/org/apache/sis/geometry/GeneralDirectPositionTest.java (original)
+++ sis/branches/JDK7/sis-referencing/src/test/java/org/apache/sis/geometry/GeneralDirectPositionTest.java Tue Dec 18 16:07:20 2012
@@ -18,6 +18,7 @@ package org.apache.sis.geometry;
import java.util.Arrays;
import org.apache.sis.test.TestCase;
+import org.apache.sis.test.DependsOn;
import org.junit.Test;
import static org.apache.sis.test.Assert.*;
@@ -32,6 +33,7 @@ import static org.opengis.test.Validator
* @version 0.3
* @module
*/
+@DependsOn(AbstractDirectPositionTest.class)
public final strictfp class GeneralDirectPositionTest extends TestCase {
/**
* Tests the {@link GeneralDirectPosition#toString()} method.
Modified: sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/math/MathFunctions.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/math/MathFunctions.java?rev=1423503&r1=1423502&r2=1423503&view=diff
==============================================================================
--- sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/math/MathFunctions.java (original)
+++ sis/branches/JDK7/sis-utility/src/main/java/org/apache/sis/math/MathFunctions.java Tue Dec 18 16:07:20 2012
@@ -197,23 +197,6 @@ public final class MathFunctions extends
}
/**
- * Returns {@code true} if every values in the given {@code double} array could be casted
- * to the {@code float} type without precision lost. This method treats all {@code NaN} values
- * as equal.
- *
- * @param values The value to test for their precision.
- * @return {@code true} if every values can be casted to the {@code float} type without precision lost.
- */
- public static boolean isSimplePrecision(final double... values) {
- for (final double value : values) {
- if (Double.doubleToLongBits(value) != Double.doubleToLongBits((float) value)) {
- return false;
- }
- }
- return true;
- }
-
- /**
* Returns the number of fraction digits needed for formatting in base 10 numbers of the given
* accuracy. If the {@code strict} argument is {@code true}, then for any given {@code accuracy}
* this method returns a value <var>n</var> such as the difference between adjacent numbers
Modified: sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/math/MathFunctionsTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/math/MathFunctionsTest.java?rev=1423503&r1=1423502&r2=1423503&view=diff
==============================================================================
--- sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/math/MathFunctionsTest.java (original)
+++ sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/math/MathFunctionsTest.java Tue Dec 18 16:07:20 2012
@@ -84,15 +84,6 @@ public final strictfp class MathFunction
}
/**
- * Tests {@link MathFunctions#isSimplePrecision(double[])}.
- */
- @Test
- public void testIsSimplePrecision() {
- assertTrue (isSimplePrecision(2, 0.5, 0.25, Double.NaN, Double.POSITIVE_INFINITY));
- assertFalse(isSimplePrecision(2, 0.5, 1.0 / 3));
- }
-
- /**
* Tests {@link MathFunctions#fractionDigitsForDelta(double, boolean)}.
*/
@Test