Beispiel #1
0
        public static ushort Pack(Vector2sb vector)
        {
            ulong x = (ulong)(vector.X) << 0;
            ulong y = (ulong)(vector.Y) << 8;

            return((ushort)(x | y));
        }
Beispiel #2
0
        public static ushort Pack(int xBits, int yBits, Vector2sb vector)
        {
            Contract.Requires(0 <= xBits && xBits <= 8, "xBits must be between 0 and 8 inclusive.");
            Contract.Requires(0 <= yBits && yBits <= 8, "yBits must be between 0 and 8 inclusive.");
            Contract.Requires(xBits + yBits <= 16);
            ulong x = (ulong)(vector.X) >> (16 - xBits);
            ulong y = (ulong)(vector.Y) >> (16 - yBits);

            y <<= xBits;
            return((ushort)(x | y));
        }
Beispiel #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Vector8sb"/> using the specified vector and values.
 /// </summary>
 /// <param name="value">A vector containing the values with which to initialize the first 2 components</param>
 /// <param name="v2">Value for the V2 component of the vector.</param>
 /// <param name="v3">Value for the V3 component of the vector.</param>
 /// <param name="v4">Value for the V4 component of the vector.</param>
 /// <param name="v5">Value for the V5 component of the vector.</param>
 /// <param name="v6">Value for the V6 component of the vector.</param>
 /// <param name="v7">Value for the V7 component of the vector.</param>
 public Vector8sb(Vector2sb value, sbyte v2, sbyte v3, sbyte v4, sbyte v5, sbyte v6, sbyte v7, sbyte v8, sbyte v9)
 {
     V0 = value.X;
     V1 = value.Y;
     V2 = v2;
     V3 = v3;
     V4 = v4;
     V5 = v5;
     V6 = v6;
     V7 = v7;
 }
Beispiel #4
0
        public static PolarCoordinate CartesianToPolar(Vector2sb value)
        {
            double theta = Functions.Atan2(value.Y, value.X);

            if (theta < 0)
            {
                theta += 2 * Constants.Pi;
            }
            return(new PolarCoordinate(
                       theta,
                       (double)Functions.Sqrt(value.X * value.X + value.Y * value.Y)));
        }
Beispiel #5
0
        public static Vector2f Normalize(Vector2sb value)
        {
            var absolute = Absolute(value);

            if (absolute <= float.Epsilon)
            {
                return(Vector2sb.Zero);
            }
            else
            {
                return((Vector2f)value / absolute);
            }
        }
Beispiel #6
0
 public static bool All(Vector2sb value)
 {
     return(value.X != 0 && value.Y != 0);
 }
Beispiel #7
0
 public static bool Any(Vector2sb value)
 {
     return(value.X != 0 || value.Y != 0);
 }
Beispiel #8
0
 /// <summary>
 /// Returns a value that indicates whether two vectors are equal.
 /// </summary>
 /// <param name="left">The first vector to compare.</param>
 /// <param name="right">The second vector to compare.</param>
 /// <returns>true if the left and right are equal; otherwise, false.</returns>
 public static bool Equals(Vector2sb left, Vector2sb right)
 {
     return(left == right);
 }
Beispiel #9
0
 public static int Dot(Vector2sb left, Vector2sb right)
 {
     return(left.X * right.X + left.Y * right.Y);
 }
Beispiel #10
0
 public static Vector2sb Clamp(Vector2sb value, Vector2sb min, Vector2sb max)
 {
     return(new Vector2sb(Functions.Clamp(value.X, min.X, max.X), Functions.Clamp(value.Y, min.Y, max.Y)));
 }
Beispiel #11
0
 /// <summary>
 /// Divides a vector by a scalar and returns the result.
 /// </summary>
 /// <param name="vector">The vector to be divided (the dividend).</param>
 /// <param name="scalar">The scalar to divide by (the divisor).</param>
 /// <returns>The result of dividing left by right (the quotient).</returns>
 public static Vector2i Divide(Vector2sb vector, int scalar)
 {
     return(new Vector2i(vector.X / scalar, vector.Y / scalar));
 }
Beispiel #12
0
 public static Vector2d Map(Vector2sb value, Func <sbyte, double> mapping)
 {
     return(new Vector2d(mapping(value.X), mapping(value.Y)));
 }
