Chris@16: // Boost.Geometry (aka GGL, Generic Geometry Library) Chris@16: Chris@16: // Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands. Chris@16: // Copyright (c) 2008-2012 Bruno Lalande, Paris, France. Chris@16: // Copyright (c) 2009-2012 Mateusz Loskot, London, UK. Chris@16: Chris@16: // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library Chris@16: // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands. Chris@16: Chris@16: // Use, modification and distribution is subject to the Boost Software License, Chris@16: // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at Chris@16: // http://www.boost.org/LICENSE_1_0.txt) Chris@16: Chris@16: #ifndef BOOST_GEOMETRY_STRATEGIES_CARTESIAN_AREA_SURVEYOR_HPP Chris@16: #define BOOST_GEOMETRY_STRATEGIES_CARTESIAN_AREA_SURVEYOR_HPP Chris@16: Chris@16: Chris@16: #include Chris@16: Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: Chris@16: Chris@16: namespace boost { namespace geometry Chris@16: { Chris@16: Chris@16: namespace strategy { namespace area Chris@16: { Chris@16: Chris@16: /*! Chris@16: \brief Area calculation for cartesian points Chris@16: \ingroup strategies Chris@16: \details Calculates area using the Surveyor's formula, a well-known Chris@16: triangulation algorithm Chris@16: \tparam PointOfSegment \tparam_segment_point Chris@16: \tparam CalculationType \tparam_calculation Chris@16: Chris@16: \qbk{ Chris@16: [heading See also] Chris@16: [link geometry.reference.algorithms.area.area_2_with_strategy area (with strategy)] Chris@16: } Chris@16: Chris@16: */ Chris@16: template Chris@16: < Chris@16: typename PointOfSegment, Chris@16: typename CalculationType = void Chris@16: > Chris@16: class surveyor Chris@16: { Chris@16: public : Chris@16: // If user specified a calculation type, use that type, Chris@16: // whatever it is and whatever the point-type is. Chris@16: // Else, use the pointtype, but at least double Chris@16: typedef typename Chris@16: boost::mpl::if_c Chris@16: < Chris@16: boost::is_void::type::value, Chris@16: typename select_most_precise Chris@16: < Chris@16: typename coordinate_type::type, Chris@16: double Chris@16: >::type, Chris@16: CalculationType Chris@16: >::type return_type; Chris@16: Chris@16: Chris@16: private : Chris@16: Chris@16: class summation Chris@16: { Chris@16: friend class surveyor; Chris@16: Chris@16: return_type sum; Chris@16: public : Chris@16: Chris@16: inline summation() : sum(return_type()) Chris@16: { Chris@16: // Strategy supports only 2D areas Chris@16: assert_dimension(); Chris@16: } Chris@16: inline return_type area() const Chris@16: { Chris@16: return_type result = sum; Chris@16: return_type const two = 2; Chris@16: result /= two; Chris@16: return result; Chris@16: } Chris@16: }; Chris@16: Chris@16: public : Chris@16: typedef summation state_type; Chris@16: typedef PointOfSegment segment_point_type; Chris@16: Chris@16: static inline void apply(PointOfSegment const& p1, Chris@16: PointOfSegment const& p2, Chris@16: summation& state) Chris@16: { Chris@16: // SUM += x2 * y1 - x1 * y2; Chris@16: state.sum += detail::determinant(p2, p1); Chris@16: } Chris@16: Chris@16: static inline return_type result(summation const& state) Chris@16: { Chris@16: return state.area(); Chris@16: } Chris@16: Chris@16: }; Chris@16: Chris@16: #ifndef DOXYGEN_NO_STRATEGY_SPECIALIZATIONS Chris@16: Chris@16: namespace services Chris@16: { Chris@16: template Chris@16: struct default_strategy Chris@16: { Chris@16: typedef strategy::area::surveyor type; Chris@16: }; Chris@16: Chris@16: } // namespace services Chris@16: Chris@16: #endif // DOXYGEN_NO_STRATEGY_SPECIALIZATIONS Chris@16: Chris@16: Chris@16: }} // namespace strategy::area Chris@16: Chris@16: Chris@16: Chris@16: }} // namespace boost::geometry Chris@16: Chris@16: Chris@16: #endif // BOOST_GEOMETRY_STRATEGIES_CARTESIAN_AREA_SURVEYOR_HPP