// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. // Copied from: https://github.com/dotnet/corefx/tree/master/src/System.Drawing.Primitives/src/System/Drawing using System; using System.ComponentModel; namespace Terminal.Gui { /// /// Represents an ordered pair of x and y coordinates that define a point in a two-dimensional plane. /// public struct PointF : IEquatable { /// /// Creates a new instance of the class with member data left uninitialized. /// public static readonly PointF Empty; private float x; // Do not rename (binary serialization) private float y; // Do not rename (binary serialization) /// /// Initializes a new instance of the class with the specified coordinates. /// public PointF (float x, float y) { this.x = x; this.y = y; } /// /// Gets a value indicating whether this is empty. /// [Browsable (false)] public bool IsEmpty => x == 0f && y == 0f; /// /// Gets the x-coordinate of this . /// public float X { get => x; set => x = value; } /// /// Gets the y-coordinate of this . /// public float Y { get => y; set => y = value; } /// /// Translates a by a given . /// public static PointF operator + (PointF pt, Size sz) => Add (pt, sz); /// /// Translates a by the negative of a given . /// public static PointF operator - (PointF pt, Size sz) => Subtract (pt, sz); /// /// Translates a by a given . /// public static PointF operator + (PointF pt, SizeF sz) => Add (pt, sz); /// /// Translates a by the negative of a given . /// public static PointF operator - (PointF pt, SizeF sz) => Subtract (pt, sz); /// /// Compares two objects. The result specifies whether the values of the /// and properties of the two /// objects are equal. /// public static bool operator == (PointF left, PointF right) => left.X == right.X && left.Y == right.Y; /// /// Compares two objects. The result specifies whether the values of the /// or properties of the two /// objects are unequal. /// public static bool operator != (PointF left, PointF right) => !(left == right); /// /// Translates a by a given . /// public static PointF Add (PointF pt, Size sz) => new PointF (pt.X + sz.Width, pt.Y + sz.Height); /// /// Translates a by the negative of a given . /// public static PointF Subtract (PointF pt, Size sz) => new PointF (pt.X - sz.Width, pt.Y - sz.Height); /// /// Translates a by a given . /// public static PointF Add (PointF pt, SizeF sz) => new PointF (pt.X + sz.Width, pt.Y + sz.Height); /// /// Translates a by the negative of a given . /// public static PointF Subtract (PointF pt, SizeF sz) => new PointF (pt.X - sz.Width, pt.Y - sz.Height); /// /// Compares two objects. The result specifies whether the values of the /// and properties of the two /// objects are equal. /// public override bool Equals (object obj) => obj is PointF && Equals ((PointF)obj); /// /// Compares two objects. The result specifies whether the values of the /// and properties of the two /// objects are equal. /// public bool Equals (PointF other) => this == other; /// /// Generates a hashcode from the X and Y components /// /// public override int GetHashCode () { return X.GetHashCode() ^ Y.GetHashCode (); } /// /// Returns a string including the X and Y values /// /// public override string ToString () => "{X=" + x.ToString () + ", Y=" + y.ToString () + "}"; } }