From 9303af9c44e59e96253d87781804c09e83616d13 Mon Sep 17 00:00:00 2001 From: Brandon Thetford Date: Sun, 25 Feb 2024 16:47:03 -0700 Subject: [PATCH] Remove Size and SizeF --- Terminal.Gui/Types/Size.TemporaryOperators.cs | 11 -- Terminal.Gui/Types/Size.cs | 159 ------------------ Terminal.Gui/Types/SizeF.cs | 114 ------------- UnitTests/Types/SizeTests.cs | 67 -------- 4 files changed, 351 deletions(-) delete mode 100644 Terminal.Gui/Types/Size.TemporaryOperators.cs delete mode 100644 Terminal.Gui/Types/Size.cs delete mode 100644 Terminal.Gui/Types/SizeF.cs delete mode 100644 UnitTests/Types/SizeTests.cs diff --git a/Terminal.Gui/Types/Size.TemporaryOperators.cs b/Terminal.Gui/Types/Size.TemporaryOperators.cs deleted file mode 100644 index 0f941446b..000000000 --- a/Terminal.Gui/Types/Size.TemporaryOperators.cs +++ /dev/null @@ -1,11 +0,0 @@ -namespace Terminal.Gui; - -public partial struct Size -{ - public static implicit operator Size (System.Drawing.Size sds) => new (sds.Width, sds.Height); - public static implicit operator System.Drawing.Size (Size tgs) => new (tgs.Width, tgs.Height); - public static bool operator != (Size left, System.Drawing.Size right) => new System.Drawing.Size (left.Width,left.Height) != right; - public static bool operator == (Size left, System.Drawing.Size right) => new System.Drawing.Size (left.Width,left.Height) == right; - public static bool operator != (System.Drawing.Size left, Size right) => left != new System.Drawing.Size(right.Width,right.Height); - public static bool operator == (System.Drawing.Size left, Size right) => left == new System.Drawing.Size(right.Width,right.Height); -} diff --git a/Terminal.Gui/Types/Size.cs b/Terminal.Gui/Types/Size.cs deleted file mode 100644 index 31ea28106..000000000 --- a/Terminal.Gui/Types/Size.cs +++ /dev/null @@ -1,159 +0,0 @@ -// -// System.Drawing.Size.cs -// -// Author: -// Mike Kestner (mkestner@speakeasy.net) -// -// Copyright (C) 2001 Mike Kestner -// Copyright (C) 2004 Novell, Inc. http://www.novell.com -// - -namespace Terminal.Gui; - -/// Stores an ordered pair of integers, which specify a Height and Width. -public partial struct Size -{ - private int width, height; - - /// Gets a Size structure that has a Height and Width value of 0. - public static readonly Size Empty; - - /// Addition Operator - /// Addition of two Size structures. - public static Size operator + (Size sz1, Size sz2) - { - return new Size ( - sz1.Width + sz2.Width, - sz1.Height + sz2.Height - ); - } - - /// Equality Operator - /// - /// Compares two Size objects. The return value is based on the equivalence of the Width and Height properties of - /// the two Sizes. - /// - public static bool operator == (Size sz1, Size sz2) { return sz1.Width == sz2.Width && sz1.Height == sz2.Height; } - - /// Inequality Operator - /// - /// Compares two Size objects. The return value is based on the equivalence of the Width and Height properties of - /// the two Sizes. - /// - public static bool operator != (Size sz1, Size sz2) { return sz1.Width != sz2.Width || sz1.Height != sz2.Height; } - - /// Subtraction Operator - /// Subtracts two Size structures. - public static Size operator - (Size sz1, Size sz2) - { - return new Size ( - sz1.Width - sz2.Width, - sz1.Height - sz2.Height - ); - } - - /// Size to Point Conversion - /// Returns a Point based on the dimensions of a given Size. Requires explicit cast. - public static explicit operator Point (Size size) { return new Point (size.Width, size.Height); } - - /// Size Constructor - /// Creates a Size from a Point value. - public Size (Point pt) - { - width = pt.X; - height = pt.Y; - } - - /// Size Constructor - /// Creates a Size from specified dimensions. - public Size (int width, int height) - { - if (width < 0 || height < 0) - { - throw new ArgumentException ("Either Width and Height must be greater or equal to 0."); - } - - this.width = width; - this.height = height; - } - - /// IsEmpty Property - /// Indicates if both Width and Height are zero. - public bool IsEmpty => width == 0 && height == 0; - - /// Width Property - /// The Width coordinate of the Size. - public int Width - { - get => width; - set - { - if (value < 0) - { - throw new ArgumentException ("Width must be greater or equal to 0."); - } - - width = value; - } - } - - /// Height Property - /// The Height coordinate of the Size. - public int Height - { - get => height; - set - { - if (value < 0) - { - throw new ArgumentException ("Height must be greater or equal to 0."); - } - - height = value; - } - } - - /// Equals Method - /// Checks equivalence of this Size and another object. - public override bool Equals (object obj) - { - if (!(obj is Size)) - { - return false; - } - - return this == (Size)obj; - } - - /// GetHashCode Method - /// Calculates a hashing value. - public override int GetHashCode () { return width ^ height; } - - /// ToString Method - /// Formats the Size as a string in coordinate notation. - public override string ToString () { return string.Format ("{{Width={0}, Height={1}}}", width, height); } - - /// Adds the width and height of one Size structure to the width and height of another Size structure. - /// The add. - /// The first Size structure to add. - /// The second Size structure to add. - public static Size Add (Size sz1, Size sz2) - { - return new Size ( - sz1.Width + sz2.Width, - sz1.Height + sz2.Height - ); - } - - /// Subtracts the width and height of one Size structure to the width and height of another Size structure. - /// The subtract. - /// The first Size structure to subtract. - /// The second Size structure to subtract. - public static Size Subtract (Size sz1, Size sz2) - { - return new Size ( - sz1.Width - sz2.Width, - sz1.Height - sz2.Height - ); - } -} diff --git a/Terminal.Gui/Types/SizeF.cs b/Terminal.Gui/Types/SizeF.cs deleted file mode 100644 index 91c7bf09f..000000000 --- a/Terminal.Gui/Types/SizeF.cs +++ /dev/null @@ -1,114 +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 the size of a rectangular region with an ordered pair of width and height. -public struct SizeF : IEquatable -{ - /// Initializes a new instance of the class. - public static readonly SizeF Empty; - - /// - /// Initializes a new instance of the class from the specified existing - /// . - /// - public SizeF (SizeF size) - { - Width = size.Width; - Height = size.Height; - } - - /// - /// Initializes a new instance of the class from the specified - /// . - /// - public SizeF (PointF pt) - { - Width = pt.X; - Height = pt.Y; - } - - /// Initializes a new instance of the class from the specified dimensions. - public SizeF (float width, float height) - { - Width = width; - Height = height; - } - - /// Performs vector addition of two objects. - public static SizeF operator + (SizeF sz1, SizeF sz2) { return Add (sz1, sz2); } - - /// Contracts a by another - public static SizeF operator - (SizeF sz1, SizeF sz2) { return Subtract (sz1, sz2); } - - /// Multiplies by a producing . - /// Multiplier of type . - /// Multiplicand of type . - /// Product of type . - public static SizeF operator * (float left, SizeF right) { return Multiply (right, left); } - - /// Multiplies by a producing . - /// Multiplicand of type . - /// Multiplier of type . - /// Product of type . - public static SizeF operator * (SizeF left, float right) { return Multiply (left, right); } - - /// Divides by a producing . - /// Dividend of type . - /// Divisor of type . - /// Result of type . - public static SizeF operator / (SizeF left, float right) { return new SizeF (left.Width / right, left.Height / right); } - - /// Tests whether two objects are identical. - public static bool operator == (SizeF sz1, SizeF sz2) { return sz1.Width == sz2.Width && sz1.Height == sz2.Height; } - - /// Tests whether two objects are different. - public static bool operator != (SizeF sz1, SizeF sz2) { return !(sz1 == sz2); } - - /// Converts the specified to a . - public static explicit operator PointF (SizeF size) { return new PointF (size.Width, size.Height); } - - /// Tests whether this has zero width and height. - [Browsable (false)] - public bool IsEmpty => Width == 0 && Height == 0; - - /// Represents the horizontal component of this . - public float Width { get; set; } - - /// Represents the vertical component of this . - public float Height { get; set; } - - /// Performs vector addition of two objects. - public static SizeF Add (SizeF sz1, SizeF sz2) { return new SizeF (sz1.Width + sz2.Width, sz1.Height + sz2.Height); } - - /// Contracts a by another . - public static SizeF Subtract (SizeF sz1, SizeF sz2) { return new SizeF (sz1.Width - sz2.Width, sz1.Height - sz2.Height); } - - /// - /// Tests to see whether the specified object is a with the same dimensions as - /// this . - /// - public override bool Equals (object obj) { return obj is SizeF && Equals ((SizeF)obj); } - - /// Tests whether two objects are identical. - public bool Equals (SizeF other) { return this == other; } - - /// Generates a hashcode from the width and height - /// - public override int GetHashCode () { return Width.GetHashCode () ^ Height.GetHashCode (); } - - /// Creates a human-readable string that represents this . - public override string ToString () { return "{Width=" + Width + ", Height=" + Height + "}"; } - - /// Multiplies by a producing . - /// Multiplicand of type . - /// Multiplier of type . - /// Product of type SizeF. - private static SizeF Multiply (SizeF size, float multiplier) { return new SizeF (size.Width * multiplier, size.Height * multiplier); } -} diff --git a/UnitTests/Types/SizeTests.cs b/UnitTests/Types/SizeTests.cs deleted file mode 100644 index fc8827924..000000000 --- a/UnitTests/Types/SizeTests.cs +++ /dev/null @@ -1,67 +0,0 @@ -namespace Terminal.Gui.TypeTests; - -public class SizeTests -{ - [Fact] - public void Size_Equals () - { - var size1 = new Size (); - var size2 = new Size (); - Assert.Equal (size1, size2); - - size1 = new Size (3, 4); - size2 = new Size (3, 4); - Assert.Equal (size1, size2); - - size1 = new Size (3, 4); - size2 = new Size (4, 4); - Assert.NotEqual (size1, size2); - } - - [Fact] - public void Size_New () - { - var size = new Size (); - Assert.True (size.IsEmpty); - - size = new Size (new Point ()); - Assert.True (size.IsEmpty); - - size = new Size (3, 4); - Assert.False (size.IsEmpty); - - Action action = () => new Size (-3, 4); - var ex = Assert.Throws (action); - Assert.Equal ("Either Width and Height must be greater or equal to 0.", ex.Message); - - action = () => new Size (3, -4); - ex = Assert.Throws (action); - Assert.Equal ("Either Width and Height must be greater or equal to 0.", ex.Message); - - action = () => new Size (-3, -4); - ex = Assert.Throws (action); - Assert.Equal ("Either Width and Height must be greater or equal to 0.", ex.Message); - } - - [Fact] - public void Size_SetsValue () - { - var size = new Size { Width = 0, Height = 0 }; - Assert.True (size.IsEmpty); - - size = new Size { Width = 3, Height = 4 }; - Assert.False (size.IsEmpty); - - Action action = () => { size = new Size { Width = -3, Height = 4 }; }; - var ex = Assert.Throws (action); - Assert.Equal ("Width must be greater or equal to 0.", ex.Message); - - action = () => { size = new Size { Width = 3, Height = -4 }; }; - ex = Assert.Throws (action); - Assert.Equal ("Height must be greater or equal to 0.", ex.Message); - - action = () => { size = new Size { Width = -3, Height = -4 }; }; - ex = Assert.Throws (action); - Assert.Equal ("Width must be greater or equal to 0.", ex.Message); - } -}