using System; namespace SAMP.API { public struct Vector2 { #region Struct Variables private float m_fpX, m_fpY; #endregion #region Constructor /// /// Initializes a new instance of the struct. /// /// X position. /// Y position. public Vector2(float x, float y) { this.m_fpX = x; this.m_fpY = y; } /// /// Initializes a new instance of the struct. /// /// Uniform position. public Vector2(float v) { this.m_fpX = v; this.m_fpY = v; } /// /// Initializes a new instance of the struct. /// /// The to copy. public Vector2(Vector2 v) { this.m_fpX = v.X; this.m_fpY = v.Y; } /// /// Initializes a new instance of the struct. /// /// The to copy. public Vector2(Vector3 v) { this.m_fpX = v.X; this.m_fpY = v.Y; } #endregion #region Accessors & Mutators /// /// Gets the zero-pointed . /// public static Vector2 Zero { get { return new Vector2(0.0f, 0.0f); } } /// /// Gets or sets the X position of this . /// public float X { get { return this.m_fpX; } set { this.m_fpX = value; } } /// /// Gets or sets the Y position of this . /// public float Y { get { return this.m_fpY; } set { this.m_fpY = value; } } #endregion #region Operator Overloads /// /// Adds a to a , yielding a new . /// /// The first to add. /// The second to add. /// The that is the sum of the values of v1 and v2. public static Vector2 operator +(Vector2 v1, Vector2 v2) { return new Vector2(v1.X + v2.X, v1.Y + v2.Y); } /// /// Subtracts a from a , yielding a new . /// /// The to subtract from (the minuend). /// The to subtract (the subtrahend). /// The that is the v1 minus v2. public static Vector2 operator -(Vector2 v1, Vector2 v2) { return new Vector2(v1.X + v2.X, v1.Y + v2.Y); } /// /// Computes the product of v1 and v2, yielding a new . /// /// The to multiply. /// The to multiply. /// The that is the v1 * v2. public static Vector2 operator *(Vector2 v1, Vector2 v2) { return new Vector2(v1.X * v2.X, v1.Y * v2.Y); } /// /// Computes the division of v1 and v2, yielding a new . /// /// The to divide (the divident)./param> /// The to divide (the divisor). /// The that is the v1 / v2. public static Vector2 operator /(Vector2 v1, Vector2 v2) { return new Vector2(v1.X / v2.X, v1.Y / v2.Y); } #endregion #region Method Overrides /// /// Returns a that represents the current . /// /// A that represents the current . public override string ToString() { return string.Format("{{X: {0}, Y: {1}}}", this.X, this.Y); } #endregion #region Static Methods /// /// Calculates the distance between two objects. /// /// The base term. /// The factor term. /// Returns a representing the distance between v1 and v2. public static double Distance(Vector2 v1, Vector2 v2) { return Math.Sqrt( Math.Pow((double)v1.X - (double)v2.X, 2) + Math.Pow((double)v1.Y - (double)v2.Y, 2)); } /// /// Calculates the dot product of two vectors. /// /// The base term. /// The factor term. /// Returns a representing the dot product of v1 and v2. public static Vector2 Dot(Vector2 v1, Vector2 v2) { return new Vector2( x: v1.X * v2.X, y: v1.Y * v2.Y); } #endregion #region Public Methods /// /// Calculates the distance between the current and another. /// /// The term. /// Returns a representing the distance between v and the current . public double Distance(Vector2 v) { return Vector2.Distance(this, v); } #endregion }; };