예제 #1
0
파일: Vector8b.cs 프로젝트: bonomali/Ibasa
 /// <summary>
 /// Writes the given <see cref="Vector8b"/> to an <see cref="Ibasa.IO.BinaryWriter">.
 /// </summary>
 public static void Write(this Ibasa.IO.BinaryWriter writer, Vector8b 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
파일: Vector8b.cs 프로젝트: bonomali/Ibasa
        public static long Pack(Vector8b vector)
        {
            ulong v0 = (ulong)(vector.V0) << 0;
            ulong v1 = (ulong)(vector.V1) << 8;
            ulong v2 = (ulong)(vector.V2) << 16;
            ulong v3 = (ulong)(vector.V3) << 24;
            ulong v4 = (ulong)(vector.V4) << 32;
            ulong v5 = (ulong)(vector.V5) << 40;
            ulong v6 = (ulong)(vector.V6) << 48;
            ulong v7 = (ulong)(vector.V7) << 56;

            return((long)(v0 | v1 | v2 | v3 | v4 | v5 | v6 | v7));
        }
예제 #3
0
파일: Vector8b.cs 프로젝트: bonomali/Ibasa
        /// <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 Vector8f Normalize(Vector8b value)
        {
            var absolute = Absolute(value);

            if (absolute <= float.Epsilon)
            {
                return(Vector8b.Zero);
            }
            else
            {
                return((Vector8f)value / absolute);
            }
        }
예제 #4
0
파일: Vector8b.cs 프로젝트: bonomali/Ibasa
 /// <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(Vector8b value)
 {
     return(Functions.Sqrt(AbsoluteSquared(value)));
 }
예제 #5
0
파일: Vector8b.cs 프로젝트: bonomali/Ibasa
 /// <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(Vector8b value)
 {
     return(Dot(value, value));
 }
예제 #6
0
파일: Vector8b.cs 프로젝트: bonomali/Ibasa
 /// <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(Vector8b value, Predicate <byte> 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));
 }
예제 #7
0
파일: Vector8b.cs 프로젝트: bonomali/Ibasa
 /// <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(Vector8b 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);
 }
예제 #8
0
파일: Vector8b.cs 프로젝트: bonomali/Ibasa
 /// <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 Vector8b Abs(Vector8b value)
 {
     return(new Vector8b(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)));
 }
예제 #9
0
파일: Vector8b.cs 프로젝트: bonomali/Ibasa
 /// <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(Vector8b value, Func <byte, 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)));
 }
예제 #10
0
파일: Vector8b.cs 프로젝트: bonomali/Ibasa
 /// <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 Vector8i Divide(Vector8b vector, int scalar)
 {
     return(new Vector8i(vector.V0 / scalar, vector.V1 / scalar, vector.V2 / scalar, vector.V3 / scalar, vector.V4 / scalar, vector.V5 / scalar, vector.V6 / scalar, vector.V7 / scalar));
 }
예제 #11
0
파일: Vector8b.cs 프로젝트: bonomali/Ibasa
 /// <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 Vector8i Multiply(Vector8b vector, int scalar)
 {
     return(new Vector8i(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
파일: Vector8b.cs 프로젝트: bonomali/Ibasa
 /// <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 Vector8i Subtract(Vector8b left, Vector8b right)
 {
     return(new Vector8i(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
파일: Vector8b.cs 프로젝트: bonomali/Ibasa
 /// <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 Vector8i Add(Vector8b left, Vector8b right)
 {
     return(new Vector8i(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));
 }
예제 #14
0
파일: Vector8b.cs 프로젝트: bonomali/Ibasa
 /// <summary>
 /// Returns the additive inverse of a vector.
 /// </summary>
 /// <param name="value">A vector.</param>
 /// <returns>The negative of value.</returns>
 public static Vector8i Negative(Vector8b value)
 {
     return(new Vector8i(-value.V0, -value.V1, -value.V2, -value.V3, -value.V4, -value.V5, -value.V6, -value.V7));
 }
예제 #15
0
파일: Vector8b.cs 프로젝트: bonomali/Ibasa
        public static long Pack(int v0Bits, int v1Bits, int v2Bits, int v3Bits, int v4Bits, int v5Bits, int v6Bits, int v7Bits, Vector8b vector)
        {
            Contract.Requires(0 <= v0Bits && v0Bits <= 8, "v0Bits must be between 0 and 8 inclusive.");
            Contract.Requires(0 <= v1Bits && v1Bits <= 8, "v1Bits must be between 0 and 8 inclusive.");
            Contract.Requires(0 <= v2Bits && v2Bits <= 8, "v2Bits must be between 0 and 8 inclusive.");
            Contract.Requires(0 <= v3Bits && v3Bits <= 8, "v3Bits must be between 0 and 8 inclusive.");
            Contract.Requires(0 <= v4Bits && v4Bits <= 8, "v4Bits must be between 0 and 8 inclusive.");
            Contract.Requires(0 <= v5Bits && v5Bits <= 8, "v5Bits must be between 0 and 8 inclusive.");
            Contract.Requires(0 <= v6Bits && v6Bits <= 8, "v6Bits must be between 0 and 8 inclusive.");
            Contract.Requires(0 <= v7Bits && v7Bits <= 8, "v7Bits must be between 0 and 8 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));
        }
예제 #16
0
파일: Vector8b.cs 프로젝트: bonomali/Ibasa
 /// <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(Vector8b left, Vector8b right)
 {
     return(left == right);
 }
예제 #17
0
파일: Vector8b.cs 프로젝트: bonomali/Ibasa
 /// <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(Vector8b value, Func <byte, 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
파일: Vector8b.cs 프로젝트: bonomali/Ibasa
 /// <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(Vector8b left, Vector8b 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);
 }
예제 #19
0
파일: Vector8b.cs 프로젝트: bonomali/Ibasa
 /// <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 Vector8i Modulate(Vector8b left, Vector8b right)
 {
     return(new Vector8i(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
파일: Vector8b.cs 프로젝트: bonomali/Ibasa
 /// <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(Vector8b value, Predicate <byte> 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));
 }
예제 #21
0
파일: Vector8b.cs 프로젝트: bonomali/Ibasa
 /// <summary>
 /// Returns a vector that contains the lowest value from each pair of components.
 /// </summary>
 /// <param name="value1">The first vector.</param>
 /// <param name="value2">The second vector.</param>
 /// <returns>The lowest of each component in left and the matching component in right.</returns>
 public static Vector8b Min(Vector8b value1, Vector8b value2)
 {
     return(new Vector8b(Functions.Min(value1.V0, value2.V0), Functions.Min(value1.V1, value2.V1), Functions.Min(value1.V2, value2.V2), Functions.Min(value1.V3, value2.V3), Functions.Min(value1.V4, value2.V4), Functions.Min(value1.V5, value2.V5), Functions.Min(value1.V6, value2.V6), Functions.Min(value1.V7, value2.V7)));
 }
예제 #22
0
파일: Vector8b.cs 프로젝트: bonomali/Ibasa
 /// <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 Vector8b Clamp(Vector8b value, Vector8b min, Vector8b max)
 {
     return(new Vector8b(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)));
 }