Remove Size and SizeF

This commit is contained in:
Brandon Thetford
2024-02-25 16:47:03 -07:00
parent c66951baa0
commit 9303af9c44
4 changed files with 0 additions and 351 deletions

View File

@@ -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);
}

View File

@@ -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;
/// <summary>Stores an ordered pair of integers, which specify a Height and Width.</summary>
public partial struct Size
{
private int width, height;
/// <summary>Gets a Size structure that has a Height and Width value of 0.</summary>
public static readonly Size Empty;
/// <summary>Addition Operator</summary>
/// <remarks>Addition of two Size structures.</remarks>
public static Size operator + (Size sz1, Size sz2)
{
return new Size (
sz1.Width + sz2.Width,
sz1.Height + sz2.Height
);
}
/// <summary>Equality Operator</summary>
/// <remarks>
/// Compares two Size objects. The return value is based on the equivalence of the Width and Height properties of
/// the two Sizes.
/// </remarks>
public static bool operator == (Size sz1, Size sz2) { return sz1.Width == sz2.Width && sz1.Height == sz2.Height; }
/// <summary>Inequality Operator</summary>
/// <remarks>
/// Compares two Size objects. The return value is based on the equivalence of the Width and Height properties of
/// the two Sizes.
/// </remarks>
public static bool operator != (Size sz1, Size sz2) { return sz1.Width != sz2.Width || sz1.Height != sz2.Height; }
/// <summary>Subtraction Operator</summary>
/// <remarks>Subtracts two Size structures.</remarks>
public static Size operator - (Size sz1, Size sz2)
{
return new Size (
sz1.Width - sz2.Width,
sz1.Height - sz2.Height
);
}
/// <summary>Size to Point Conversion</summary>
/// <remarks>Returns a Point based on the dimensions of a given Size. Requires explicit cast.</remarks>
public static explicit operator Point (Size size) { return new Point (size.Width, size.Height); }
/// <summary>Size Constructor</summary>
/// <remarks>Creates a Size from a Point value.</remarks>
public Size (Point pt)
{
width = pt.X;
height = pt.Y;
}
/// <summary>Size Constructor</summary>
/// <remarks>Creates a Size from specified dimensions.</remarks>
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;
}
/// <summary>IsEmpty Property</summary>
/// <remarks>Indicates if both Width and Height are zero.</remarks>
public bool IsEmpty => width == 0 && height == 0;
/// <summary>Width Property</summary>
/// <remarks>The Width coordinate of the Size.</remarks>
public int Width
{
get => width;
set
{
if (value < 0)
{
throw new ArgumentException ("Width must be greater or equal to 0.");
}
width = value;
}
}
/// <summary>Height Property</summary>
/// <remarks>The Height coordinate of the Size.</remarks>
public int Height
{
get => height;
set
{
if (value < 0)
{
throw new ArgumentException ("Height must be greater or equal to 0.");
}
height = value;
}
}
/// <summary>Equals Method</summary>
/// <remarks>Checks equivalence of this Size and another object.</remarks>
public override bool Equals (object obj)
{
if (!(obj is Size))
{
return false;
}
return this == (Size)obj;
}
/// <summary>GetHashCode Method</summary>
/// <remarks>Calculates a hashing value.</remarks>
public override int GetHashCode () { return width ^ height; }
/// <summary>ToString Method</summary>
/// <remarks>Formats the Size as a string in coordinate notation.</remarks>
public override string ToString () { return string.Format ("{{Width={0}, Height={1}}}", width, height); }
/// <summary>Adds the width and height of one Size structure to the width and height of another Size structure.</summary>
/// <returns>The add.</returns>
/// <param name="sz1">The first Size structure to add.</param>
/// <param name="sz2">The second Size structure to add.</param>
public static Size Add (Size sz1, Size sz2)
{
return new Size (
sz1.Width + sz2.Width,
sz1.Height + sz2.Height
);
}
/// <summary>Subtracts the width and height of one Size structure to the width and height of another Size structure.</summary>
/// <returns>The subtract.</returns>
/// <param name="sz1">The first Size structure to subtract.</param>
/// <param name="sz2">The second Size structure to subtract.</param>
public static Size Subtract (Size sz1, Size sz2)
{
return new Size (
sz1.Width - sz2.Width,
sz1.Height - sz2.Height
);
}
}

View File

