diff --git a/CHANGELOG.md b/CHANGELOG.md
index f24ec36..9fc730b 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -13,11 +13,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Added new library X10D.Hosting.
- Added .NET 7 target.
- X10D: Added `IntrinsicExtensions` and `IntrinsicUtility` which offer methods for vectors in `System.Runtime.Instrinsics`. (#70)
-- X10D: Added `MathUtility.Bias(float, float)`.
+- X10D: Added `MathUtility.Bias(float, float)` and `MathUtility.Bias(double, double)`.
- X10D: Added `MathUtility.InverseLerp(float, float, float)` and `MathUtility.InverseLerp(double, double, double)`
- X10D: Added `MathUtility.ScaleRange(float, float, float, float, float)`
and `MathUtility.ScaleRange(double, double, double, double, double)`
- X10D:
+- X10D: Added `MathUtility.SmoothStep(float, float, float)` and `MathUtility.SmoothStep(double, double, double)`.
Added `Circle`, `CircleF`, `Cuboid`, `Ellipse`, `EllipseF`, `Line3D`, `Line`, `LineF`, `Polygon`, `PolygonF`, `Polyhedron`,
and `Sphere`, to complement System.Drawing structs such as `Point` and `Rectangle`
- X10D: Added `Color.Deconstruct()` - with optional alpha parameter.
diff --git a/X10D.Tests/src/Math/MathUtilityTests.cs b/X10D.Tests/src/Math/MathUtilityTests.cs
index cd23081..b230986 100644
--- a/X10D.Tests/src/Math/MathUtilityTests.cs
+++ b/X10D.Tests/src/Math/MathUtilityTests.cs
@@ -150,4 +150,25 @@ public class MathUtilityTests
float result = MathUtility.ScaleRange(0.5f, 0.0f, 1.0f, 5.0f, 10.0f);
Assert.AreEqual(7.5f, result);
}
+
+ [TestMethod]
+ public void SmoothStep_ShouldReturnHigher_GivenAlpha1()
+ {
+ Assert.AreEqual(20.0f, MathUtility.SmoothStep(10.0f, 20.0f, 1.0f));
+ Assert.AreEqual(20.0, MathUtility.SmoothStep(10.0, 20.0, 1.0));
+ }
+
+ [TestMethod]
+ public void SmoothStep_ShouldReturnLower_GivenAlpha0()
+ {
+ Assert.AreEqual(10.0f, MathUtility.SmoothStep(10.0f, 20.0f, 0.0f));
+ Assert.AreEqual(10.0, MathUtility.SmoothStep(10.0, 20.0, 0.0));
+ }
+
+ [TestMethod]
+ public void SmoothStep_ShouldReturnMidPoint_GivenAlphaPoint5()
+ {
+ Assert.AreEqual(15.0f, MathUtility.SmoothStep(10.0f, 20.0f, 0.5f));
+ Assert.AreEqual(15.0, MathUtility.SmoothStep(10.0, 20.0, 0.5));
+ }
}
diff --git a/X10D/src/Math/MathUtility.cs b/X10D/src/Math/MathUtility.cs
index 7e1bd59..d76b03a 100644
--- a/X10D/src/Math/MathUtility.cs
+++ b/X10D/src/Math/MathUtility.cs
@@ -308,4 +308,32 @@ public static class MathUtility
double alpha = (value - oldMin) / oldRange;
return (alpha * newRange) + newMin;
}
+
+ ///
+ /// Performs smooth Hermite interpolation from one value to a target using a specified alpha.
+ ///
+ /// The interpolation source.
+ /// The interpolation target.
+ /// The interpolation alpha.
+ /// The interpolation result.
+ public static float SmoothStep(float value, float target, float alpha)
+ {
+ alpha = System.Math.Clamp(alpha, 0.0f, 1.0f);
+ alpha = -2.0f * alpha * alpha * alpha + 3.0f * alpha * alpha;
+ return target * alpha + value * (1.0f - alpha);
+ }
+
+ ///
+ /// Performs smooth Hermite interpolation from one value to a target using a specified alpha.
+ ///
+ /// The interpolation source.
+ /// The interpolation target.
+ /// The interpolation alpha.
+ /// The interpolation result.
+ public static double SmoothStep(double value, double target, double alpha)
+ {
+ alpha = System.Math.Clamp(alpha, 0.0, 1.0);
+ alpha = -2.0 * alpha * alpha * alpha + 3.0 * alpha * alpha;
+ return target * alpha + value * (1.0 - alpha);
+ }
}