File indexing completed on 2025-01-18 09:35:23
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
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 }
0060 #endif
0061
0062
0063
0064
0065
0066
0067
0068
0069
0070
0071
0072
0073
0074
0075
0076 template <typename Point1, typename Point2>
0077
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 }}
0095
0096 #endif