@@ -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;
/// <summary>Represents the size of a rectangular region with an ordered pair of width and height.</summary>
public struct SizeF : IEquatable<SizeF>
{
/// <summary>Initializes a new instance of the <see cref='Terminal.Gui.SizeF'/> class.</summary>
public static readonly SizeF Empty;
/// <summary>
/// Initializes a new instance of the <see cref='Terminal.Gui.SizeF'/> class from the specified existing
/// <see cref='Terminal.Gui.SizeF'/>.
/// </summary>
public SizeF (SizeF size)
{
Width = size.Width;
Height = size.Height;
}
/// <summary>
/// Initializes a new instance of the <see cref='Terminal.Gui.SizeF'/> class from the specified
/// <see cref='Terminal.Gui.PointF'/>.
/// </summary>
public SizeF (PointF pt)
{
Width = pt.X;
Height = pt.Y;
}
/// <summary>Initializes a new instance of the <see cref='Terminal.Gui.SizeF'/> class from the specified dimensions.</summary>
public SizeF (float width, float height)
{
Width = width;
Height = height;
}
/// <summary>Performs vector addition of two <see cref='Terminal.Gui.SizeF'/> objects.</summary>
public static SizeF operator + (SizeF sz1, SizeF sz2) { return Add (sz1, sz2); }
/// <summary>Contracts a <see cref='Terminal.Gui.SizeF'/> by another <see cref='Terminal.Gui.SizeF'/></summary>
public static SizeF operator - (SizeF sz1, SizeF sz2) { return Subtract (sz1, sz2); }
/// <summary>Multiplies <see cref="SizeF"/> by a <see cref="float"/> producing <see cref="SizeF"/>.</summary>
/// <param name="left">Multiplier of type <see cref="float"/>.</param>
/// <param name="right">Multiplicand of type <see cref="SizeF"/>.</param>
/// <returns>Product of type <see cref="SizeF"/>.</returns>
public static SizeF operator * (float left, SizeF right) { return Multiply (right, left); }
/// <summary>Multiplies <see cref="SizeF"/> by a <see cref="float"/> producing <see cref="SizeF"/>.</summary>
/// <param name="left">Multiplicand of type <see cref="SizeF"/>.</param>
/// <param name="right">Multiplier of type <see cref="float"/>.</param>
/// <returns>Product of type <see cref="SizeF"/>.</returns>
public static SizeF operator * (SizeF left, float right) { return Multiply (left, right); }
/// <summary>Divides <see cref="SizeF"/> by a <see cref="float"/> producing <see cref="SizeF"/>.</summary>
/// <param name="left">Dividend of type <see cref="SizeF"/>.</param>
/// <param name="right">Divisor of type <see cref="int"/>.</param>
/// <returns>Result of type <see cref="SizeF"/>.</returns>
public static SizeF operator / (SizeF left, float right) { return new SizeF (left.Width / right, left.Height / right); }
/// <summary>Tests whether two <see cref='Terminal.Gui.SizeF'/> objects are identical.</summary>
public static bool operator == (SizeF sz1, SizeF sz2) { return sz1.Width == sz2.Width && sz1.Height == sz2.Height; }
/// <summary>Tests whether two <see cref='Terminal.Gui.SizeF'/> objects are different.</summary>
public static bool operator != (SizeF sz1, SizeF sz2) { return !(sz1 == sz2); }
/// <summary>Converts the specified <see cref='Terminal.Gui.SizeF'/> to a <see cref='Terminal.Gui.PointF'/>.</summary>
public static explicit operator PointF (SizeF size) { return new PointF (size.Width, size.Height); }
/// <summary>Tests whether this <see cref='Terminal.Gui.SizeF'/> has zero width and height.</summary>
[Browsable (false)]
public bool IsEmpty => Width == 0 && Height == 0;
/// <summary>Represents the horizontal component of this <see cref='Terminal.Gui.SizeF'/>.</summary>
public float Width { get; set; }
/// <summary>Represents the vertical component of this <see cref='Terminal.Gui.SizeF'/>.</summary>
public float Height { get; set; }
/// <summary>Performs vector addition of two <see cref='Terminal.Gui.SizeF'/> objects.</summary>
public static SizeF Add (SizeF sz1, SizeF sz2) { return new SizeF (sz1.Width + sz2.Width, sz1.Height + sz2.Height); }
/// <summary>Contracts a <see cref='Terminal.Gui.SizeF'/> by another <see cref='Terminal.Gui.SizeF'/>.</summary>
public static SizeF Subtract (SizeF sz1, SizeF sz2) { return new SizeF (sz1.Width - sz2.Width, sz1.Height - sz2.Height); }
/// <summary>
/// Tests to see whether the specified object is a <see cref='Terminal.Gui.SizeF'/> with the same dimensions as
/// this <see cref='Terminal.Gui.SizeF'/>.
/// </summary>
public override bool Equals (object obj) { return obj is SizeF && Equals ((SizeF)obj); }
/// <summary>Tests whether two <see cref='Terminal.Gui.SizeF'/> objects are identical.</summary>
public bool Equals (SizeF other) { return this == other; }
/// <summary>Generates a hashcode from the width and height</summary>
/// <returns></returns>
public override int GetHashCode () { return Width.GetHashCode () ^ Height.GetHashCode (); }
/// <summary>Creates a human-readable string that represents this <see cref='Terminal.Gui.SizeF'/>.</summary>
public override string ToString () { return "{Width=" + Width + ", Height=" + Height + "}"; }
/// <summary>Multiplies <see cref="SizeF"/> by a <see cref="float"/> producing <see cref="SizeF"/>.</summary>
/// <param name="size">Multiplicand of type <see cref="SizeF"/>.</param>
/// <param name="multiplier">Multiplier of type <see cref="float"/>.</param>
/// <returns>Product of type SizeF.</returns>
private static SizeF Multiply (SizeF size, float multiplier) { return new SizeF (size.Width * multiplier, size.Height * multiplier); }
}

View File

@@ -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<ArgumentException> (action);
Assert.Equal ("Either Width and Height must be greater or equal to 0.", ex.Message);
action = () => new Size (3, -4);
ex = Assert.Throws<ArgumentException> (action);
Assert.Equal ("Either Width and Height must be greater or equal to 0.", ex.Message);
action = () => new Size (-3, -4);
ex = Assert.Throws<ArgumentException> (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<ArgumentException> (action);
Assert.Equal ("Width must be greater or equal to 0.", ex.Message);
action = () => { size = new Size { Width = 3, Height = -4 }; };
ex = Assert.Throws<ArgumentException> (action);
Assert.Equal ("Height must be greater or equal to 0.", ex.Message);
action = () => { size = new Size { Width = -3, Height = -4 }; };
ex = Assert.Throws<ArgumentException> (action);
Assert.Equal ("Width must be greater or equal to 0.", ex.Message);
}
}