using UnityEngine; using M = System.Math; // ReSharper disable InconsistentNaming namespace ARLocation { [System.Serializable] public struct DVector3 { public double x; public double y; public double z; public DVector3(Vector3 v) { x = v.x; y = v.y; z = v.z; } /// /// Gets the magnitude of the vector. /// /// The magnitude. public double magnitude { get { return M.Sqrt(x * x + y * y + z * z); } } /// /// Gets the normalized version of this vector. /// /// The normalized. public DVector3 normalized { get { var m = magnitude; if (m < 0.00000001) { return new DVector3(); } return new DVector3(x, y, z) / magnitude; } } /// /// Initializes a new instance of the struct. /// public DVector3(double newX = 0.0, double newY = 0.0, double newZ = 0.0) { x = newX; y = newY; z = newZ; } /// /// Converts to a Vector3. /// /// The vector2. public Vector3 toVector3() { return new Vector3((float)x, (float)y, (float)z); } /// /// Equals the specified v and e. /// /// The equals. /// V. /// E. public bool Equals(DVector3 v, double e = 0.00005) { return (M.Abs(x - v.x) <= e) && (M.Abs(y - v.y) <= e) && (M.Abs(z - v.z) <= e); } /// /// Normalize this instance. /// public void Normalize() { double m = magnitude; x /= m; y /= m; z /= m; } /// /// Set the specified x and y. /// /// /// /// public void Set(double xx = 0.0, double yy = 0.0, double zz = 0.0) { x = xx; y = yy; z = zz; } /// /// Returns a that represents the current . /// /// A that represents the current . override public string ToString() { return "(" + x + ", " + y + ", " + z + ")"; } /// /// Dot the specified a and b. /// /// The dot. /// The alpha component. /// The blue component. public static double Dot(DVector3 a, DVector3 b) { return a.x * b.x + a.y * b.y + a.z * b.z; } /// /// Distance the specified a and b. /// /// The distance. /// The alpha component. /// The blue component. public static double Distance(DVector3 a, DVector3 b) { return M.Sqrt(a.x * b.x + a.y * b.y + a.z * b.z); } /// /// Lerp the specified a, b and t. /// /// The lerp. /// The alpha component. /// The blue component. /// T. public static DVector3 Lerp(DVector3 a, DVector3 b, double t) { double s = M.Max(0, M.Min(t, 1)); return a * (1 - s) + b * s; } /// /// Computes the product of a and b, yielding a new . /// /// The to multiply. /// The to multiply. /// The that is the a * b. public static DVector3 operator *(DVector3 a, double b) { return new DVector3( b * a.x, b * a.y, b * a.z ); } /// /// Computes the product of a and b, yielding a new . /// /// The to multiply. /// The to multiply. /// The that is the a * b. public static DVector3 operator *(double b, DVector3 a) { return new DVector3( b * a.x, b * a.y, b * a.z ); } /// /// Computes the division of a and b, yielding a new . /// /// The to divide (the divident). /// The to divide (the divisor). /// The that is the a / b. public static DVector3 operator /(DVector3 a, double b) { return new DVector3( a.x / b, a.y / b, a.z / b ); } /// /// Adds a to a , yielding a new . /// /// The first to add. /// The second to add. /// The that is the sum of the values of a and b. public static DVector3 operator +(DVector3 a, DVector3 b) { return new DVector3( a.x + b.x, a.y + b.y, a.z + b.z ); } /// /// Subtracts a from a , yielding a new . /// /// The to subtract from (the minuend). /// The to subtract (the subtrahend). /// The that is the a minus b. public static DVector3 operator -(DVector3 a, DVector3 b) { return new DVector3( a.x - b.x, a.y - b.y, a.z - b.z ); } } }