bounds.js 918 B

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