Browse Source

interpolation: barycentric condition fix, full coverage

Signed-off-by: Christoph Ruegg <git@cdrnet.ch>
pull/36/head
Christoph Ruegg 17 years ago
parent
commit
a23436c35b
  1. 3
      src/Numerics/Interpolation/Algorithms/BarycentricInterpolation.cs
  2. 9
      src/UnitTests/InterpolationTests/InterpolationFunctionalContract.cs

3
src/Numerics/Interpolation/Algorithms/BarycentricInterpolation.cs

@ -166,8 +166,9 @@ namespace MathNet.Numerics.Interpolation.Algorithms
} }
// trivial case: on a known sample point? // 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]; return _values[closestPoint];
} }

9
src/UnitTests/InterpolationTests/InterpolationFunctionalContract.cs

@ -69,8 +69,8 @@ namespace MathNet.Numerics.UnitTests.InterpolationTests
"InterpolationMatchesNodePoints", "InterpolationMatchesNodePoints",
() => () =>
{ {
var points = new List<double> { 1, 2, 2.3, 3, 8 }; var points = new List<double> { -0.2, 0, 1, 2, 2.3, 3, 8 };
var values = new List<double> { 50, 20, 30, 10, -20 }; var values = new List<double> { -10, 5, 50, 20, 30, 10, -20 };
var interpolation = Factory(points, values); var interpolation = Factory(points, values);
for (int i = 0; i < points.Count; i++) for (int i = 0; i < points.Count; i++)
@ -79,6 +79,11 @@ namespace MathNet.Numerics.UnitTests.InterpolationTests
values[i], values[i],
interpolation.Interpolate(points[i]), interpolation.Interpolate(points[i]),
1e-12); 1e-12);
Assert.AreApproximatelyEqual(
values[i],
interpolation.Interpolate(points[i].Increment(50)),
1e-8);
} }
}); });
} }

Loading…
Cancel
Save