mirror of
https://github.com/boostorg/geometry.git
synced 2025-05-09 23:24:02 +00:00
[buffer][test] split multi_point_buffer test into normal unit test
and robustness test (growth)
This commit is contained in:
parent
3c57ee2cae
commit
2f0b9d05bd
@ -69,141 +69,6 @@ void test_all()
|
||||
distance_strategy(0.54), side_strategy, point_strategy, 99);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
template
|
||||
<
|
||||
typename GeometryOut,
|
||||
template<typename, typename> class JoinStrategy,
|
||||
template<typename, typename> class EndStrategy,
|
||||
typename Geometry
|
||||
>
|
||||
double test_growth(Geometry const& geometry, int n, int d, double distance)
|
||||
{
|
||||
namespace bg = boost::geometry;
|
||||
|
||||
typedef typename bg::coordinate_type<Geometry>::type coordinate_type;
|
||||
typedef typename bg::point_type<Geometry>::type point_type;
|
||||
|
||||
// extern int point_buffer_count;
|
||||
std::ostringstream complete;
|
||||
complete
|
||||
<< "point" << "_"
|
||||
<< "growth" << "_"
|
||||
<< string_from_type<coordinate_type>::name()
|
||||
<< "_" << "r"
|
||||
<< "_" << n
|
||||
<< "_" << d
|
||||
// << "_" << point_buffer_count
|
||||
;
|
||||
|
||||
//std::cout << complete.str() << std::endl;
|
||||
|
||||
std::ostringstream filename;
|
||||
filename << "buffer_" << complete.str() << ".svg";
|
||||
|
||||
std::ofstream svg(filename.str().c_str());
|
||||
|
||||
#ifdef BOOST_GEOMETRY_DEBUG_WITH_MAPPER
|
||||
bg::svg_mapper<point_type> mapper(svg, 500, 500);
|
||||
|
||||
{
|
||||
bg::model::box<point_type> box;
|
||||
bg::envelope(geometry, box);
|
||||
|
||||
bg::buffer(box, box, distance * 1.01);
|
||||
mapper.add(box);
|
||||
}
|
||||
#endif
|
||||
|
||||
JoinStrategy
|
||||
<
|
||||
point_type,
|
||||
typename bg::point_type<GeometryOut>::type
|
||||
> join_strategy;
|
||||
EndStrategy
|
||||
<
|
||||
point_type,
|
||||
typename bg::point_type<GeometryOut>::type
|
||||
> end_strategy;
|
||||
|
||||
typedef bg::strategy::buffer::distance_symmetric<coordinate_type> distance_strategy_type;
|
||||
distance_strategy_type distance_strategy(distance);
|
||||
|
||||
std::vector<GeometryOut> buffered;
|
||||
|
||||
typedef typename bg::rescale_policy_type<point_type>::type
|
||||
rescale_policy_type;
|
||||
rescale_policy_type rescale_policy
|
||||
= bg::get_rescale_policy<rescale_policy_type>(geometry);
|
||||
|
||||
bg::detail::buffer::buffer_inserter<GeometryOut>(geometry,
|
||||
std::back_inserter(buffered),
|
||||
distance_strategy,
|
||||
join_strategy,
|
||||
end_strategy,
|
||||
rescale_policy
|
||||
#ifdef BOOST_GEOMETRY_DEBUG_WITH_MAPPER
|
||||
, mapper
|
||||
#endif
|
||||
);
|
||||
|
||||
typename bg::default_area_result<GeometryOut>::type area = 0;
|
||||
BOOST_FOREACH(GeometryOut const& polygon, buffered)
|
||||
{
|
||||
area += bg::area(polygon);
|
||||
}
|
||||
|
||||
#ifdef BOOST_GEOMETRY_DEBUG_WITH_MAPPER
|
||||
// Map input geometry in green
|
||||
mapper.map(geometry, "opacity:0.5;fill:rgb(0,128,0);stroke:rgb(0,128,0);stroke-width:10");
|
||||
|
||||
BOOST_FOREACH(GeometryOut const& polygon, buffered)
|
||||
{
|
||||
mapper.map(polygon, "opacity:0.4;fill:rgb(255,255,128);stroke:rgb(0,0,0);stroke-width:3");
|
||||
}
|
||||
#endif
|
||||
|
||||
return area;
|
||||
}
|
||||
|
||||
template <typename P>
|
||||
void test_growth(int n, int distance_count)
|
||||
{
|
||||
srand(int(time(NULL)));
|
||||
//std::cout << typeid(bg::coordinate_type<P>::type).name() << std::endl;
|
||||
boost::timer t;
|
||||
|
||||
namespace buf = bg::strategy::buffer;
|
||||
typedef bg::model::polygon<P> polygon;
|
||||
typedef bg::model::multi_point<P> multi_point_type;
|
||||
|
||||
multi_point_type multi_point;
|
||||
for (int i = 0; i < n; i++)
|
||||
{
|
||||
P point(rand() % 100, rand() % 100);
|
||||
multi_point.push_back(point);
|
||||
}
|
||||
|
||||
//std::cout << bg::wkt(multi_point) << std::endl;
|
||||
|
||||
double previous_area = 0;
|
||||
double epsilon = 0.1;
|
||||
double distance = 15.0;
|
||||
for (int d = 0; d < distance_count; d++, distance += epsilon)
|
||||
{
|
||||
double area = test_growth<polygon, buf::join_miter, buf::end_round>(multi_point, n, d, distance);
|
||||
if (area < previous_area)
|
||||
{
|
||||
std::cout << "Error: " << area << " < " << previous_area << std::endl
|
||||
<< " n=" << n << " distance=" << distance
|
||||
<< bg::wkt(multi_point) << std::endl;
|
||||
}
|
||||
previous_area = area;
|
||||
}
|
||||
std::cout << "n=" << n << " time=" << t.elapsed() << std::endl;
|
||||
}
|
||||
|
||||
int test_main(int, char* [])
|
||||
@ -211,13 +76,5 @@ int test_main(int, char* [])
|
||||
test_all<true, bg::model::point<double, 2, bg::cs::cartesian> >();
|
||||
test_all<false, bg::model::point<double, 2, bg::cs::cartesian> >();
|
||||
|
||||
|
||||
#ifdef BOOST_GEOMETRY_BUFFER_TEST_GROWTH
|
||||
for (int i = 5; i <= 50; i++)
|
||||
{
|
||||
test_growth<bg::model::point<double, 2, bg::cs::cartesian> >(i, 20);
|
||||
}
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
139
test/robustness/overlay/buffer/multi_point_growth.cpp
Normal file
139
test/robustness/overlay/buffer/multi_point_growth.cpp
Normal file
@ -0,0 +1,139 @@
|
||||
// Boost.Geometry (aka GGL, Generic Geometry Library)
|
||||
// Performance Test
|
||||
|
||||
// Copyright (c) 2012-2015 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)
|
||||
|
||||
#include <boost/geometry.hpp>
|
||||
#include <boost/geometry/multi/geometries/multi_geometries.hpp>
|
||||
|
||||
#include <boost/foreach.hpp>
|
||||
#include <boost/timer.hpp>
|
||||
#include <fstream>
|
||||
|
||||
|
||||
namespace bg = boost::geometry;
|
||||
|
||||
template
|
||||
<
|
||||
typename GeometryOut,
|
||||
typename Geometry
|
||||
>
|
||||
double test_growth(Geometry const& geometry, int n, int d, double distance)
|
||||
{
|
||||
|
||||
typedef typename bg::coordinate_type<Geometry>::type coordinate_type;
|
||||
typedef typename bg::point_type<Geometry>::type point_type;
|
||||
|
||||
// extern int point_buffer_count;
|
||||
std::ostringstream complete;
|
||||
complete
|
||||
<< "point_growth"
|
||||
<< "_" << "r"
|
||||
<< "_" << n
|
||||
<< "_" << d
|
||||
// << "_" << point_buffer_count
|
||||
;
|
||||
|
||||
//std::cout << complete.str() << std::endl;
|
||||
|
||||
std::ostringstream filename;
|
||||
filename << "buffer_" << complete.str() << ".svg";
|
||||
|
||||
std::ofstream svg(filename.str().c_str());
|
||||
|
||||
#ifdef BOOST_GEOMETRY_DEBUG_WITH_MAPPER
|
||||
bg::svg_mapper<point_type> mapper(svg, 500, 500);
|
||||
|
||||
{
|
||||
bg::model::box<point_type> box;
|
||||
bg::envelope(geometry, box);
|
||||
|
||||
bg::buffer(box, box, distance * 1.01);
|
||||
mapper.add(box);
|
||||
}
|
||||
#endif
|
||||
|
||||
bg::strategy::buffer::join_round join_strategy(100);
|
||||
bg::strategy::buffer::end_flat end_strategy;
|
||||
bg::strategy::buffer::point_circle point_strategy;
|
||||
bg::strategy::buffer::side_straight side_strategy;
|
||||
|
||||
typedef bg::strategy::buffer::distance_symmetric<coordinate_type> distance_strategy_type;
|
||||
distance_strategy_type distance_strategy(distance);
|
||||
|
||||
std::vector<GeometryOut> buffered;
|
||||
|
||||
bg::buffer(geometry, buffered,
|
||||
distance_strategy, side_strategy,
|
||||
join_strategy, end_strategy, point_strategy);
|
||||
|
||||
|
||||
typename bg::default_area_result<GeometryOut>::type area = 0;
|
||||
BOOST_FOREACH(GeometryOut const& polygon, buffered)
|
||||
{
|
||||
area += bg::area(polygon);
|
||||
}
|
||||
|
||||
#ifdef BOOST_GEOMETRY_DEBUG_WITH_MAPPER
|
||||
// Map input geometry in green
|
||||
mapper.map(geometry, "opacity:0.5;fill:rgb(0,128,0);stroke:rgb(0,128,0);stroke-width:10");
|
||||
|
||||
BOOST_FOREACH(GeometryOut const& polygon, buffered)
|
||||
{
|
||||
mapper.map(polygon, "opacity:0.4;fill:rgb(255,255,128);stroke:rgb(0,0,0);stroke-width:3");
|
||||
}
|
||||
#endif
|
||||
|
||||
return area;
|
||||
}
|
||||
|
||||
template <typename P>
|
||||
void test_growth(int n, int distance_count)
|
||||
{
|
||||
srand(int(time(NULL)));
|
||||
//std::cout << typeid(bg::coordinate_type<P>::type).name() << std::endl;
|
||||
boost::timer t;
|
||||
|
||||
namespace buf = bg::strategy::buffer;
|
||||
typedef bg::model::polygon<P> polygon;
|
||||
typedef bg::model::multi_point<P> multi_point_type;
|
||||
|
||||
multi_point_type multi_point;
|
||||
for (int i = 0; i < n; i++)
|
||||
{
|
||||
P point(rand() % 100, rand() % 100);
|
||||
multi_point.push_back(point);
|
||||
}
|
||||
|
||||
//std::cout << bg::wkt(multi_point) << std::endl;
|
||||
|
||||
double previous_area = 0;
|
||||
double epsilon = 0.1;
|
||||
double distance = 15.0;
|
||||
for (int d = 0; d < distance_count; d++, distance += epsilon)
|
||||
{
|
||||
double area = test_growth<polygon>(multi_point, n, d, distance);
|
||||
if (area < previous_area)
|
||||
{
|
||||
std::cout << "Error: " << area << " < " << previous_area << std::endl
|
||||
<< " n=" << n << " distance=" << distance
|
||||
<< bg::wkt(multi_point) << std::endl;
|
||||
}
|
||||
previous_area = area;
|
||||
}
|
||||
std::cout << "n=" << n << " time=" << t.elapsed() << std::endl;
|
||||
}
|
||||
|
||||
int main(int, char* [])
|
||||
{
|
||||
for (int i = 5; i <= 50; i++)
|
||||
{
|
||||
test_growth<bg::model::point<double, 2, bg::cs::cartesian> >(i, 20);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user