Path: blob/master/thirdparty/rvo2/rvo2_2d/Definitions.h
9906 views
/*1* Definitions.h2* RVO2 Library3*4* Copyright 2008 University of North Carolina at Chapel Hill5*6* Licensed under the Apache License, Version 2.0 (the "License");7* you may not use this file except in compliance with the License.8* You may obtain a copy of the License at9*10* http://www.apache.org/licenses/LICENSE-2.011*12* Unless required by applicable law or agreed to in writing, software13* distributed under the License is distributed on an "AS IS" BASIS,14* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.15* See the License for the specific language governing permissions and16* limitations under the License.17*18* Please send all bug reports to <[email protected]>.19*20* The authors may be contacted via:21*22* Jur van den Berg, Stephen J. Guy, Jamie Snape, Ming C. Lin, Dinesh Manocha23* Dept. of Computer Science24* 201 S. Columbia St.25* Frederick P. Brooks, Jr. Computer Science Bldg.26* Chapel Hill, N.C. 27599-317527* United States of America28*29* <http://gamma.cs.unc.edu/RVO2/>30*/3132#ifndef RVO2D_DEFINITIONS_H_33#define RVO2D_DEFINITIONS_H_3435/**36* \file Definitions.h37* \brief Contains functions and constants used in multiple classes.38*/3940#include <algorithm>41#include <cmath>42#include <cstddef>43#include <cstdint>44#include <limits>45#include <vector>4647#include "Vector2.h"4849/**50* \brief A sufficiently small positive number.51*/52const float RVO_EPSILON = 0.00001f;5354namespace RVO2D {55class Agent2D;56class Obstacle2D;57class RVOSimulator2D;5859/**60* \brief Computes the squared distance from a line segment with the61* specified endpoints to a specified point.62* \param a The first endpoint of the line segment.63* \param b The second endpoint of the line segment.64* \param c The point to which the squared distance is to65* be calculated.66* \return The squared distance from the line segment to the point.67*/68inline float distSqPointLineSegment(const Vector2 &a, const Vector2 &b,69const Vector2 &c)70{71const float r = ((c - a) * (b - a)) / absSq(b - a);7273if (r < 0.0f) {74return absSq(c - a);75}76else if (r > 1.0f) {77return absSq(c - b);78}79else {80return absSq(c - (a + r * (b - a)));81}82}8384/**85* \brief Computes the signed distance from a line connecting the86* specified points to a specified point.87* \param a The first point on the line.88* \param b The second point on the line.89* \param c The point to which the signed distance is to90* be calculated.91* \return Positive when the point c lies to the left of the line ab.92*/93inline float leftOf(const Vector2 &a, const Vector2 &b, const Vector2 &c)94{95return det(a - c, b - a);96}9798/**99* \brief Computes the square of a float.100* \param a The float to be squared.101* \return The square of the float.102*/103inline float sqr(float a)104{105return a * a;106}107}108109#endif /* RVO2D_DEFINITIONS_H_ */110111112