Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:36:50

0001 // Boost.Geometry (aka GGL, Generic Geometry Library)
0002 
0003 // Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands.
0004 // Copyright (c) 2008-2012 Bruno Lalande, Paris, France.
0005 // Copyright (c) 2009-2012 Mateusz Loskot, London, UK.
0006 // Copyright (c) 2017 Adam Wulkiewicz, Lodz, Poland.
0007 
0008 // This file was modified by Oracle on 2016-2020.
0009 // Modifications copyright (c) 2016-2020, Oracle and/or its affiliates.
0010 
0011 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
0012 
0013 // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
0014 // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
0015 
0016 // Use, modification and distribution is subject to the Boost Software License,
0017 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
0018 // http://www.boost.org/LICENSE_1_0.txt)
0019 
0020 #ifndef BOOST_GEOMETRY_STRATEGY_CARTESIAN_AREA_HPP
0021 #define BOOST_GEOMETRY_STRATEGY_CARTESIAN_AREA_HPP
0022 
0023 
0024 //#include <boost/geometry/arithmetic/determinant.hpp>
0025 #include <boost/geometry/core/access.hpp>
0026 #include <boost/geometry/core/coordinate_type.hpp>
0027 #include <boost/geometry/core/coordinate_dimension.hpp>
0028 #include <boost/geometry/strategy/area.hpp>
0029 #include <boost/geometry/util/select_most_precise.hpp>
0030 
0031 
0032 namespace boost { namespace geometry
0033 {
0034 
0035 namespace strategy { namespace area
0036 {
0037 
0038 /*!
0039 \brief Cartesian area calculation
0040 \ingroup strategies
0041 \details Calculates cartesian area using the trapezoidal rule
0042 \tparam CalculationType \tparam_calculation
0043 
0044 \qbk{
0045 [heading See also]
0046 [link geometry.reference.algorithms.area.area_2_with_strategy area (with strategy)]
0047 }
0048 
0049 */
0050 template
0051 <
0052     typename CalculationType = void
0053 >
0054 class cartesian
0055 {
0056 public :
0057     template <typename Geometry>
0058     struct result_type
0059         : strategy::area::detail::result_type
0060             <
0061                 Geometry,
0062                 CalculationType
0063             >
0064     {};
0065 
0066     template <typename Geometry>
0067     class state
0068     {
0069         friend class cartesian;
0070 
0071         typedef typename result_type<Geometry>::type return_type;
0072 
0073     public:
0074         inline state()
0075             : sum(0)
0076         {
0077             // Strategy supports only 2D areas
0078             assert_dimension<Geometry, 2>();
0079         }
0080 
0081     private:
0082         inline return_type area() const
0083         {
0084             return_type const two = 2;
0085             return sum / two;
0086         }
0087 
0088         return_type sum;
0089     };
0090 
0091     template <typename PointOfSegment, typename Geometry>
0092     static inline void apply(PointOfSegment const& p1,
0093                              PointOfSegment const& p2,
0094                              state<Geometry>& st)
0095     {
0096         typedef typename state<Geometry>::return_type return_type;
0097 
0098         // Below formulas are equivalent, however the two lower ones
0099         // suffer less from accuracy loss for great values of coordinates.
0100         // See: https://svn.boost.org/trac/boost/ticket/11928
0101 
0102         // SUM += x2 * y1 - x1 * y2;
0103         // state.sum += detail::determinant<return_type>(p2, p1);
0104 
0105         // SUM += (x2 - x1) * (y2 + y1)
0106         //state.sum += (return_type(get<0>(p2)) - return_type(get<0>(p1)))
0107         //           * (return_type(get<1>(p2)) + return_type(get<1>(p1)));
0108 
0109         // SUM += (x1 + x2) * (y1 - y2)
0110         st.sum += (return_type(get<0>(p1)) + return_type(get<0>(p2)))
0111                 * (return_type(get<1>(p1)) - return_type(get<1>(p2)));
0112     }
0113 
0114     template <typename Geometry>
0115     static inline auto result(state<Geometry>& st)
0116     {
0117         return st.area();
0118     }
0119 
0120 };
0121 
0122 #ifndef DOXYGEN_NO_STRATEGY_SPECIALIZATIONS
0123 
0124 namespace services
0125 {
0126     template <>
0127     struct default_strategy<cartesian_tag>
0128     {
0129         typedef strategy::area::cartesian<> type;
0130     };
0131 
0132 } // namespace services
0133 
0134 #endif // DOXYGEN_NO_STRATEGY_SPECIALIZATIONS
0135 
0136 
0137 }} // namespace strategy::area
0138 
0139 
0140 
0141 }} // namespace boost::geometry
0142 
0143 
0144 #endif // BOOST_GEOMETRY_STRATEGY_CARTESIAN_AREA_HPP