diff --git a/X10D/src/DoubleExtensions/DoubleExtensions.cs b/X10D/src/DoubleExtensions/DoubleExtensions.cs
index 2de42d6..36d3c0e 100644
--- a/X10D/src/DoubleExtensions/DoubleExtensions.cs
+++ b/X10D/src/DoubleExtensions/DoubleExtensions.cs
@@ -1,5 +1,4 @@
using System;
-using System.Runtime.CompilerServices;
namespace X10D
{
@@ -61,12 +60,11 @@ namespace X10D
/// The interpolation source.
/// The interpolation alpha.
///
- /// The interpolation result as determined by (1 - ) * +
- /// * .
+ /// The interpolation result as determined by (1 - alpha) * value + alpha * target.
///
public static double LerpFrom(this double target, double value, double alpha)
{
- return LerpInternal(value, target, alpha);
+ return MathUtils.Lerp(value, target, alpha);
}
///
@@ -76,12 +74,11 @@ namespace X10D
/// The interpolation target.
/// The interpolation alpha.
///
- /// The interpolation result as determined by (1 - ) * +
- /// * .
+ /// The interpolation result as determined by (1 - alpha) * value + alpha * target.
///
public static double LerpTo(this double value, double target, double alpha)
{
- return LerpInternal(value, target, alpha);
+ return MathUtils.Lerp(value, target, alpha);
}
///
@@ -91,12 +88,11 @@ namespace X10D
/// The interpolation source.
/// The interpolation target.
///
- /// The interpolation result as determined by (1 - ) * +
- /// * .
+ /// The interpolation result as determined by (1 - alpha) * value + alpha * target.
///
public static double LerpWith(this double alpha, double value, double target)
{
- return LerpInternal(value, target, alpha);
+ return MathUtils.Lerp(value, target, alpha);
}
///
@@ -141,13 +137,5 @@ namespace X10D
{
return value != 0.0;
}
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- internal static double LerpInternal(double a, double b, double t)
- {
- // rookie mistake: a + t * (b - a)
- // "precise" method: (1 - t) * a + t * b
- return (1.0 - t) * a + t * b;
- }
}
}
diff --git a/X10D/src/Int16Extensions/Int16Extensions.cs b/X10D/src/Int16Extensions/Int16Extensions.cs
index 2619b61..174f708 100644
--- a/X10D/src/Int16Extensions/Int16Extensions.cs
+++ b/X10D/src/Int16Extensions/Int16Extensions.cs
@@ -89,42 +89,11 @@ namespace X10D
/// The interpolation source.
/// The interpolation alpha.
///
- /// The interpolation result as determined by (1 - ) * +
- /// * .
+ /// The interpolation result as determined by (1 - alpha) * value + alpha * target.
///
public static double LerpFrom(this short target, double value, double alpha)
{
- return DoubleExtensions.LerpInternal(value, target, alpha);
- }
-
- ///
- /// Linearly interpolates from the current value to a specified target using a specified alpha.
- ///
- /// The interpolation source.
- /// The interpolation target.
- /// The interpolation alpha.
- ///
- /// The interpolation result as determined by (1 - ) * +
- /// * .
- ///
- public static double LerpTo(this short value, double target, double alpha)
- {
- return DoubleExtensions.LerpInternal(value, target, alpha);
- }
-
- ///
- /// Linearly interpolates to a specified target from a specified source, using the current value as the alpha value.
- ///
- /// The interpolation alpha.
- /// The interpolation source.
- /// The interpolation target.
- ///
- /// The interpolation result as determined by (1 - ) * +
- /// * .
- ///
- public static double LerpWith(this short alpha, double value, double target)
- {
- return DoubleExtensions.LerpInternal(value, target, alpha);
+ return MathUtils.Lerp(value, target, alpha);
}
///
@@ -134,12 +103,11 @@ namespace X10D
/// The interpolation source.
/// The interpolation alpha.
///
- /// The interpolation result as determined by (1 - ) * +
- /// * .
+ /// The interpolation result as determined by (1 - alpha) * value + alpha * target.
///
public static float LerpFrom(this short target, float value, float alpha)
{
- return SingleExtensions.LerpInternal(value, target, alpha);
+ return MathUtils.Lerp(value, target, alpha);
}
///
@@ -149,12 +117,25 @@ namespace X10D
/// The interpolation target.
/// The interpolation alpha.
///
- /// The interpolation result as determined by (1 - ) * +
- /// * .
+ /// The interpolation result as determined by (1 - alpha) * value + alpha * target.
+ ///
+ public static double LerpTo(this short value, double target, double alpha)
+ {
+ return MathUtils.Lerp(value, target, alpha);
+ }
+
+ ///
+ /// Linearly interpolates from the current value to a specified target using a specified alpha.
+ ///
+ /// The interpolation source.
+ /// The interpolation target.
+ /// The interpolation alpha.
+ ///
+ /// The interpolation result as determined by (1 - alpha) * value + alpha * target.
///
public static float LerpTo(this short value, float target, float alpha)
{
- return SingleExtensions.LerpInternal(value, target, alpha);
+ return MathUtils.Lerp(value, target, alpha);
}
///
@@ -164,12 +145,25 @@ namespace X10D
/// The interpolation source.
/// The interpolation target.
///
- /// The interpolation result as determined by (1 - ) * +
- /// * .
+ /// The interpolation result as determined by (1 - alpha) * value + alpha * target.
+ ///
+ public static double LerpWith(this short alpha, double value, double target)
+ {
+ return MathUtils.Lerp(value, target, alpha);
+ }
+
+ ///
+ /// Linearly interpolates to a specified target from a specified source, using the current value as the alpha value.
+ ///
+ /// The interpolation alpha.
+ /// The interpolation source.
+ /// The interpolation target.
+ ///
+ /// The interpolation result as determined by (1 - alpha) * value + alpha * target.
///
public static float LerpWith(this short alpha, float value, float target)
{
- return SingleExtensions.LerpInternal(value, target, alpha);
+ return MathUtils.Lerp(value, target, alpha);
}
///
diff --git a/X10D/src/Int32Extensions/Int32Extensions.cs b/X10D/src/Int32Extensions/Int32Extensions.cs
index 1316a2c..db5e36a 100644
--- a/X10D/src/Int32Extensions/Int32Extensions.cs
+++ b/X10D/src/Int32Extensions/Int32Extensions.cs
@@ -89,42 +89,11 @@ namespace X10D
/// The interpolation source.
/// The interpolation alpha.
///
- /// The interpolation result as determined by (1 - ) * +
- /// * .
+ /// The interpolation result as determined by (1 - alpha) * value + alpha * target.
///
public static double LerpFrom(this int target, double value, double alpha)
{
- return DoubleExtensions.LerpInternal(value, target, alpha);
- }
-
- ///
- /// Linearly interpolates from the current value to a specified target using a specified alpha.
- ///
- /// The interpolation source.
- /// The interpolation target.
- /// The interpolation alpha.
- ///
- /// The interpolation result as determined by (1 - ) * +
- /// * .
- ///
- public static double LerpTo(this int value, double target, double alpha)
- {
- return DoubleExtensions.LerpInternal(value, target, alpha);
- }
-
- ///
- /// Linearly interpolates to a specified target from a specified source, using the current value as the alpha value.
- ///
- /// The interpolation alpha.
- /// The interpolation source.
- /// The interpolation target.
- ///
- /// The interpolation result as determined by (1 - ) * +
- /// * .
- ///
- public static double LerpWith(this int alpha, double value, double target)
- {
- return DoubleExtensions.LerpInternal(value, target, alpha);
+ return MathUtils.Lerp(value, target, alpha);
}
///
@@ -134,12 +103,11 @@ namespace X10D
/// The interpolation source.
/// The interpolation alpha.
///
- /// The interpolation result as determined by (1 - ) * +
- /// * .
+ /// The interpolation result as determined by (1 - alpha) * value + alpha * target.
///
public static float LerpFrom(this int target, float value, float alpha)
{
- return SingleExtensions.LerpInternal(value, target, alpha);
+ return MathUtils.Lerp(value, target, alpha);
}
///
@@ -149,12 +117,25 @@ namespace X10D
/// The interpolation target.
/// The interpolation alpha.
///
- /// The interpolation result as determined by (1 - ) * +
- /// * .
+ /// The interpolation result as determined by (1 - alpha) * value + alpha * target.
+ ///
+ public static double LerpTo(this int value, double target, double alpha)
+ {
+ return MathUtils.Lerp(value, target, alpha);
+ }
+
+ ///
+ /// Linearly interpolates from the current value to a specified target using a specified alpha.
+ ///
+ /// The interpolation source.
+ /// The interpolation target.
+ /// The interpolation alpha.
+ ///
+ /// The interpolation result as determined by (1 - alpha) * value + alpha * target.
///
public static float LerpTo(this int value, float target, float alpha)
{
- return SingleExtensions.LerpInternal(value, target, alpha);
+ return MathUtils.Lerp(value, target, alpha);
}
///
@@ -164,12 +145,25 @@ namespace X10D
/// The interpolation source.
/// The interpolation target.
///
- /// The interpolation result as determined by (1 - ) * +
- /// * .
+ /// The interpolation result as determined by (1 - alpha) * value + alpha * target.
+ ///
+ public static double LerpWith(this int alpha, double value, double target)
+ {
+ return MathUtils.Lerp(value, target, alpha);
+ }
+
+ ///
+ /// Linearly interpolates to a specified target from a specified source, using the current value as the alpha value.
+ ///
+ /// The interpolation alpha.
+ /// The interpolation source.
+ /// The interpolation target.
+ ///
+ /// The interpolation result as determined by (1 - alpha) * value + alpha * target.
///
public static float LerpWith(this int alpha, float value, float target)
{
- return SingleExtensions.LerpInternal(value, target, alpha);
+ return MathUtils.Lerp(value, target, alpha);
}
///
diff --git a/X10D/src/Int64Extensions/Int64Extensions.cs b/X10D/src/Int64Extensions/Int64Extensions.cs
index 2789a69..fb32ddb 100644
--- a/X10D/src/Int64Extensions/Int64Extensions.cs
+++ b/X10D/src/Int64Extensions/Int64Extensions.cs
@@ -114,42 +114,11 @@ namespace X10D
/// The interpolation source.
/// The interpolation alpha.
///
- /// The interpolation result as determined by (1 - ) * +
- /// * .
+ /// The interpolation result as determined by (1 - alpha) * value + alpha * target.
///
public static double LerpFrom(this long target, double value, double alpha)
{
- return DoubleExtensions.LerpInternal(value, target, alpha);
- }
-
- ///
- /// Linearly interpolates from the current value to a specified target using a specified alpha.
- ///
- /// The interpolation source.
- /// The interpolation target.
- /// The interpolation alpha.
- ///
- /// The interpolation result as determined by (1 - ) * +
- /// * .
- ///
- public static double LerpTo(this long value, double target, double alpha)
- {
- return DoubleExtensions.LerpInternal(value, target, alpha);
- }
-
- ///
- /// Linearly interpolates to a specified target from a specified source, using the current value as the alpha value.
- ///
- /// The interpolation alpha.
- /// The interpolation source.
- /// The interpolation target.
- ///
- /// The interpolation result as determined by (1 - ) * +
- /// * .
- ///
- public static double LerpWith(this long alpha, double value, double target)
- {
- return DoubleExtensions.LerpInternal(value, target, alpha);
+ return MathUtils.Lerp(value, target, alpha);
}
///
@@ -159,12 +128,11 @@ namespace X10D
/// The interpolation source.
/// The interpolation alpha.
///
- /// The interpolation result as determined by (1 - ) * +
- /// * .
+ /// The interpolation result as determined by (1 - alpha) * value + alpha * target.
///
public static float LerpFrom(this long target, float value, float alpha)
{
- return SingleExtensions.LerpInternal(value, target, alpha);
+ return MathUtils.Lerp(value, target, alpha);
}
///
@@ -174,12 +142,25 @@ namespace X10D
/// The interpolation target.
/// The interpolation alpha.
///
- /// The interpolation result as determined by (1 - ) * +
- /// * .
+ /// The interpolation result as determined by (1 - alpha) * value + alpha * target.
+ ///
+ public static double LerpTo(this long value, double target, double alpha)
+ {
+ return MathUtils.Lerp(value, target, alpha);
+ }
+
+ ///
+ /// Linearly interpolates from the current value to a specified target using a specified alpha.
+ ///
+ /// The interpolation source.
+ /// The interpolation target.
+ /// The interpolation alpha.
+ ///
+ /// The interpolation result as determined by (1 - alpha) * value + alpha * target.
///
public static float LerpTo(this long value, float target, float alpha)
{
- return SingleExtensions.LerpInternal(value, target, alpha);
+ return MathUtils.Lerp(value, target, alpha);
}
///
@@ -189,12 +170,25 @@ namespace X10D
/// The interpolation source.
/// The interpolation target.
///
- /// The interpolation result as determined by (1 - ) * +
- /// * .
+ /// The interpolation result as determined by (1 - alpha) * value + alpha * target.
+ ///
+ public static double LerpWith(this long alpha, double value, double target)
+ {
+ return MathUtils.Lerp(value, target, alpha);
+ }
+
+ ///
+ /// Linearly interpolates to a specified target from a specified source, using the current value as the alpha value.
+ ///
+ /// The interpolation alpha.
+ /// The interpolation source.
+ /// The interpolation target.
+ ///
+ /// The interpolation result as determined by (1 - alpha) * value + alpha * target.
///
public static float LerpWith(this long alpha, float value, float target)
{
- return SingleExtensions.LerpInternal(value, target, alpha);
+ return MathUtils.Lerp(value, target, alpha);
}
///
diff --git a/X10D/src/MathUtils.cs b/X10D/src/MathUtils.cs
new file mode 100644
index 0000000..1cc86d9
--- /dev/null
+++ b/X10D/src/MathUtils.cs
@@ -0,0 +1,38 @@
+namespace X10D
+{
+ ///
+ /// Provides static helpers methods for mathematical functions not found in the .NET class.
+ ///
+ public static class MathUtils
+ {
+ ///
+ /// Linearly interpolates from one value to a target using a specified alpha.
+ ///
+ /// The interpolation source.
+ /// The interpolation target.
+ /// The interpolation alpha.
+ ///
+ /// The interpolation result as determined by (1 - alpha) * value + alpha * target.
+ ///
+ public static float Lerp(float value, float target, float alpha)
+ {
+ return (float)Lerp(value * 1.0, target, alpha);
+ }
+
+ ///
+ /// Linearly interpolates from one value to a target using a specified alpha.
+ ///
+ /// The interpolation source.
+ /// The interpolation target.
+ /// The interpolation alpha.
+ ///
+ /// The interpolation result as determined by (1 - alpha) * value + alpha * target.
+ ///
+ public static double Lerp(double value, double target, double alpha)
+ {
+ // rookie mistake: a + t * (b - a)
+ // "precise" method: (1 - t) * a + t * b
+ return ((1.0 - alpha) * value) + (alpha * target);
+ }
+ }
+}
diff --git a/X10D/src/SingleExtensions/SingleExtensions.cs b/X10D/src/SingleExtensions/SingleExtensions.cs
index f86584d..b2ef168 100644
--- a/X10D/src/SingleExtensions/SingleExtensions.cs
+++ b/X10D/src/SingleExtensions/SingleExtensions.cs
@@ -1,5 +1,4 @@
-using System;
-using System.Runtime.CompilerServices;
+using System;
namespace X10D
{
@@ -61,12 +60,11 @@ namespace X10D
/// The interpolation source.
/// The interpolation alpha.
///
- /// The interpolation result as determined by (1 - ) * +
- /// * .
+ /// The interpolation result as determined by (1 - alpha) * value + alpha * target.
///
public static float LerpFrom(this float target, float value, float alpha)
{
- return LerpInternal(value, target, alpha);
+ return MathUtils.Lerp(value, target, alpha);
}
///
@@ -76,12 +74,11 @@ namespace X10D
/// The interpolation target.
/// The interpolation alpha.
///
- /// The interpolation result as determined by (1 - ) * +
- /// * .
+ /// The interpolation result as determined by (1 - alpha) * value + alpha * target.
///
public static float LerpTo(this float value, float target, float alpha)
{
- return LerpInternal(value, target, alpha);
+ return MathUtils.Lerp(value, target, alpha);
}
///
@@ -91,12 +88,11 @@ namespace X10D
/// The interpolation source.
/// The interpolation target.
///
- /// The interpolation result as determined by (1 - ) * +
- /// * .
+ /// The interpolation result as determined by (1 - alpha) * value + alpha * target.
///
public static float LerpWith(this float alpha, float value, float target)
{
- return LerpInternal(value, target, alpha);
+ return MathUtils.Lerp(value, target, alpha);
}
///
@@ -141,13 +137,5 @@ namespace X10D
{
return value != 0.0f;
}
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- internal static float LerpInternal(float a, float b, float t)
- {
- // rookie mistake: a + t * (b - a)
- // "precise" method: (1 - t) * a + t * b
- return (1.0f - t) * a + t * b;
- }
}
}