Capsule.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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/Segment.h>
  9. // A capsule is the set of points that are equidistant from a segment, the
  10. // common distance called the radius.
  11. namespace WwiseGTE
  12. {
  13. template <int N, typename Real>
  14. class Capsule
  15. {
  16. public:
  17. // Construction and destruction. The default constructor sets the
  18. // segment to have endpoints p0 = (-1,0,...,0) and p1 = (1,0,...,0),
  19. // and the radius is 1.
  20. Capsule()
  21. :
  22. radius((Real)1)
  23. {
  24. }
  25. Capsule(Segment<N, Real> const& inSegment, Real inRadius)
  26. :
  27. segment(inSegment),
  28. radius(inRadius)
  29. {
  30. }
  31. // Public member access.
  32. Segment<N, Real> segment;
  33. Real radius;
  34. public:
  35. // Comparisons to support sorted containers.
  36. bool operator==(Capsule const& capsule) const
  37. {
  38. return segment == capsule.segment && radius == capsule.radius;
  39. }
  40. bool operator!=(Capsule const& capsule) const
  41. {
  42. return !operator==(capsule);
  43. }
  44. bool operator< (Capsule const& capsule) const
  45. {
  46. if (segment < capsule.segment)
  47. {
  48. return true;
  49. }
  50. if (segment > capsule.segment)
  51. {
  52. return false;
  53. }
  54. return radius < capsule.radius;
  55. }
  56. bool operator<=(Capsule const& capsule) const
  57. {
  58. return !capsule.operator<(*this);
  59. }
  60. bool operator> (Capsule const& capsule) const
  61. {
  62. return capsule.operator<(*this);
  63. }
  64. bool operator>=(Capsule const& capsule) const
  65. {
  66. return !operator<(capsule);
  67. }
  68. };
  69. // Template alias for convenience.
  70. template <typename Real>
  71. using Capsule3 = Capsule<3, Real>;
  72. }