1 // Boost.Geometry (aka GGL, Generic Geometry Library)
3 // Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands.
4 // Copyright (c) 2008-2012 Bruno Lalande, Paris, France.
5 // Copyright (c) 2009-2012 Mateusz Loskot, London, UK.
6 // Copyright (c) 2017 Adam Wulkiewicz, Lodz, Poland.
8 // This file was modified by Oracle on 2016, 2017, 2018.
9 // Modifications copyright (c) 2016-2018, Oracle and/or its affiliates.
11 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
13 // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
14 // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
16 // Use, modification and distribution is subject to the Boost Software License,
17 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
18 // http://www.boost.org/LICENSE_1_0.txt)
20 #ifndef BOOST_GEOMETRY_STRATEGIES_CARTESIAN_AREA_HPP
21 #define BOOST_GEOMETRY_STRATEGIES_CARTESIAN_AREA_HPP
24 #include <boost/mpl/if.hpp>
26 //#include <boost/geometry/arithmetic/determinant.hpp>
27 #include <boost/geometry/core/access.hpp>
28 #include <boost/geometry/core/coordinate_type.hpp>
29 #include <boost/geometry/core/coordinate_dimension.hpp>
30 #include <boost/geometry/strategies/area.hpp>
31 #include <boost/geometry/util/select_most_precise.hpp>
34 namespace boost { namespace geometry
37 namespace strategy { namespace area
41 \brief Cartesian area calculation
43 \details Calculates cartesian area using the trapezoidal rule
44 \tparam CalculationType \tparam_calculation
48 [link geometry.reference.algorithms.area.area_2_with_strategy area (with strategy)]
54 typename CalculationType = void
59 template <typename Geometry>
61 : strategy::area::detail::result_type
68 template <typename Geometry>
71 friend class cartesian;
73 typedef typename result_type<Geometry>::type return_type;
79 // Strategy supports only 2D areas
80 assert_dimension<Geometry, 2>();
84 inline return_type area() const
86 return_type const two = 2;
93 template <typename PointOfSegment, typename Geometry>
94 static inline void apply(PointOfSegment const& p1,
95 PointOfSegment const& p2,
98 typedef typename state<Geometry>::return_type return_type;
100 // Below formulas are equivalent, however the two lower ones
101 // suffer less from accuracy loss for great values of coordinates.
102 // See: https://svn.boost.org/trac/boost/ticket/11928
104 // SUM += x2 * y1 - x1 * y2;
105 // state.sum += detail::determinant<return_type>(p2, p1);
107 // SUM += (x2 - x1) * (y2 + y1)
108 //state.sum += (return_type(get<0>(p2)) - return_type(get<0>(p1)))
109 // * (return_type(get<1>(p2)) + return_type(get<1>(p1)));
111 // SUM += (x1 + x2) * (y1 - y2)
112 st.sum += (return_type(get<0>(p1)) + return_type(get<0>(p2)))
113 * (return_type(get<1>(p1)) - return_type(get<1>(p2)));
116 template <typename Geometry>
117 static inline typename result_type<Geometry>::type
118 result(state<Geometry>& st)
125 #ifndef DOXYGEN_NO_STRATEGY_SPECIALIZATIONS
130 struct default_strategy<cartesian_tag>
132 typedef strategy::area::cartesian<> type;
135 } // namespace services
137 #endif // DOXYGEN_NO_STRATEGY_SPECIALIZATIONS
140 }} // namespace strategy::area
144 }} // namespace boost::geometry
147 #endif // BOOST_GEOMETRY_STRATEGIES_CARTESIAN_AREA_HPP