Пример #1
0
        public static short Pack(Vector2b vector)
        {
            ulong x = (ulong)(vector.X) << 0;
            ulong y = (ulong)(vector.Y) << 8;

            return((short)(x | y));
        }
Пример #2
0
        public static short Pack(int xBits, int yBits, Vector2b 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((short)(x | y));
        }
Пример #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Vector8b"/> 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 Vector8b(Vector2b value, byte v2, byte v3, byte v4, byte v5, byte v6, byte v7, byte v8, byte v9)
 {
     V0 = value.X;
     V1 = value.Y;
     V2 = v2;
     V3 = v3;
     V4 = v4;
     V5 = v5;
     V6 = v6;
     V7 = v7;
 }
Пример #4
0
        /// <summary>
        /// Transforms a vector in cartesian coordinates to polar coordinates.
        /// </summary>
        /// <param name="value">The vector to transform.</param>
        /// <returns>The polar coordinates of value.</returns>
        public static PolarCoordinate CartesianToPolar(Vector2b 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)));
        }
Пример #5
0
        /// <summary>
        /// Computes the normalized value (or unit) of a vector.
        /// </summary>
        /// <param name="value">A vector.</param>
        /// <returns>The normalized value of value.</returns>
        public static Vector2f Normalize(Vector2b value)
        {
            var absolute = Absolute(value);

            if (absolute <= float.Epsilon)
            {
                return(Vector2b.Zero);
            }
            else
            {
                return((Vector2f)value / absolute);
            }
        }
Пример #6
0
 /// <summary>
 /// Computes the absolute squared value of a vector and returns the result.
 /// </summary>
 /// <param name="value">A vector.</param>
 /// <returns>The absolute squared value of value.</returns>
 public static int AbsoluteSquared(Vector2b value)
 {
     return(Dot(value, value));
 }
Пример #7
0
 /// <summary>
 /// Determines whether any component of a vector is non-zero.
 /// </summary>
 /// <param name="value">A vector.</param>
 /// <returns>true if any components are non-zero; false otherwise.</returns>
 public static bool Any(Vector2b value)
 {
     return(value.X != 0 || value.Y != 0);
 }
Пример #8
0
 /// <summary>
 /// Determines whether any components of a vector satisfy a condition.
 /// </summary>
 /// <param name="value">A vector.</param>
 /// <param name="predicate">A function to test each component for a condition.</param>
 /// <returns>true if any component of the vector passes the test in the specified
 /// predicate; otherwise, false.</returns>
 public static bool Any(Vector2b value, Predicate <byte> predicate)
 {
     return(predicate(value.X) || predicate(value.Y));
 }
Пример #9
0
 /// <summary>
 /// Calculates the dot product (inner product) of two vectors.
 /// </summary>
 /// <param name="left">First source vector.</param>
 /// <param name="right">Second source vector.</param>
 /// <returns>The dot product of the two vectors.</returns>
 public static int Dot(Vector2b left, Vector2b right)
 {
     return(left.X * right.X + left.Y * right.Y);
 }
Пример #10
0
 /// <summary>
 /// Determines whether all components of a vector are non-zero.
 /// </summary>
 /// <param name="value">A vector.</param>
 /// <returns>true if all components are non-zero; false otherwise.</returns>
 public static bool All(Vector2b value)
 {
     return(value.X != 0 && value.Y != 0);
 }
Пример #11
0
 /// <summary>
 /// Returns a vector that contains the highest value from each pair of components.
 /// </summary>
 /// <param name="value1">The first vector.</param>
 /// <param name="value2">The second vector.</param>
 /// <returns>The highest of each component in left and the matching component in right.</returns>
 public static Vector2b Max(Vector2b value1, Vector2b value2)
 {
     return(new Vector2b(Functions.Max(value1.X, value2.X), Functions.Max(value1.Y, value2.Y)));
 }
Пример #12
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(Vector2b left, Vector2b right)
 {
     return(left == right);
 }
Пример #13
0
 /// <summary>
 /// Maps the components of a vector and returns the result.
 /// </summary>
 /// <param name="value">The vector to map.</param>
 /// <param name="mapping">A mapping function to apply to each component.</param>
 /// <returns>The result of mapping each component of value.</returns>
 public static Vector2h Map(Vector2b value, Func <byte, Half> mapping)
 {
     return(new Vector2h(mapping(value.X), mapping(value.Y)));
 }
Пример #14
0
 /// <summary>
 /// Maps the components of a vector and returns the result.
 /// </summary>
 /// <param name="value">The vector to map.</param>
 /// <param name="mapping">A mapping function to apply to each component.</param>
 /// <returns>The result of mapping each component of value.</returns>
 public static Vector2ui Map(Vector2b value, Func <byte, uint> mapping)
 {
     return(new Vector2ui(mapping(value.X), mapping(value.Y)));
 }
Пример #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(Vector2b value)
 {
     return(new Vector2i(-value.X, -value.Y));
 }
