mirror of
https://github.com/boostorg/geometry.git
synced 2025-05-10 07:34:03 +00:00
In the rtree/pack_create replace (void)variable to boost::ignore_unused_variable_warning().
141 lines
4.5 KiB
C++
141 lines
4.5 KiB
C++
// Boost.Geometry (aka GGL, Generic Geometry Library)
|
|
// Unit Test
|
|
|
|
// Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands.
|
|
// Use, modification and distribution is subject to the Boost Software License,
|
|
// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
|
// http://www.boost.org/LICENSE_1_0.txt)
|
|
|
|
#ifndef BOOST_GEOMETRY_TEST_CONVEX_HULL_HPP
|
|
#define BOOST_GEOMETRY_TEST_CONVEX_HULL_HPP
|
|
|
|
#include <boost/variant/variant.hpp>
|
|
|
|
#include <geometry_test_common.hpp>
|
|
|
|
#include <boost/geometry/algorithms/convex_hull.hpp>
|
|
#include <boost/geometry/algorithms/area.hpp>
|
|
#include <boost/geometry/algorithms/num_points.hpp>
|
|
|
|
#include <boost/geometry/strategies/strategies.hpp>
|
|
|
|
#include <boost/geometry/io/wkt/read.hpp>
|
|
#include <boost/geometry/io/wkt/write.hpp>
|
|
|
|
#include <boost/geometry/geometries/polygon.hpp>
|
|
|
|
|
|
template <typename Geometry, typename Hull>
|
|
void check_convex_hull(Geometry const& geometry, Hull const& hull,
|
|
std::size_t /*size_original*/, std::size_t size_hull,
|
|
double expected_area, bool reverse)
|
|
{
|
|
std::size_t n = bg::num_points(hull);
|
|
|
|
BOOST_CHECK_MESSAGE(n == size_hull,
|
|
"convex hull: " << bg::wkt(geometry)
|
|
<< " -> " << bg::wkt(hull)
|
|
<< " type "
|
|
<< (typeid(typename bg::coordinate_type<Hull>::type).name())
|
|
<< " -> Expected: " << size_hull
|
|
<< " detected: " << n);
|
|
|
|
|
|
// We omit this check as it is not important for the hull algorithm
|
|
// BOOST_CHECK(bg::num_points(geometry) == size_original);
|
|
|
|
typename bg::default_area_result<Geometry>::type ah = bg::area(hull);
|
|
if (reverse)
|
|
{
|
|
ah = -ah;
|
|
}
|
|
|
|
BOOST_CHECK_CLOSE(ah, expected_area, 0.001);
|
|
}
|
|
|
|
template <typename Hull, typename Strategy, typename Geometry>
|
|
void test_convex_hull(Geometry const& geometry,
|
|
std::size_t size_original, std::size_t size_hull,
|
|
double expected_area,
|
|
bool reverse)
|
|
{
|
|
Hull hull;
|
|
|
|
// Test version with output iterator
|
|
bg::detail::convex_hull::convex_hull_insert(geometry, std::back_inserter(hull.outer()));
|
|
check_convex_hull(geometry, hull,
|
|
size_original, size_hull, expected_area, reverse);
|
|
|
|
// Test version with ring as output
|
|
bg::clear(hull);
|
|
bg::convex_hull(geometry, hull.outer());
|
|
check_convex_hull(geometry, hull, size_original, size_hull, expected_area, false);
|
|
|
|
// Test version with polygon as output
|
|
bg::clear(hull);
|
|
bg::convex_hull(geometry, hull);
|
|
check_convex_hull(geometry, hull, size_original, size_hull, expected_area, false);
|
|
|
|
// Test version with strategy
|
|
bg::clear(hull);
|
|
bg::convex_hull(geometry, hull.outer(), Strategy());
|
|
check_convex_hull(geometry, hull, size_original, size_hull, expected_area, false);
|
|
|
|
// Test version with output iterator and strategy
|
|
bg::clear(hull);
|
|
bg::detail::convex_hull::convex_hull_insert(geometry, std::back_inserter(hull.outer()), Strategy());
|
|
check_convex_hull(geometry, hull, size_original, size_hull, expected_area, reverse);
|
|
}
|
|
|
|
|
|
template <typename Geometry, bool Clockwise>
|
|
void test_geometry_order(std::string const& wkt,
|
|
std::size_t size_original, std::size_t size_hull,
|
|
double expected_area)
|
|
{
|
|
typedef bg::model::polygon
|
|
<
|
|
typename bg::point_type<Geometry>::type,
|
|
Clockwise
|
|
> hull_type;
|
|
|
|
typedef bg::strategy::convex_hull::graham_andrew
|
|
<
|
|
Geometry,
|
|
typename bg::point_type<Geometry>::type
|
|
> strategy_type;
|
|
|
|
Geometry geometry;
|
|
bg::read_wkt(wkt, geometry);
|
|
boost::variant<Geometry> v(geometry);
|
|
|
|
test_convex_hull<hull_type, strategy_type>(geometry, size_original, size_hull, expected_area, !Clockwise);
|
|
test_convex_hull<hull_type, strategy_type>(v, size_original, size_hull, expected_area, !Clockwise);
|
|
}
|
|
|
|
template <typename Geometry>
|
|
void test_geometry(std::string const& wkt,
|
|
std::size_t size_original, std::size_t size_hull,
|
|
double expected_area)
|
|
{
|
|
test_geometry_order<Geometry, true>(wkt, size_original, size_hull, expected_area);
|
|
test_geometry_order<Geometry, false>(wkt, size_original, size_hull, expected_area);
|
|
}
|
|
|
|
template <typename Geometry>
|
|
void test_empty_input()
|
|
{
|
|
Geometry geometry;
|
|
bg::model::polygon
|
|
<
|
|
typename bg::point_type<Geometry>::type
|
|
> hull;
|
|
|
|
bg::convex_hull(geometry, hull);
|
|
BOOST_CHECK_MESSAGE(bg::num_points(hull) == 0, "Output convex hull should be empty" );
|
|
}
|
|
|
|
|
|
|
|
#endif
|