commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From er...@apache.org
Subject svn commit: r1491625 - in /commons/proper/math/trunk/src: main/java/org/apache/commons/math3/analysis/polynomials/PolynomialSplineFunction.java test/java/org/apache/commons/math3/analysis/polynomials/PolynomialSplineFunctionTest.java
Date Mon, 10 Jun 2013 22:22:31 GMT
Author: erans
Date: Mon Jun 10 22:22:31 2013
New Revision: 1491625

URL: http://svn.apache.org/r1491625
Log:
MATH-991
Method to check whether a point is within the interpolation range.

Modified:
    commons/proper/math/trunk/src/main/java/org/apache/commons/math3/analysis/polynomials/PolynomialSplineFunction.java
    commons/proper/math/trunk/src/test/java/org/apache/commons/math3/analysis/polynomials/PolynomialSplineFunctionTest.java

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/analysis/polynomials/PolynomialSplineFunction.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/analysis/polynomials/PolynomialSplineFunction.java?rev=1491625&r1=1491624&r2=1491625&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math3/analysis/polynomials/PolynomialSplineFunction.java
(original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math3/analysis/polynomials/PolynomialSplineFunction.java
Mon Jun 10 22:22:31 2013
@@ -229,4 +229,19 @@ public class PolynomialSplineFunction im
         System.arraycopy(knots, 0, out, 0, n + 1);
         return out;
     }
+
+    /**
+     * Indicates whether a point is within the interpolation range.
+     *
+     * @param x Point.
+     * @return {@code true} if {@code x} is a valid point.
+     */
+    public boolean isValidPoint(double x) {
+        if (x < knots[0] ||
+            x > knots[n]) {
+            return false;
+        } else {
+            return true;
+        }
+    }
 }

Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math3/analysis/polynomials/PolynomialSplineFunctionTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math3/analysis/polynomials/PolynomialSplineFunctionTest.java?rev=1491625&r1=1491624&r2=1491625&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math3/analysis/polynomials/PolynomialSplineFunctionTest.java
(original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math3/analysis/polynomials/PolynomialSplineFunctionTest.java
Mon Jun 10 22:22:31 2013
@@ -134,6 +134,41 @@ public class PolynomialSplineFunctionTes
         }
     }
 
+    @Test
+    public void testIsValidPoint() {
+        final PolynomialSplineFunction spline =
+            new PolynomialSplineFunction(knots, polynomials);
+        final double xMin = knots[0];
+        final double xMax = knots[knots.length - 1];
+
+        double x;
+
+        x = xMin;
+        Assert.assertTrue(spline.isValidPoint(x));
+        // Ensure that no exception is thrown.
+        spline.value(x);
+
+        x = xMax;
+        Assert.assertTrue(spline.isValidPoint(x));
+        // Ensure that no exception is thrown.
+        spline.value(x);
+ 
+        final double xRange = xMax - xMin;
+        x = xMin + xRange / 3.4;
+        Assert.assertTrue(spline.isValidPoint(x));
+        // Ensure that no exception is thrown.
+        spline.value(x);
+
+        final double small = 1e-8;
+        x = xMin - small;
+        Assert.assertFalse(spline.isValidPoint(x));
+        // Ensure that an exception would have been thrown.
+        try {
+            spline.value(x);
+            Assert.fail("OutOfRangeException expected");
+        } catch (OutOfRangeException expected) {}
+    }
+
     /**
      *  Do linear search to find largest knot point less than or equal to x.
      *  Implementation does binary search.



Mime
View raw message