1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- #ifndef BOOST_GEOMETRY_ARITHMETIC_NORMALIZE_HPP
- #define BOOST_GEOMETRY_ARITHMETIC_NORMALIZE_HPP
- #include <boost/geometry/core/coordinate_type.hpp>
- #include <boost/geometry/arithmetic/arithmetic.hpp>
- #include <boost/geometry/arithmetic/dot_product.hpp>
- #include <boost/geometry/util/math.hpp>
- namespace boost { namespace geometry
- {
- #ifndef DOXYGEN_NO_DETAIL
- namespace detail
- {
- template <typename Point>
- inline typename coordinate_type<Point>::type vec_length_sqr(Point const& pt)
- {
- return dot_product(pt, pt);
- }
- template <typename Point>
- inline typename coordinate_type<Point>::type vec_length(Point const& pt)
- {
-
- return math::sqrt(dot_product(pt, pt));
- }
- template <typename Point>
- inline bool vec_normalize(Point & pt, typename coordinate_type<Point>::type & len)
- {
- typedef typename coordinate_type<Point>::type coord_t;
- coord_t const c0 = 0;
- len = vec_length(pt);
- if (math::equals(len, c0))
- {
- return false;
- }
- divide_value(pt, len);
- return true;
- }
- template <typename Point>
- inline bool vec_normalize(Point & pt)
- {
- typedef typename coordinate_type<Point>::type coord_t;
- coord_t len;
- return vec_normalize(pt, len);
- }
- }
- #endif
- }}
- #endif
|