Created
May 25, 2024 13:58
-
-
Save gruhh/da30eaa6615f6a9cf8932bf6ee171d15 to your computer and use it in GitHub Desktop.
Zero-One Circumference Clamp in CSharp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <summary> | |
/// Class Circumference | |
/// </summary> | |
public static class Circumference | |
{ | |
/// <summary> | |
/// Clamps the circumference to a [0..1] float | |
/// <example>For example: | |
/// <code> | |
/// float f = ZeroOneClamp(1.2f); | |
/// </code> | |
/// results in <c>f</c>'s having the value .2f. | |
/// <code> | |
/// float f = ZeroOneClamp(-1.2f); | |
/// </code> | |
/// results in <c>f</c>'s having the value .8f. | |
/// <code> | |
/// float f = ZeroOneClamp(1f + 1.2f); | |
/// </code> | |
/// results in <c>f</c>'s having the value .2f. | |
/// </example> | |
/// </summary> | |
/// <returns>Float value in the range 0.0 and 1.0.</returns> | |
public static float ZeroOneClamp(float f) | |
{ | |
if (f % 1 > 0) | |
f %= 1; | |
else if (f % 1 < 0) | |
f = 1 + f % 1; | |
return f; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment