]> git.proxmox.com Git - ceph.git/blobdiff - ceph/src/boost/boost/geometry/strategies/cartesian/centroid_bashein_detmer.hpp
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / boost / boost / geometry / strategies / cartesian / centroid_bashein_detmer.hpp
index 39e1ffd3d7e98ff2887ac899678ef4c109b124fa..d4713da92d8142a2d26f549b79197c282f284537 100644 (file)
@@ -4,8 +4,8 @@
 // Copyright (c) 2008-2015 Bruno Lalande, Paris, France.
 // Copyright (c) 2009-2015 Mateusz Loskot, London, UK.
 
-// This file was modified by Oracle on 2015-2020.
-// Modifications copyright (c) 2015-2020, Oracle and/or its affiliates.
+// This file was modified by Oracle on 2015-2021.
+// Modifications copyright (c) 2015-2021, Oracle and/or its affiliates.
 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
 
 // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
@@ -118,8 +118,8 @@ Statements:
  */
 template
 <
-    typename Point,
-    typename PointOfSegment = Point,
+    typename Ignored1 = void,
+    typename Ignored2 = void,
     typename CalculationType = void
 >
 class bashein_detmer
@@ -129,41 +129,52 @@ private :
     //   whatever it is and whatever the point-type(s) are.
     // Else, use the most appropriate coordinate type
     //    of the two points, but at least double
-    typedef std::conditional_t
-        <
-            std::is_void<CalculationType>::value,
-            typename select_most_precise
-                <
-                    typename coordinate_type<Point>::type,
-                    typename coordinate_type<PointOfSegment>::type,
-                    double
-                >::type,
-            CalculationType
-        > calculation_type;
+    template <typename GeometryPoint, typename ResultPoint>
+    struct calculation_type
+        : std::conditional
+            <
+                std::is_void<CalculationType>::value,
+                typename select_most_precise
+                    <
+                        typename coordinate_type<GeometryPoint>::type,
+                        typename coordinate_type<ResultPoint>::type,
+                        double
+                    >::type,
+                CalculationType
+            >
+    {};
 
     /*! subclass to keep state */
+    template <typename GeometryPoint, typename ResultPoint>
     class sums
     {
+        typedef typename calculation_type<GeometryPoint, ResultPoint>::type calc_type;
+
         friend class bashein_detmer;
         std::size_t count;
-        calculation_type sum_a2;
-        calculation_type sum_x;
-        calculation_type sum_y;
+        calc_type sum_a2;
+        calc_type sum_x;
+        calc_type sum_y;
 
     public :
         inline sums()
             : count(0)
-            , sum_a2(calculation_type())
-            , sum_x(calculation_type())
-            , sum_y(calculation_type())
+            , sum_a2(calc_type())
+            , sum_x(calc_type())
+            , sum_y(calc_type())
         {}
     };
 
 public :
-    typedef sums state_type;
+    template <typename GeometryPoint, typename ResultPoint>
+    struct state_type
+    {
+        typedef sums<GeometryPoint, ResultPoint> type;
+    };
 
-    static inline void apply(PointOfSegment const& p1,
-            PointOfSegment const& p2, sums& state)
+    template <typename GeometryPoint, typename ResultPoint>
+    static inline void apply(GeometryPoint const& p1, GeometryPoint const& p2,
+                             sums<GeometryPoint, ResultPoint>& state)
     {
         /* Algorithm:
         For each segment:
@@ -176,29 +187,35 @@ public :
         return POINT(sum_x / (3 * sum_a2), sum_y / (3 * sum_a2) )
         */
 
+        typedef typename calculation_type<GeometryPoint, ResultPoint>::type calc_type;
+
         // Get coordinates and promote them to calculation_type
-        calculation_type const x1 = boost::numeric_cast<calculation_type>(get<0>(p1));
-        calculation_type const y1 = boost::numeric_cast<calculation_type>(get<1>(p1));
-        calculation_type const x2 = boost::numeric_cast<calculation_type>(get<0>(p2));
-        calculation_type const y2 = boost::numeric_cast<calculation_type>(get<1>(p2));
-        calculation_type const ai = geometry::detail::determinant<calculation_type>(p1, p2);
+        calc_type const x1 = boost::numeric_cast<calc_type>(get<0>(p1));
+        calc_type const y1 = boost::numeric_cast<calc_type>(get<1>(p1));
+        calc_type const x2 = boost::numeric_cast<calc_type>(get<0>(p2));
+        calc_type const y2 = boost::numeric_cast<calc_type>(get<1>(p2));
+        calc_type const ai = geometry::detail::determinant<calc_type>(p1, p2);
         state.count++;
         state.sum_a2 += ai;
         state.sum_x += ai * (x1 + x2);
         state.sum_y += ai * (y1 + y2);
     }
 
-    static inline bool result(sums const& state, Point& centroid)
+    template <typename GeometryPoint, typename ResultPoint>
+    static inline bool result(sums<GeometryPoint, ResultPoint> const& state,
+                              ResultPoint& centroid)
     {
-        calculation_type const zero = calculation_type();
+        typedef typename calculation_type<GeometryPoint, ResultPoint>::type calc_type;
+
+        calc_type const zero = calc_type();
         if (state.count > 0 && ! math::equals(state.sum_a2, zero))
         {
-            calculation_type const v3 = 3;
-            calculation_type const a3 = v3 * state.sum_a2;
+            calc_type const v3 = 3;
+            calc_type const a3 = v3 * state.sum_a2;
 
             typedef typename geometry::coordinate_type
                 <
-                    Point
+                    ResultPoint
                 >::type coordinate_type;
 
             // Prevent NaN centroid coordinates