IntRect.cs 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. using System.Runtime.InteropServices;
  2. namespace AtomicEngine
  3. {
  4. [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
  5. public struct IntRect
  6. {
  7. public IntRect(int left, int top, int right, int bottom)
  8. {
  9. this.Left = left;
  10. this.Top = top;
  11. this.Right = right;
  12. this.Bottom = bottom;
  13. }
  14. public int Width { get { return Right - Left; } }
  15. public int Height { get { return Bottom - Top; } }
  16. public void Inflate(int horizontalAmount, int verticalAmount)
  17. {
  18. Left -= horizontalAmount;
  19. Right += horizontalAmount;
  20. Top -= verticalAmount;
  21. Bottom += verticalAmount;
  22. }
  23. public bool Contains(Vector2 vector)
  24. {
  25. int x = (int)vector.X;
  26. int y = (int)vector.Y;
  27. if (x < Left || y < Top || x >= Right || y >= Bottom)
  28. return false;
  29. return true;
  30. }
  31. /// Left coordinate.
  32. public int Left;
  33. /// Top coordinate.
  34. public int Top;
  35. /// Right coordinate.
  36. public int Right;
  37. /// Bottom coordinate.
  38. public int Bottom;
  39. }
  40. }