123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216 |
- using System;
- using System.Diagnostics;
- using System.Runtime.Serialization;
- namespace CommonLang.Geometry
- {
-
-
-
-
-
- public struct Point : IEquatable<Point>
- {
- #region Private Fields
- private static readonly Point zeroPoint = new Point();
- #endregion
- #region Public Fields
-
-
-
-
- public int X;
-
-
-
-
- public int Y;
- #endregion
- #region Properties
-
-
-
- public static Point Zero
- {
- get { return zeroPoint; }
- }
- #endregion
- #region Internal Properties
- internal string DebugDisplayString
- {
- get
- {
- return string.Concat(
- this.X.ToString(), " ",
- this.Y.ToString()
- );
- }
- }
- #endregion
- #region Constructors
-
-
-
-
-
- public Point(int x, int y)
- {
- this.X = x;
- this.Y = y;
- }
-
-
-
-
- public Point(int value)
- {
- this.X = value;
- this.Y = value;
- }
- #endregion
- #region Operators
-
-
-
-
-
-
- public static Point operator +(Point value1, Point value2)
- {
- return new Point(value1.X + value2.X, value1.Y + value2.Y);
- }
-
-
-
-
-
-
- public static Point operator -(Point value1, Point value2)
- {
- return new Point(value1.X - value2.X, value1.Y - value2.Y);
- }
-
-
-
-
-
-
- public static Point operator *(Point value1, Point value2)
- {
- return new Point(value1.X * value2.X, value1.Y * value2.Y);
- }
-
-
-
-
-
-
- public static Point operator /(Point source, Point divisor)
- {
- return new Point(source.X / divisor.X, source.Y / divisor.Y);
- }
-
-
-
-
-
-
- public static bool operator ==(Point a, Point b)
- {
- return a.Equals(b);
- }
-
-
-
-
-
-
- public static bool operator !=(Point a, Point b)
- {
- return !a.Equals(b);
- }
- #endregion
- #region Public methods
-
-
-
-
-
- public override bool Equals(object obj)
- {
- return (obj is Point) && Equals((Point)obj);
- }
-
-
-
-
-
- public bool Equals(Point other)
- {
- return ((X == other.X) && (Y == other.Y));
- }
-
-
-
-
- public override int GetHashCode()
- {
- return X ^ Y;
- }
-
-
-
-
-
- public override string ToString()
- {
- return "{X:" + X + " Y:" + Y + "}";
- }
-
-
-
-
- public Vector2 ToVector2()
- {
- return new Vector2(X, Y);
- }
- #endregion
- }
- }
|