/// <summary> /// Clamps the other Rect to this one. /// </summary> /// <param name="extends">Extends.</param> /// <param name="other">Other.</param> public static Rect Clamp(this Rect extends, Rect other) { Vector2 min = extends.Clamp(other.min); Vector2 max = extends.Clamp(other.max); return RectUtils.MinMaxRect(min, max); }
public static bool Overlaps(this Rect rect, Circle circle) { if (!rect.Overlaps(circle.Bounds)) return false; var clamped = rect.Clamp(circle.Position); float distance = (circle.Position - clamped).sqrMagnitude; return distance < circle.Radius * circle.Radius; }
//---------------------------------------------------------------------------------------------------------------------------------------------- public static double Rescale(this double value, double from_min, double from_max, double to_min, double to_max) { //clamp value double temp = value.Clamp(from_min, from_max); //offset to zero temp = temp - from_min; //rescale to 0..1 temp = temp / (from_max - from_min); //rescale to new length temp = temp * (to_max - to_min); //offset to new min temp = temp + to_min; return temp; }
//---------------------------------------------------------------------------------------------------------------------------------------------- public static float Rescale(this float value, float from_min, float from_max, float to_min, float to_max) { //clamp value float temp = value.Clamp(from_min, from_max); //offset to zero temp = temp - from_min; //rescale to 0..1 temp = temp / (from_max - from_min); //rescale to new length temp = temp * (to_max - to_min); //offset to new min temp = temp + to_min; return temp; }
public static Single Lerp( this Single t, Single from, Single to ) { return t.Clamp (0,1) * (to - from) + from; }
/// <summary> /// Converts an <see cref="double"/> to a <see cref="byte"/> first restricting the value between the /// minimum and maximum allowable ranges. /// </summary> /// <param name="value">The <see cref="double"/> this method extends.</param> /// <returns>The <see cref="byte"/></returns> public static byte ToByte(this double value) { return (byte)value.Clamp(0, 255); }
public static byte AngleToByte(this double angle) { return (byte)(angle.Clamp(0, Math.PI) / Math.PI * 255); }
/** * Casts a float to byte by clamping it between 0 and 1 and then multiplying by 255. */ public static byte ToByte(this float value) { return (byte) (value.Clamp(0, 1)*255); }
public static double Clamp(this double d, MinMax range) { return d.Clamp(range.Min, range.Max); }
public static float Clamp(this float f, Vector2 v) { return f.Clamp(v.x, v.y); }
public static Double Lerp( this Double t, Double from, Double to ) { return t.Clamp (0,1) * (to - from) + from; }
public static Color4 ToColor4(this System.Windows.Media.Color color) { color.Clamp(); return new global::SharpDX.Color4(color.R / 255f, color.G / 255f, color.B / 255f, color.A / 255f); }
public static int Clamp( this int Number ) { return Number.Clamp( 0, int.MaxValue ); }
public static int Clamp(this int i, MinMax range) { return i.Clamp((int)range.Min, (int)range.Max); }
public static Vector4f Saturate( this Vector4f v ) { return v.Clamp( 0.0f, 1.0f ); }
public static float Saturate( this float x ) { return x.Clamp( 0.0f, 1.0f ); }
public static float Saturate( this int x ) { return x.Clamp( 0, 256 ); }
public static Decimal Lerp( this Decimal t, Decimal from, Decimal to ) { return t.Clamp (0,1) * (to - from) + from; }
public static Quaternion Clamp(this Quaternion toClamp, Vector3 forward, float degreeFreedom) { return toClamp.Clamp(forward, degreeFreedom, degreeFreedom, degreeFreedom); }
public static void Clamp(this Vector2 thisVector, float floor) { thisVector.Clamp(floor, 0f); }
public static float Clamp(this float f, MinMax range) { return f.Clamp(range.Min, range.Max); }