Rect2I.cs 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. [StructLayout(LayoutKind.Sequential), SerializeObject]
  9. public struct Rect2I
  10. {
  11. public Rect2I(int x, int y, int width, int height)
  12. {
  13. this.x = x;
  14. this.y = y;
  15. this.width = width;
  16. this.height = height;
  17. }
  18. public static bool operator== (Rect2I lhs, Rect2I rhs)
  19. {
  20. return lhs.x == rhs.x && lhs.y == rhs.y && lhs.width == rhs.width && lhs.height == rhs.height;
  21. }
  22. public static bool operator!= (Rect2I lhs, Rect2I rhs)
  23. {
  24. return !(lhs == rhs);
  25. }
  26. public bool Contains(Vector2I point)
  27. {
  28. if(point.x >= x && point.x < (x + width))
  29. {
  30. if(point.y >= y && point.y < (y + height))
  31. return true;
  32. }
  33. return false;
  34. }
  35. public override bool Equals(object other)
  36. {
  37. if (!(other is Rect2I))
  38. return false;
  39. Rect2I rect = (Rect2I)other;
  40. if (x.Equals(rect.x) && y.Equals(rect.y) && width.Equals(rect.width) && height.Equals(rect.height))
  41. return true;
  42. return false;
  43. }
  44. public override int GetHashCode()
  45. {
  46. return base.GetHashCode();
  47. }
  48. public override string ToString()
  49. {
  50. return String.Format("(x:{0} y:{1} width:{2} height:{3})", x, y, width, height);
  51. }
  52. public int x, y, width, height;
  53. }
  54. }