// 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.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; /// Initializes a new instance of the class with the specified coordinates. public PointF (float x, float y) { X = x; 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; set; } /// Gets the y-coordinate of this . public float Y { get; set; } /// Translates a by a given . public static PointF operator + (PointF pt, Size sz) { return Add (pt, sz); } /// Translates a by the negative of a given . public static PointF operator - (PointF pt, Size sz) { return Subtract (pt, sz); } /// Translates a by a given . public static PointF operator + (PointF pt, SizeF sz) { return Add (pt, sz); } /// Translates a by the negative of a given . public static PointF operator - (PointF pt, SizeF sz) { return 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) { return 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) { return !(left == right); } /// Translates a by a given . public static PointF Add (PointF pt, Size sz) { return 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) { return new PointF (pt.X - sz.Width, pt.Y - sz.Height); } /// Translates a by a given . public static PointF Add (PointF pt, SizeF sz) { return 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) { return 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) { return 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) { return 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 () { return "{X=" + X + ", Y=" + Y + "}"; } }