TizzyT

PointM & SizeM -TizzyT

Jun 14th, 2019
254
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.57 KB | None | 0 0
  1. namespace System.Drawing
  2. {
  3.     public struct PointM
  4.     {
  5.         public decimal X { get; }
  6.         public decimal Y { get; }
  7.         public bool IsEmpty { get; }
  8.         public PointM(decimal X, decimal Y)
  9.         {
  10.             this.X = X;
  11.             this.Y = Y;
  12.             IsEmpty = X == 0m && Y == 0m;
  13.         }
  14.         public static PointM Add(PointM Point, Size Size) => Point + Size;
  15.         public static PointM Add(PointM Point, SizeM Size) => Point + Size;
  16.         public override bool Equals(object Point) => Point.GetType() == GetType() && ((PointM)Point).X == X && ((PointM)Point).Y == Y;
  17.         public override int GetHashCode() => X.GetHashCode() ^ Y.GetHashCode();
  18.         public static PointM Subtract(PointM Point, Size Size) => Point - Size;
  19.         public static PointM Subtract(PointM Point, SizeM Size) => Point - Size;
  20.         public static PointM operator +(PointM Point, SizeM Size) => new PointM(Point.X + Size.Width, Point.Y + Size.Height);
  21.         public static PointM operator +(PointM Point, Size Size) => new PointM(Point.X + Size.Width, Point.Y + Size.Height);
  22.         public static bool operator ==(PointM Point1, PointM Point2) => Point1.X == Point2.X && Point1.Y == Point2.Y;
  23.         public static bool operator !=(PointM Point1, PointM Point2) => !(Point1 == Point2);
  24.         public static PointM operator -(PointM Point, SizeM Size) => new PointM(Point.X - Size.Width, Point.Y - Size.Height);
  25.         public static PointM operator -(PointM Point, Size Size) => new PointM(Point.X - Size.Width, Point.Y - Size.Height);
  26.         public override string ToString() => "{ X:" + X + ", Y:" + Y + " }";
  27.     }
  28.  
  29.     public struct SizeM
  30.     {
  31.         public decimal Width { get; }
  32.         public decimal Height { get; }
  33.         public bool IsEmpty { get; }
  34.         public SizeM(PointM Point)
  35.         {
  36.             Width = Point.X;
  37.             Height = Point.Y;
  38.             IsEmpty = Width == 0m && Height == 0m;
  39.         }
  40.         public SizeM(SizeM Size)
  41.         {
  42.             Width = Size.Width;
  43.             Height = Size.Height;
  44.             IsEmpty = Width == 0m && Height == 0m;
  45.         }
  46.         public SizeM(decimal Width, decimal Height)
  47.         {
  48.             this.Width = Width;
  49.             this.Height = Height;
  50.             IsEmpty = Width == 0m && Height == 0m;
  51.         }
  52.         public static SizeM Add(SizeM Size1, SizeM Size2) => Size1 + Size2;
  53.         public override bool Equals(object Size) => Size.GetType() == GetType() && ((SizeM)Size).Width == Width && ((SizeM)Size).Height == Height;
  54.         public override int GetHashCode() => Width.GetHashCode() ^ Height.GetHashCode();
  55.         public static SizeM Subtract(SizeM Size1, SizeM Size2) => Size1 - Size2;
  56.         public PointM ToPointM() => (PointM)this;
  57.         public Size ToSize() => (Size)this;
  58.         public override string ToString() => "{ Width:" + Width + ", Height:" + Height + " }";
  59.         public static explicit operator Size(SizeM Size) => new Size((int)Size.Width, (int)Size.Height);
  60.         public static SizeM operator +(SizeM Size1, SizeM Size2) => new SizeM(Size1.Width + Size2.Width, Size1.Height + Size2.Height);
  61.         public static SizeM operator -(SizeM Size1, SizeM Size2) => new SizeM(Size1.Width - Size2.Width, Size1.Height - Size2.Height);
  62.         public static explicit operator PointM(SizeM Size) => new PointM(Size.Width, Size.Height);
  63.         public static bool operator ==(SizeM Size1, SizeM Size2) => Size1.Width == Size2.Width && Size1.Height == Size2.Height;
  64.         public static bool operator !=(SizeM Size1, SizeM Size2) => !(Size1 == Size2);
  65.     }
  66. }
Advertisement
Add Comment
Please, Sign In to add comment