Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-15 09:50:29

0001 // Boost.Geometry (aka GGL, Generic Geometry Library)
0002 
0003 // Copyright (c) 2008-2012 Bruno Lalande, Paris, France.
0004 // Copyright (c) 2008-2012 Barend Gehrels, Amsterdam, the Netherlands.
0005 // Copyright (c) 2009-2012 Mateusz Loskot, London, UK.
0006 // Copyright (c) 2023 Adam Wulkiewicz, Lodz, Poland.
0007 
0008 // This file was modified by Oracle on 2021.
0009 // Modifications copyright (c) 2021 Oracle and/or its affiliates.
0010 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
0011 
0012 // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
0013 // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
0014 
0015 // Use, modification and distribution is subject to the Boost Software License,
0016 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
0017 // http://www.boost.org/LICENSE_1_0.txt)
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     \brief Adds the same value to each coordinate of a point
0037     \ingroup arithmetic
0038     \details
0039     \tparam Point \tparam_point
0040     \param p point
0041     \param value value to add
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     \brief Adds a point to another
0056     \ingroup arithmetic
0057     \details The coordinates of the second point will be added to those of the first point.
0058              The second point is not modified.
0059     \tparam Point1 \tparam_point
0060     \tparam Point2 \tparam_point
0061     \param p1 first point
0062     \param p2 second point
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     \brief Subtracts the same value to each coordinate of a point
0079     \ingroup arithmetic
0080     \details
0081     \tparam Point \tparam_point
0082     \param p point
0083     \param value value to subtract
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     \brief Subtracts a point to another
0098     \ingroup arithmetic
0099     \details The coordinates of the second point will be subtracted to those of the first point.
0100              The second point is not modified.
0101     \tparam Point1 \tparam_point
0102     \tparam Point2 \tparam_point
0103     \param p1 first point
0104     \param p2 second point
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     \brief Multiplies each coordinate of a point by the same value
0121     \ingroup arithmetic
0122     \details
0123     \tparam Point \tparam_point
0124     \param p point
0125     \param value value to multiply by
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     \brief Multiplies a point by another
0140     \ingroup arithmetic
0141     \details The coordinates of the first point will be multiplied by those of the second point.
0142              The second point is not modified.
0143     \tparam Point1 \tparam_point
0144     \tparam Point2 \tparam_point
0145     \param p1 first point
0146     \param p2 second point
0147     \note This is *not* a dot, cross or wedge product. It is a mere field-by-field multiplication.
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     \brief Divides each coordinate of the same point by a value
0164     \ingroup arithmetic
0165     \details
0166     \tparam Point \tparam_point
0167     \param p point
0168     \param value value to divide by
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     \brief Divides a point by another
0183     \ingroup arithmetic
0184     \details The coordinates of the first point will be divided by those of the second point.
0185              The second point is not modified.
0186     \tparam Point1 \tparam_point
0187     \tparam Point2 \tparam_point
0188     \param p1 first point
0189     \param p2 second point
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     \brief Assign each coordinate of a point the same value
0206     \ingroup arithmetic
0207     \details
0208     \tparam Point \tparam_point
0209     \param p point
0210     \param value value to assign
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     \brief Assign a point with another
0225     \ingroup arithmetic
0226     \details The coordinates of the first point will be assigned those of the second point.
0227              The second point is not modified.
0228     \tparam Point1 \tparam_point
0229     \tparam Point2 \tparam_point
0230     \param p1 first point
0231     \param p2 second point
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 }} // namespace boost::geometry
0247 
0248 
0249 #endif // BOOST_GEOMETRY_ARITHMETIC_ARITHMETIC_HPP