Simple Math and Geometry convenience improvements
See original GitHub issueSummary
The following suggestions were gathered while using the engine for a number of projects. The intention is to make one’s life easier by providing shortcuts for common calculations.
List of suggestions
- Vector component properties for
Vector2
andVector3
types. Obtaining the X, Y and Z vector components quickly. Names are arguable. Implementation example:
struct Vector3 {
Vector3 XVector { get { return new Vector3 (this.X, 0f, 0f); } }
Vector3 YVector { get { return new Vector3 (0f, this.Y, 0f); } }
Vector3 ZVector { get { return new Vector3 (0f, 0f, this.Z); } }
}
-
More coordinate selector properties for
Rect
. Convenient access for:TopMiddle
,RightMiddle
,BottomMiddle
andLeftMiddle
coordinates. -
A saturation function to the
MathF
class. Similar toSign
, but accepts an epsilon value too. Implementation example:
float Saturate (float val, float eps)
{
if (Abs (val) <= eps) return 0f;
return Sign (val);
}
-
Clamp
is quite often used with0f
and1f
as boundaries. Let’s create a function for that:Clamp01
. -
Inverse linear interpolation to
MathF
, and possibly toVector2
andVector3
. Implementation example:
float InvLerp (float value, float min, float max)
{
return (value - min) / (max - min);
}
-
Inverse linear interpolation with
0f
and1f
as boundaries. -
Introduce the well known
smoothstep
function toMathF
. The formula isx * x * (3 - 2 * x)
.
Issue Analytics
- State:
- Created 6 years ago
- Comments:24 (23 by maintainers)
Top GitHub Comments
If you wanted to go the extra mile you could add unit tests for this to the DualityTests project. That’d also give you a chance to test every case without needing to setup a game project. You’ll need to install the NUnit test adapter in order or run the unit tests.
@helle253 Yep, nothing on that Todo list has been done yet. Have at it.