1 // Boost.Geometry (aka GGL, Generic Geometry Library)
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.
7 // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
8 // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
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)
14 #ifndef BOOST_GEOMETRY_ARITHMETIC_DOT_PRODUCT_HPP
15 #define BOOST_GEOMETRY_ARITHMETIC_DOT_PRODUCT_HPP
20 #include <boost/concept/requires.hpp>
22 #include <boost/geometry/geometries/concepts/point_concept.hpp>
23 #include <boost/geometry/util/select_coordinate_type.hpp>
25 namespace boost { namespace geometry
28 #ifndef DOXYGEN_NO_DETAIL
32 template <typename P1, typename P2, std::size_t Dimension, std::size_t DimensionCount>
33 struct dot_product_maker
35 typedef typename select_coordinate_type<P1, P2>::type coordinate_type;
37 static inline coordinate_type apply(P1 const& p1, P2 const& p2)
39 return get<Dimension>(p1) * get<Dimension>(p2)
40 + dot_product_maker<P1, P2, Dimension+1, DimensionCount>::apply(p1, p2);
44 template <typename P1, typename P2, std::size_t DimensionCount>
45 struct dot_product_maker<P1, P2, DimensionCount, DimensionCount>
47 typedef typename select_coordinate_type<P1, P2>::type coordinate_type;
49 static inline coordinate_type apply(P1 const& p1, P2 const& p2)
51 return get<DimensionCount>(p1) * get<DimensionCount>(p2);
56 #endif // DOXYGEN_NO_DETAIL
60 \brief Computes the dot product (or scalar product) of 2 vectors (points).
62 \tparam Point1 \tparam_point
63 \tparam Point2 \tparam_point
65 \param p2 second point
66 \return the dot product
68 template <typename Point1, typename Point2>
69 inline typename select_coordinate_type<Point1, Point2>::type dot_product(
70 Point1 const& p1, Point2 const& p2)
72 BOOST_CONCEPT_ASSERT( (concepts::ConstPoint<Point1>) );
73 BOOST_CONCEPT_ASSERT( (concepts::ConstPoint<Point2>) );
75 return detail::dot_product_maker
78 0, dimension<Point1>::type::value - 1
82 }} // namespace boost::geometry
84 #endif // BOOST_GEOMETRY_ARITHMETIC_DOT_PRODUCT_HPP