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.
7 // This file was modified by Oracle on 2016.
8 // Modifications copyright (c) 2016, Oracle and/or its affiliates.
10 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
12 // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
13 // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
15 // Use, modification and distribution is subject to the Boost Software License,
16 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
17 // http://www.boost.org/LICENSE_1_0.txt)
19 #ifndef BOOST_GEOMETRY_STRATEGIES_CARTESIAN_AREA_SURVEYOR_HPP
20 #define BOOST_GEOMETRY_STRATEGIES_CARTESIAN_AREA_SURVEYOR_HPP
23 #include <boost/mpl/if.hpp>
25 //#include <boost/geometry/arithmetic/determinant.hpp>
26 #include <boost/geometry/core/coordinate_type.hpp>
27 #include <boost/geometry/core/coordinate_dimension.hpp>
28 #include <boost/geometry/util/select_most_precise.hpp>
31 namespace boost { namespace geometry
34 namespace strategy { namespace area
38 \brief Area calculation for cartesian points
40 \details Calculates area using the Surveyor's formula, a well-known
41 triangulation algorithm
42 \tparam PointOfSegment \tparam_segment_point
43 \tparam CalculationType \tparam_calculation
47 [link geometry.reference.algorithms.area.area_2_with_strategy area (with strategy)]
53 typename PointOfSegment,
54 typename CalculationType = void
59 // If user specified a calculation type, use that type,
60 // whatever it is and whatever the point-type is.
61 // Else, use the pointtype, but at least double
65 boost::is_void<CalculationType>::type::value,
66 typename select_most_precise
68 typename coordinate_type<PointOfSegment>::type,
79 friend class surveyor;
84 inline summation() : sum(return_type())
86 // Strategy supports only 2D areas
87 assert_dimension<PointOfSegment, 2>();
89 inline return_type area() const
91 return_type result = sum;
92 return_type const two = 2;
99 typedef summation state_type;
100 typedef PointOfSegment segment_point_type;
102 static inline void apply(PointOfSegment const& p1,
103 PointOfSegment const& p2,
106 // Below formulas are equivalent, however the two lower ones
107 // suffer less from accuracy loss for great values of coordinates.
108 // See: https://svn.boost.org/trac/boost/ticket/11928
110 // SUM += x2 * y1 - x1 * y2;
111 // state.sum += detail::determinant<return_type>(p2, p1);
113 // SUM += (x2 - x1) * (y2 + y1)
114 //state.sum += (return_type(get<0>(p2)) - return_type(get<0>(p1)))
115 // * (return_type(get<1>(p2)) + return_type(get<1>(p1)));
117 // SUM += (x1 + x2) * (y1 - y2)
118 state.sum += (return_type(get<0>(p1)) + return_type(get<0>(p2)))
119 * (return_type(get<1>(p1)) - return_type(get<1>(p2)));
122 static inline return_type result(summation const& state)
129 #ifndef DOXYGEN_NO_STRATEGY_SPECIALIZATIONS
133 template <typename Point>
134 struct default_strategy<cartesian_tag, Point>
136 typedef strategy::area::surveyor<Point> type;
139 } // namespace services
141 #endif // DOXYGEN_NO_STRATEGY_SPECIALIZATIONS
144 }} // namespace strategy::area
148 }} // namespace boost::geometry
151 #endif // BOOST_GEOMETRY_STRATEGIES_CARTESIAN_AREA_SURVEYOR_HPP