VinnoRect.cs 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. using System;
  2. using System.IO;
  3. namespace fis.Vid.Visuals
  4. {
  5. public class VinnoRect
  6. {
  7. public double Left { get; }
  8. public double Right { get; }
  9. public double Top { get; }
  10. public double Bottom { get; }
  11. public double Width => Math.Abs(Right - Left);
  12. public double Height => Math.Abs(Bottom - Top);
  13. public VinnoPoint TopLeft => new VinnoPoint(Left, Top);
  14. public VinnoPoint TopRight => new VinnoPoint(Right, Top);
  15. public VinnoPoint BottomLeft => new VinnoPoint(Left, Bottom);
  16. public VinnoPoint BottomRight => new VinnoPoint(Right, Bottom);
  17. public VinnoRect(double x, double y, double width, double height)
  18. {
  19. if ((width < 0.0) || (height < 0.0))
  20. {
  21. throw new ArgumentException("width and height can not less than 0.");
  22. }
  23. Left = x;
  24. Top = y;
  25. Right = Left + width;
  26. Bottom = Top + height;
  27. }
  28. public VinnoRect(VinnoPoint topLeft, VinnoPoint bottomRight)
  29. {
  30. Left = topLeft.X;
  31. Top = topLeft.Y;
  32. Right = bottomRight.X;
  33. Bottom = bottomRight.Y;
  34. }
  35. public static bool operator ==(VinnoRect rect1, VinnoRect rect2)
  36. {
  37. return ((((rect1.Left == rect2.Left) && (rect1.Right == rect2.Right)) && (rect1.Bottom == rect2.Bottom)) &&
  38. (rect1.Top == rect2.Top));
  39. }
  40. public static bool operator !=(VinnoRect rect1, VinnoRect rect2)
  41. {
  42. return !(rect1 == rect2);
  43. }
  44. public static bool Equals(VinnoRect rect1, VinnoRect rect2)
  45. {
  46. return ((((rect1.Left == rect2.Left) && (rect1.Right == rect2.Right)) && (rect1.Bottom == rect2.Bottom)) &&
  47. (rect1.Top == rect2.Top));
  48. }
  49. public override bool Equals(object o)
  50. {
  51. if ((o == null) || !(o is VinnoRect))
  52. {
  53. return false;
  54. }
  55. VinnoRect rect = (VinnoRect)o;
  56. return Equals(this, rect);
  57. }
  58. public bool Equals(VinnoRect value)
  59. {
  60. return Equals(this, value);
  61. }
  62. public override int GetHashCode()
  63. {
  64. return (((Left.GetHashCode() ^ Right.GetHashCode()) ^ Top.GetHashCode()) ^ Bottom.GetHashCode());
  65. }
  66. public override string ToString()
  67. {
  68. return $"L:{Left},R:{Right},T:{Top},B:{Bottom}";
  69. }
  70. }
  71. }