From a23436c35b3783fd6654d4199fd08e66c907202e Mon Sep 17 00:00:00 2001 From: Christoph Ruegg Date: Fri, 14 Aug 2009 15:44:56 +0800 Subject: [PATCH] interpolation: barycentric condition fix, full coverage Signed-off-by: Christoph Ruegg --- .../Interpolation/Algorithms/BarycentricInterpolation.cs | 3 ++- .../InterpolationFunctionalContract.cs | 9 +++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/Numerics/Interpolation/Algorithms/BarycentricInterpolation.cs b/src/Numerics/Interpolation/Algorithms/BarycentricInterpolation.cs index 981760f1..3a588545 100644 --- a/src/Numerics/Interpolation/Algorithms/BarycentricInterpolation.cs +++ b/src/Numerics/Interpolation/Algorithms/BarycentricInterpolation.cs @@ -166,8 +166,9 @@ namespace MathNet.Numerics.Interpolation.Algorithms } // trivial case: on a known sample point? - if (offset.AlmostZero()) + if (offset == 0.0) { + // NOTE (cdrnet, 200908) not offset.AlmostZero() by design return _values[closestPoint]; } diff --git a/src/UnitTests/InterpolationTests/InterpolationFunctionalContract.cs b/src/UnitTests/InterpolationTests/InterpolationFunctionalContract.cs index 8f5a4e66..26f1ecbc 100644 --- a/src/UnitTests/InterpolationTests/InterpolationFunctionalContract.cs +++ b/src/UnitTests/InterpolationTests/InterpolationFunctionalContract.cs @@ -69,8 +69,8 @@ namespace MathNet.Numerics.UnitTests.InterpolationTests "InterpolationMatchesNodePoints", () => { - var points = new List { 1, 2, 2.3, 3, 8 }; - var values = new List { 50, 20, 30, 10, -20 }; + var points = new List { -0.2, 0, 1, 2, 2.3, 3, 8 }; + var values = new List { -10, 5, 50, 20, 30, 10, -20 }; var interpolation = Factory(points, values); for (int i = 0; i < points.Count; i++) @@ -79,6 +79,11 @@ namespace MathNet.Numerics.UnitTests.InterpolationTests values[i], interpolation.Interpolate(points[i]), 1e-12); + + Assert.AreApproximatelyEqual( + values[i], + interpolation.Interpolate(points[i].Increment(50)), + 1e-8); } }); }