Rect2.cs 2.2 KB

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