Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-10-18 08:46:42

0001 // Boost.Geometry
0002 
0003 // Copyright (c) 2025 Adam Wulkiewicz, Lodz, Poland.
0004 
0005 // Copyright (c) 2021, Oracle and/or its affiliates.
0006 
0007 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
0008 
0009 // Licensed under the Boost Software License version 1.0.
0010 // http://www.boost.org/users/license.html
0011 
0012 #ifndef BOOST_GEOMETRY_STRATEGIES_CENTROID_CARTESIAN_HPP
0013 #define BOOST_GEOMETRY_STRATEGIES_CENTROID_CARTESIAN_HPP
0014 
0015 
0016 #include <boost/geometry/strategies/cartesian/centroid_average.hpp>
0017 #include <boost/geometry/strategies/cartesian/centroid_bashein_detmer.hpp>
0018 #include <boost/geometry/strategies/cartesian/centroid_weighted_length.hpp>
0019 
0020 #include <boost/geometry/strategies/detail.hpp>
0021 #include <boost/geometry/strategies/centroid/services.hpp>
0022 
0023 #include <boost/geometry/util/type_traits.hpp>
0024 
0025 
0026 namespace boost { namespace geometry
0027 {
0028 
0029 namespace strategies { namespace centroid
0030 {
0031 
0032 #ifndef DOXYGEN_NO_DETAIL
0033 namespace detail
0034 {
0035 
0036 template <typename CalculationType = void>
0037 struct cartesian
0038 {
0039     template <typename Geometry>
0040     static auto centroid(Geometry const&,
0041                          std::enable_if_t
0042                             <
0043                                 util::is_pointlike<Geometry>::value
0044                             > * = nullptr)
0045     {
0046         return strategy::centroid::average<>();
0047     }
0048 
0049     template <typename Geometry>
0050     static auto centroid(Geometry const&,
0051                          std::enable_if_t
0052                             <
0053                                 util::is_polylinear<Geometry>::value
0054                             > * = nullptr)
0055     {
0056         return strategy::centroid::weighted_length<void, void, CalculationType>();
0057     }
0058 
0059     template <typename Geometry>
0060     static auto centroid(Geometry const&,
0061                          std::enable_if_t
0062                             <
0063                                 util::is_polygonal<Geometry>::value
0064                              // TODO: This condition was used for the legacy default strategy
0065                              // && geometry::dimension<Geometry>::value == 2
0066                             > * = nullptr)
0067     {
0068         return strategy::centroid::bashein_detmer<void, void, CalculationType>();
0069     }
0070 
0071     // TODO: Box and Segment should have proper strategies.
0072     template <typename Geometry, typename Point>
0073     static auto centroid(Geometry const&, Point const&,
0074                          std::enable_if_t
0075                             <
0076                                 util::is_segment<Geometry>::value
0077                              || util::is_box<Geometry>::value
0078                             > * = nullptr)
0079     {
0080         return strategy::centroid::not_applicable_strategy();
0081     }
0082 };
0083 
0084 
0085 } // namespace detail
0086 #endif // DOXYGEN_NO_DETAIL
0087 
0088 
0089 template <typename CalculationType = void>
0090 struct cartesian
0091     : public strategies::detail::cartesian_base
0092     , public strategies::centroid::detail::cartesian<CalculationType>
0093 {};
0094 
0095 
0096 namespace services
0097 {
0098 
0099 template <typename Geometry>
0100 struct default_strategy<Geometry, cartesian_tag>
0101 {
0102     using type = strategies::centroid::cartesian<>;
0103 };
0104 
0105 
0106 template <typename PC, typename PG>
0107 struct strategy_converter<strategy::centroid::average<PC, PG> >
0108 {
0109     static auto get(strategy::centroid::average<PC, PG> const&)
0110     {
0111         return strategies::centroid::cartesian<>();
0112     }
0113 };
0114 
0115 template <typename PC, typename PG>
0116 struct strategy_converter<strategy::centroid::weighted_length<PC, PG> >
0117 {
0118     static auto get(strategy::centroid::weighted_length<PC, PG> const&)
0119     {
0120         return strategies::centroid::cartesian<>();
0121     }
0122 };
0123 
0124 template <typename PC, typename PG, typename CT>
0125 struct strategy_converter<strategy::centroid::bashein_detmer<PC, PG, CT> >
0126 {
0127     static auto get(strategy::centroid::bashein_detmer<PC, PG, CT> const&)
0128     {
0129         return strategies::centroid::cartesian<CT>();
0130     }
0131 };
0132 
0133 } // namespace services
0134 
0135 }} // namespace strategies::centroid
0136 
0137 }} // namespace boost::geometry
0138 
0139 #endif // BOOST_GEOMETRY_STRATEGIES_CENTROID_CARTESIAN_HPP