/// <summary> /// Writes the given <see cref="Vector8s"/> to an <see cref="Ibasa.IO.BinaryWriter">. /// </summary> public static void Write(this Ibasa.IO.BinaryWriter writer, Vector8s 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); }
/// <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(Vector8s value) { var absolute = Absolute(value); if (absolute <= float.Epsilon) { return(Vector8s.Zero); } else { return((Vector8f)value / absolute); } }
/// <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(Vector8s value) { return(Functions.Sqrt(AbsoluteSquared(value))); }
/// <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(Vector8s value) { return(Dot(value, value)); }
/// <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(Vector8s value, Predicate <short> 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)); }
/// <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(Vector8s 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); }
/// <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 Vector8s Abs(Vector8s value) { return(new Vector8s(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))); }
/// <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(Vector8s value, Func <short, 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))); }
/// <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(Vector8s 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)); }
/// <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(Vector8s 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)); }
/// <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(Vector8s left, Vector8s 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)); }
/// <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(Vector8s left, Vector8s 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)); }
/// <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(Vector8s value) { return(new Vector8i(-value.V0, -value.V1, -value.V2, -value.V3, -value.V4, -value.V5, -value.V6, -value.V7)); }
public static long Pack(int v0Bits, int v1Bits, int v2Bits, int v3Bits, int v4Bits, int v5Bits, int v6Bits, int v7Bits, Vector8s vector) { Contract.Requires(0 <= v0Bits && v0Bits <= 16, "v0Bits must be between 0 and 16 inclusive."); Contract.Requires(0 <= v1Bits && v1Bits <= 16, "v1Bits must be between 0 and 16 inclusive."); Contract.Requires(0 <= v2Bits && v2Bits <= 16, "v2Bits must be between 0 and 16 inclusive."); Contract.Requires(0 <= v3Bits && v3Bits <= 16, "v3Bits must be between 0 and 16 inclusive."); Contract.Requires(0 <= v4Bits && v4Bits <= 16, "v4Bits must be between 0 and 16 inclusive."); Contract.Requires(0 <= v5Bits && v5Bits <= 16, "v5Bits must be between 0 and 16 inclusive."); Contract.Requires(0 <= v6Bits && v6Bits <= 16, "v6Bits must be between 0 and 16 inclusive."); Contract.Requires(0 <= v7Bits && v7Bits <= 16, "v7Bits must be between 0 and 16 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)); }
/// <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(Vector8s left, Vector8s right) { return(left == right); }
/// <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 Vector8ui Map(Vector8s value, Func <short, uint> mapping) { return(new Vector8ui(mapping(value.V0), mapping(value.V1), mapping(value.V2), mapping(value.V3), mapping(value.V4), mapping(value.V5), mapping(value.V6), mapping(value.V7))); }
/// <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(Vector8s left, Vector8s 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); }
/// <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(Vector8s left, Vector8s 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)); }
/// <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(Vector8s value, Predicate <short> 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)); }
/// <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 Vector8s Max(Vector8s value1, Vector8s value2) { return(new Vector8s(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))); }
/// <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 Vector8s Clamp(Vector8s value, Vector8s min, Vector8s max) { return(new Vector8s(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))); }