Exemplo n.º 1
0
		/// <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);
		}
Exemplo n.º 2
0
        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;
        }
Exemplo n.º 3
0
        //----------------------------------------------------------------------------------------------------------------------------------------------

        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;
        }
Exemplo n.º 4
0
        //----------------------------------------------------------------------------------------------------------------------------------------------

        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;
        }
Exemplo n.º 5
0
 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);
 }
Exemplo n.º 7
0
 public static byte AngleToByte(this double angle)
 {
     return (byte)(angle.Clamp(0, Math.PI) / Math.PI * 255);
 }
Exemplo n.º 8
0
 /**
  * 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);
 }
Exemplo n.º 9
0
 public static double Clamp(this double d, MinMax range)
 {
     return d.Clamp(range.Min, range.Max);
 }
Exemplo n.º 10
0
	public static float Clamp(this float f, Vector2 v) { return f.Clamp(v.x, v.y); }
Exemplo n.º 11
0
 public static Double Lerp(
     this Double t,
     Double from,
     Double to
     )
 {
     return t.Clamp (0,1) * (to - from) + from;
 }
Exemplo n.º 12
0
 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);
 }
Exemplo n.º 13
0
		public static int Clamp( this int Number ) {
			return Number.Clamp( 0, int.MaxValue );
		}
Exemplo n.º 14
0
 public static int Clamp(this int i, MinMax range)
 {
     return i.Clamp((int)range.Min, (int)range.Max);
 }
Exemplo n.º 15
0
 public static Vector4f Saturate( this Vector4f v )
 {
     return v.Clamp( 0.0f, 1.0f );
 }
Exemplo n.º 16
0
 public static float Saturate( this float x )
 {
     return x.Clamp( 0.0f, 1.0f );
 }
Exemplo n.º 17
0
 public static float Saturate( this int x )
 {
     return x.Clamp( 0, 256 );
 }
Exemplo n.º 18
0
 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);
 }
Exemplo n.º 21
0
 public static float Clamp(this float f, MinMax range)
 {
     return f.Clamp(range.Min, range.Max);
 }