예제 #1
0
 /// <summary>
 /// Writes the given <see cref="Vector8l"/> to an <see cref="Ibasa.IO.BinaryWriter">.
 /// </summary>
 public static void Write(this Ibasa.IO.BinaryWriter writer, Vector8l vector)
 {
     writer.Write(vector.V0);
     writer.Write(vector.V1);
     writer.Write(vector.V2);
     writer.Write(vector.V3);
     writer.Write(vector.V4);
     writer.Write(vector.V5);
     writer.Write(vector.V6);
     writer.Write(vector.V7);
 }
예제 #2
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 Vector8d Normalize(Vector8l value)
        {
            var absolute = Absolute(value);

            if (absolute <= double.Epsilon)
            {
                return(Vector8l.Zero);
            }
            else
            {
                return((Vector8d)value / absolute);
            }
        }
예제 #3
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 double Absolute(Vector8l value)
 {
     return(Functions.Sqrt(AbsoluteSquared(value)));
 }
예제 #4
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 long AbsoluteSquared(Vector8l value)
 {
     return(Dot(value, value));
 }
예제 #5
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(Vector8l value, Predicate <long> predicate)
 {
     return(predicate(value.V0) || predicate(value.V1) || predicate(value.V2) || predicate(value.V3) || predicate(value.V4) || predicate(value.V5) || predicate(value.V6) || predicate(value.V7));
 }
예제 #6
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 Vector8sb Map(Vector8l value, Func <long, sbyte> mapping)
 {
     return(new Vector8sb(mapping(value.V0), mapping(value.V1), mapping(value.V2), mapping(value.V3), mapping(value.V4), mapping(value.V5), mapping(value.V6), mapping(value.V7)));
 }
예제 #7
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 Vector8l Abs(Vector8l value)
 {
     return(new Vector8l(Functions.Abs(value.V0), Functions.Abs(value.V1), Functions.Abs(value.V2), Functions.Abs(value.V3), Functions.Abs(value.V4), Functions.Abs(value.V5), Functions.Abs(value.V6), Functions.Abs(value.V7)));
 }
예제 #8
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 Vector8l Divide(Vector8l vector, long scalar)
 {
     return(new Vector8l(vector.V0 / scalar, vector.V1 / scalar, vector.V2 / scalar, vector.V3 / scalar, vector.V4 / scalar, vector.V5 / scalar, vector.V6 / scalar, vector.V7 / scalar));
 }
예제 #9
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(Vector8l left, Vector8l right)
 {
     return(left == right);
 }
예제 #10
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 Vector8l Subtract(Vector8l left, Vector8l right)
 {
     return(new Vector8l(left.V0 - right.V0, left.V1 - right.V1, left.V2 - right.V2, left.V3 - right.V3, left.V4 - right.V4, left.V5 - right.V5, left.V6 - right.V6, left.V7 - right.V7));
 }
예제 #11
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 Vector8l Multiply(Vector8l vector, long scalar)
 {
     return(new Vector8l(vector.V0 * scalar, vector.V1 * scalar, vector.V2 * scalar, vector.V3 * scalar, vector.V4 * scalar, vector.V5 * scalar, vector.V6 * scalar, vector.V7 * scalar));
 }
예제 #12
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 Vector8l Add(Vector8l left, Vector8l right)
 {
     return(new Vector8l(left.V0 + right.V0, left.V1 + right.V1, left.V2 + right.V2, left.V3 + right.V3, left.V4 + right.V4, left.V5 + right.V5, left.V6 + right.V6, left.V7 + right.V7));
 }
예제 #13
0
 /// <summary>
 /// Returns the additive inverse of a vector.
 /// </summary>
 /// <param name="value">A vector.</param>
 /// <returns>The negative of value.</returns>
 public static Vector8l Negative(Vector8l value)
 {
     return(new Vector8l(-value.V0, -value.V1, -value.V2, -value.V3, -value.V4, -value.V5, -value.V6, -value.V7));
 }
