summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Core/Point.cs
diff options
context:
space:
mode:
authorJason Smith <jason.smith@xamarin.com>2016-03-22 13:02:25 -0700
committerJason Smith <jason.smith@xamarin.com>2016-03-22 16:13:41 -0700
commit17fdde66d94155fc62a034fa6658995bef6fd6e5 (patch)
treeb5e5073a2a7b15cdbe826faa5c763e270a505729 /Xamarin.Forms.Core/Point.cs
downloadxamarin-forms-17fdde66d94155fc62a034fa6658995bef6fd6e5.tar.gz
xamarin-forms-17fdde66d94155fc62a034fa6658995bef6fd6e5.tar.bz2
xamarin-forms-17fdde66d94155fc62a034fa6658995bef6fd6e5.zip
Initial import
Diffstat (limited to 'Xamarin.Forms.Core/Point.cs')
-rw-r--r--Xamarin.Forms.Core/Point.cs95
1 files changed, 95 insertions, 0 deletions
diff --git a/Xamarin.Forms.Core/Point.cs b/Xamarin.Forms.Core/Point.cs
new file mode 100644
index 00000000..5c6f5471
--- /dev/null
+++ b/Xamarin.Forms.Core/Point.cs
@@ -0,0 +1,95 @@
+using System;
+using System.Diagnostics;
+using System.Globalization;
+
+namespace Xamarin.Forms
+{
+ [DebuggerDisplay("X={X}, Y={Y}")]
+ [TypeConverter(typeof(PointTypeConverter))]
+ public struct Point
+ {
+ public double X { get; set; }
+
+ public double Y { get; set; }
+
+ public static Point Zero = new Point();
+
+ public override string ToString()
+ {
+ return string.Format("{{X={0} Y={1}}}", X.ToString(CultureInfo.InvariantCulture), Y.ToString(CultureInfo.InvariantCulture));
+ }
+
+ public Point(double x, double y) : this()
+ {
+ X = x;
+ Y = y;
+ }
+
+ public Point(Size sz) : this()
+ {
+ X = sz.Width;
+ Y = sz.Height;
+ }
+
+ public override bool Equals(object o)
+ {
+ if (!(o is Point))
+ return false;
+
+ return this == (Point)o;
+ }
+
+ public override int GetHashCode()
+ {
+ return X.GetHashCode() ^ (Y.GetHashCode() * 397);
+ }
+
+ public Point Offset(double dx, double dy)
+ {
+ Point p = this;
+ p.X += dx;
+ p.Y += dy;
+ return p;
+ }
+
+ public Point Round()
+ {
+ return new Point(Math.Round(X), Math.Round(Y));
+ }
+
+ public bool IsEmpty
+ {
+ get { return (X == 0) && (Y == 0); }
+ }
+
+ public static explicit operator Size(Point pt)
+ {
+ return new Size(pt.X, pt.Y);
+ }
+
+ public static Point operator +(Point pt, Size sz)
+ {
+ return new Point(pt.X + sz.Width, pt.Y + sz.Height);
+ }
+
+ public static Point operator -(Point pt, Size sz)
+ {
+ return new Point(pt.X - sz.Width, pt.Y - sz.Height);
+ }
+
+ public static bool operator ==(Point ptA, Point ptB)
+ {
+ return (ptA.X == ptB.X) && (ptA.Y == ptB.Y);
+ }
+
+ public static bool operator !=(Point ptA, Point ptB)
+ {
+ return (ptA.X != ptB.X) || (ptA.Y != ptB.Y);
+ }
+
+ public double Distance(Point other)
+ {
+ return Math.Sqrt(Math.Pow(X - other.X, 2) + Math.Pow(Y - other.Y, 2));
+ }
+ }
+} \ No newline at end of file