diff options
Diffstat (limited to 'boost/geometry/arithmetic')
-rw-r--r-- | boost/geometry/arithmetic/arithmetic.hpp | 30 | ||||
-rw-r--r-- | boost/geometry/arithmetic/cross_product.hpp | 128 | ||||
-rw-r--r-- | boost/geometry/arithmetic/determinant.hpp | 4 | ||||
-rw-r--r-- | boost/geometry/arithmetic/dot_product.hpp | 4 |
4 files changed, 147 insertions, 19 deletions
diff --git a/boost/geometry/arithmetic/arithmetic.hpp b/boost/geometry/arithmetic/arithmetic.hpp index fbc3ca443e..3ab66b27f5 100644 --- a/boost/geometry/arithmetic/arithmetic.hpp +++ b/boost/geometry/arithmetic/arithmetic.hpp @@ -139,7 +139,7 @@ struct point_assignment template <typename Point> inline void add_value(Point& p, typename detail::param<Point>::type value) { - BOOST_CONCEPT_ASSERT( (concept::Point<Point>) ); + BOOST_CONCEPT_ASSERT( (concepts::Point<Point>) ); for_each_coordinate(p, detail::value_operation @@ -162,8 +162,8 @@ inline void add_value(Point& p, typename detail::param<Point>::type value) template <typename Point1, typename Point2> inline void add_point(Point1& p1, Point2 const& p2) { - BOOST_CONCEPT_ASSERT( (concept::Point<Point1>) ); - BOOST_CONCEPT_ASSERT( (concept::ConstPoint<Point2>) ); + BOOST_CONCEPT_ASSERT( (concepts::Point<Point1>) ); + BOOST_CONCEPT_ASSERT( (concepts::ConstPoint<Point2>) ); for_each_coordinate(p1, detail::point_operation<Point2, std::plus>(p2)); } @@ -179,7 +179,7 @@ inline void add_point(Point1& p1, Point2 const& p2) template <typename Point> inline void subtract_value(Point& p, typename detail::param<Point>::type value) { - BOOST_CONCEPT_ASSERT( (concept::Point<Point>) ); + BOOST_CONCEPT_ASSERT( (concepts::Point<Point>) ); for_each_coordinate(p, detail::value_operation @@ -202,8 +202,8 @@ inline void subtract_value(Point& p, typename detail::param<Point>::type value) template <typename Point1, typename Point2> inline void subtract_point(Point1& p1, Point2 const& p2) { - BOOST_CONCEPT_ASSERT( (concept::Point<Point1>) ); - BOOST_CONCEPT_ASSERT( (concept::ConstPoint<Point2>) ); + BOOST_CONCEPT_ASSERT( (concepts::Point<Point1>) ); + BOOST_CONCEPT_ASSERT( (concepts::ConstPoint<Point2>) ); for_each_coordinate(p1, detail::point_operation<Point2, std::minus>(p2)); } @@ -219,7 +219,7 @@ inline void subtract_point(Point1& p1, Point2 const& p2) template <typename Point> inline void multiply_value(Point& p, typename detail::param<Point>::type value) { - BOOST_CONCEPT_ASSERT( (concept::Point<Point>) ); + BOOST_CONCEPT_ASSERT( (concepts::Point<Point>) ); for_each_coordinate(p, detail::value_operation @@ -243,8 +243,8 @@ inline void multiply_value(Point& p, typename detail::param<Point>::type value) template <typename Point1, typename Point2> inline void multiply_point(Point1& p1, Point2 const& p2) { - BOOST_CONCEPT_ASSERT( (concept::Point<Point1>) ); - BOOST_CONCEPT_ASSERT( (concept::ConstPoint<Point2>) ); + BOOST_CONCEPT_ASSERT( (concepts::Point<Point1>) ); + BOOST_CONCEPT_ASSERT( (concepts::ConstPoint<Point2>) ); for_each_coordinate(p1, detail::point_operation<Point2, std::multiplies>(p2)); } @@ -260,7 +260,7 @@ inline void multiply_point(Point1& p1, Point2 const& p2) template <typename Point> inline void divide_value(Point& p, typename detail::param<Point>::type value) { - BOOST_CONCEPT_ASSERT( (concept::Point<Point>) ); + BOOST_CONCEPT_ASSERT( (concepts::Point<Point>) ); for_each_coordinate(p, detail::value_operation @@ -283,8 +283,8 @@ inline void divide_value(Point& p, typename detail::param<Point>::type value) template <typename Point1, typename Point2> inline void divide_point(Point1& p1, Point2 const& p2) { - BOOST_CONCEPT_ASSERT( (concept::Point<Point1>) ); - BOOST_CONCEPT_ASSERT( (concept::ConstPoint<Point2>) ); + BOOST_CONCEPT_ASSERT( (concepts::Point<Point1>) ); + BOOST_CONCEPT_ASSERT( (concepts::ConstPoint<Point2>) ); for_each_coordinate(p1, detail::point_operation<Point2, std::divides>(p2)); } @@ -300,7 +300,7 @@ inline void divide_point(Point1& p1, Point2 const& p2) template <typename Point> inline void assign_value(Point& p, typename detail::param<Point>::type value) { - BOOST_CONCEPT_ASSERT( (concept::Point<Point>) ); + BOOST_CONCEPT_ASSERT( (concepts::Point<Point>) ); for_each_coordinate(p, detail::value_assignment @@ -322,8 +322,8 @@ inline void assign_value(Point& p, typename detail::param<Point>::type value) template <typename Point1, typename Point2> inline void assign_point(Point1& p1, Point2 const& p2) { - BOOST_CONCEPT_ASSERT( (concept::Point<Point1>) ); - BOOST_CONCEPT_ASSERT( (concept::ConstPoint<Point2>) ); + BOOST_CONCEPT_ASSERT( (concepts::Point<Point1>) ); + BOOST_CONCEPT_ASSERT( (concepts::ConstPoint<Point2>) ); for_each_coordinate(p1, detail::point_assignment<Point2>(p2)); } diff --git a/boost/geometry/arithmetic/cross_product.hpp b/boost/geometry/arithmetic/cross_product.hpp new file mode 100644 index 0000000000..485c2123b6 --- /dev/null +++ b/boost/geometry/arithmetic/cross_product.hpp @@ -0,0 +1,128 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) + +// Copyright (c) 2009-2012 Mateusz Loskot, London, UK. +// Copyright (c) 2008-2012 Barend Gehrels, Amsterdam, the Netherlands. +// Copyright (c) 2008-2012 Bruno Lalande, Paris, France. + +// This file was modified by Oracle on 2016. +// Modifications copyright (c) 2016, Oracle and/or its affiliates. +// Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle + +// Use, modification and distribution is subject to the Boost Software License, +// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#ifndef BOOST_GEOMETRY_ARITHMETIC_CROSS_PRODUCT_HPP +#define BOOST_GEOMETRY_ARITHMETIC_CROSS_PRODUCT_HPP + + +#include <cstddef> + +#include <boost/mpl/assert.hpp> +#include <boost/mpl/size_t.hpp> + +#include <boost/geometry/core/access.hpp> +#include <boost/geometry/core/coordinate_dimension.hpp> + +#include <boost/geometry/geometries/concepts/point_concept.hpp> + + +namespace boost { namespace geometry +{ + +#ifndef DOXYGEN_NO_DETAIL +namespace detail +{ + +template <std::size_t Dimension> +struct cross_product +{ + // We define cross product only for 2d (see Wolfram) and 3d. + // In Math, it is also well-defined for 7-dimension. + // Generalisation of cross product to n-dimension is defined as + // wedge product but it is not direct analogue to binary cross product. + BOOST_MPL_ASSERT_MSG((false), + NOT_IMPLEMENTED_FOR_THIS_DIMENSION, + (mpl::size_t<Dimension>)); +}; + +template <> +struct cross_product<2> +{ + template <typename P1, typename P2, typename ResultP> + static inline void apply(P1 const& p1, P2 const& p2, ResultP& result) + { + assert_dimension<P1, 2>(); + assert_dimension<P2, 2>(); + assert_dimension<ResultP, 2>(); + + // For 2-dimensions, analog of the cross product U(x,y) and V(x,y) is + // Ux * Vy - Uy * Vx + // which is returned as 0-component (or X) of 2d vector, 1-component is undefined. + set<0>(result, get<0>(p1) * get<1>(p2) - get<1>(p1) * get<0>(p2)); + } +}; + +template <> +struct cross_product<3> +{ + template <typename P1, typename P2, typename ResultP> + static inline void apply(P1 const& p1, P2 const& p2, ResultP& result) + { + assert_dimension<P1, 3>(); + assert_dimension<P2, 3>(); + assert_dimension<ResultP, 3>(); + + set<0>(result, get<1>(p1) * get<2>(p2) - get<2>(p1) * get<1>(p2)); + set<1>(result, get<2>(p1) * get<0>(p2) - get<0>(p1) * get<2>(p2)); + set<2>(result, get<0>(p1) * get<1>(p2) - get<1>(p1) * get<0>(p2)); + } +}; + +} // namespace detail +#endif // DOXYGEN_NO_DETAIL + + +/*! +\brief Computes the cross product of two vectors. +\details All vectors should have the same dimension, 3 or 2. +\ingroup arithmetic +\param p1 first vector +\param p2 second vector +\return the cross product vector + */ +template <typename ResultP, typename P1, typename P2> +inline ResultP cross_product(P1 const& p1, P2 const& p2) +{ + BOOST_CONCEPT_ASSERT( (concepts::Point<ResultP>) ); + BOOST_CONCEPT_ASSERT( (concepts::ConstPoint<P1>) ); + BOOST_CONCEPT_ASSERT( (concepts::ConstPoint<P2>) ); + + ResultP result; + detail::cross_product<dimension<ResultP>::value>::apply(p1, p2, result); + return result; +} + +/*! +\brief Computes the cross product of two vectors. +\details All vectors should have the same dimension, 3 or 2. +\ingroup arithmetic +\param p1 first vector +\param p2 second vector +\return the cross product vector +*/ +template <typename P> +inline P cross_product(P const& p1, P const& p2) +{ + BOOST_CONCEPT_ASSERT((concepts::Point<P>)); + BOOST_CONCEPT_ASSERT((concepts::ConstPoint<P>)); + + P result; + detail::cross_product<dimension<P>::value>::apply(p1, p2, result); + return result; +} + + +}} // namespace boost::geometry + +#endif // BOOST_GEOMETRY_ARITHMETIC_CROSS_PRODUCT_HPP diff --git a/boost/geometry/arithmetic/determinant.hpp b/boost/geometry/arithmetic/determinant.hpp index a8e46ca9a0..59c596b124 100644 --- a/boost/geometry/arithmetic/determinant.hpp +++ b/boost/geometry/arithmetic/determinant.hpp @@ -59,8 +59,8 @@ inline ReturnType determinant(U const& ux, U const& uy template <typename ReturnType, typename U, typename V> inline ReturnType determinant(U const& u, V const& v) { - BOOST_CONCEPT_ASSERT( (concept::ConstPoint<U>) ); - BOOST_CONCEPT_ASSERT( (concept::ConstPoint<V>) ); + BOOST_CONCEPT_ASSERT( (concepts::ConstPoint<U>) ); + BOOST_CONCEPT_ASSERT( (concepts::ConstPoint<V>) ); return calculate_determinant < diff --git a/boost/geometry/arithmetic/dot_product.hpp b/boost/geometry/arithmetic/dot_product.hpp index fc2b3844e6..747bd01ab0 100644 --- a/boost/geometry/arithmetic/dot_product.hpp +++ b/boost/geometry/arithmetic/dot_product.hpp @@ -69,8 +69,8 @@ template <typename Point1, typename Point2> inline typename select_coordinate_type<Point1, Point2>::type dot_product( Point1 const& p1, Point2 const& p2) { - BOOST_CONCEPT_ASSERT( (concept::ConstPoint<Point1>) ); - BOOST_CONCEPT_ASSERT( (concept::ConstPoint<Point2>) ); + BOOST_CONCEPT_ASSERT( (concepts::ConstPoint<Point1>) ); + BOOST_CONCEPT_ASSERT( (concepts::ConstPoint<Point2>) ); return detail::dot_product_maker < |