bounds.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.isOverlap = exports.isOverflow = exports.isInBounds = exports.parseAABB = void 0;
  4. function parseAABB(min2) {
  5. const { min, max } = min2;
  6. return [
  7. [min[0], min[1]],
  8. [max[0], max[1]],
  9. ];
  10. }
  11. exports.parseAABB = parseAABB;
  12. /**
  13. * Whether the `point` in `bounds`.
  14. * @param point
  15. * @param bounds
  16. */
  17. function isInBounds(point, bounds) {
  18. const [x, y] = point;
  19. const [min, max] = bounds;
  20. return x >= min[0] && x <= max[0] && y >= min[1] && y <= max[1];
  21. }
  22. exports.isInBounds = isInBounds;
  23. /**
  24. * Whether `b1` is overflow from `b2`.
  25. * @param b1
  26. * @param b2
  27. */
  28. function isOverflow(b1, b2) {
  29. const [min, max] = b1;
  30. return !(isInBounds(min, b2) && isInBounds(max, b2));
  31. }
  32. exports.isOverflow = isOverflow;
  33. /**
  34. * Whether `b1` is overlap with `b2`.
  35. * @param b1
  36. * @param b2
  37. * @returns
  38. */
  39. function isOverlap(b1, b2) {
  40. const [min1, max1] = b1;
  41. const [min2, max2] = b2;
  42. return (min1[0] < max2[0] &&
  43. max1[0] > min2[0] &&
  44. min1[1] < max2[1] &&
  45. max1[1] > min2[1]);
  46. }
  47. exports.isOverlap = isOverlap;
  48. //# sourceMappingURL=bounds.js.map