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. /// <summary>
  15. /// Creates a new 2D rectangle.
  16. /// </summary>
  17. /// <param name="x">Left-most coordinate of the rectangle.</param>
  18. /// <param name="y">Top-most coordinate of the rectangle.</param>
  19. /// <param name="width">Width of the rectangle.</param>
  20. /// <param name="height">Height of the rectangle.</param>
  21. public Rect2(float x, float y, float width, float height)
  22. {
  23. this.x = x;
  24. this.y = y;
  25. this.width = width;
  26. this.height = height;
  27. }
  28. public static bool operator ==(Rect2 lhs, Rect2 rhs)
  29. {
  30. return lhs.x == rhs.x && lhs.y == rhs.y && lhs.width == rhs.width && lhs.height == rhs.height;
  31. }
  32. public static bool operator !=(Rect2 lhs, Rect2 rhs)
  33. {
  34. return !(lhs == rhs);
  35. }
  36. /// <inheritdoc/>
  37. public override bool Equals(object other)
  38. {
  39. if (!(other is Rect2))
  40. return false;
  41. Rect2 rect = (Rect2)other;
  42. if (x.Equals(rect.x) && y.Equals(rect.y) && width.Equals(rect.width) && height.Equals(rect.height))
  43. return true;
  44. return false;
  45. }
  46. /// <inheritdoc/>
  47. public override int GetHashCode()
  48. {
  49. return base.GetHashCode();
  50. }
  51. /// <inheritdoc/>
  52. public override string ToString()
  53. {
  54. return String.Format("(x:{0} y:{1} width:{2} height:{3})", x, y, width, height);
  55. }
  56. public float x, y, width, height;
  57. }
  58. }