123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- // 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;
- /// <summary>Represents an ordered pair of x and y coordinates that define a point in a two-dimensional plane.</summary>
- public struct PointF : IEquatable<PointF>
- {
- /// <summary>Creates a new instance of the <see cref='Terminal.Gui.PointF'/> class with member data left uninitialized.</summary>
- public static readonly PointF Empty;
- /// <summary>Initializes a new instance of the <see cref='Terminal.Gui.PointF'/> class with the specified coordinates.</summary>
- public PointF (float x, float y)
- {
- X = x;
- Y = y;
- }
- /// <summary>Gets a value indicating whether this <see cref='Terminal.Gui.PointF'/> is empty.</summary>
- [Browsable (false)]
- public bool IsEmpty => X == 0f && Y == 0f;
- /// <summary>Gets the x-coordinate of this <see cref='Terminal.Gui.PointF'/>.</summary>
- public float X { get; set; }
- /// <summary>Gets the y-coordinate of this <see cref='Terminal.Gui.PointF'/>.</summary>
- public float Y { get; set; }
- /// <summary>Translates a <see cref='Terminal.Gui.PointF'/> by a given <see cref='Terminal.Gui.Size'/> .</summary>
- public static PointF operator + (PointF pt, Size sz) { return Add (pt, sz); }
- /// <summary>Translates a <see cref='Terminal.Gui.PointF'/> by the negative of a given <see cref='Terminal.Gui.Size'/> .</summary>
- public static PointF operator - (PointF pt, Size sz) { return Subtract (pt, sz); }
- /// <summary>Translates a <see cref='Terminal.Gui.PointF'/> by a given <see cref='Terminal.Gui.SizeF'/> .</summary>
- public static PointF operator + (PointF pt, SizeF sz) { return Add (pt, sz); }
- /// <summary>Translates a <see cref='Terminal.Gui.PointF'/> by the negative of a given <see cref='Terminal.Gui.SizeF'/> .</summary>
- public static PointF operator - (PointF pt, SizeF sz) { return Subtract (pt, sz); }
- /// <summary>
- /// Compares two <see cref='Terminal.Gui.PointF'/> objects. The result specifies whether the values of the
- /// <see cref='Terminal.Gui.PointF.X'/> and <see cref='Terminal.Gui.PointF.Y'/> properties of the two
- /// <see cref='Terminal.Gui.PointF'/> objects are equal.
- /// </summary>
- public static bool operator == (PointF left, PointF right) { return left.X == right.X && left.Y == right.Y; }
- /// <summary>
- /// Compares two <see cref='Terminal.Gui.PointF'/> objects. The result specifies whether the values of the
- /// <see cref='Terminal.Gui.PointF.X'/> or <see cref='Terminal.Gui.PointF.Y'/> properties of the two
- /// <see cref='Terminal.Gui.PointF'/> objects are unequal.
- /// </summary>
- public static bool operator != (PointF left, PointF right) { return !(left == right); }
- /// <summary>Translates a <see cref='Terminal.Gui.PointF'/> by a given <see cref='Terminal.Gui.Size'/> .</summary>
- public static PointF Add (PointF pt, Size sz) { return new PointF (pt.X + sz.Width, pt.Y + sz.Height); }
- /// <summary>Translates a <see cref='Terminal.Gui.PointF'/> by the negative of a given <see cref='Terminal.Gui.Size'/> .</summary>
- public static PointF Subtract (PointF pt, Size sz) { return new PointF (pt.X - sz.Width, pt.Y - sz.Height); }
- /// <summary>Translates a <see cref='Terminal.Gui.PointF'/> by a given <see cref='Terminal.Gui.SizeF'/> .</summary>
- public static PointF Add (PointF pt, SizeF sz) { return new PointF (pt.X + sz.Width, pt.Y + sz.Height); }
- /// <summary>Translates a <see cref='Terminal.Gui.PointF'/> by the negative of a given <see cref='Terminal.Gui.SizeF'/> .</summary>
- public static PointF Subtract (PointF pt, SizeF sz) { return new PointF (pt.X - sz.Width, pt.Y - sz.Height); }
- /// <summary>
- /// Compares two <see cref='Terminal.Gui.PointF'/> objects. The result specifies whether the values of the
- /// <see cref='Terminal.Gui.PointF.X'/> and <see cref='Terminal.Gui.PointF.Y'/> properties of the two
- /// <see cref='Terminal.Gui.PointF'/> objects are equal.
- /// </summary>
- public override bool Equals (object obj) { return obj is PointF && Equals ((PointF)obj); }
- /// <summary>
- /// Compares two <see cref='Terminal.Gui.PointF'/> objects. The result specifies whether the values of the
- /// <see cref='Terminal.Gui.PointF.X'/> and <see cref='Terminal.Gui.PointF.Y'/> properties of the two
- /// <see cref='Terminal.Gui.PointF'/> objects are equal.
- /// </summary>
- public bool Equals (PointF other) { return this == other; }
- /// <summary>Generates a hashcode from the X and Y components</summary>
- /// <returns></returns>
- public override int GetHashCode () { return X.GetHashCode () ^ Y.GetHashCode (); }
- /// <summary>Returns a string including the X and Y values</summary>
- /// <returns></returns>
- public override string ToString () { return "{X=" + X + ", Y=" + Y + "}"; }
- }
|