Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:35:23

0001 // Boost.Geometry (aka GGL, Generic Geometry Library)
0002 
0003 // Copyright (c) 2016, Oracle and/or its affiliates.
0004 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
0005 
0006 // Use, modification and distribution is subject to the Boost Software License,
0007 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
0008 // http://www.boost.org/LICENSE_1_0.txt)
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     // NOTE: hypot() could be used instead of sqrt()
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 } // namespace detail
0067 #endif // DOXYGEN_NO_DETAIL
0068 
0069 }} // namespace boost::geometry
0070 
0071 #endif // BOOST_GEOMETRY_ARITHMETIC_NORMALIZE_HPP