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) 2008-2012 Bruno Lalande, Paris, France.
0004 // Copyright (c) 2008-2012 Barend Gehrels, Amsterdam, the Netherlands.
0005 // Copyright (c) 2009-2012 Mateusz Loskot, London, UK.
0006 
0007 // This file was modified by Oracle on 2020.
0008 // Modifications copyright (c) 2020, Oracle and/or its affiliates.
0009 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
0010 
0011 // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
0012 // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
0013 
0014 // Use, modification and distribution is subject to the Boost Software License,
0015 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
0016 // http://www.boost.org/LICENSE_1_0.txt)
0017 
0018 #ifndef BOOST_GEOMETRY_ARITHMETIC_DOT_PRODUCT_HPP
0019 #define BOOST_GEOMETRY_ARITHMETIC_DOT_PRODUCT_HPP
0020 
0021 
0022 #include <cstddef>
0023 
0024 #include <boost/concept/requires.hpp>
0025 
0026 #include <boost/geometry/geometries/concepts/point_concept.hpp>
0027 #include <boost/geometry/util/select_coordinate_type.hpp>
0028 
0029 namespace boost { namespace geometry
0030 {
0031 
0032 #ifndef DOXYGEN_NO_DETAIL
0033 namespace detail
0034 {
0035 
0036 template <typename P1, typename P2, std::size_t Dimension, std::size_t DimensionCount>
0037 struct dot_product_maker
0038 {
0039     typedef typename select_coordinate_type<P1, P2>::type coordinate_type;
0040 
0041     static constexpr coordinate_type apply(P1 const& p1, P2 const& p2)
0042     {
0043         return get<Dimension>(p1) * get<Dimension>(p2)
0044             + dot_product_maker<P1, P2, Dimension+1, DimensionCount>::apply(p1, p2);
0045     }
0046 };
0047 
0048 template <typename P1, typename P2, std::size_t DimensionCount>
0049 struct dot_product_maker<P1, P2, DimensionCount, DimensionCount>
0050 {
0051     typedef typename select_coordinate_type<P1, P2>::type coordinate_type;
0052 
0053     static constexpr coordinate_type apply(P1 const& p1, P2 const& p2)
0054     {
0055         return get<DimensionCount>(p1) * get<DimensionCount>(p2);
0056     }
0057 };
0058 
0059 } // namespace detail
0060 #endif // DOXYGEN_NO_DETAIL
0061 
0062 
0063 /*!
0064     \brief Computes the dot product (or scalar product) of 2 vectors (points).
0065     \ingroup arithmetic
0066     \tparam Point1 \tparam_point
0067     \tparam Point2 \tparam_point
0068     \param p1 first point
0069     \param p2 second point
0070     \return the dot product
0071 
0072     \qbk{[heading Examples]}
0073     \qbk{[dot_product] [dot_product_output]}
0074 
0075  */
0076 template <typename Point1, typename Point2>
0077 // workaround for VS2015
0078 #if !defined(_MSC_VER) || (_MSC_VER >= 1910)
0079 constexpr
0080 #endif
0081 inline typename select_coordinate_type<Point1, Point2>::type dot_product(
0082         Point1 const& p1, Point2 const& p2)
0083 {
0084     BOOST_CONCEPT_ASSERT( (concepts::ConstPoint<Point1>) );
0085     BOOST_CONCEPT_ASSERT( (concepts::ConstPoint<Point2>) );
0086 
0087     return detail::dot_product_maker
0088         <
0089             Point1, Point2,
0090             0, dimension<Point1>::type::value - 1
0091         >::apply(p1, p2);
0092 }
0093 
0094 }} // namespace boost::geometry
0095 
0096 #endif // BOOST_GEOMETRY_ARITHMETIC_DOT_PRODUCT_HPP