Rect2I.cs 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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)]
  9. public class 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 int x, y, width, height;
  49. }
  50. }