diff --git a/Rock.Math.UnitTests/PiecewiseFunctionTests.cs b/Rock.Math.UnitTests/PiecewiseFunctionTests.cs index c18656f..e8ded1d 100644 --- a/Rock.Math.UnitTests/PiecewiseFunctionTests.cs +++ b/Rock.Math.UnitTests/PiecewiseFunctionTests.cs @@ -1904,6 +1904,23 @@ public void HandlesNegativeLinearFunctionAtIncludedLowerBound() Assert.AreEqual(0.0, result.GetValue(1.0001)); Assert.AreEqual(0.0, result.GetValue(1.5)); } + + [Test] + public void HandlesIntersectionAtPieceThatSpansASinglePoint() + { + var linear = new LinearFunction(25, 0); + var pwf = new PiecewiseFunction + { + { 0.8, false, 2 }, // min < x < .8 : 2 + { 0.8, 20 }, // .8 <= x <= .8 : 20 + }; + + PiecewiseFunction result = null; + Assert.DoesNotThrow(() => result = PiecewiseFunction.EqualTo(pwf, linear)); + Assert.AreEqual(0.0, result.GetValue(0.8 - .000005)); + Assert.AreEqual(1.0, result.GetValue(0.8)); + Assert.AreEqual(0.0, result.GetValue(0.8 + .000005)); + } } [TestFixture] diff --git a/Rock.Math/PiecewiseFunction.cs b/Rock.Math/PiecewiseFunction.cs index 590c983..1654b70 100644 --- a/Rock.Math/PiecewiseFunction.cs +++ b/Rock.Math/PiecewiseFunction.cs @@ -1160,7 +1160,10 @@ private static PiecewiseFunction PiecewiseLinearInequality( result.Add(currentLowerBound, true, equalTo ? 1.0 : 0.0); } - result.Add(piece.UpperBound, piece.IncludeUpperBound, trueAfterIntersection ? 1.0 : 0.0); + if (!piece.UpperBound.ApproximatelyEquals(currentLowerBound)) + { + result.Add(piece.UpperBound, piece.IncludeUpperBound, trueAfterIntersection ? 1.0 : 0.0); + } } else if (intersection.ApproximatelyEquals(piece.UpperBound)) {