annotate DEPENDENCIES/generic/include/boost/geometry/arithmetic/arithmetic.hpp @ 125:34e428693f5d vext

Vext -> Repoint
author Chris Cannam
date Thu, 14 Jun 2018 11:15:39 +0100
parents c530137014c0
children
rev   line source
Chris@16 1 // Boost.Geometry (aka GGL, Generic Geometry Library)
Chris@16 2
Chris@16 3 // Copyright (c) 2008-2012 Bruno Lalande, Paris, France.
Chris@16 4 // Copyright (c) 2008-2012 Barend Gehrels, Amsterdam, the Netherlands.
Chris@16 5 // Copyright (c) 2009-2012 Mateusz Loskot, London, UK.
Chris@16 6
Chris@16 7 // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
Chris@16 8 // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
Chris@16 9
Chris@16 10 // Use, modification and distribution is subject to the Boost Software License,
Chris@16 11 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
Chris@16 12 // http://www.boost.org/LICENSE_1_0.txt)
Chris@16 13
Chris@16 14 #ifndef BOOST_GEOMETRY_ARITHMETIC_ARITHMETIC_HPP
Chris@16 15 #define BOOST_GEOMETRY_ARITHMETIC_ARITHMETIC_HPP
Chris@16 16
Chris@16 17 #include <functional>
Chris@16 18
Chris@16 19 #include <boost/call_traits.hpp>
Chris@16 20 #include <boost/concept/requires.hpp>
Chris@16 21
Chris@16 22 #include <boost/geometry/core/coordinate_type.hpp>
Chris@16 23 #include <boost/geometry/geometries/concepts/point_concept.hpp>
Chris@16 24 #include <boost/geometry/util/for_each_coordinate.hpp>
Chris@16 25
Chris@16 26
Chris@16 27 namespace boost { namespace geometry
Chris@16 28 {
Chris@16 29
Chris@16 30 #ifndef DOXYGEN_NO_DETAIL
Chris@16 31 namespace detail
Chris@16 32 {
Chris@16 33
Chris@16 34
Chris@16 35 template <typename P>
Chris@16 36 struct param
Chris@16 37 {
Chris@16 38 typedef typename boost::call_traits
Chris@16 39 <
Chris@16 40 typename coordinate_type<P>::type
Chris@16 41 >::param_type type;
Chris@16 42 };
Chris@16 43
Chris@16 44
Chris@16 45 template <typename C, template <typename> class Function>
Chris@16 46 struct value_operation
Chris@16 47 {
Chris@16 48 C m_value;
Chris@16 49
Chris@16 50 inline value_operation(C const &value)
Chris@16 51 : m_value(value)
Chris@16 52 {}
Chris@16 53
Chris@16 54 template <typename P, int I>
Chris@16 55 inline void apply(P& point) const
Chris@16 56 {
Chris@16 57 set<I>(point, Function<C>()(get<I>(point), m_value));
Chris@16 58 }
Chris@16 59 };
Chris@16 60
Chris@16 61 template <typename PointSrc, template <typename> class Function>
Chris@16 62 struct point_operation
Chris@16 63 {
Chris@16 64 typedef typename coordinate_type<PointSrc>::type coordinate_type;
Chris@16 65 PointSrc const& m_source_point;
Chris@16 66
Chris@16 67 inline point_operation(PointSrc const& point)
Chris@16 68 : m_source_point(point)
Chris@16 69 {}
Chris@16 70
Chris@16 71 template <typename PointDst, int I>
Chris@16 72 inline void apply(PointDst& dest_point) const
Chris@16 73 {
Chris@16 74 set<I>(dest_point,
Chris@16 75 Function<coordinate_type>()(get<I>(dest_point), get<I>(m_source_point)));
Chris@16 76 }
Chris@16 77 };
Chris@16 78
Chris@16 79
Chris@16 80 template <typename C>
Chris@16 81 struct value_assignment
Chris@16 82 {
Chris@16 83 C m_value;
Chris@16 84
Chris@16 85 inline value_assignment(C const &value)
Chris@16 86 : m_value(value)
Chris@16 87 {}
Chris@16 88
Chris@16 89 template <typename P, int I>
Chris@16 90 inline void apply(P& point) const
Chris@16 91 {
Chris@16 92 set<I>(point, m_value);
Chris@16 93 }
Chris@16 94 };
Chris@16 95
Chris@16 96 template <typename PointSrc>
Chris@16 97 struct point_assignment
Chris@16 98 {
Chris@16 99 PointSrc const& m_source_point;
Chris@16 100
Chris@16 101 inline point_assignment(PointSrc const& point)
Chris@16 102 : m_source_point(point)
Chris@16 103 {}
Chris@16 104
Chris@16 105 template <typename PointDst, int I>
Chris@16 106 inline void apply(PointDst& dest_point) const
Chris@16 107 {
Chris@16 108 set<I>(dest_point, get<I>(m_source_point));
Chris@16 109 }
Chris@16 110 };
Chris@16 111
Chris@16 112
Chris@16 113 } // namespace detail
Chris@16 114 #endif // DOXYGEN_NO_DETAIL
Chris@16 115
Chris@16 116 /*!
Chris@16 117 \brief Adds the same value to each coordinate of a point
Chris@16 118 \ingroup arithmetic
Chris@16 119 \details
Chris@101 120 \tparam Point \tparam_point
Chris@16 121 \param p point
Chris@16 122 \param value value to add
Chris@16 123 */
Chris@16 124 template <typename Point>
Chris@16 125 inline void add_value(Point& p, typename detail::param<Point>::type value)
Chris@16 126 {
Chris@16 127 BOOST_CONCEPT_ASSERT( (concept::Point<Point>) );
Chris@16 128
Chris@16 129 for_each_coordinate(p, detail::value_operation<typename coordinate_type<Point>::type, std::plus>(value));
Chris@16 130 }
Chris@16 131
Chris@16 132 /*!
Chris@16 133 \brief Adds a point to another
Chris@16 134 \ingroup arithmetic
Chris@16 135 \details The coordinates of the second point will be added to those of the first point.
Chris@16 136 The second point is not modified.
Chris@101 137 \tparam Point1 \tparam_point
Chris@101 138 \tparam Point2 \tparam_point
Chris@16 139 \param p1 first point
Chris@16 140 \param p2 second point
Chris@16 141 */
Chris@16 142 template <typename Point1, typename Point2>
Chris@16 143 inline void add_point(Point1& p1, Point2 const& p2)
Chris@16 144 {
Chris@101 145 BOOST_CONCEPT_ASSERT( (concept::Point<Point1>) );
Chris@16 146 BOOST_CONCEPT_ASSERT( (concept::ConstPoint<Point2>) );
Chris@16 147
Chris@16 148 for_each_coordinate(p1, detail::point_operation<Point2, std::plus>(p2));
Chris@16 149 }
Chris@16 150
Chris@16 151 /*!
Chris@16 152 \brief Subtracts the same value to each coordinate of a point
Chris@16 153 \ingroup arithmetic
Chris@16 154 \details
Chris@101 155 \tparam Point \tparam_point
Chris@16 156 \param p point
Chris@16 157 \param value value to subtract
Chris@16 158 */
Chris@16 159 template <typename Point>
Chris@16 160 inline void subtract_value(Point& p, typename detail::param<Point>::type value)
Chris@16 161 {
Chris@16 162 BOOST_CONCEPT_ASSERT( (concept::Point<Point>) );
Chris@16 163
Chris@16 164 for_each_coordinate(p, detail::value_operation<typename coordinate_type<Point>::type, std::minus>(value));
Chris@16 165 }
Chris@16 166
Chris@16 167 /*!
Chris@16 168 \brief Subtracts a point to another
Chris@16 169 \ingroup arithmetic
Chris@16 170 \details The coordinates of the second point will be subtracted to those of the first point.
Chris@16 171 The second point is not modified.
Chris@101 172 \tparam Point1 \tparam_point
Chris@101 173 \tparam Point2 \tparam_point
Chris@16 174 \param p1 first point
Chris@16 175 \param p2 second point
Chris@16 176 */
Chris@16 177 template <typename Point1, typename Point2>
Chris@16 178 inline void subtract_point(Point1& p1, Point2 const& p2)
Chris@16 179 {
Chris@101 180 BOOST_CONCEPT_ASSERT( (concept::Point<Point1>) );
Chris@16 181 BOOST_CONCEPT_ASSERT( (concept::ConstPoint<Point2>) );
Chris@16 182
Chris@16 183 for_each_coordinate(p1, detail::point_operation<Point2, std::minus>(p2));
Chris@16 184 }
Chris@16 185
Chris@16 186 /*!
Chris@16 187 \brief Multiplies each coordinate of a point by the same value
Chris@16 188 \ingroup arithmetic
Chris@16 189 \details
Chris@101 190 \tparam Point \tparam_point
Chris@16 191 \param p point
Chris@16 192 \param value value to multiply by
Chris@16 193 */
Chris@16 194 template <typename Point>
Chris@16 195 inline void multiply_value(Point& p, typename detail::param<Point>::type value)
Chris@16 196 {
Chris@16 197 BOOST_CONCEPT_ASSERT( (concept::Point<Point>) );
Chris@16 198
Chris@16 199 for_each_coordinate(p, detail::value_operation<typename coordinate_type<Point>::type, std::multiplies>(value));
Chris@16 200 }
Chris@16 201
Chris@16 202 /*!
Chris@16 203 \brief Multiplies a point by another
Chris@16 204 \ingroup arithmetic
Chris@16 205 \details The coordinates of the first point will be multiplied by those of the second point.
Chris@16 206 The second point is not modified.
Chris@101 207 \tparam Point1 \tparam_point
Chris@101 208 \tparam Point2 \tparam_point
Chris@16 209 \param p1 first point
Chris@16 210 \param p2 second point
Chris@16 211 \note This is *not* a dot, cross or wedge product. It is a mere field-by-field multiplication.
Chris@16 212 */
Chris@16 213 template <typename Point1, typename Point2>
Chris@16 214 inline void multiply_point(Point1& p1, Point2 const& p2)
Chris@16 215 {
Chris@101 216 BOOST_CONCEPT_ASSERT( (concept::Point<Point1>) );
Chris@16 217 BOOST_CONCEPT_ASSERT( (concept::ConstPoint<Point2>) );
Chris@16 218
Chris@16 219 for_each_coordinate(p1, detail::point_operation<Point2, std::multiplies>(p2));
Chris@16 220 }
Chris@16 221
Chris@16 222 /*!
Chris@16 223 \brief Divides each coordinate of the same point by a value
Chris@16 224 \ingroup arithmetic
Chris@16 225 \details
Chris@101 226 \tparam Point \tparam_point
Chris@16 227 \param p point
Chris@16 228 \param value value to divide by
Chris@16 229 */
Chris@16 230 template <typename Point>
Chris@16 231 inline void divide_value(Point& p, typename detail::param<Point>::type value)
Chris@16 232 {
Chris@16 233 BOOST_CONCEPT_ASSERT( (concept::Point<Point>) );
Chris@16 234
Chris@16 235 for_each_coordinate(p, detail::value_operation<typename coordinate_type<Point>::type, std::divides>(value));
Chris@16 236 }
Chris@16 237
Chris@16 238 /*!
Chris@16 239 \brief Divides a point by another
Chris@16 240 \ingroup arithmetic
Chris@16 241 \details The coordinates of the first point will be divided by those of the second point.
Chris@16 242 The second point is not modified.
Chris@101 243 \tparam Point1 \tparam_point
Chris@101 244 \tparam Point2 \tparam_point
Chris@16 245 \param p1 first point
Chris@16 246 \param p2 second point
Chris@16 247 */
Chris@16 248 template <typename Point1, typename Point2>
Chris@16 249 inline void divide_point(Point1& p1, Point2 const& p2)
Chris@16 250 {
Chris@101 251 BOOST_CONCEPT_ASSERT( (concept::Point<Point1>) );
Chris@16 252 BOOST_CONCEPT_ASSERT( (concept::ConstPoint<Point2>) );
Chris@16 253
Chris@16 254 for_each_coordinate(p1, detail::point_operation<Point2, std::divides>(p2));
Chris@16 255 }
Chris@16 256
Chris@16 257 /*!
Chris@16 258 \brief Assign each coordinate of a point the same value
Chris@16 259 \ingroup arithmetic
Chris@16 260 \details
Chris@101 261 \tparam Point \tparam_point
Chris@16 262 \param p point
Chris@16 263 \param value value to assign
Chris@16 264 */
Chris@16 265 template <typename Point>
Chris@16 266 inline void assign_value(Point& p, typename detail::param<Point>::type value)
Chris@16 267 {
Chris@16 268 BOOST_CONCEPT_ASSERT( (concept::Point<Point>) );
Chris@16 269
Chris@16 270 for_each_coordinate(p, detail::value_assignment<typename coordinate_type<Point>::type>(value));
Chris@16 271 }
Chris@16 272
Chris@16 273 /*!
Chris@16 274 \brief Assign a point with another
Chris@16 275 \ingroup arithmetic
Chris@16 276 \details The coordinates of the first point will be assigned those of the second point.
Chris@16 277 The second point is not modified.
Chris@101 278 \tparam Point1 \tparam_point
Chris@101 279 \tparam Point2 \tparam_point
Chris@16 280 \param p1 first point
Chris@16 281 \param p2 second point
Chris@16 282 */
Chris@16 283 template <typename Point1, typename Point2>
Chris@101 284 inline void assign_point(Point1& p1, Point2 const& p2)
Chris@16 285 {
Chris@101 286 BOOST_CONCEPT_ASSERT( (concept::Point<Point1>) );
Chris@16 287 BOOST_CONCEPT_ASSERT( (concept::ConstPoint<Point2>) );
Chris@16 288
Chris@16 289 for_each_coordinate(p1, detail::point_assignment<Point2>(p2));
Chris@16 290 }
Chris@16 291
Chris@16 292
Chris@16 293 }} // namespace boost::geometry
Chris@16 294
Chris@16 295
Chris@16 296 #endif // BOOST_GEOMETRY_ARITHMETIC_ARITHMETIC_HPP