public static int Pack(Vector2s vector) { ulong x = (ulong)(vector.X) << 0; ulong y = (ulong)(vector.Y) << 16; return((int)(x | y)); }
/// <summary> /// Initializes a new instance of the <see cref="Vector8s"/> 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 Vector8s(Vector2s value, short v2, short v3, short v4, short v5, short v6, short v7, short v8, short v9) { V0 = value.X; V1 = value.Y; V2 = v2; V3 = v3; V4 = v4; V5 = v5; V6 = v6; V7 = v7; }
public static int Pack(int xBits, int yBits, Vector2s vector) { Contract.Requires(0 <= xBits && xBits <= 16, "xBits must be between 0 and 16 inclusive."); Contract.Requires(0 <= yBits && yBits <= 16, "yBits must be between 0 and 16 inclusive."); Contract.Requires(xBits + yBits <= 32); ulong x = (ulong)(vector.X) >> (32 - xBits); ulong y = (ulong)(vector.Y) >> (32 - yBits); y <<= xBits; return((int)(x | y)); }
/// <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(Vector2s 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))); }
/// <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(Vector2s value) { var absolute = Absolute(value); if (absolute <= float.Epsilon) { return(Vector2s.Zero); } else { return((Vector2f)value / absolute); } }
/// <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(Vector2s value) { return(value.X != 0 && value.Y != 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(Vector2s left, Vector2s right) { return(left.X * right.X + left.Y * right.Y); }
/// <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(Vector2s left, Vector2s 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 Vector2sb Map(Vector2s value, Func <short, sbyte> mapping) { return(new Vector2sb(mapping(value.X), mapping(value.Y))); }
/// <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(Vector2s value, Func <short, long> mapping) { return(new Vector2l(mapping(value.X), mapping(value.Y))); }
/// <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(Vector2s value, Func <short, float> mapping) { return(new Vector2f(mapping(value.X), mapping(value.Y))); }
/// <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(Vector2s value) { return(Dot(value, value)); }
/// <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(Vector2s value) { return(value.X != 0 || value.Y != 0); }
/// <summary> /// Writes the given <see cref="Vector2s"/> to an <see cref="Ibasa.IO.BinaryWriter">. /// </summary> public static void Write(this Ibasa.IO.BinaryWriter writer, Vector2s vector) { writer.Write(vector.X); writer.Write(vector.Y); }
/// <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 Vector2s Clamp(Vector2s value, Vector2s min, Vector2s max) { return(new Vector2s(Functions.Clamp(value.X, min.X, max.X), Functions.Clamp(value.Y, min.Y, max.Y))); }
/// <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 Vector2s Max(Vector2s value1, Vector2s value2) { return(new Vector2s(Functions.Max(value1.X, value2.X), Functions.Max(value1.Y, value2.Y))); }
/// <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 Vector2s Abs(Vector2s value) { return(new Vector2s(Functions.Abs(value.X), Functions.Abs(value.Y))); }
/// <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(Vector2s left, Vector2s right) { return(new Vector2i(left.X * right.X, left.Y * right.Y)); }
/// <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(Vector2s value, Predicate <short> predicate) { return(predicate(value.X) || predicate(value.Y)); }
/// <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(Vector2s value) { return(new Vector2i(-value.X, -value.Y)); }
/// <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(Vector2s value) { return(Functions.Sqrt(AbsoluteSquared(value))); }
/// <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(Vector2s left, Vector2s right) { return(new Vector2i(left.X + right.X, left.Y + right.Y)); }
/// <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(Vector2s value, Func <short, double> mapping) { return(new Vector2d(mapping(value.X), mapping(value.Y))); }
/// <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(Vector2s left, Vector2s right) { return(new Vector2i(left.X - right.X, left.Y - right.Y)); }
/// <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(Vector2s value, Func <short, Half> mapping) { return(new Vector2h(mapping(value.X), mapping(value.Y))); }
/// <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(Vector2s vector, int scalar) { return(new Vector2i(vector.X * scalar, vector.Y * scalar)); }
/// <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(Vector2s value, Func <short, uint> mapping) { return(new Vector2ui(mapping(value.X), mapping(value.Y))); }
/// <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(Vector2s vector, int scalar) { return(new Vector2i(vector.X / scalar, vector.Y / scalar)); }