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 | |
33 | #ifndef RVO2D_DEFINITIONS_H_ |
34 | #define RVO2D_DEFINITIONS_H_ |
35 | |
36 | /** |
37 | * \file Definitions.h |
38 | * \brief Contains functions and constants used in multiple classes. |
39 | */ |
40 | |
41 | #include <algorithm> |
42 | #include <cmath> |
43 | #include <cstddef> |
44 | #include <cstdint> |
45 | #include <limits> |
46 | #include <vector> |
47 | |
48 | #include "Vector2.h" |
49 | |
50 | /** |
51 | * \brief A sufficiently small positive number. |
52 | */ |
53 | const float RVO_EPSILON = 0.00001f; |
54 | |
55 | namespace RVO2D { |
56 | class Agent2D; |
57 | class Obstacle2D; |
58 | class RVOSimulator2D; |
59 | |
60 | /** |
61 | * \brief Computes the squared distance from a line segment with the |
62 | * specified endpoints to a specified point. |
63 | * \param a The first endpoint of the line segment. |
64 | * \param b The second endpoint of the line segment. |
65 | * \param c The point to which the squared distance is to |
66 | * be calculated. |
67 | * \return The squared distance from the line segment to the point. |
68 | */ |
69 | inline float distSqPointLineSegment(const Vector2 &a, const Vector2 &b, |
70 | const Vector2 &c) |
71 | { |
72 | const float r = ((c - a) * (b - a)) / absSq(b - a); |
73 | |
74 | if (r < 0.0f) { |
75 | return absSq(c - a); |
76 | } |
77 | else if (r > 1.0f) { |
78 | return absSq(c - b); |
79 | } |
80 | else { |
81 | return absSq(c - (a + r * (b - a))); |
82 | } |
83 | } |
84 | |
85 | /** |
86 | * \brief Computes the signed distance from a line connecting the |
87 | * specified points to a specified point. |
88 | * \param a The first point on the line. |
89 | * \param b The second point on the line. |
90 | * \param c The point to which the signed distance is to |
91 | * be calculated. |
92 | * \return Positive when the point c lies to the left of the line ab. |
93 | */ |
94 | inline float leftOf(const Vector2 &a, const Vector2 &b, const Vector2 &c) |
95 | { |
96 | return det(a - c, b - a); |
97 | } |
98 | |
99 | /** |
100 | * \brief Computes the square of a float. |
101 | * \param a The float to be squared. |
102 | * \return The square of the float. |
103 | */ |
104 | inline float sqr(float a) |
105 | { |
106 | return a * a; |
107 | } |
108 | } |
109 | |
110 | #endif /* RVO2D_DEFINITIONS_H_ */ |
111 | |