using System;
namespace SAMP
{
public struct Vector2
{
#region Class Variables
private float _x, _y;
#endregion
#region Constructor
///
/// Creates a new Vector2 object.
///
/// X position.
/// Y position.
public Vector2(float x, float y)
{
this._x = x;
this._y = y;
}
///
/// Creates a new Vector2 object.
///
/// Uniform position.
public Vector2(float v)
{
this._x = v;
this._y = v;
}
///
/// Creates a new Vector2 object.
///
/// Vector2 to copy.
public Vector2(Vector2 v)
{
this._x = v.X;
this._y = v.Y;
}
///
/// Creates a new Vector2 object.
///
/// Vector3 to copy.
public Vector2(Vector3 v)
{
this._x = v.X;
this._y = v.Y;
}
#endregion
#region Accessors & Mutators
///
/// Gets a zero-pointed Vector2.
///
public static Vector2 Zero
{
get { return new Vector2(0f, 0f); }
}
///
/// Gets or sets the X position of this Vector2.
///
public float X
{
get { return this._x; }
set { this._x = value; }
}
///
/// Gets or sets the Y position of this Vector2.
///
public float Y
{
get { return this._y; }
set { this._y = value; }
}
#endregion
#region Operator Overloads
///
/// Add two Vector2 objects.
///
/// The base term Vector2.
/// The factor term Vector2
/// Returns the sum of v1 and v2.
public static Vector2 operator +(Vector2 v1, Vector2 v2)
{
return new Vector2(v1.X + v2.X, v1.Y + v2.Y);
}
///
/// Subtract two Vector2 objects.
///
/// The base term Vector2.
/// The factor term Vector2
/// Returns the value of v2 subratcted from v1.
public static Vector2 operator -(Vector2 v1, Vector2 v2)
{
return new Vector2(v1.X + v2.X, v1.Y + v2.Y);
}
///
/// Add two Vector2 objects.
///
/// The base term Vector2.
/// The factor term Vector2
/// Returns the sum of v1 and v2.
public static Vector2 operator *(Vector2 v1, Vector2 v2)
{
return new Vector2(v1.X * v2.X, v1.Y * v2.Y);
}
///
/// Subtract two Vector2 objects.
///
/// The base term Vector2.
/// The factor term Vector2
/// Returns the value of v2 subratcted from v1.
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 System.String that represents the Vector2.
///
/// A System.String that represents the current Vector2.
public override string ToString()
{
return string.Format("{{X: {0}, Y: {1}}}", this.X, this.Y);
}
#endregion
#region Static Methods
///
/// Determines the distance between two Vector2 objects.
///
/// The base Vector2 term.
/// The factor Vector2 term.
/// Returns a double precision decimal 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));
}
#endregion
#region Public Methods
///
/// Determines the distance between this Vector2 and another Vector3.
///
/// The Vector2 term.
/// Returns a double precision decimal representing the distance between v and this Vector2.
public double Distance(Vector2 v)
{
return Vector2.Distance(this, v);
}
///
/// Calculates the dot product of two vectors.
///
/// The base Vector2 term.
/// The factor Vector2 term.
/// Returns the dot product of v1 and v2.
public Vector2 Dot(Vector2 v1, Vector2 v2)
{
return new Vector2(
x: v1.X * v2.X,
y: v1.Y * v2.Y);
}
#endregion
};
};