Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. import { Bounds } from "types"
  2. /**
  3. * Get whether two bounds collide.
  4. * @param a Bounds
  5. * @param b Bounds
  6. * @returns
  7. */
  8. export function boundsCollide(a: Bounds, b: Bounds) {
  9. return !(
  10. a.maxX < b.minX ||
  11. a.minX > b.maxX ||
  12. a.maxY < b.minY ||
  13. a.minY > b.maxY
  14. )
  15. }
  16. /**
  17. * Get whether the bounds of A contain the bounds of B. A perfect match will return true.
  18. * @param a Bounds
  19. * @param b Bounds
  20. * @returns
  21. */
  22. export function boundsContain(a: Bounds, b: Bounds) {
  23. return (
  24. a.minX < b.minX && a.minY < b.minY && a.maxY > b.maxY && a.maxX > b.maxX
  25. )
  26. }
  27. /**
  28. * Get whether the bounds of A are contained by the bounds of B.
  29. * @param a Bounds
  30. * @param b Bounds
  31. * @returns
  32. */
  33. export function boundsContained(a: Bounds, b: Bounds) {
  34. return boundsContain(b, a)
  35. }
  36. /**
  37. * Get whether two bounds are identical.
  38. * @param a Bounds
  39. * @param b Bounds
  40. * @returns
  41. */
  42. export function boundsAreEqual(a: Bounds, b: Bounds) {
  43. return !(
  44. b.maxX !== a.maxX ||
  45. b.minX !== a.minX ||
  46. b.maxY !== a.maxY ||
  47. b.minY !== a.minY
  48. )
  49. }
  50. /**
  51. * Get whether a point is inside of a bounds.
  52. * @param A
  53. * @param b
  54. * @returns
  55. */
  56. export function pointInBounds(A: number[], b: Bounds) {
  57. return !(A[0] < b.minX || A[0] > b.maxX || A[1] < b.minY || A[1] > b.maxY)
  58. }