Пример #16
0
 /// <summary>
 /// Maps the components of a vector and returns the result.
 /// </summary>
 /// <param name="value">The vector to map.</param>
 /// <param name="mapping">A mapping function to apply to each component.</param>
 /// <returns>The result of mapping each component of value.</returns>
 public static Vector2d Map(Vector2b value, Func <byte, double> mapping)
 {
     return(new Vector2d(mapping(value.X), mapping(value.Y)));
 }
Пример #17
0
 /// <summary>
 /// Multiplys the components of two vectors and returns the result.
 /// </summary>
 /// <param name="left">The first vector to modulate.</param>
 /// <param name="right">The second vector to modulate.</param>
 /// <returns>The result of multiplying each component of left by the matching component in right.</returns>
 public static Vector2i Modulate(Vector2b left, Vector2b right)
 {
     return(new Vector2i(left.X * right.X, left.Y * right.Y));
 }
Пример #18
0
 /// <summary>
 /// Returns the absolute value (per component).
 /// </summary>
 /// <param name="value">A vector.</param>
 /// <returns>The absolute value (per component) of value.</returns>
 public static Vector2b Abs(Vector2b value)
 {
     return(new Vector2b(Functions.Abs(value.X), Functions.Abs(value.Y)));
 }
Пример #19
0
 /// <summary>
 /// Writes the given <see cref="Vector2b"/> to an <see cref="Ibasa.IO.BinaryWriter">.
 /// </summary>
 public static void Write(this Ibasa.IO.BinaryWriter writer, Vector2b vector)
 {
     writer.Write(vector.X);
     writer.Write(vector.Y);
 }
Пример #20
0
 /// <summary>
 /// Computes the absolute value (or modulus or magnitude) of a vector and returns the result.
 /// </summary>
 /// <param name="value">A vector.</param>
 /// <returns>The absolute value of value.</returns>
 public static float Absolute(Vector2b value)
 {
     return(Functions.Sqrt(AbsoluteSquared(value)));
 }
Пример #21
0
 /// <summary>
 /// Maps the components of a vector and returns the result.
 /// </summary>
 /// <param name="value">The vector to map.</param>
 /// <param name="mapping">A mapping function to apply to each component.</param>
 /// <returns>The result of mapping each component of value.</returns>
 public static Vector2sb Map(Vector2b value, Func <byte, sbyte> mapping)
 {
     return(new Vector2sb(mapping(value.X), mapping(value.Y)));
 }
Пример #22
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(Vector2b left, Vector2b right)
 {
     return(new Vector2i(left.X + right.X, left.Y + right.Y));
 }
Пример #23
0
 /// <summary>
 /// Constrains each component to a given range.
 /// </summary>
 /// <param name="value">A vector to constrain.</param>
 /// <param name="min">The minimum values for each component.</param>
 /// <param name="max">The maximum values for each component.</param>
 /// <returns>A vector with each component constrained to the given range.</returns>
 public static Vector2b Clamp(Vector2b value, Vector2b min, Vector2b max)
 {
     return(new Vector2b(Functions.Clamp(value.X, min.X, max.X), Functions.Clamp(value.Y, min.Y, max.Y)));
 }
Пример #24
0
 /// <summary>
 /// Maps the components of a vector and returns the result.
 /// </summary>
 /// <param name="value">The vector to map.</param>
 /// <param name="mapping">A mapping function to apply to each component.</param>
 /// <returns>The result of mapping each component of value.</returns>
 public static Vector2f Map(Vector2b value, Func <byte, float> mapping)
 {
     return(new Vector2f(mapping(value.X), mapping(value.Y)));
 }
Пример #25
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(Vector2b left, Vector2b right)
 {
     return(new Vector2i(left.X - right.X, left.Y - right.Y));
 }
Пример #26
0
 /// <summary>
 /// Maps the components of a vector and returns the result.
 /// </summary>
 /// <param name="value">The vector to map.</param>
 /// <param name="mapping">A mapping function to apply to each component.</param>
 /// <returns>The result of mapping each component of value.</returns>
 public static Vector2l Map(Vector2b value, Func <byte, long> mapping)
 {
     return(new Vector2l(mapping(value.X), mapping(value.Y)));
 }
Пример #27
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(Vector2b vector, int scalar)
 {
     return(new Vector2i(vector.X * scalar, vector.Y * scalar));
 }
Пример #28
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(Vector2b vector, int scalar)
 {
     return(new Vector2i(vector.X / scalar, vector.Y / scalar));
 }
Пример #29
0
 /// <summary>
 /// Maps the components of a vector and returns the result.
 /// </summary>
 /// <param name="value">The vector to map.</param>
 /// <param name="mapping">A mapping function to apply to each component.</param>
 /// <returns>The result of mapping each component of value.</returns>
 public static Vector2us Map(Vector2b value, Func <byte, ushort> mapping)
 {
     return(new Vector2us(mapping(value.X), mapping(value.Y)));
 }