using System.Runtime.CompilerServices; using UnityEngine; namespace Boxfriend.Extensions { public static class MathExtensions { /// /// Checks if value is within specified range. /// /// Lowest value of the range /// Largest value of the range /// True if less than min and greater than max [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool InRange(this int value, int min, int max) => (value >= min) && (value <= max); /// /// Checks if value is within specified range. /// /// Lowest value of the range /// Largest value of the range /// True if less than min and greater than max [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool InRange(this float value, float min, float max) => (value >= min) && (value <= max); /// /// Checks if value is within specified range. /// /// Lowest value of the range /// Largest value of the range /// True if less than min and greater than max [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool InRange(this double value, double min, double max) => (value >= min) && (value <= max); public static Vector2 Rotate(this Vector2 vector, float degrees) { float sin = Mathf.Sin(degrees * Mathf.Deg2Rad); float cos = Mathf.Cos(degrees * Mathf.Deg2Rad); float tx = vector.x; float ty = vector.y; vector.x = (cos * tx) - (sin * ty); vector.y = (sin * tx) + (cos * ty); return vector; } } }