//////////////////////////////////////////////////////////////////////////////// // // Paella // Copyright (C) 2015 - Thomas FORGIONE, Emilie JALRAS, Marion LENFANT, Thierry MALON, Amandine PAILLOUX // Authors : // Thomas FORGIONE // Emilie JALRAS // Marion LENFANT // Thierry MALON // Amandine PAILLOUX // // This file is part of the project Paella // This software is provided 'as-is', without any express or implied warranty. // In no event will the authors be held liable for any damages arising from the use of this software. // // Permission is granted to anyone to use this software for any purpose, // including commercial applications, and to alter it and redistribute it freely, // subject to the following restrictions: // // 1. The origin of this software must not be misrepresented; // you must not claim that you wrote the original software. // If you use this software in a product, an acknowledgment // in the product documentation would be appreciated but is not required. // // 2. Altered source versions must be plainly marked as such, // and must not be misrepresented as being the original software. // // 3. This notice may not be removed or altered from any source distribution. //////////////////////////////////////////////////////////////////////////////// #ifndef MATHFUNCTIONS_HPP #define MATHFUNCTIONS_HPP #include #include namespace geo { ////////////////////////////////////////////////////////////////// /// \ingroup geometry /// \brief Compute the projection of an element on a container /// /// \param elementToProject element to project /// /// \param first Iterator to the first element of the container /// /// \param last Iterator after the last element /// /// \param distance Function that takes for argument a T and a element of the /// container and that returns the distance between these elements. /// /// \return An iterator the closest element in the array /// /// \deprecated Use min_element instead /// ////////////////////////////////////////////////////////////////// template InputIt project(T const& elementToProject, InputIt first, InputIt last, Distance const& distance); ////////////////////////////////////////////////////////////////// /// \ingroup geometry /// \brief Template utility for Segments ////////////////////////////////////////////////////////////////// template using Segment = std::pair, Vector>; /////////////////////////////////////////////////////////////////// /// \ingroup geometry /// \brief Compute the distance between a point and a segment /// /// \param v The point /// /// \param p1 The first point of the segment /// \param p2 The second point of the segment /// /// \return The norm-2 distance between v and the closest point in s /// /// To use this function, the template class vector_size must be /// defined on T1, T2, and T3, with a value containing the size /// of the vector, and the functions `get_x`, `get_y` and `get_z` /// (if the size is high enough). There will be an error if the /// vector_size::value are different for two vectors. /// For example /// /// \code /// struct my_vector /// { /// float my_x; /// float my_y; /// }; /// /// template<> /// struct vector_size /// { /// constexpr std::size_t N = 2; /// }; /// /// template<> /// float const& get_x(my_vector const& v) /// { /// return v.my_x; /// } /// /// // And the same for y... /// \endcode ////////////////////////////////////////////////////////////////// template float distanceToSegment(T1 const& v, T2 const& p1, T3 const& p2); } // namespace geo #include "Geometry/MathFunctions.inl" #endif // MATHFUNCTIONS_HPP