Rect2.cs 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Runtime.InteropServices;
  5. using System.Text;
  6. namespace BansheeEngine
  7. {
  8. /// <summary>
  9. /// Represents a 2D rectangle using real values. Rectangle is represented with an origin in top left and width/height.
  10. /// </summary>
  11. [StructLayout(LayoutKind.Sequential), SerializeObject]
  12. public struct Rect2 // Note: Must match C++ struct Rect2
  13. {
  14. public float x, y, width, height;
  15. /// <summary>
  16. /// Creates a new 2D rectangle.
  17. /// </summary>
  18. /// <param name="x">Left-most coordinate of the rectangle.</param>
  19. /// <param name="y">Top-most coordinate of the rectangle.</param>
  20. /// <param name="width">Width of the rectangle.</param>
  21. /// <param name="height">Height of the rectangle.</param>
  22. public Rect2(float x, float y, float width, float height)
  23. {
  24. this.x = x;
  25. this.y = y;
  26. this.width = width;
  27. this.height = height;
  28. }
  29. public static bool operator ==(Rect2 lhs, Rect2 rhs)
  30. {
  31. return lhs.x == rhs.x && lhs.y == rhs.y && lhs.width == rhs.width && lhs.height == rhs.height;
  32. }
  33. public static bool operator !=(Rect2 lhs, Rect2 rhs)
  34. {
  35. return !(lhs == rhs);
  36. }
  37. /// <inheritdoc/>
  38. public override bool Equals(object other)
  39. {
  40. if (!(other is Rect2))
  41. return false;
  42. Rect2 rect = (Rect2)other;
  43. if (x.Equals(rect.x) && y.Equals(rect.y) && width.Equals(rect.width) && height.Equals(rect.height))
  44. return true;
  45. return false;
  46. }
  47. /// <inheritdoc/>
  48. public override int GetHashCode()
  49. {
  50. return base.GetHashCode();
  51. }
  52. /// <inheritdoc/>
  53. public override string ToString()
  54. {
  55. return String.Format("(x:{0} y:{1} width:{2} height:{3})", x, y, width, height);
  56. }
  57. }
  58. }