Chris@16: // Boost.Geometry (aka GGL, Generic Geometry Library) Chris@16: Chris@16: // Copyright (c) 2008-2012 Bruno Lalande, Paris, France. Chris@16: // Copyright (c) 2008-2012 Barend Gehrels, Amsterdam, the Netherlands. Chris@16: // Copyright (c) 2009-2012 Mateusz Loskot, London, UK. Chris@16: Chris@16: // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library Chris@16: // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands. Chris@16: Chris@16: // Use, modification and distribution is subject to the Boost Software License, Chris@16: // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at Chris@16: // http://www.boost.org/LICENSE_1_0.txt) Chris@16: Chris@16: #ifndef BOOST_GEOMETRY_ARITHMETIC_ARITHMETIC_HPP Chris@16: #define BOOST_GEOMETRY_ARITHMETIC_ARITHMETIC_HPP Chris@16: Chris@16: #include Chris@16: Chris@16: #include Chris@16: #include Chris@16: Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: Chris@16: Chris@16: namespace boost { namespace geometry Chris@16: { Chris@16: Chris@16: #ifndef DOXYGEN_NO_DETAIL Chris@16: namespace detail Chris@16: { Chris@16: Chris@16: Chris@16: template Chris@16: struct param Chris@16: { Chris@16: typedef typename boost::call_traits Chris@16: < Chris@16: typename coordinate_type

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