| | | 1 | | // Copyright (c) 2020-2024 dotBunny Inc. |
| | | 2 | | // dotBunny licenses this file to you under the BSL-1.0 license. |
| | | 3 | | // See the LICENSE file in the project root for more information. |
| | | 4 | | |
| | | 5 | | using System.Runtime.CompilerServices; |
| | | 6 | | |
| | | 7 | | namespace GDX.Mathematics |
| | | 8 | | { |
| | | 9 | | /// <summary> |
| | | 10 | | /// Some simple logic to pick a value from a range. |
| | | 11 | | /// </summary> |
| | | 12 | | public static class Range |
| | | 13 | | { |
| | | 14 | | /// <summary> |
| | | 15 | | /// Returns the <see cref="double" /> between <paramref name="minValue" /> and |
| | | 16 | | /// <paramref name="maxValue" /> range at <paramref name="percent" />. |
| | | 17 | | /// </summary> |
| | | 18 | | /// <param name="percent">The percentage (0-1) used to find a value in the range provided.</param> |
| | | 19 | | /// <param name="minValue">The lowest possible value.</param> |
| | | 20 | | /// <param name="maxValue">The highest possible value.</param> |
| | | 21 | | /// <returns>A <see cref="double" /> value.</returns> |
| | | 22 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | | 23 | | public static double GetDouble(double percent, double minValue = double.MinValue, |
| | | 24 | | double maxValue = double.MaxValue) |
| | 71 | 25 | | { |
| | 71 | 26 | | return maxValue * percent + minValue * (1d - percent); |
| | 71 | 27 | | } |
| | | 28 | | |
| | | 29 | | /// <summary> |
| | | 30 | | /// Returns the <see cref="int" /> between <paramref name="minValue" /> and |
| | | 31 | | /// <paramref name="maxValue" /> range at <paramref name="percent" />. |
| | | 32 | | /// </summary> |
| | | 33 | | /// <param name="percent">The percentage (0-1) used to find a value in the range provided.</param> |
| | | 34 | | /// <param name="minValue">The lowest possible value.</param> |
| | | 35 | | /// <param name="maxValue">The highest possible value.</param> |
| | | 36 | | /// <returns>The <see cref="int" /> value.</returns> |
| | | 37 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | | 38 | | public static int GetInteger(double percent, int minValue = int.MinValue, int maxValue = int.MaxValue) |
| | 179 | 39 | | { |
| | 179 | 40 | | return (int)(maxValue * percent + minValue * (1d - percent)); |
| | 179 | 41 | | } |
| | | 42 | | |
| | | 43 | | /// <summary> |
| | | 44 | | /// Returns the <see cref="float" /> between <paramref name="minValue" /> and |
| | | 45 | | /// <paramref name="maxValue" /> range at <paramref name="percent" />. |
| | | 46 | | /// </summary> |
| | | 47 | | /// <param name="percent">The percentage (0-1) used to find a value in the range provided.</param> |
| | | 48 | | /// <param name="minValue">The lowest possible value.</param> |
| | | 49 | | /// <param name="maxValue">The highest possible value.</param> |
| | | 50 | | /// <returns>A <see cref="float" /> value.</returns> |
| | | 51 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | | 52 | | public static float GetSingle(double percent, float minValue = float.MinValue, float maxValue = float.MaxValue) |
| | 69 | 53 | | { |
| | 69 | 54 | | return (float)(maxValue * percent + minValue * (1d - percent)); |
| | 69 | 55 | | } |
| | | 56 | | |
| | | 57 | | /// <summary> |
| | | 58 | | /// Returns the <see cref="uint" /> between <paramref name="minValue" /> and |
| | | 59 | | /// <paramref name="maxValue" /> range at <paramref name="percent" />. |
| | | 60 | | /// </summary> |
| | | 61 | | /// <param name="percent">The percentage (0-1) used to find a value in the range provided.</param> |
| | | 62 | | /// <param name="minValue">The lowest possible value.</param> |
| | | 63 | | /// <param name="maxValue">The highest possible value.</param> |
| | | 64 | | /// <returns>A <see cref="uint" /> value.</returns> |
| | | 65 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | | 66 | | public static uint GetUnsignedInteger(double percent, uint minValue = uint.MinValue, |
| | | 67 | | uint maxValue = uint.MaxValue) |
| | 72 | 68 | | { |
| | 72 | 69 | | return (uint)(maxValue * percent + minValue * (1d - percent)); |
| | 72 | 70 | | } |
| | | 71 | | } |
| | | 72 | | } |