using System.Runtime.CompilerServices; namespace GameKit.Dependencies.Utilities { /// /// Various utility classes relating to floats. /// public static class UInts { /// /// Pads an index a specified value. Preferred over typical padding so that pad values used with skins can be easily found in the code. /// public static string Pad(this uint value, int padding) { if (padding < 0) padding = 0; return value.ToString().PadLeft(padding, '0'); } /// /// Provides a random inclusive int within a given range. Preferred over Unity's Random to eliminate confusion as Unity uses inclusive for floats max, and exclusive for int max. /// /// Inclusive minimum value. /// Inclusive maximum value. /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public static uint RandomInclusiveRange(uint minimum, uint maximum) => (uint)Ints.RandomInclusiveRange((int)minimum, (int)maximum); /// /// Provides a random exclusive int within a given range. Preferred over Unity's Random to eliminate confusion as Unity uses inclusive for floats max, and exclusive for int max. /// /// Inclusive minimum value. /// Exclusive maximum value. /// [MethodImpl(MethodImplOptions.AggressiveInlining)] public static uint RandomExclusiveRange(uint minimum, uint maximum) => (uint)Ints.RandomExclusiveRange((int)minimum, (int)maximum); /// /// Returns a clamped int within a specified range. /// /// Value to clamp. /// Minimum value. /// Maximum value. /// public static uint Clamp(uint value, uint minimum, uint maximum) { if (value < minimum) value = minimum; else if (value > maximum) value = maximum; return value; } /// /// Returns whichever value is lower. /// public static uint Min(uint a, uint b) => (a < b) ? a : b; /// /// Determins if all values passed in are the same. /// /// Values to check. /// True if all values are the same. [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool ValuesMatch(params uint[] values) => Ints.ValuesMatch((int[])(object)values); } }