Added multi/closure.hpp

Added point_order/closure/difference to robustness tests (partly)

[SVN r67397]
This commit is contained in:
Barend Gehrels 2010-12-21 21:44:38 +00:00
parent 97245d28ba
commit a1963d328a
7 changed files with 80 additions and 53 deletions

View File

@ -58,6 +58,7 @@ inline void make_pie(Polygon& polygon,
bg::exterior_ring(polygon).push_back(bg::make<p>(int(x), int(y)));
}
bg::exterior_ring(polygon).push_back(bg::make<p>(int(cx), int(cy)));
bg::correct(polygon);
}
@ -132,13 +133,13 @@ inline void holify_multi(MultiPolygon& multi_polygon)
template <typename T>
template <typename T, bool Clockwise, bool Closed>
void test_pie(int total_segment_count, T factor_p, T factor_q,
bool multi, bool multi_st, bool svg)
bool multi, bool single_selftangent, bool svg)
{
boost::timer t;
typedef bg::model::d2::point_xy<T> point_type;
typedef bg::model::polygon<point_type> polygon;
typedef bg::model::polygon<point_type, Clockwise, Closed> polygon;
typedef bg::model::multi_polygon<polygon> multi_polygon;
int good_count = 0;
@ -193,7 +194,7 @@ void test_pie(int total_segment_count, T factor_p, T factor_q,
bool good = false;
// Represent as either multi-polygon, or as single-self-touching-polygon (INVALID)
if (multi_st)
if (single_selftangent)
{
polygon q1 = q;
for (unsigned int i = 1; i < q2.outer().size(); i++)
@ -233,10 +234,10 @@ void test_pie(int total_segment_count, T factor_p, T factor_q,
}
template <typename T>
void test_all(bool multi, bool multi_st, bool svg)
template <typename T, bool Clockwise, bool Closed>
void test_all(bool multi, bool single_selftangent, bool svg)
{
test_pie<T>(24, 0.55, 0.45, multi, multi_st, svg);
test_pie<T, Clockwise, Closed>(24, 0.55, 0.45, multi, single_selftangent, svg);
}
int main(int argc, char** argv)
@ -244,9 +245,19 @@ int main(int argc, char** argv)
try
{
bool svg = argc > 1 && std::string(argv[1]) == std::string("svg");
bool multi = argc > 2 && std::string(argv[2]) == std::string("multi");
bool ccw = argc > 3 && std::string(argv[3]) == std::string("ccw");
bool single_selftangent = false; // keep false, true does not work!
//test_all<float>();
test_all<double>(true, false, svg);
// template par's are: CoordinateType, Clockwise, Closed
if (ccw)
{
test_all<double, false, true>(multi, single_selftangent, svg);
}
else
{
test_all<double, true, true>(multi, single_selftangent, svg);
}
//test_all<long double>();
}
catch(std::exception const& e)

View File

@ -26,14 +26,13 @@
#include <boost/geometry/geometry.hpp>
#include <boost/geometry/multi/multi.hpp>
//#include <boost/geometry/multi/algorithms/detail/overlay/assemble.hpp>
#include <boost/geometry/multi/geometries/multi_polygon.hpp>
#include <boost/geometry/extensions/gis/io/wkt/wkt.hpp>
#include <boost/geometry/extensions/io/svg/svg_mapper.hpp>
template <typename Polygon, typename Generator>
inline void make_box(Polygon& polygon, Generator& generator)
inline void make_polygon(Polygon& polygon, Generator& generator)
{
typedef typename bg::point_type<Polygon>::type point_type;
typedef typename bg::coordinate_type<Polygon>::type coordinate_type;
@ -76,8 +75,10 @@ bool test_recursive_boxes(MultiPolygon& result, int& index,
{
p.resize(1);
q.resize(1);
make_box(p.front(), generator);
make_box(q.front(), generator);
make_polygon(p.front(), generator);
make_polygon(q.front(), generator);
bg::correct(p);
bg::correct(q);
}
else
{
@ -112,11 +113,12 @@ bool test_recursive_boxes(MultiPolygon& result, int& index,
bg::unique(mp);
//result = mp;
bg::simplify(mp, result, 0.01);
bg::correct(mp);
return true;
}
template <typename T>
template <typename T, bool Clockwise>
void test_all(int seed, int count, bool svg, int level)
{
boost::timer t;
@ -131,7 +133,7 @@ void test_all(int seed, int count, bool svg, int level)
typedef bg::model::polygon
<
bg::model::d2::point_xy<T>
bg::model::d2::point_xy<T>, Clockwise
//, true, false
> polygon;
typedef bg::model::multi_polygon<polygon> mp;
@ -153,6 +155,8 @@ int main(int argc, char** argv)
{
try
{
// Arguments:
// {count} {seed} {"svg"} {level}
int count = argc > 1 ? boost::lexical_cast<int>(argv[1]) : 10;
int seed = (argc > 2 && std::string(argv[2]) != std::string("#"))
? boost::lexical_cast<int>(argv[2])
@ -162,7 +166,7 @@ int main(int argc, char** argv)
? boost::lexical_cast<int>(argv[4]): 3;
//test_all<float>(seed, count, svg, 1e-3);
test_all<double>(seed, count, svg, level);
test_all<double, false>(seed, count, svg, level);
#if defined(HAVE_TTMATH)
// test_recursive_boxes<ttmath_big>(selection, "t");

View File

@ -37,42 +37,35 @@ static bool test_overlay_p_q(std::string const& caseid,
typedef typename bg::coordinate_type<G1>::type coordinate_type;
typedef typename bg::point_type<G1>::type point_type;
typedef bg::detail::overlay::turn_info<point_type> turn_type;
typedef bg::strategy_intersection
<
typename bg::cs_tag<point_type>::type,
G1,
G2,
turn_type,
CalculationType
> strategy;
std::vector<OutputType> out_i, out_u;
bg::model::multi_polygon<OutputType> out_i, out_u, out_d;
CalculationType area_p = bg::area(p);
CalculationType area_q = bg::area(q);
CalculationType area_i = 0;
CalculationType area_u = 0;
bg::intersection(p, q, out_i);
CalculationType area_i = bg::area(out_i);
bg::union_(p, q, out_u);
CalculationType area_u = bg::area(out_u);
double sum = (area_p + area_q) - area_u - area_i;
bool wrong = std::abs(sum) > tolerance;
#ifdef USE_DIFFERENCE
bg::difference(p, q, out_d);
CalculationType area_d = bg::area(out_d);
double sum_d = (area_u - area_q) - area_d;
bool wrong_d = std::abs(sum_d) > tolerance;
if (wrong_d)
{
wrong = true;
}
#endif
bg::intersection_inserter<OutputType>(p, q, std::back_inserter(out_i), strategy());
for (typename std::vector<OutputType>::iterator it = out_i.begin();
it != out_i.end();
++it)
{
area_i += bg::area(*it);
}
bg::union_inserter<OutputType>(p, q, std::back_inserter(out_u), strategy());
for (typename std::vector<OutputType>::iterator it = out_u.begin();
it != out_u.end();
++it)
{
area_u += bg::area(*it);
}
double diff = (area_p + area_q) - area_u - area_i;
bool wrong = std::abs(diff) > tolerance;
if (wrong || force_output)
{
if (wrong)
@ -88,7 +81,11 @@ static bool test_overlay_p_q(std::string const& caseid,
<< " area u: " << area_u
<< " area p: " << area_p
<< " area q: " << area_q
<< " diff: " << diff
<< " sum: " << sum
#ifdef USE_DIFFERENCE
<< " area d: " << area_d
<< " sum d: " << sum_d
#endif
<< std::endl
<< std::setprecision(20)
<< " p: " << bg::wkt(p) << std::endl
@ -119,19 +116,23 @@ static bool test_overlay_p_q(std::string const& caseid,
mapper.map(q, "fill-opacity:0.3;fill:rgb(51,51,153);"
"stroke:rgb(51,51,153);stroke-width:3");
for (typename std::vector<OutputType>::const_iterator it = out_i.begin();
it != out_i.end(); ++it)
for (BOOST_AUTO(it, out_i.begin()); it != out_i.end(); ++it)
{
mapper.map(*it, "fill-opacity:0.1;stroke-opacity:0.4;fill:rgb(255,0,0);"
"stroke:rgb(255,0,0);stroke-width:4");
}
for (typename std::vector<OutputType>::const_iterator it = out_u.begin();
it != out_u.end(); ++it)
for (BOOST_AUTO(it, out_u.begin()); it != out_u.end(); ++it)
{
mapper.map(*it, "fill-opacity:0.1;stroke-opacity:0.4;fill:rgb(255,0,0);"
"stroke:rgb(255,0,255);stroke-width:4");
}
#ifdef USE_DIFFERENCE
for (BOOST_AUTO(it, out_d.begin()); it != out_d.end(); ++it)
{
mapper.map(*it, "fill-opacity:0.1;stroke-opacity:0.4;fill:rgb(255,255,0);"
"stroke:rgb(255,255,0);stroke-width:4");
}
#endif
}
return result;
}

View File

@ -27,6 +27,9 @@ static std::string identical[2] =
{"POLYGON((0 0,0 1,1 1,1 0,0 0))",
"POLYGON((1 1,1 0,0 0,0 1,1 1))"};
static std::string disjoint[2] =
{"POLYGON((3 0,3 1,4 1,4 0,3 0))",
"POLYGON((3 4,3 5,4 5,4 4,3 4))"};
static std::string new_hole[2] =
{"POLYGON((2 2,2 5,5 5,5 2,2 2))",

View File

@ -61,6 +61,10 @@ void test_areal()
test_one<Polygon, Polygon, Polygon>("identical",
identical[0], identical[1], 1, 0, 5, 1.0);
// disjoint
test_one<Polygon, Polygon, Polygon>("disjoint",
disjoint[0], disjoint[1], 2, 0, 10, 2.0);
// inside each other, having intersections; holes separate intersections
test_one<Polygon, Polygon, Polygon>("intersect_holes_intersect",
intersect_holes_intersect[0], intersect_holes_intersect[1],
@ -223,8 +227,10 @@ void test_all()
typedef bg::model::box<P> box;
test_areal<ring, polygon>();
// Open
test_areal<bg::model::linear_ring<P, true, false>, bg::model::polygon<P, true, false> >();
// Counter clockwise
test_areal<bg::model::linear_ring<P, false>, bg::model::polygon<P, false> >();

View File

@ -45,7 +45,9 @@ namespace boost { namespace geometry { namespace traits {
// by specializing the "use_std" traits to false.
// It should therefore implement the traits:: clear / append_point
template <typename P>
struct custom_linestring2 : std::deque<P> {};
struct custom_linestring2 : std::deque<P> // std::pair<typename std::vector<P>::const_iterator, typename std::vector<P>::const_iterator>
{
};
namespace boost { namespace geometry { namespace traits {
template <typename P>

View File

@ -150,7 +150,7 @@ void test_all()
typedef bg::model::linear_ring<P, true, false> ring_open;
typedef bg::model::polygon<P, true, false> polygon_open;
typedef bg::model::multi_polygon<polygon_open> multi_polygon_open;
// TODO: enable next combination (bug somewhere in get_turns with open polygon)
// TODO: fix next combination (bug somewhere in probably assemble, with open polygon)
//test_areal<ring_open, polygon_open, multi_polygon_open>();
test_areal_clip<polygon, multi_polygon, box>();