Beispiel #13
0
 public static float Absolute(Vector2sb value)
 {
     return(Functions.Sqrt(AbsoluteSquared(value)));
 }
Beispiel #14
0
 public static Vector2s Map(Vector2sb value, Func <sbyte, short> mapping)
 {
     return(new Vector2s(mapping(value.X), mapping(value.Y)));
 }
Beispiel #15
0
 /// <summary>
 /// Returns the additive inverse of a vector.
 /// </summary>
 /// <param name="value">A vector.</param>
 /// <returns>The negative of value.</returns>
 public static Vector2i Negative(Vector2sb value)
 {
     return(new Vector2i(-value.X, -value.Y));
 }
Beispiel #16
0
 public static Vector2i Modulate(Vector2sb left, Vector2sb right)
 {
     return(new Vector2i(left.X * right.X, left.Y * right.Y));
 }
Beispiel #17
0
 /// <summary>
 /// Writes the given <see cref="Vector2sb"/> to an <see cref="Ibasa.IO.BinaryWriter">.
 /// </summary>
 public static void Write(this Ibasa.IO.BinaryWriter writer, Vector2sb vector)
 {
     writer.Write(vector.X);
     writer.Write(vector.Y);
 }
Beispiel #18
0
 public static Vector2sb Abs(Vector2sb value)
 {
     return(new Vector2sb(Functions.Abs(value.X), Functions.Abs(value.Y)));
 }
Beispiel #19
0
 public static bool Any(Vector2sb value, Predicate <sbyte> predicate)
 {
     return(predicate(value.X) || predicate(value.Y));
 }
Beispiel #20
0
 public static Vector2h Map(Vector2sb value, Func <sbyte, Half> mapping)
 {
     return(new Vector2h(mapping(value.X), mapping(value.Y)));
 }
Beispiel #21
0
 public static int AbsoluteSquared(Vector2sb value)
 {
     return(Dot(value, value));
 }
Beispiel #22
0
 public static Vector2ui Map(Vector2sb value, Func <sbyte, uint> mapping)
 {
     return(new Vector2ui(mapping(value.X), mapping(value.Y)));
 }
Beispiel #23
0
 /// <summary>
 /// Adds two vectors and returns the result.
 /// </summary>
 /// <param name="left">The first value to add.</param>
 /// <param name="right">The second value to add.</param>
 /// <returns>The sum of left and right.</returns>
 public static Vector2i Add(Vector2sb left, Vector2sb right)
 {
     return(new Vector2i(left.X + right.X, left.Y + right.Y));
 }
Beispiel #24
0
 public static Vector2sb Max(Vector2sb value1, Vector2sb value2)
 {
     return(new Vector2sb(Functions.Max(value1.X, value2.X), Functions.Max(value1.Y, value2.Y)));
 }
Beispiel #25
0
 public static Vector2f Map(Vector2sb value, Func <sbyte, float> mapping)
 {
     return(new Vector2f(mapping(value.X), mapping(value.Y)));
 }
Beispiel #26
0
 /// <summary>
 /// Subtracts one vectors from another and returns the result.
 /// </summary>
 /// <param name="left">The value to subtract from (the minuend).</param>
 /// <param name="right">The value to subtract (the subtrahend).</param>
 /// <returns>The result of subtracting right from left (the difference).</returns>
 public static Vector2i Subtract(Vector2sb left, Vector2sb right)
 {
     return(new Vector2i(left.X - right.X, left.Y - right.Y));
 }
Beispiel #27
0
 public static Vector2l Map(Vector2sb value, Func <sbyte, long> mapping)
 {
     return(new Vector2l(mapping(value.X), mapping(value.Y)));
 }
Beispiel #28
0
 /// <summary>
 /// Returns the product of a vector and scalar.
 /// </summary>
 /// <param name="vector">The vector to multiply.</param>
 /// <param name="scalar">The scalar to multiply.</param>
 /// <returns>The product of the left and right parameters.</returns>
 public static Vector2i Multiply(Vector2sb vector, int scalar)
 {
     return(new Vector2i(vector.X * scalar, vector.Y * scalar));
 }