// ----------------------------------------------------------------------- // // 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; } } public static Vector operator -(Vector a) { return new Vector(-a.x, -a.y); } public static Vector operator +(Vector a, Vector b) { return new Vector(a.x + b.x, a.y + b.y); } public static Vector operator -(Vector a, Vector b) { return new Vector(a.x - b.x, a.y - b.y); } public static explicit operator Point(Vector a) { return new Point(a.x, a.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); } public Vector WithX(double x) { return new Vector(x, this.y); } public Vector WithY(double y) { return new Vector(this.x, y); } } }