diff options
Diffstat (limited to 'boost/geometry/arithmetic/arithmetic.hpp')
-rw-r--r-- | boost/geometry/arithmetic/arithmetic.hpp | 101 |
1 files changed, 70 insertions, 31 deletions
diff --git a/boost/geometry/arithmetic/arithmetic.hpp b/boost/geometry/arithmetic/arithmetic.hpp index 6eb31f488e..fbc3ca443e 100644 --- a/boost/geometry/arithmetic/arithmetic.hpp +++ b/boost/geometry/arithmetic/arithmetic.hpp @@ -22,6 +22,7 @@ #include <boost/geometry/core/coordinate_type.hpp> #include <boost/geometry/geometries/concepts/point_concept.hpp> #include <boost/geometry/util/for_each_coordinate.hpp> +#include <boost/geometry/util/select_most_precise.hpp> namespace boost { namespace geometry @@ -32,80 +33,94 @@ namespace detail { -template <typename P> +template <typename Point> struct param { typedef typename boost::call_traits < - typename coordinate_type<P>::type + typename coordinate_type<Point>::type >::param_type type; }; -template <typename C, template <typename> class Function> +template <typename Value, template <typename> class Function> struct value_operation { - C m_value; + Value m_value; - inline value_operation(C const &value) + inline value_operation(Value const &value) : m_value(value) {} - template <typename P, int I> - inline void apply(P& point) const + template <typename PointDst, std::size_t Index> + inline void apply(PointDst& point_dst) const { - set<I>(point, Function<C>()(get<I>(point), m_value)); + set<Index>(point_dst, + Function + < + typename geometry::select_most_precise + < + Value, + typename geometry::coordinate_type<PointDst>::type + >::type + >()(get<Index>(point_dst), m_value)); } }; template <typename PointSrc, template <typename> class Function> struct point_operation { - typedef typename coordinate_type<PointSrc>::type coordinate_type; - PointSrc const& m_source_point; + PointSrc const& m_point_src; inline point_operation(PointSrc const& point) - : m_source_point(point) + : m_point_src(point) {} - template <typename PointDst, int I> - inline void apply(PointDst& dest_point) const + template <typename PointDst, std::size_t Index> + inline void apply(PointDst& point_dst) const { - set<I>(dest_point, - Function<coordinate_type>()(get<I>(dest_point), get<I>(m_source_point))); + set<Index>(point_dst, + Function + < + typename geometry::select_most_precise + < + typename geometry::coordinate_type<PointSrc>::type, + typename geometry::coordinate_type<PointDst>::type + >::type + >()(get<Index>(point_dst), get<Index>(m_point_src))); } }; -template <typename C> +template <typename Value> struct value_assignment { - C m_value; + Value m_value; - inline value_assignment(C const &value) + inline value_assignment(Value const &value) : m_value(value) {} - template <typename P, int I> - inline void apply(P& point) const + template <typename PointDst, std::size_t Index> + inline void apply(PointDst& point_dst) const { - set<I>(point, m_value); + set<Index>(point_dst, m_value); } }; template <typename PointSrc> struct point_assignment { - PointSrc const& m_source_point; + PointSrc const& m_point_src; inline point_assignment(PointSrc const& point) - : m_source_point(point) + : m_point_src(point) {} - template <typename PointDst, int I> - inline void apply(PointDst& dest_point) const + template <typename PointDst, std::size_t Index> + inline void apply(PointDst& point_dst) const { - set<I>(dest_point, get<I>(m_source_point)); + set<Index>(point_dst, get<Index>(m_point_src)); } }; @@ -126,7 +141,12 @@ inline void add_value(Point& p, typename detail::param<Point>::type value) { BOOST_CONCEPT_ASSERT( (concept::Point<Point>) ); - for_each_coordinate(p, detail::value_operation<typename coordinate_type<Point>::type, std::plus>(value)); + for_each_coordinate(p, + detail::value_operation + < + typename coordinate_type<Point>::type, + std::plus + >(value)); } /*! @@ -161,7 +181,12 @@ inline void subtract_value(Point& p, typename detail::param<Point>::type value) { BOOST_CONCEPT_ASSERT( (concept::Point<Point>) ); - for_each_coordinate(p, detail::value_operation<typename coordinate_type<Point>::type, std::minus>(value)); + for_each_coordinate(p, + detail::value_operation + < + typename coordinate_type<Point>::type, + std::minus + >(value)); } /*! @@ -196,7 +221,12 @@ inline void multiply_value(Point& p, typename detail::param<Point>::type value) { BOOST_CONCEPT_ASSERT( (concept::Point<Point>) ); - for_each_coordinate(p, detail::value_operation<typename coordinate_type<Point>::type, std::multiplies>(value)); + for_each_coordinate(p, + detail::value_operation + < + typename coordinate_type<Point>::type, + std::multiplies + >(value)); } /*! @@ -232,7 +262,12 @@ inline void divide_value(Point& p, typename detail::param<Point>::type value) { BOOST_CONCEPT_ASSERT( (concept::Point<Point>) ); - for_each_coordinate(p, detail::value_operation<typename coordinate_type<Point>::type, std::divides>(value)); + for_each_coordinate(p, + detail::value_operation + < + typename coordinate_type<Point>::type, + std::divides + >(value)); } /*! @@ -267,7 +302,11 @@ inline void assign_value(Point& p, typename detail::param<Point>::type value) { BOOST_CONCEPT_ASSERT( (concept::Point<Point>) ); - for_each_coordinate(p, detail::value_assignment<typename coordinate_type<Point>::type>(value)); + for_each_coordinate(p, + detail::value_assignment + < + typename coordinate_type<Point>::type + >(value)); } /*! |