예제 #14
0
        public static long Pack(int v0Bits, int v1Bits, int v2Bits, int v3Bits, int v4Bits, int v5Bits, int v6Bits, int v7Bits, Vector8l vector)
        {
            Contract.Requires(0 <= v0Bits && v0Bits <= 64, "v0Bits must be between 0 and 64 inclusive.");
            Contract.Requires(0 <= v1Bits && v1Bits <= 64, "v1Bits must be between 0 and 64 inclusive.");
            Contract.Requires(0 <= v2Bits && v2Bits <= 64, "v2Bits must be between 0 and 64 inclusive.");
            Contract.Requires(0 <= v3Bits && v3Bits <= 64, "v3Bits must be between 0 and 64 inclusive.");
            Contract.Requires(0 <= v4Bits && v4Bits <= 64, "v4Bits must be between 0 and 64 inclusive.");
            Contract.Requires(0 <= v5Bits && v5Bits <= 64, "v5Bits must be between 0 and 64 inclusive.");
            Contract.Requires(0 <= v6Bits && v6Bits <= 64, "v6Bits must be between 0 and 64 inclusive.");
            Contract.Requires(0 <= v7Bits && v7Bits <= 64, "v7Bits must be between 0 and 64 inclusive.");
            Contract.Requires(v0Bits + v1Bits + v2Bits + v3Bits + v4Bits + v5Bits + v6Bits + v7Bits <= 64);
            ulong v0 = (ulong)(vector.V0) >> (64 - v0Bits);
            ulong v1 = (ulong)(vector.V1) >> (64 - v1Bits);

            v1 <<= v0Bits;
            ulong v2 = (ulong)(vector.V2) >> (64 - v2Bits);

            v2 <<= v0Bits + v1Bits;
            ulong v3 = (ulong)(vector.V3) >> (64 - v3Bits);

            v3 <<= v0Bits + v1Bits + v2Bits;
            ulong v4 = (ulong)(vector.V4) >> (64 - v4Bits);

            v4 <<= v0Bits + v1Bits + v2Bits + v3Bits;
            ulong v5 = (ulong)(vector.V5) >> (64 - v5Bits);

            v5 <<= v0Bits + v1Bits + v2Bits + v3Bits + v4Bits;
            ulong v6 = (ulong)(vector.V6) >> (64 - v6Bits);

            v6 <<= v0Bits + v1Bits + v2Bits + v3Bits + v4Bits + v5Bits;
            ulong v7 = (ulong)(vector.V7) >> (64 - v7Bits);

            v7 <<= v0Bits + v1Bits + v2Bits + v3Bits + v4Bits + v5Bits + v6Bits;
            return((long)(v0 | v1 | v2 | v3 | v4 | v5 | v6 | v7));
        }
예제 #15
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 Vector8h Map(Vector8l value, Func <long, Half> mapping)
 {
     return(new Vector8h(mapping(value.V0), mapping(value.V1), mapping(value.V2), mapping(value.V3), mapping(value.V4), mapping(value.V5), mapping(value.V6), mapping(value.V7)));
 }
예제 #16
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 long Dot(Vector8l left, Vector8l right)
 {
     return(left.V0 * right.V0 + left.V1 * right.V1 + left.V2 * right.V2 + left.V3 * right.V3 + left.V4 * right.V4 + left.V5 * right.V5 + left.V6 * right.V6 + left.V7 * right.V7);
 }
예제 #17
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 Vector8us Map(Vector8l value, Func <long, ushort> mapping)
 {
     return(new Vector8us(mapping(value.V0), mapping(value.V1), mapping(value.V2), mapping(value.V3), mapping(value.V4), mapping(value.V5), mapping(value.V6), mapping(value.V7)));
 }
예제 #18
0
 /// <summary>
 /// Determines whether all 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 every component of the vector passes the test in the specified
 /// predicate; otherwise, false.</returns>
 public static bool All(Vector8l value, Predicate <long> predicate)
 {
     return(predicate(value.V0) && predicate(value.V1) && predicate(value.V2) && predicate(value.V3) && predicate(value.V4) && predicate(value.V5) && predicate(value.V6) && predicate(value.V7));
 }
예제 #19
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 Vector8l Modulate(Vector8l left, Vector8l right)
 {
     return(new Vector8l(left.V0 * right.V0, left.V1 * right.V1, left.V2 * right.V2, left.V3 * right.V3, left.V4 * right.V4, left.V5 * right.V5, left.V6 * right.V6, left.V7 * right.V7));
 }
예제 #20
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(Vector8l value)
 {
     return(value.V0 != 0 || value.V1 != 0 || value.V2 != 0 || value.V3 != 0 || value.V4 != 0 || value.V5 != 0 || value.V6 != 0 || value.V7 != 0);
 }
예제 #21
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 Vector8l Max(Vector8l value1, Vector8l value2)
 {
     return(new Vector8l(Functions.Max(value1.V0, value2.V0), Functions.Max(value1.V1, value2.V1), Functions.Max(value1.V2, value2.V2), Functions.Max(value1.V3, value2.V3), Functions.Max(value1.V4, value2.V4), Functions.Max(value1.V5, value2.V5), Functions.Max(value1.V6, value2.V6), Functions.Max(value1.V7, value2.V7)));
 }
예제 #22
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 Vector8l Clamp(Vector8l value, Vector8l min, Vector8l max)
 {
     return(new Vector8l(Functions.Clamp(value.V0, min.V0, max.V0), Functions.Clamp(value.V1, min.V1, max.V1), Functions.Clamp(value.V2, min.V2, max.V2), Functions.Clamp(value.V3, min.V3, max.V3), Functions.Clamp(value.V4, min.V4, max.V4), Functions.Clamp(value.V5, min.V5, max.V5), Functions.Clamp(value.V6, min.V6, max.V6), Functions.Clamp(value.V7, min.V7, max.V7)));
 }