Line.h 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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 line is represented by P+t*D, where P is an origin point, D is a
  10. // unit-length direction vector, and t is any real number. The user must
  11. // ensure that D is unit length.
  12. namespace WwiseGTE
  13. {
  14. template <int N, typename Real>
  15. class Line
  16. {
  17. public:
  18. // Construction and destruction. The default constructor sets the
  19. // origin to (0,...,0) and the line direction to (1,0,...,0).
  20. Line()
  21. {
  22. origin.MakeZero();
  23. direction.MakeUnit(0);
  24. }
  25. Line(Vector<N, Real> const& inOrigin, Vector<N, Real> const& inDirection)
  26. :
  27. origin(inOrigin),
  28. direction(inDirection)
  29. {
  30. }
  31. // Public member access. The direction must be unit length.
  32. Vector<N, Real> origin, direction;
  33. public:
  34. // Comparisons to support sorted containers.
  35. bool operator==(Line const& line) const
  36. {
  37. return origin == line.origin && direction == line.direction;
  38. }
  39. bool operator!=(Line const& line) const
  40. {
  41. return !operator==(line);
  42. }
  43. bool operator< (Line const& line) const
  44. {
  45. if (origin < line.origin)
  46. {
  47. return true;
  48. }
  49. if (origin > line.origin)
  50. {
  51. return false;
  52. }
  53. return direction < line.direction;
  54. }
  55. bool operator<=(Line const& line) const
  56. {
  57. return !line.operator<(*this);
  58. }
  59. bool operator> (Line const& line) const
  60. {
  61. return line.operator<(*this);
  62. }
  63. bool operator>=(Line const& line) const
  64. {
  65. return !operator<(line);
  66. }
  67. };
  68. // Template aliases for convenience.
  69. template <typename Real>
  70. using Line2 = Line<2, Real>;
  71. template <typename Real>
  72. using Line3 = Line<3, Real>;
  73. }