IntrCircle2Arc2.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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/IntrCircle2Circle2.h>
  9. #include <Mathematics/Arc2.h>
  10. namespace WwiseGTE
  11. {
  12. template <typename Real>
  13. class FIQuery<Real, Circle2<Real>, Arc2<Real>>
  14. {
  15. public:
  16. struct Result
  17. {
  18. bool intersect;
  19. // The number of intersections is 0, 1, 2 or maxInt =
  20. // std::numeric_limits<int>::max(). When 1, the arc and circle
  21. // intersect in a single point. When 2, the arc is not on the
  22. // circle and they intersect in two points. When maxInt, the
  23. // arc is on the circle.
  24. int numIntersections;
  25. // Valid only when numIntersections = 1 or 2.
  26. Vector2<Real> point[2];
  27. // Valid only when numIntersections = maxInt.
  28. Arc2<Real> arc;
  29. };
  30. Result operator()(Circle2<Real> const& circle, Arc2<Real> const& arc)
  31. {
  32. Result result;
  33. Circle2<Real> circleOfArc(arc.center, arc.radius);
  34. FIQuery<Real, Circle2<Real>, Circle2<Real>> ccQuery;
  35. auto ccResult = ccQuery(circle, circleOfArc);
  36. if (!ccResult.intersect)
  37. {
  38. result.intersect = false;
  39. result.numIntersections = 0;
  40. return result;
  41. }
  42. if (ccResult.numIntersections == std::numeric_limits<int>::max())
  43. {
  44. // The arc is on the circle.
  45. result.intersect = true;
  46. result.numIntersections = std::numeric_limits<int>::max();
  47. result.arc = arc;
  48. return result;
  49. }
  50. // Test whether circle-circle intersection points are on the arc.
  51. for (int i = 0; i < ccResult.numIntersections; ++i)
  52. {
  53. result.numIntersections = 0;
  54. if (arc.Contains(ccResult.point[i]))
  55. {
  56. result.point[result.numIntersections++] = ccResult.point[i];
  57. result.intersect = true;
  58. }
  59. }
  60. return result;
  61. }
  62. };
  63. }