using System;
using System.ComponentModel;
using System.ComponentModel.Design.Serialization;
using System.Reflection;
using System.Text;
using System.Collections;
using System.Globalization;
using System.Windows;
using System.Windows.Media;
using System.Runtime.InteropServices;
using MS.Internal;
using MS.Internal.WindowsBase;
using System.Diagnostics;
using System.Windows.Markup;
using System.Windows.Converters;
using BOOL = System.UInt32;
using WORD = System.UInt16;
using Float = System.Single;
namespace System.Windows
{
public struct Point : IFormattable
{
public Point(double x, double y)
{
_x = x;
_y = y;
}
public void Offset(double offsetX, double offsetY)
{
_x += offsetX;
_y += offsetY;
}
public static Point operator +(Point point, Vector vector)
{
return new Point(point._x + vector._x, point._y + vector._y);
}
public static Point Add(Point point, Vector vector)
{
return new Point(point._x + vector._x, point._y + vector._y);
}
public static Point operator -(Point point, Vector vector)
{
return new Point(point._x - vector._x, point._y - vector._y);
}
public static Point Subtract(Point point, Vector vector)
{
return new Point(point._x - vector._x, point._y - vector._y);
}
public static Vector operator -(Point point1, Point point2)
{
return new Vector(point1._x - point2._x, point1._y - point2._y);
}
public static Vector Subtract(Point point1, Point point2)
{
return new Vector(point1._x - point2._x, point1._y - point2._y);
}
public static Point operator *(Point point, Matrix matrix)
{
return matrix.Transform(point);
}
public static Point Multiply(Point point, Matrix matrix)
{
return matrix.Transform(point);
}
public static explicit operator Size(Point point)
{
return new Size(Math.Abs(point._x), Math.Abs(point._y));
}
public static explicit operator Vector(Point point)
{
return new Vector(point._x, point._y);
}
public static bool operator ==(Point point1, Point point2)
{
return point1.X == point2.X &&
point1.Y == point2.Y;
}
public static bool operator !=(Point point1, Point point2)
{
return !(point1 == point2);
}
public static bool Equals(Point point1, Point point2)
{
return point1.X.Equals(point2.X) &&
point1.Y.Equals(point2.Y);
}
public override bool Equals(object o)
{
if ((null == o) || !(o is Point))
{
return false;
}
Point value = (Point)o;
return Point.Equals(this, value);
}
public bool Equals(Point value)
{
return Point.Equals(this, value);
}
public override int GetHashCode()
{
return X.GetHashCode() ^
Y.GetHashCode();
}
public static Point Parse(string source)
{
IFormatProvider formatProvider = System.Windows.Markup.TypeConverterHelper.InvariantEnglishUS;
TokenizerHelper th = new TokenizerHelper(source, formatProvider);
Point value;
String firstToken = th.NextTokenRequired();
value = new Point(
Convert.ToDouble(firstToken, formatProvider),
Convert.ToDouble(th.NextTokenRequired(), formatProvider));
th.LastTokenRequired();
return value;
}
public double X
{
get
{
return _x;
}
set
{
_x = value;
}
}
public double Y
{
get
{
return _y;
}
set
{
_y = value;
}
}
public override string ToString()
{
return ConvertToString(null , null);
}
public string ToString(IFormatProvider provider)
{
return ConvertToString(null, provider);
}
string IFormattable.ToString(string format, IFormatProvider provider)
{
return ConvertToString(format, provider);
}
internal string ConvertToString(string format, IFormatProvider provider)
{
char separator = MS.Internal.TokenizerHelper.GetNumericListSeparator(provider);
return String.Format(provider,
"{1:" + format + "}{0}{2:" + format + "}",
separator,
_x,
_y);
}
internal double _x;
internal double _y;
}
[Serializable]
[TypeConverter(typeof(VectorConverter))]
[ValueSerializer(typeof(VectorValueSerializer))]
public struct Vector : IFormattable
{
public static bool operator ==(Vector vector1, Vector vector2)
{
return vector1.X == vector2.X &&
vector1.Y == vector2.Y;
}
public static bool operator !=(Vector vector1, Vector vector2)
{
return !(vector1 == vector2);
}
public static bool Equals(Vector vector1, Vector vector2)
{
return vector1.X.Equals(vector2.X) &&
vector1.Y.Equals(vector2.Y);
}
public override bool Equals(object o)
{
if ((null == o) || !(o is Vector))
{
return false;
}
Vector value = (Vector)o;
return Vector.Equals(this, value);
}
public bool Equals(Vector value)
{
return Vector.Equals(this, value);
}
public override int GetHashCode()
{
return X.GetHashCode() ^
Y.GetHashCode();
}
public static Vector Parse(string source)
{
IFormatProvider formatProvider = System.Windows.Markup.TypeConverterHelper.InvariantEnglishUS;
TokenizerHelper th = new TokenizerHelper(source, formatProvider);
Vector value;
String firstToken = th.NextTokenRequired();
value = new Vector(
Convert.ToDouble(firstToken, formatProvider),
Convert.ToDouble(th.NextTokenRequired(), formatProvider));
th.LastTokenRequired();
return value;
}
public double X
{
get
{
return _x;
}
set
{
_x = value;
}
}
public double Y
{
get
{
return _y;
}
set
{
_y = value;
}
}
public override string ToString()
{
return ConvertToString(null /* format string */, null /* format provider */);
}
public string ToString(IFormatProvider provider)
{
return ConvertToString(null /* format string */, provider);
}
string IFormattable.ToString(string format, IFormatProvider provider)
{
return ConvertToString(format, provider);
}
internal string ConvertToString(string format, IFormatProvider provider)
{
char separator = MS.Internal.TokenizerHelper.GetNumericListSeparator(provider);
return String.Format(provider,
"{1:" + format + "}{0}{2:" + format + "}",
separator,
_x,
_y);
}
internal double _x;
internal double _y;
public Vector(double x, double y)
{
_x = x;
_y = y;
}
public double Length
{
get
{
return Math.Sqrt(_x * _x + _y * _y);
}
}
public double LengthSquared
{
get
{
return _x * _x + _y * _y;
}
}
public void Normalize()
{
this /= Math.Max(Math.Abs(_x), Math.Abs(_y));
this /= Length;
}
public static double CrossProduct(Vector vector1, Vector vector2)
{
return vector1._x * vector2._y - vector1._y * vector2._x;
}
public static double AngleBetween(Vector vector1, Vector vector2)
{
double sin = vector1._x * vector2._y - vector2._x * vector1._y;
double cos = vector1._x * vector2._x + vector1._y * vector2._y;
return Math.Atan2(sin, cos) * (180 / Math.PI);
}
public static Vector operator -(Vector vector)
{
return new Vector(-vector._x, -vector._y);
}
public void Negate()
{
_x = -_x;
_y = -_y;
}
public static Vector operator +(Vector vector1, Vector vector2)
{
return new Vector(vector1._x + vector2._x,
vector1._y + vector2._y);
}
public static Vector Add(Vector vector1, Vector vector2)
{
return new Vector(vector1._x + vector2._x,
vector1._y + vector2._y);
}
public static Vector operator -(Vector vector1, Vector vector2)
{
return new Vector(vector1._x - vector2._x,
vector1._y - vector2._y);
}
public static Vector Subtract(Vector vector1, Vector vector2)
{
return new Vector(vector1._x - vector2._x,
vector1._y - vector2._y);
}
public static Point operator +(Vector vector, Point point)
{
return new Point(point._x + vector._x, point._y + vector._y);
}
public static Point Add(Vector vector, Point point)
{
return new Point(point._x + vector._x, point._y + vector._y);
}
public static Vector operator *(Vector vector, double scalar)
{
return new Vector(vector._x * scalar,
vector._y * scalar);
}
public static Vector Multiply(Vector vector, double scalar)
{
return new Vector(vector._x * scalar,
vector._y * scalar);
}
public static Vector operator *(double scalar, Vector vector)
{
return new Vector(vector._x * scalar,
vector._y * scalar);
}
public static Vector Multiply(double scalar, Vector vector)
{
return new Vector(vector._x * scalar,
vector._y * scalar);
}
public static Vector operator /(Vector vector, double scalar)
{
return vector * (1.0 / scalar);
}
public static Vector Divide(Vector vector, double scalar)
{
return vector * (1.0 / scalar);
}
public static Vector operator *(Vector vector, Matrix matrix)
{
return matrix.Transform(vector);
}
public static Vector Multiply(Vector vector, Matrix matrix)
{
return matrix.Transform(vector);
}
public static double operator *(Vector vector1, Vector vector2)
{
return vector1._x * vector2._x + vector1._y * vector2._y;
}
public static double Multiply(Vector vector1, Vector vector2)
{
return vector1._x * vector2._x + vector1._y * vector2._y;
}
public static double Determinant(Vector vector1, Vector vector2)
{
return vector1._x * vector2._y - vector1._y * vector2._x;
}
public static explicit operator Size(Vector vector)
{
return new Size(Math.Abs(vector._x), Math.Abs(vector._y));
}
public static explicit operator Point(Vector vector)
{
return new Point(vector._x, vector._y);
}
}
}