IntrAlignedBox2AlignedBox2.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. // David Eberly, Geometric Tools, Redmond WA 98052
  2. // Copyright (c) 1998-2020
  3. // Distributed under the Boost Software License, Version 1.0.
  4. // https://www.boost.org/LICENSE_1_0.txt
  5. // https://www.geometrictools.com/License/Boost/LICENSE_1_0.txt
  6. // Version: 4.0.2019.08.13
  7. #pragma once
  8. #include <Mathematics/FIQuery.h>
  9. #include <Mathematics/TIQuery.h>
  10. #include <Mathematics/AlignedBox.h>
  11. // The queries consider the box to be a solid.
  12. //
  13. // The aligned-aligned queries use simple min-max comparisions. The
  14. // interesection of aligned boxes is an aligned box, possibly degenerate,
  15. // where min[d] == max[d] for at least one dimension d.
  16. namespace WwiseGTE
  17. {
  18. template <typename Real>
  19. class TIQuery<Real, AlignedBox2<Real>, AlignedBox2<Real>>
  20. {
  21. public:
  22. struct Result
  23. {
  24. bool intersect;
  25. };
  26. Result operator()(AlignedBox2<Real> const& box0, AlignedBox2<Real> const& box1)
  27. {
  28. Result result;
  29. for (int i = 0; i < 2; i++)
  30. {
  31. if (box0.max[i] < box1.min[i] || box0.min[i] > box1.max[i])
  32. {
  33. result.intersect = false;
  34. return result;
  35. }
  36. }
  37. result.intersect = true;
  38. return result;
  39. }
  40. };
  41. template <typename Real>
  42. class FIQuery<Real, AlignedBox2<Real>, AlignedBox2<Real>>
  43. {
  44. public:
  45. struct Result
  46. {
  47. bool intersect;
  48. AlignedBox2<Real> box;
  49. };
  50. Result operator()(AlignedBox2<Real> const& box0, AlignedBox2<Real> const& box1)
  51. {
  52. Result result;
  53. for (int i = 0; i < 2; i++)
  54. {
  55. if (box0.max[i] < box1.min[i] || box0.min[i] > box1.max[i])
  56. {
  57. result.intersect = false;
  58. return result;
  59. }
  60. }
  61. for (int i = 0; i < 2; i++)
  62. {
  63. if (box0.max[i] <= box1.max[i])
  64. {
  65. result.box.max[i] = box0.max[i];
  66. }
  67. else
  68. {
  69. result.box.max[i] = box1.max[i];
  70. }
  71. if (box0.min[i] <= box1.min[i])
  72. {
  73. result.box.min[i] = box1.min[i];
  74. }
  75. else
  76. {
  77. result.box.min[i] = box0.min[i];
  78. }
  79. }
  80. result.intersect = true;
  81. return result;
  82. }
  83. };
  84. }