mirror of
https://github.com/oliverbooth/X10D
synced 2024-11-10 02:45:41 +00:00
Add MathUtility.ScaleRange
This commit is contained in:
parent
384ec3f61c
commit
eadb66f470
@ -7,6 +7,7 @@
|
|||||||
- Added .NET 7 target
|
- Added .NET 7 target
|
||||||
|
|
||||||
- X10D: Added `MathUtility.InverseLerp(float, float, float)` and `MathUtility.InverseLerp(double, 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: 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 `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
|
- X10D: Added `Color.Deconstruct()` - with optional alpha parameter
|
||||||
- X10D: Added `Color.GetClosestConsoleColor()`
|
- X10D: Added `Color.GetClosestConsoleColor()`
|
||||||
|
@ -99,4 +99,34 @@ public static class MathUtility
|
|||||||
// "precise" method: (1 - t) * a + t * b
|
// "precise" method: (1 - t) * a + t * b
|
||||||
return ((1.0 - alpha) * value) + (alpha * target);
|
return ((1.0 - alpha) * value) + (alpha * target);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Converts a value from being a percentage of one range, to being the same percentage in a new range.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="value">The value to convert.</param>
|
||||||
|
/// <param name="oldMin">The old minimum value.</param>
|
||||||
|
/// <param name="oldMax">The old maximum value.</param>
|
||||||
|
/// <param name="newMin">The new minimum value.</param>
|
||||||
|
/// <param name="newMax">The new maximum value.</param>
|
||||||
|
/// <returns>The scaled value.</returns>
|
||||||
|
public static float ScaleRange(float value, float oldMin, float oldMax, float newMin, float newMax)
|
||||||
|
{
|
||||||
|
float alpha = InverseLerp(value, oldMin, oldMax);
|
||||||
|
return Lerp(newMin, newMax, alpha);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Converts a value from being a percentage of one range, to being the same percentage in a new range.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="value">The value to convert.</param>
|
||||||
|
/// <param name="oldMin">The old minimum value.</param>
|
||||||
|
/// <param name="oldMax">The old maximum value.</param>
|
||||||
|
/// <param name="newMin">The new minimum value.</param>
|
||||||
|
/// <param name="newMax">The new maximum value.</param>
|
||||||
|
/// <returns>The scaled value.</returns>
|
||||||
|
public static double ScaleRange(double value, double oldMin, double oldMax, double newMin, double newMax)
|
||||||
|
{
|
||||||
|
double alpha = InverseLerp(value, oldMin, oldMax);
|
||||||
|
return Lerp(newMin, newMax, alpha);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user