You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by er...@apache.org on 2013/06/10 23:24:07 UTC
svn commit: r1491606 - in /commons/proper/math/trunk/src:
main/java/org/apache/commons/math3/analysis/interpolation/
test/java/org/apache/commons/math3/analysis/interpolation/
Author: erans
Date: Mon Jun 10 21:24:07 2013
New Revision: 1491606
URL: http://svn.apache.org/r1491606
Log:
MATH-989
Added method to check whether a point is within the interpolation range.
Modified:
commons/proper/math/trunk/src/main/java/org/apache/commons/math3/analysis/interpolation/BicubicSplineInterpolatingFunction.java
commons/proper/math/trunk/src/test/java/org/apache/commons/math3/analysis/interpolation/BicubicSplineInterpolatingFunctionTest.java
Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/analysis/interpolation/BicubicSplineInterpolatingFunction.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/analysis/interpolation/BicubicSplineInterpolatingFunction.java?rev=1491606&r1=1491605&r2=1491606&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math3/analysis/interpolation/BicubicSplineInterpolatingFunction.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math3/analysis/interpolation/BicubicSplineInterpolatingFunction.java Mon Jun 10 21:24:07 2013
@@ -173,6 +173,24 @@ public class BicubicSplineInterpolatingF
}
/**
+ * Indicates whether a point is within the interpolation range.
+ *
+ * @param x First coordinate.
+ * @param y Second coordinate.
+ * @return {@code true} if (x, y) is a valid point.
+ */
+ public boolean isValidPoint(double x, double y) {
+ if (x < xval[0] ||
+ x > xval[xval.length - 1] ||
+ y < yval[0] ||
+ y > yval[yval.length - 1]) {
+ return false;
+ } else {
+ return true;
+ }
+ }
+
+ /**
* @param x x-coordinate.
* @param y y-coordinate.
* @return the value at point (x, y) of the first partial derivative with
Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math3/analysis/interpolation/BicubicSplineInterpolatingFunctionTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math3/analysis/interpolation/BicubicSplineInterpolatingFunctionTest.java?rev=1491606&r1=1491605&r2=1491606&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math3/analysis/interpolation/BicubicSplineInterpolatingFunctionTest.java (original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math3/analysis/interpolation/BicubicSplineInterpolatingFunctionTest.java Mon Jun 10 21:24:07 2013
@@ -18,6 +18,7 @@ package org.apache.commons.math3.analysi
import org.apache.commons.math3.exception.DimensionMismatchException;
import org.apache.commons.math3.exception.MathIllegalArgumentException;
+import org.apache.commons.math3.exception.OutOfRangeException;
import org.apache.commons.math3.analysis.BivariateFunction;
import org.apache.commons.math3.distribution.UniformRealDistribution;
import org.apache.commons.math3.random.RandomGenerator;
@@ -606,4 +607,64 @@ public final class BicubicSplineInterpol
// System.out.println();
}
}
+
+ @Test
+ public void testIsValidPoint() {
+ final double xMin = -12;
+ final double xMax = 34;
+ final double yMin = 5;
+ final double yMax = 67;
+ final double[] xval = new double[] { xMin, xMax };
+ final double[] yval = new double[] { yMin, yMax };
+ final double[][] f = new double[][] { { 1, 2 },
+ { 3, 4 } };
+ final double[][] dFdX = f;
+ final double[][] dFdY = f;
+ final double[][] dFdXdY = f;
+
+ final BicubicSplineInterpolatingFunction bcf
+ = new BicubicSplineInterpolatingFunction(xval, yval, f,
+ dFdX, dFdY, dFdXdY);
+
+ double x, y;
+
+ x = xMin;
+ y = yMin;
+ Assert.assertTrue(bcf.isValidPoint(x, y));
+ // Ensure that no exception is thrown.
+ bcf.value(x, y);
+
+ x = xMax;
+ y = yMax;
+ Assert.assertTrue(bcf.isValidPoint(x, y));
+ // Ensure that no exception is thrown.
+ bcf.value(x, y);
+
+ final double xRange = xMax - xMin;
+ final double yRange = yMax - yMin;
+ x = xMin + xRange / 3.4;
+ y = yMin + yRange / 1.2;
+ Assert.assertTrue(bcf.isValidPoint(x, y));
+ // Ensure that no exception is thrown.
+ bcf.value(x, y);
+
+ final double small = 1e-8;
+ x = xMin - small;
+ y = yMax;
+ Assert.assertFalse(bcf.isValidPoint(x, y));
+ // Ensure that an exception would have been thrown.
+ try {
+ bcf.value(x, y);
+ Assert.fail("OutOfRangeException expected");
+ } catch (OutOfRangeException expected) {}
+
+ x = xMin;
+ y = yMax + small;
+ Assert.assertFalse(bcf.isValidPoint(x, y));
+ // Ensure that an exception would have been thrown.
+ try {
+ bcf.value(x, y);
+ Assert.fail("OutOfRangeException expected");
+ } catch (OutOfRangeException expected) {}
+ }
}