// Copyright (c) 2009-2012 Mateusz Loskot, London, UK.
// Copyright (c) 2017 Adam Wulkiewicz, Lodz, Poland.
-// This file was modified by Oracle on 2017-2020.
-// Modifications copyright (c) 2017-2020 Oracle and/or its affiliates.
+// This file was modified by Oracle on 2017-2021.
+// Modifications copyright (c) 2017-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
#ifndef BOOST_GEOMETRY_ALGORITHMS_AREA_HPP
#define BOOST_GEOMETRY_ALGORITHMS_AREA_HPP
-#include <boost/concept_check.hpp>
#include <boost/core/ignore_unused.hpp>
#include <boost/range/begin.hpp>
#include <boost/range/end.hpp>
#include <boost/range/size.hpp>
#include <boost/range/value_type.hpp>
-#include <boost/variant/apply_visitor.hpp>
-#include <boost/variant/static_visitor.hpp>
-#include <boost/variant/variant_fwd.hpp>
-
#include <boost/geometry/core/closure.hpp>
#include <boost/geometry/core/exterior_ring.hpp>
#include <boost/geometry/core/interior_rings.hpp>
#include <boost/geometry/core/point_type.hpp>
#include <boost/geometry/core/ring_type.hpp>
#include <boost/geometry/core/tags.hpp>
-
-#include <boost/geometry/geometries/concepts/check.hpp>
+#include <boost/geometry/core/visit.hpp>
#include <boost/geometry/algorithms/detail/calculate_null.hpp>
#include <boost/geometry/algorithms/detail/calculate_sum.hpp>
// #include <boost/geometry/algorithms/detail/throw_on_empty_input.hpp>
#include <boost/geometry/algorithms/detail/multi_sum.hpp>
+#include <boost/geometry/algorithms/detail/visit.hpp>
#include <boost/geometry/algorithms/area_result.hpp>
#include <boost/geometry/algorithms/default_area_result.hpp>
-#include <boost/geometry/strategies/area/services.hpp>
-#include <boost/geometry/strategies/default_strategy.hpp>
-#include <boost/geometry/strategy/area.hpp>
+#include <boost/geometry/geometries/adapted/boost_variant.hpp> // For backward compatibility
+#include <boost/geometry/geometries/concepts/check.hpp>
+#include <boost/geometry/strategies/area/services.hpp>
+#include <boost/geometry/strategies/area/cartesian.hpp>
+#include <boost/geometry/strategies/area/geographic.hpp>
+#include <boost/geometry/strategies/area/spherical.hpp>
#include <boost/geometry/strategies/concepts/area_concept.hpp>
+#include <boost/geometry/strategies/default_strategy.hpp>
#include <boost/geometry/util/math.hpp>
-#include <boost/geometry/util/order_as_direction.hpp>
-#include <boost/geometry/views/closeable_view.hpp>
-#include <boost/geometry/views/reversible_view.hpp>
+
+#include <boost/geometry/views/detail/closed_clockwise_view.hpp>
namespace boost { namespace geometry
struct box_area
{
- template <typename Box, typename Strategy>
+ template <typename Box, typename Strategies>
static inline typename coordinate_type<Box>::type
- apply(Box const& box, Strategy const&)
+ apply(Box const& box, Strategies const& strategies)
{
// Currently only works for 2D Cartesian boxes
assert_dimension<Box, 2>();
- return (get<max_corner, 0>(box) - get<min_corner, 0>(box))
- * (get<max_corner, 1>(box) - get<min_corner, 1>(box));
+ return strategies.area(box).apply(box);
}
};
-template
-<
- iterate_direction Direction,
- closure_selector Closure
->
struct ring_area
{
template <typename Ring, typename Strategies>
// An open ring has at least three points,
// A closed ring has at least four points,
// if not, there is no (zero) area
- if (boost::size(ring)
- < core_detail::closure::minimum_ring_size<Closure>::value)
+ if (boost::size(ring) < detail::minimum_ring_size<Ring>::value)
{
return typename area_result<Ring, Strategies>::type();
}
- typedef typename reversible_view<Ring const, Direction>::type rview_type;
- typedef typename closeable_view
- <
- rview_type const, Closure
- >::type view_type;
- typedef typename boost::range_iterator<view_type const>::type iterator_type;
-
- rview_type rview(ring);
- view_type view(rview);
- iterator_type it = boost::begin(view);
- iterator_type end = boost::end(view);
+ detail::closed_clockwise_view<Ring const> const view(ring);
+ auto it = boost::begin(view);
+ auto const end = boost::end(view);
- strategy_type strategy = strategies.area(ring);
+ strategy_type const strategy = strategies.area(ring);
typename strategy_type::template state<Ring> state;
- for (iterator_type previous = it++;
- it != end;
- ++previous, ++it)
+ for (auto previous = it++; it != end; ++previous, ++it)
{
strategy.apply(*previous, *it, state);
}
template <typename Ring>
struct area<Ring, ring_tag>
: detail::area::ring_area
- <
- order_as_direction<geometry::point_order<Ring>::value>::value,
- geometry::closure<Ring>::value
- >
{};
static inline typename area_result<Polygon, Strategy>::type
apply(Polygon const& polygon, Strategy const& strategy)
{
- return calculate_polygon_sum::apply<
- typename area_result<Polygon, Strategy>::type,
- detail::area::ring_area
- <
- order_as_direction<geometry::point_order<Polygon>::value>::value,
- geometry::closure<Polygon>::value
- >
+ return calculate_polygon_sum::apply
+ <
+ typename area_result<Polygon, Strategy>::type,
+ detail::area::ring_area
>(polygon, strategy);
}
};
} // namespace resolve_strategy
-namespace resolve_variant
+namespace resolve_dynamic
{
-template <typename Geometry>
+template <typename Geometry, typename Tag = typename geometry::tag<Geometry>::type>
struct area
{
template <typename Strategy>
}
};
-template <BOOST_VARIANT_ENUM_PARAMS(typename T)>
-struct area<boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)> >
+template <typename Geometry>
+struct area<Geometry, dynamic_geometry_tag>
{
- typedef boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)> variant_type;
-
template <typename Strategy>
- struct visitor
- : boost::static_visitor<typename area_result<variant_type, Strategy>::type>
+ static inline typename area_result<Geometry, Strategy>::type
+ apply(Geometry const& geometry, Strategy const& strategy)
{
- Strategy const& m_strategy;
-
- visitor(Strategy const& strategy): m_strategy(strategy) {}
-
- template <typename Geometry>
- typename area_result<variant_type, Strategy>::type
- operator()(Geometry const& geometry) const
+ typename area_result<Geometry, Strategy>::type result = 0;
+ traits::visit<Geometry>::apply([&](auto const& g)
{
- return area<Geometry>::apply(geometry, m_strategy);
- }
- };
+ result = area<util::remove_cref_t<decltype(g)>>::apply(g, strategy);
+ }, geometry);
+ return result;
+ }
+};
+template <typename Geometry>
+struct area<Geometry, geometry_collection_tag>
+{
template <typename Strategy>
- static inline typename area_result<variant_type, Strategy>::type
- apply(variant_type const& geometry,
- Strategy const& strategy)
+ static inline typename area_result<Geometry, Strategy>::type
+ apply(Geometry const& geometry, Strategy const& strategy)
{
- return boost::apply_visitor(visitor<Strategy>(strategy), geometry);
+ typename area_result<Geometry, Strategy>::type result = 0;
+ detail::visit_breadth_first([&](auto const& g)
+ {
+ result += area<util::remove_cref_t<decltype(g)>>::apply(g, strategy);
+ return true;
+ }, geometry);
+ return result;
}
};
-} // namespace resolve_variant
+} // namespace resolve_dynamic
/*!
// detail::throw_on_empty_input(geometry);
- return resolve_variant::area<Geometry>::apply(geometry, default_strategy());
+ return resolve_dynamic::area<Geometry>::apply(geometry, default_strategy());
}
/*!
// detail::throw_on_empty_input(geometry);
- return resolve_variant::area<Geometry>::apply(geometry, strategy);
+ return resolve_dynamic::area<Geometry>::apply(geometry, strategy);
}