// Boost.Geometry (aka GGL, Generic Geometry Library) // Copyright (c) 2008-2012 Bruno Lalande, Paris, France. // Copyright (c) 2008-2012 Barend Gehrels, Amsterdam, the Netherlands. // Copyright (c) 2009-2012 Mateusz Loskot, London, UK. // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands. // 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_ARITHMETIC_HPP #define BOOST_GEOMETRY_ARITHMETIC_ARITHMETIC_HPP #include #include #include #include #include #include namespace boost { namespace geometry { #ifndef DOXYGEN_NO_DETAIL namespace detail { template struct param { typedef typename boost::call_traits < typename coordinate_type

::type >::param_type type; }; template class Function> struct value_operation { C m_value; inline value_operation(C const &value) : m_value(value) {} template inline void apply(P& point) const { set(point, Function()(get(point), m_value)); } }; template class Function> struct point_operation { typedef typename coordinate_type::type coordinate_type; PointSrc const& m_source_point; inline point_operation(PointSrc const& point) : m_source_point(point) {} template inline void apply(PointDst& dest_point) const { set(dest_point, Function()(get(dest_point), get(m_source_point))); } }; template struct value_assignment { C m_value; inline value_assignment(C const &value) : m_value(value) {} template inline void apply(P& point) const { set(point, m_value); } }; template struct point_assignment { PointSrc const& m_source_point; inline point_assignment(PointSrc const& point) : m_source_point(point) {} template inline void apply(PointDst& dest_point) const { set(dest_point, get(m_source_point)); } }; } // namespace detail #endif // DOXYGEN_NO_DETAIL /*! \brief Adds the same value to each coordinate of a point \ingroup arithmetic \details \param p point \param value value to add */ template inline void add_value(Point& p, typename detail::param::type value) { BOOST_CONCEPT_ASSERT( (concept::Point) ); for_each_coordinate(p, detail::value_operation::type, std::plus>(value)); } /*! \brief Adds a point to another \ingroup arithmetic \details The coordinates of the second point will be added to those of the first point. The second point is not modified. \param p1 first point \param p2 second point */ template inline void add_point(Point1& p1, Point2 const& p2) { BOOST_CONCEPT_ASSERT( (concept::Point) ); BOOST_CONCEPT_ASSERT( (concept::ConstPoint) ); for_each_coordinate(p1, detail::point_operation(p2)); } /*! \brief Subtracts the same value to each coordinate of a point \ingroup arithmetic \details \param p point \param value value to subtract */ template inline void subtract_value(Point& p, typename detail::param::type value) { BOOST_CONCEPT_ASSERT( (concept::Point) ); for_each_coordinate(p, detail::value_operation::type, std::minus>(value)); } /*! \brief Subtracts a point to another \ingroup arithmetic \details The coordinates of the second point will be subtracted to those of the first point. The second point is not modified. \param p1 first point \param p2 second point */ template inline void subtract_point(Point1& p1, Point2 const& p2) { BOOST_CONCEPT_ASSERT( (concept::Point) ); BOOST_CONCEPT_ASSERT( (concept::ConstPoint) ); for_each_coordinate(p1, detail::point_operation(p2)); } /*! \brief Multiplies each coordinate of a point by the same value \ingroup arithmetic \details \param p point \param value value to multiply by */ template inline void multiply_value(Point& p, typename detail::param::type value) { BOOST_CONCEPT_ASSERT( (concept::Point) ); for_each_coordinate(p, detail::value_operation::type, std::multiplies>(value)); } /*! \brief Multiplies a point by another \ingroup arithmetic \details The coordinates of the first point will be multiplied by those of the second point. The second point is not modified. \param p1 first point \param p2 second point \note This is *not* a dot, cross or wedge product. It is a mere field-by-field multiplication. */ template inline void multiply_point(Point1& p1, Point2 const& p2) { BOOST_CONCEPT_ASSERT( (concept::Point) ); BOOST_CONCEPT_ASSERT( (concept::ConstPoint) ); for_each_coordinate(p1, detail::point_operation(p2)); } /*! \brief Divides each coordinate of the same point by a value \ingroup arithmetic \details \param p point \param value value to divide by */ template inline void divide_value(Point& p, typename detail::param::type value) { BOOST_CONCEPT_ASSERT( (concept::Point) ); for_each_coordinate(p, detail::value_operation::type, std::divides>(value)); } /*! \brief Divides a point by another \ingroup arithmetic \details The coordinates of the first point will be divided by those of the second point. The second point is not modified. \param p1 first point \param p2 second point */ template inline void divide_point(Point1& p1, Point2 const& p2) { BOOST_CONCEPT_ASSERT( (concept::Point) ); BOOST_CONCEPT_ASSERT( (concept::ConstPoint) ); for_each_coordinate(p1, detail::point_operation(p2)); } /*! \brief Assign each coordinate of a point the same value \ingroup arithmetic \details \param p point \param value value to assign */ template inline void assign_value(Point& p, typename detail::param::type value) { BOOST_CONCEPT_ASSERT( (concept::Point) ); for_each_coordinate(p, detail::value_assignment::type>(value)); } /*! \brief Assign a point with another \ingroup arithmetic \details The coordinates of the first point will be assigned those of the second point. The second point is not modified. \param p1 first point \param p2 second point */ template inline void assign_point(Point1& p1, const Point2& p2) { BOOST_CONCEPT_ASSERT( (concept::Point) ); BOOST_CONCEPT_ASSERT( (concept::ConstPoint) ); for_each_coordinate(p1, detail::point_assignment(p2)); } }} // namespace boost::geometry #endif // BOOST_GEOMETRY_ARITHMETIC_ARITHMETIC_HPP