File indexing completed on 2025-01-18 09:35:23
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #ifndef BOOST_GEOMETRY_ARITHMETIC_NORMALIZE_HPP
0011 #define BOOST_GEOMETRY_ARITHMETIC_NORMALIZE_HPP
0012
0013
0014 #include <boost/geometry/core/coordinate_type.hpp>
0015
0016 #include <boost/geometry/arithmetic/arithmetic.hpp>
0017 #include <boost/geometry/arithmetic/dot_product.hpp>
0018 #include <boost/geometry/util/math.hpp>
0019
0020
0021 namespace boost { namespace geometry
0022 {
0023
0024 #ifndef DOXYGEN_NO_DETAIL
0025 namespace detail
0026 {
0027
0028 template <typename Point>
0029 inline typename coordinate_type<Point>::type vec_length_sqr(Point const& pt)
0030 {
0031 return dot_product(pt, pt);
0032 }
0033
0034 template <typename Point>
0035 inline typename coordinate_type<Point>::type vec_length(Point const& pt)
0036 {
0037
0038 return math::sqrt(dot_product(pt, pt));
0039 }
0040
0041 template <typename Point>
0042 inline bool vec_normalize(Point & pt, typename coordinate_type<Point>::type & len)
0043 {
0044 typedef typename coordinate_type<Point>::type coord_t;
0045
0046 coord_t const c0 = 0;
0047 len = vec_length(pt);
0048
0049 if (math::equals(len, c0))
0050 {
0051 return false;
0052 }
0053
0054 divide_value(pt, len);
0055 return true;
0056 }
0057
0058 template <typename Point>
0059 inline bool vec_normalize(Point & pt)
0060 {
0061 typedef typename coordinate_type<Point>::type coord_t;
0062 coord_t len;
0063 return vec_normalize(pt, len);
0064 }
0065
0066 }
0067 #endif
0068
0069 }}
0070
0071 #endif