Lozenge3.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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/Rectangle.h>
  9. #include <Mathematics/Vector3.h>
  10. namespace WwiseGTE
  11. {
  12. // A lozenge is the set of points that are equidistant from a rectangle,
  13. // the common distance called the radius.
  14. template <typename Real>
  15. class Lozenge3
  16. {
  17. public:
  18. // Construction and destruction. The default constructor sets the
  19. // rectangle to have origin (0,0,0), axes (1,0,0) and (0,1,0), and
  20. // both extents 1. The default radius is 1.
  21. Lozenge3()
  22. :
  23. radius((Real)1)
  24. {
  25. }
  26. Lozenge3(Rectangle<3, Real> const& inRectangle, Real inRadius)
  27. :
  28. rectangle(inRectangle),
  29. radius(inRadius)
  30. {
  31. }
  32. // Public member access.
  33. Rectangle<3, Real> rectangle;
  34. Real radius;
  35. // Comparisons to support sorted containers.
  36. bool operator==(Lozenge3 const& other) const
  37. {
  38. return rectangle == other.rectangle && radius == other.radius;
  39. }
  40. bool operator!=(Lozenge3 const& other) const
  41. {
  42. return !operator==(other);
  43. }
  44. bool operator< (Lozenge3 const& other) const
  45. {
  46. if (rectangle < other.rectangle)
  47. {
  48. return true;
  49. }
  50. if (rectangle > other.rectangle)
  51. {
  52. return false;
  53. }
  54. return radius < other.radius;
  55. }
  56. bool operator<=(Lozenge3 const& other) const
  57. {
  58. return !other.operator<(*this);
  59. }
  60. bool operator> (Lozenge3 const& other) const
  61. {
  62. return other.operator<(*this);
  63. }
  64. bool operator>=(Lozenge3 const& other) const
  65. {
  66. return !operator<(other);
  67. }
  68. };
  69. }