// ----------------------------------------------------------------------- // // Copyright 2014 MIT Licence. See licence.md for more information. // // ----------------------------------------------------------------------- namespace Perspex { using System; using System.Globalization; /// /// Defines a vector. /// public struct Vector { /// /// The X vector. /// private double x; /// /// The Y vector. /// private double y; /// /// Initializes a new instance of the structure. /// /// The X vector. /// The Y vector. public Vector(double x, double y) { this.x = x; this.y = y; } /// /// Gets the X vector. /// public double X { get { return this.x; } } /// /// Gets the Y vector. /// public double Y { get { return this.y; } } /// /// Converts the to a . /// /// The vector. public static explicit operator Point(Vector a) { return new Point(a.x, a.y); } /// /// Negates a vector. /// /// The vector. /// The negated vector. public static Vector operator -(Vector a) { return new Vector(-a.x, -a.y); } /// /// Adds two vectors. /// /// The first vector. /// The second vector. /// A vector that is the result of the addition. public static Vector operator +(Vector a, Vector b) { return new Vector(a.x + b.x, a.y + b.y); } /// /// Subtracts two vectors. /// /// The first vector. /// The second vector. /// A vector that is the result of the subtraction. public static Vector operator -(Vector a, Vector b) { return new Vector(a.x - b.x, a.y - b.y); } /// /// Returns the string representation of the point. /// /// The string representation of the point. public override string ToString() { return string.Format(CultureInfo.InvariantCulture, "{0}, {1}", this.x, this.y); } /// /// Returns a new vector with the specified X coordinate. /// /// The X coordinate. /// The new vector. public Vector WithX(double x) { return new Vector(x, this.y); } /// /// Returns a new vector with the specified Y coordinate. /// /// The Y coordinate. /// The new vector. public Vector WithY(double y) { return new Vector(this.x, y); } } }