diff --git a/Terminal.Gui/Types/Point.TemporaryOperators.cs b/Terminal.Gui/Types/Point.TemporaryOperators.cs deleted file mode 100644 index 0f0428d26..000000000 --- a/Terminal.Gui/Types/Point.TemporaryOperators.cs +++ /dev/null @@ -1,11 +0,0 @@ -namespace Terminal.Gui; - -public partial struct Point -{ - public static implicit operator System.Drawing.Point (Terminal.Gui.Point tgp) => new (tgp.X, tgp.Y); - public static implicit operator Point (System.Drawing.Point sdp) => new (sdp.X, sdp.Y); - public static bool operator != (Point left, System.Drawing.Point right) => new System.Drawing.Point (left.X,left.Y) != right; - public static bool operator == (Point left, System.Drawing.Point right) => new System.Drawing.Point (left.X,left.Y) == right; - public static bool operator != (System.Drawing.Point left, Point right) => left != new System.Drawing.Point(right.X,right.Y); - public static bool operator == (System.Drawing.Point left, Point right) => left == new System.Drawing.Point(right.X,right.Y); -} diff --git a/Terminal.Gui/Types/Point.cs b/Terminal.Gui/Types/Point.cs deleted file mode 100644 index c9e1f5f3b..000000000 --- a/Terminal.Gui/Types/Point.cs +++ /dev/null @@ -1,148 +0,0 @@ -// -// System.Drawing.Point.cs -// -// Author: -// Mike Kestner (mkestner@speakeasy.net) -// -// Copyright (C) 2001 Mike Kestner -// Copyright (C) 2004 Novell, Inc. http://www.novell.com -// - -using System.Globalization; -using System.Text.Json.Serialization; - -namespace Terminal.Gui; - -/// Represents an ordered pair of integer x- and y-coordinates that defines a point in a two-dimensional plane. -public partial struct Point -{ - /// Gets or sets the x-coordinate of this Point. - [JsonInclude] - public int X; - - /// Gets or sets the y-coordinate of this Point. - [JsonInclude] - public int Y; - - // ----------------------- - // Public Shared Members - // ----------------------- - - /// Empty Shared Field - /// An uninitialized Point Structure. - public static readonly Point Empty; - - /// Addition Operator - /// Translates a Point using the Width and Height properties of the given Size. - public static Point operator + (Point pt, Size sz) { return new Point (pt.X + sz.Width, pt.Y + sz.Height); } - - /// Equality Operator - /// - /// Compares two Point objects. The return value is based on the equivalence of the X and Y properties of the two - /// points. - /// - public static bool operator == (Point left, Point right) { return left.X == right.X && left.Y == right.Y; } - - /// Inequality Operator - /// - /// Compares two Point objects. The return value is based on the equivalence of the X and Y properties of the two - /// points. - /// - public static bool operator != (Point left, Point right) { return left.X != right.X || left.Y != right.Y; } - - /// Subtraction Operator - /// Translates a Point using the negation of the Width and Height properties of the given Size. - public static Point operator - (Point pt, Size sz) { return new Point (pt.X - sz.Width, pt.Y - sz.Height); } - - /// Point to Size Conversion - /// Returns a Size based on the Coordinates of a given Point. Requires explicit cast. - public static explicit operator Size (Point p) - { - if (p.X < 0 || p.Y < 0) - { - throw new ArgumentException ("Either Width and Height must be greater or equal to 0."); - } - - return new Size (p.X, p.Y); - } - - // ----------------------- - // Public Constructors - // ----------------------- - /// Point Constructor - /// Creates a Point from a Size value. - public Point (Size sz) - { - X = sz.Width; - Y = sz.Height; - } - - /// Point Constructor - /// Creates a Point from a specified x,y coordinate pair. - public Point (int x, int y) - { - X = x; - Y = y; - } - - // ----------------------- - // Public Instance Members - // ----------------------- - - /// IsEmpty Property - /// Indicates if both X and Y are zero. - [JsonIgnore] - public bool IsEmpty => X == 0 && Y == 0; - - /// Equals Method - /// Checks equivalence of this Point and another object. - public override bool Equals (object obj) - { - if (!(obj is Point)) - { - return false; - } - - return this == (Point)obj; - } - - /// GetHashCode Method - /// Calculates a hashing value. - public override int GetHashCode () { return X ^ Y; } - - /// Offset Method - /// Moves the Point a specified distance. - public void Offset (int dx, int dy) - { - X += dx; - Y += dy; - } - - /// ToString Method - /// Formats the Point as a string in coordinate notation. - public override string ToString () - { - return string.Format ( - "{{X={0},Y={1}}}", - X.ToString (CultureInfo.InvariantCulture), - Y.ToString (CultureInfo.InvariantCulture) - ); - } - - /// Adds the specified Size to the specified Point. - /// The Point that is the result of the addition operation. - /// The Point to add. - /// The Size to add. - public static Point Add (Point pt, Size sz) { return new Point (pt.X + sz.Width, pt.Y + sz.Height); } - - /// Translates this Point by the specified Point. - /// The offset. - /// The Point used offset this Point. - public void Offset (Point p) { Offset (p.X, p.Y); } - - /// Returns the result of subtracting specified Size from the specified Point. - /// The Point that is the result of the subtraction operation. - /// The Point to be subtracted from. - /// The Size to subtract from the Point. - public static Point Subtract (Point pt, Size sz) { return new Point (pt.X - sz.Width, pt.Y - sz.Height); } -} diff --git a/Terminal.Gui/Types/PointF.cs b/Terminal.Gui/Types/PointF.cs deleted file mode 100644 index ff971dd56..000000000 --- a/Terminal.Gui/Types/PointF.cs +++ /dev/null @@ -1,93 +0,0 @@ -// 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 + "}"; } -} diff --git a/Terminal.Gui/Types/RectangleF.cs b/Terminal.Gui/Types/RectangleF.cs deleted file mode 100644 index 2a3a8d65a..000000000 --- a/Terminal.Gui/Types/RectangleF.cs +++ /dev/null @@ -1,260 +0,0 @@ -// 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; - -/// Stores the location and size of a rectangular region. -public struct RectangleF : IEquatable -{ - /// Initializes a new instance of the class. - public static readonly RectangleF Empty; - - /// - /// Initializes a new instance of the class with the specified location and - /// size. - /// - public RectangleF (float x, float y, float width, float height) - { - X = x; - Y = y; - Width = width; - Height = height; - } - - /// - /// Initializes a new instance of the class with the specified location and - /// size. - /// - public RectangleF (PointF location, SizeF size) - { - X = location.X; - Y = location.Y; - Width = size.Width; - Height = size.Height; - } - - /// Creates a new with the specified location and size. - public static RectangleF FromLTRB (float left, float top, float right, float bottom) { return new RectangleF (left, top, right - left, bottom - top); } - - /// - /// Gets or sets the coordinates of the upper-left corner of the rectangular region represented by this - /// . - /// - [Browsable (false)] - public PointF Location - { - get => new (X, Y); - set - { - X = value.X; - Y = value.Y; - } - } - - /// Gets or sets the size of this . - [Browsable (false)] - public SizeF Size - { - get => new (Width, Height); - set - { - Width = value.Width; - Height = value.Height; - } - } - - /// - /// Gets or sets the x-coordinate of the upper-left corner of the rectangular region defined by this - /// . - /// - public float X { get; set; } - - /// - /// Gets or sets the y-coordinate of the upper-left corner of the rectangular region defined by this - /// . - /// - public float Y { get; set; } - - /// Gets or sets the width of the rectangular region defined by this . - public float Width { get; set; } - - /// Gets or sets the height of the rectangular region defined by this . - public float Height { get; set; } - - /// - /// Gets the x-coordinate of the upper-left corner of the rectangular region defined by this - /// . - /// - [Browsable (false)] - public float Left => X; - - /// - /// Gets the y-coordinate of the upper-left corner of the rectangular region defined by this - /// . - /// - [Browsable (false)] - public float Top => Y; - - /// - /// Gets the x-coordinate of the lower-right corner of the rectangular region defined by this - /// . - /// - [Browsable (false)] - public float Right => X + Width; - - /// - /// Gets the y-coordinate of the lower-right corner of the rectangular region defined by this - /// . - /// - [Browsable (false)] - public float Bottom => Y + Height; - - /// - /// Tests whether this has a or - /// a of 0. - /// - [Browsable (false)] - public bool IsEmpty => Width <= 0 || Height <= 0; - - /// - /// Tests whether is a with the same location and - /// size of this . - /// - public override bool Equals (object obj) { return obj is RectangleF && Equals ((RectangleF)obj); } - - /// Returns true if two objects have equal location and size. - /// - /// - public bool Equals (RectangleF other) { return this == other; } - - /// Tests whether two objects have equal location and size. - public static bool operator == (RectangleF left, RectangleF right) - { - return left.X == right.X && left.Y == right.Y && left.Width == right.Width && left.Height == right.Height; - } - - /// Tests whether two objects differ in location or size. - public static bool operator != (RectangleF left, RectangleF right) { return !(left == right); } - - /// - /// Determines if the specified point is contained within the rectangular region defined by this - /// . - /// - public bool Contains (float x, float y) { return X <= x && x < X + Width && Y <= y && y < Y + Height; } - - /// - /// Determines if the specified point is contained within the rectangular region defined by this - /// . - /// - public bool Contains (PointF pt) { return Contains (pt.X, pt.Y); } - - /// - /// Determines if the rectangular region represented by is entirely contained within the - /// rectangular region represented by this . - /// - public bool Contains (RectangleF rect) - { - return X <= rect.X - && rect.X + rect.Width <= X + Width - && Y <= rect.Y - && rect.Y + rect.Height <= Y + Height; - } - - /// Gets the hash code for this . - public override int GetHashCode () { return (Height.GetHashCode () + Width.GetHashCode ()) ^ (X.GetHashCode () + Y.GetHashCode ()); } - - /// Inflates this by the specified amount. - public void Inflate (float x, float y) - { - X -= x; - Y -= y; - Width += 2 * x; - Height += 2 * y; - } - - /// Inflates this by the specified amount. - public void Inflate (SizeF size) { Inflate (size.Width, size.Height); } - - /// Creates a that is inflated by the specified amount. - public static RectangleF Inflate (RectangleF rect, float x, float y) - { - RectangleF r = rect; - r.Inflate (x, y); - - return r; - } - - /// Creates a Rectangle that represents the intersection between this Rectangle and rect. - public void Intersect (RectangleF rect) - { - RectangleF result = Intersect (rect, this); - - X = result.X; - Y = result.Y; - Width = result.Width; - Height = result.Height; - } - - /// - /// Creates a rectangle that represents the intersection between a and b. If there is no intersection, an empty - /// rectangle is returned. - /// - public static RectangleF Intersect (RectangleF a, RectangleF b) - { - float x1 = Math.Max (a.X, b.X); - float x2 = Math.Min (a.X + a.Width, b.X + b.Width); - float y1 = Math.Max (a.Y, b.Y); - float y2 = Math.Min (a.Y + a.Height, b.Y + b.Height); - - if (x2 >= x1 && y2 >= y1) - { - return new RectangleF (x1, y1, x2 - x1, y2 - y1); - } - - return Empty; - } - - /// Determines if this rectangle intersects with rect. - public bool IntersectsWith (RectangleF rect) - { - return rect.X < X + Width - && X < rect.X + rect.Width - && rect.Y < Y + Height - && Y < rect.Y + rect.Height; - } - - /// Creates a rectangle that represents the union between a and b. - public static RectangleF Union (RectangleF a, RectangleF b) - { - float x1 = Math.Min (a.X, b.X); - float x2 = Math.Max (a.X + a.Width, b.X + b.Width); - float y1 = Math.Min (a.Y, b.Y); - float y2 = Math.Max (a.Y + a.Height, b.Y + b.Height); - - return new RectangleF (x1, y1, x2 - x1, y2 - y1); - } - - /// Adjusts the location of this rectangle by the specified amount. - public void Offset (PointF pos) { Offset (pos.X, pos.Y); } - - /// Adjusts the location of this rectangle by the specified amount. - public void Offset (float x, float y) - { - X += x; - Y += y; - } - - /// Converts the specified to a . - public static implicit operator RectangleF (Rectangle r) { return new RectangleF (r.X, r.Y, r.Width, r.Height); } - - /// - /// Converts the and of - /// this to a human-readable string. - /// - public override string ToString () { return "{X=" + X + ",Y=" + Y + ",Width=" + Width + ",Height=" + Height + "}"; } -} diff --git a/UnitTests/Types/PointTests.cs b/UnitTests/Types/PointTests.cs deleted file mode 100644 index 782e4c398..000000000 --- a/UnitTests/Types/PointTests.cs +++ /dev/null @@ -1,66 +0,0 @@ -namespace Terminal.Gui.TypeTests; - -public class PointTests -{ - [Fact] - public void Point_Equals () - { - var point1 = new Point (); - var point2 = new Point (); - Assert.Equal (point1, point2); - - point1 = new Point (1, 2); - point2 = new Point (1, 2); - Assert.Equal (point1, point2); - - point1 = new Point (1, 2); - point2 = new Point (0, 2); - Assert.NotEqual (point1, point2); - - point1 = new Point (1, 2); - point2 = new Point (0, 3); - Assert.NotEqual (point1, point2); - } - - [Fact] - public void Point_New () - { - var point = new Point (); - Assert.True (point.IsEmpty); - - point = new Point (new Size ()); - Assert.True (point.IsEmpty); - - point = new Point (1, 2); - Assert.False (point.IsEmpty); - - point = new Point (-1, -2); - Assert.False (point.IsEmpty); - } - - [Fact] - public void Point_SetsValue () - { - var point = new Point { X = 0, Y = 0 }; - Assert.True (point.IsEmpty); - - point = new Point { X = 1, Y = 2 }; - Assert.False (point.IsEmpty); - - point = new Point { X = -1, Y = -2 }; - Assert.False (point.IsEmpty); - } - - [Fact] - public void Point_Size () - { - var point = new Point (1, 2); - var size = (Size)point; - Assert.False (size.IsEmpty); - - point = new Point (-1, 2); - Action action = () => size = (Size)point; - var ex = Assert.Throws (action); - Assert.Equal ("Either Width and Height must be greater or equal to 0.", ex.Message); - } -}