File indexing completed on 2025-12-15 09:50:29
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019 #ifndef BOOST_GEOMETRY_ARITHMETIC_ARITHMETIC_HPP
0020 #define BOOST_GEOMETRY_ARITHMETIC_ARITHMETIC_HPP
0021
0022 #include <functional>
0023
0024 #include <boost/concept/requires.hpp>
0025
0026 #include <boost/geometry/core/coordinate_type.hpp>
0027 #include <boost/geometry/geometries/concepts/point_concept.hpp>
0028 #include <boost/geometry/util/algorithm.hpp>
0029 #include <boost/geometry/util/select_coordinate_type.hpp>
0030
0031
0032 namespace boost { namespace geometry
0033 {
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043 template <typename Point>
0044 inline void add_value(Point& p, coordinate_type_t<Point> const& value)
0045 {
0046 BOOST_CONCEPT_ASSERT( (concepts::Point<Point>) );
0047
0048 detail::for_each_dimension<Point>([&](auto index)
0049 {
0050 set<index>(p, get<index>(p) + value);
0051 });
0052 }
0053
0054
0055
0056
0057
0058
0059
0060
0061
0062
0063
0064 template <typename Point1, typename Point2>
0065 inline void add_point(Point1& p1, Point2 const& p2)
0066 {
0067 BOOST_CONCEPT_ASSERT( (concepts::Point<Point1>) );
0068 BOOST_CONCEPT_ASSERT( (concepts::ConstPoint<Point2>) );
0069
0070 detail::for_each_dimension<Point1>([&](auto index)
0071 {
0072 using calc_t = typename select_coordinate_type<Point1, Point2>::type;
0073 set<index>(p1, calc_t(get<index>(p1)) + calc_t(get<index>(p2)));
0074 });
0075 }
0076
0077
0078
0079
0080
0081
0082
0083
0084
0085 template <typename Point>
0086 inline void subtract_value(Point& p, coordinate_type_t<Point> const& value)
0087 {
0088 BOOST_CONCEPT_ASSERT( (concepts::Point<Point>) );
0089
0090 detail::for_each_dimension<Point>([&](auto index)
0091 {
0092 set<index>(p, get<index>(p) - value);
0093 });
0094 }
0095
0096
0097
0098
0099
0100
0101
0102
0103
0104
0105
0106 template <typename Point1, typename Point2>
0107 inline void subtract_point(Point1& p1, Point2 const& p2)
0108 {
0109 BOOST_CONCEPT_ASSERT( (concepts::Point<Point1>) );
0110 BOOST_CONCEPT_ASSERT( (concepts::ConstPoint<Point2>) );
0111
0112 detail::for_each_dimension<Point1>([&](auto index)
0113 {
0114 using calc_t = typename select_coordinate_type<Point1, Point2>::type;
0115 set<index>(p1, calc_t(get<index>(p1)) - calc_t(get<index>(p2)));
0116 });
0117 }
0118
0119
0120
0121
0122
0123
0124
0125
0126
0127 template <typename Point>
0128 inline void multiply_value(Point& p, coordinate_type_t<Point> const& value)
0129 {
0130 BOOST_CONCEPT_ASSERT( (concepts::Point<Point>) );
0131
0132 detail::for_each_dimension<Point>([&](auto index)
0133 {
0134 set<index>(p, get<index>(p) * value);
0135 });
0136 }
0137
0138
0139
0140
0141
0142
0143
0144
0145
0146
0147
0148
0149 template <typename Point1, typename Point2>
0150 inline void multiply_point(Point1& p1, Point2 const& p2)
0151 {
0152 BOOST_CONCEPT_ASSERT( (concepts::Point<Point1>) );
0153 BOOST_CONCEPT_ASSERT( (concepts::ConstPoint<Point2>) );
0154
0155 detail::for_each_dimension<Point1>([&](auto index)
0156 {
0157 using calc_t = typename select_coordinate_type<Point1, Point2>::type;
0158 set<index>(p1, calc_t(get<index>(p1)) * calc_t(get<index>(p2)));
0159 });
0160 }
0161
0162
0163
0164
0165
0166
0167
0168
0169
0170 template <typename Point>
0171 inline void divide_value(Point& p, coordinate_type_t<Point> const& value)
0172 {
0173 BOOST_CONCEPT_ASSERT( (concepts::Point<Point>) );
0174
0175 detail::for_each_dimension<Point>([&](auto index)
0176 {
0177 set<index>(p, get<index>(p) / value);
0178 });
0179 }
0180
0181
0182
0183
0184
0185
0186
0187
0188
0189
0190
0191 template <typename Point1, typename Point2>
0192 inline void divide_point(Point1& p1, Point2 const& p2)
0193 {
0194 BOOST_CONCEPT_ASSERT( (concepts::Point<Point1>) );
0195 BOOST_CONCEPT_ASSERT( (concepts::ConstPoint<Point2>) );
0196
0197 detail::for_each_dimension<Point1>([&](auto index)
0198 {
0199 using calc_t = typename select_coordinate_type<Point1, Point2>::type;
0200 set<index>(p1, calc_t(get<index>(p1)) / calc_t(get<index>(p2)));
0201 });
0202 }
0203
0204
0205
0206
0207
0208
0209
0210
0211
0212 template <typename Point>
0213 inline void assign_value(Point& p, coordinate_type_t<Point> const& value)
0214 {
0215 BOOST_CONCEPT_ASSERT( (concepts::Point<Point>) );
0216
0217 detail::for_each_dimension<Point>([&](auto index)
0218 {
0219 set<index>(p, value);
0220 });
0221 }
0222
0223
0224
0225
0226
0227
0228
0229
0230
0231
0232
0233 template <typename Point1, typename Point2>
0234 inline void assign_point(Point1& p1, Point2 const& p2)
0235 {
0236 BOOST_CONCEPT_ASSERT( (concepts::Point<Point1>) );
0237 BOOST_CONCEPT_ASSERT( (concepts::ConstPoint<Point2>) );
0238
0239 detail::for_each_dimension<Point1>([&](auto index)
0240 {
0241 set<index>(p1, get<index>(p2));
0242 });
0243 }
0244
0245
0246 }}
0247
0248
0249 #endif