Triangle.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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/Vector.h>
  9. // The triangle is represented as an array of three vertices. The dimension
  10. // N must be 2 or larger.
  11. namespace WwiseGTE
  12. {
  13. template <int N, typename Real>
  14. class Triangle
  15. {
  16. public:
  17. // Construction and destruction. The default constructor sets
  18. // the/ vertices to (0,..,0), (1,0,...,0) and (0,1,0,...,0).
  19. Triangle()
  20. :
  21. v{ Vector<N, Real>::Zero(), Vector<N, Real>::Unit(0), Vector<N, Real>::Unit(1) }
  22. {
  23. }
  24. Triangle(Vector<N, Real> const& v0, Vector<N, Real> const& v1, Vector<N, Real> const& v2)
  25. :
  26. v{ v0, v1, v2 }
  27. {
  28. }
  29. Triangle(std::array<Vector<N, Real>, 3> const& inV)
  30. :
  31. v(inV)
  32. {
  33. }
  34. // Public member access.
  35. std::array<Vector<N, Real>, 3> v;
  36. public:
  37. // Comparisons to support sorted containers.
  38. bool operator==(Triangle const& triangle) const
  39. {
  40. return v == triangle.v;
  41. }
  42. bool operator!=(Triangle const& triangle) const
  43. {
  44. return v != triangle.v;
  45. }
  46. bool operator< (Triangle const& triangle) const
  47. {
  48. return v < triangle.v;
  49. }
  50. bool operator<=(Triangle const& triangle) const
  51. {
  52. return v <= triangle.v;
  53. }
  54. bool operator> (Triangle const& triangle) const
  55. {
  56. return v > triangle.v;
  57. }
  58. bool operator>=(Triangle const& triangle) const
  59. {
  60. return v >= triangle.v;
  61. }
  62. };
  63. // Template aliases for convenience.
  64. template <typename Real>
  65. using Triangle2 = Triangle<2, Real>;
  66. template <typename Real>
  67. using Triangle3 = Triangle<3, Real>;
  68. }