]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/geometry/include/boost/geometry/arithmetic/dot_product.hpp
bump version to 12.2.2-pve1
[ceph.git] / ceph / src / boost / libs / geometry / include / boost / geometry / arithmetic / dot_product.hpp
CommitLineData
7c673cae
FG
1// Boost.Geometry (aka GGL, Generic Geometry Library)
2
3// Copyright (c) 2008-2012 Bruno Lalande, Paris, France.
4// Copyright (c) 2008-2012 Barend Gehrels, Amsterdam, the Netherlands.
5// Copyright (c) 2009-2012 Mateusz Loskot, London, UK.
6
7// Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
8// (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
9
10// Use, modification and distribution is subject to the Boost Software License,
11// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
12// http://www.boost.org/LICENSE_1_0.txt)
13
14#ifndef BOOST_GEOMETRY_ARITHMETIC_DOT_PRODUCT_HPP
15#define BOOST_GEOMETRY_ARITHMETIC_DOT_PRODUCT_HPP
16
17
18#include <cstddef>
19
20#include <boost/concept/requires.hpp>
21
22#include <boost/geometry/geometries/concepts/point_concept.hpp>
23#include <boost/geometry/util/select_coordinate_type.hpp>
24
25namespace boost { namespace geometry
26{
27
28#ifndef DOXYGEN_NO_DETAIL
29namespace detail
30{
31
32template <typename P1, typename P2, std::size_t Dimension, std::size_t DimensionCount>
33struct dot_product_maker
34{
35 typedef typename select_coordinate_type<P1, P2>::type coordinate_type;
36
37 static inline coordinate_type apply(P1 const& p1, P2 const& p2)
38 {
39 return get<Dimension>(p1) * get<Dimension>(p2)
40 + dot_product_maker<P1, P2, Dimension+1, DimensionCount>::apply(p1, p2);
41 }
42};
43
44template <typename P1, typename P2, std::size_t DimensionCount>
45struct dot_product_maker<P1, P2, DimensionCount, DimensionCount>
46{
47 typedef typename select_coordinate_type<P1, P2>::type coordinate_type;
48
49 static inline coordinate_type apply(P1 const& p1, P2 const& p2)
50 {
51 return get<DimensionCount>(p1) * get<DimensionCount>(p2);
52 }
53};
54
55} // namespace detail
56#endif // DOXYGEN_NO_DETAIL
57
58
59/*!
60 \brief Computes the dot product (or scalar product) of 2 vectors (points).
61 \ingroup arithmetic
62 \tparam Point1 \tparam_point
63 \tparam Point2 \tparam_point
64 \param p1 first point
65 \param p2 second point
66 \return the dot product
67 */
68template <typename Point1, typename Point2>
69inline typename select_coordinate_type<Point1, Point2>::type dot_product(
70 Point1 const& p1, Point2 const& p2)
71{
72 BOOST_CONCEPT_ASSERT( (concepts::ConstPoint<Point1>) );
73 BOOST_CONCEPT_ASSERT( (concepts::ConstPoint<Point2>) );
74
75 return detail::dot_product_maker
76 <
77 Point1, Point2,
78 0, dimension<Point1>::type::value - 1
79 >::apply(p1, p2);
80}
81
82}} // namespace boost::geometry
83
84#endif // BOOST_GEOMETRY_ARITHMETIC_DOT_PRODUCT_HPP