Definitions.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /*
  2. * Definitions.h
  3. * RVO2 Library
  4. *
  5. * Copyright 2008 University of North Carolina at Chapel Hill
  6. *
  7. * Licensed under the Apache License, Version 2.0 (the "License");
  8. * you may not use this file except in compliance with the License.
  9. * You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing, software
  14. * distributed under the License is distributed on an "AS IS" BASIS,
  15. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16. * See the License for the specific language governing permissions and
  17. * limitations under the License.
  18. *
  19. * Please send all bug reports to <geom@cs.unc.edu>.
  20. *
  21. * The authors may be contacted via:
  22. *
  23. * Jur van den Berg, Stephen J. Guy, Jamie Snape, Ming C. Lin, Dinesh Manocha
  24. * Dept. of Computer Science
  25. * 201 S. Columbia St.
  26. * Frederick P. Brooks, Jr. Computer Science Bldg.
  27. * Chapel Hill, N.C. 27599-3175
  28. * United States of America
  29. *
  30. * <http://gamma.cs.unc.edu/RVO2/>
  31. */
  32. #ifndef RVO2D_DEFINITIONS_H_
  33. #define RVO2D_DEFINITIONS_H_
  34. /**
  35. * \file Definitions.h
  36. * \brief Contains functions and constants used in multiple classes.
  37. */
  38. #include <algorithm>
  39. #include <cmath>
  40. #include <cstddef>
  41. #include <cstdint>
  42. #include <limits>
  43. #include <vector>
  44. #include "Vector2.h"
  45. /**
  46. * \brief A sufficiently small positive number.
  47. */
  48. const float RVO_EPSILON = 0.00001f;
  49. namespace RVO2D {
  50. class Agent2D;
  51. class Obstacle2D;
  52. class RVOSimulator2D;
  53. /**
  54. * \brief Computes the squared distance from a line segment with the
  55. * specified endpoints to a specified point.
  56. * \param a The first endpoint of the line segment.
  57. * \param b The second endpoint of the line segment.
  58. * \param c The point to which the squared distance is to
  59. * be calculated.
  60. * \return The squared distance from the line segment to the point.
  61. */
  62. inline float distSqPointLineSegment(const Vector2 &a, const Vector2 &b,
  63. const Vector2 &c)
  64. {
  65. const float r = ((c - a) * (b - a)) / absSq(b - a);
  66. if (r < 0.0f) {
  67. return absSq(c - a);
  68. }
  69. else if (r > 1.0f) {
  70. return absSq(c - b);
  71. }
  72. else {
  73. return absSq(c - (a + r * (b - a)));
  74. }
  75. }
  76. /**
  77. * \brief Computes the signed distance from a line connecting the
  78. * specified points to a specified point.
  79. * \param a The first point on the line.
  80. * \param b The second point on the line.
  81. * \param c The point to which the signed distance is to
  82. * be calculated.
  83. * \return Positive when the point c lies to the left of the line ab.
  84. */
  85. inline float leftOf(const Vector2 &a, const Vector2 &b, const Vector2 &c)
  86. {
  87. return det(a - c, b - a);
  88. }
  89. /**
  90. * \brief Computes the square of a float.
  91. * \param a The float to be squared.
  92. * \return The square of the float.
  93. */
  94. inline float sqr(float a)
  95. {
  96. return a * a;
  97. }
  98. }
  99. #endif /* RVO2D_DEFINITIONS_H_ */