[linear linear]: remove assertion/exception (it's fragile), adapt test and fix test svg creation

This commit is contained in:
Barend Gehrels 2021-11-03 14:51:56 +01:00
parent 34b9353fea
commit 4a62f77853
7 changed files with 81 additions and 58 deletions

View File

@ -334,14 +334,10 @@ public:
strategy);
}
#if ! defined(BOOST_GEOMETRY_OVERLAY_NO_THROW)
if (enter_count != 0)
{
BOOST_THROW_EXCEPTION(inconsistent_turns_exception());
return oit;
}
#else
BOOST_GEOMETRY_ASSERT(enter_count == 0);
#endif
return process_end(entered, linestring,
current_segment_id, current_piece,

View File

@ -240,12 +240,12 @@ struct areal_areal
std::deque<turn_info> turns;
detail::touches::areal_interrupt_policy policy;
boost::geometry::get_turns
<
detail::overlay::do_reverse<geometry::point_order<Geometry1>::value>::value,
detail::overlay::do_reverse<geometry::point_order<Geometry2>::value>::value,
detail::overlay::assign_null_policy
>(geometry1, geometry2, strategy, detail::no_rescale_policy(), turns, policy);
geometry::get_turns
<
detail::overlay::do_reverse<geometry::point_order<Geometry1>::value>::value,
detail::overlay::do_reverse<geometry::point_order<Geometry2>::value>::value,
detail::overlay::assign_null_policy
>(geometry1, geometry2, strategy, detail::no_rescale_policy(), turns, policy);
return policy.result()
&& ! geometry::detail::touches::rings_containing(geometry1, geometry2, strategy)

View File

@ -18,6 +18,7 @@
#define BOOST_GEOMETRY_DEBUG_SEGMENT_IDENTIFIER
#endif
#include "geometry_test_common.hpp"
#include <boost/test/included/unit_test.hpp>
#include "test_intersection_linear_linear.hpp"
@ -1271,9 +1272,16 @@ BOOST_AUTO_TEST_CASE( test_intersection_ml_ml_degenerate )
tester::apply
(from_wkt<ML>("MULTILINESTRING((1 5, -4.3 -.1), (0 6, 8.6 6, 189.7654 5, 1 3, 6 3, 3 5, 6 2.232432, 0 4), (-6 5, 1 2.232432), (3 -1032.34324, 9 0, 189.7654 1, -1.4 3, 3 189.7654, +.3 10.0002, 1 5, 6 3, 5 1, 9 1, 10.0002 -1032.34324, -0.7654 0, 5 3, 3 4), (2.232432 2.232432, 8.6 +.4, 0.0 2.232432, 4 0, -8.8 10.0002), (1 0, 6 6, 7 2, -0 8.4), (-0.7654 3, +.6 8, 4 -1032.34324, 1 6, 0 4), (0 7, 2 1, 8 -7, 7 -.7, -1032.34324 9), (5 0, 10.0002 4, 8 7, 3 3, -8.1 5))"),
from_wkt<ML>("MULTILINESTRING((5 10.0002, 2 7, -0.7654 0, 5 3), (0 -0.7654, 4 10.0002, 4 +.1, -.8 3, -.1 8, 10.0002 2, +.9 -1032.34324))"),
#ifdef BOOST_GEOMETRY_INTERSECTION_DO_NOT_INCLUDE_ISOLATED_POINTS
from_wkt<ML>("MULTILINESTRING((-0.7654 8.88178e-16,-0.7654 0,5 3))"),
#ifdef BOOST_GEOMETRY_NO_ROBUSTNESS
#if BOOST_GEOMETRY_INTERSECTION_DO_NOT_INCLUDE_ISOLATED_POINTS
from_wkt<ML>("MULTILINESTRING()"),
#else
from_wkt<ML>("MULTILINESTRING((1.87562 6.68515,1.87562 6.68515),(1.60494 6,1.60494 6),(1.18124 4.9275,1.18124 4.9275),(1.00439 4.47984,1.00439 4.47984),(0.91526 4.25422,0.91526 4.25422),(0.729883 3.78498,0.729883 3.78498),(0.614728 3.49349,0.614728 3.49349),(0.591231 3.43401,0.591231 3.43401),(0.412281 2.98104,0.412281 2.98104),(0.358522 2.84496,0.358522 2.84496),(0.235887 2.53454,0.235887 2.53454),(0.10749 2.20953,0.10749 2.20953),(0.0954852 2.17914,0.0954852 2.17914),(-0.7654 8.88178e-16,-0.7654 8.88178e-16),(0.623783 0.722855,0.623783 0.722855),(1.01466 0.926246,1.01466 0.926246),(1.70073 1.28324,1.70073 1.28324),(1.87531 1.37408,1.87531 1.37408),(2.09493 1.48836,2.09493 1.48836),(2.3516 1.62191,2.3516 1.62191),(2.50083 1.69957,2.50083 1.69957),(3.06464 1.99294,3.06464 1.99294),(4.41962 2.698,4.41962 2.698),(4.87386 2.93436,4.87386 2.93436),(5 3,5 3),(5 3,5 3),(0.0484053 -0.635122,0.0484053 -0.635122),(0.535994 0.677175,0.535994 0.677175),(0.623165 0.911787,0.623165 0.911787),(0.92255 1.71755,0.92255 1.71755),(1.01168 1.95744,1.01168 1.95744),(1.03214 2.01251,1.03214 2.01251),(1.12031 2.2498,1.12031 2.2498),(1.36441 2.90677,1.36441 2.90677),(1.38821 2.97083,1.38821 2.97083),(1.39905 3,1.39905 3),(1.40063 3.00424,1.40063 3.00424),(1.4995 3.27036,1.4995 3.27036),(1.59592 3.52985,1.59592 3.52985),(1.99437 4.60225,1.99437 4.60225),(2.51371 6,2.51371 6),(2.54193 6.07595,2.54193 6.07595),(4 6,4 6),(4 4.74286,4 4.74286),(4 4.33333,4 4.33333),(4 4.07748,4 4.07748),(4 3.8,4 3.8),(4 3.8,4 3.8),(4 3.6,4 3.6),(4 3.5,4 3.5),(4 3.03179,4 3.03179),(4 3,4 3),(4 2.9435,4 2.9435),(4 2.82162,4 2.82162),(4 2.47965,4 2.47965),(4 1.72377,4 1.72377),(4 1.38014,4 1.38014),(3.43534 0.441146,3.43534 0.441146),(2.06005 1.27206,2.06005 1.27206),(1.88383 1.37852,1.88383 1.37852),(1.8713 1.38609,1.8713 1.38609),(1.01183 1.90535,1.01183 1.90535),(0.72677 2.07758,0.72677 2.07758),(0.619143 2.1426,0.619143 2.1426),(-0.532243 2.83823,-0.532243 2.83823),(-0.789427 2.99361,-0.789427 2.99361),(-0.756651 3.30964,-0.756651 3.30964),(-0.706503 3.66784,-0.706503 3.66784),(-0.705343 3.67612,-0.705343 3.67612),(0.502294 7.64221,0.502294 7.64221),(0.601362 7.58336,0.601362 7.58336),(0.641699 7.5594,0.641699 7.5594),(1.43457 7.08839,1.43457 7.08839),(3.26673 6,3.26673 6),(5.09496 4.91395,5.09496 4.91395),(5.26567 4.81254,5.26567 4.81254),(6.47672 4.09311,6.47672 4.09311),(8.18862 3.07616,8.18862 3.07616),(8.49103 2.89652,8.49103 2.89652),(8.5655 2.85228,8.5655 2.85228),(9.98265 0.00543606,9.98265 0.00543606),(9.09826 -100.516,9.09826 -100.516),(7.08745 -329.067,7.08745 -329.067),(5.06428 -559.024,5.06428 -559.024),(3.23365 -767.097,3.23365 -767.097),(3.16036 -775.427,3.16036 -775.427))"),
#endif
#else
#if BOOST_GEOMETRY_INTERSECTION_DO_NOT_INCLUDE_ISOLATED_POINTS
from_wkt<ML>("MULTILINESTRING((-0.7654 8.88178e-16,-0.7654 0,5 3))"),
#else
from_wkt<ML>("MULTILINESTRING((-0.756651 3.30964),(1.60494 6),\
(2.51371 6),(3.26673 6),(4 6),(8.18862 3.07616),\
(4 3.03179),(1.40063 3.00424),(1.39905 3),\
@ -1341,7 +1349,8 @@ BOOST_AUTO_TEST_CASE( test_intersection_ml_ml_degenerate )
(7.08745 -329.0674155),(5.06428 -559.024344),\
(3.23365 -767.0972558),(3.16036 -775.427199),\
(-0.7654 8.88178e-16,-0.7654 0,5 3))"),
#endif
#endif // isolated
#endif // rescaled
"mlmli21",
1e-4
);
@ -1361,6 +1370,8 @@ BOOST_AUTO_TEST_CASE( test_intersection_ml_ml_spikes )
std::cout << std::endl;
#endif
BoostGeometryWriteTestConfiguration();
typedef multi_linestring_type ML;
typedef test_intersection_of_geometries<ML, ML, ML> tester;
@ -1599,7 +1610,7 @@ BOOST_AUTO_TEST_CASE( test_intersection_ml_ml_spikes )
"mlmli-spikes-17"
);
// test cases sent by Adam on the mailing list (equal slikes)
// test cases sent by Adam on the mailing list (equal spikes)
tester::apply
(from_wkt<ML>("MULTILINESTRING((0 0,1 1,0 0))"),
from_wkt<ML>("MULTILINESTRING((0 0,1 1,0 0))"),

View File

@ -39,11 +39,11 @@ inline void check_result(Geometry1 const& geometry1,
BOOST_CHECK_MESSAGE( equals::apply(mls_int1, mls_output, tolerance)
|| equals::apply(mls_int2, mls_output, tolerance),
"case id: " << case_id
<< ", intersection L/L: " << bg::wkt(geometry1)
<< " " << bg::wkt(geometry2)
<< " -> Expected: " << bg::wkt(mls_int1)
<< " or: " << bg::wkt(mls_int2)
<< " computed: " << bg::wkt(mls_output) );
<< " Expected: len=" << bg::length(mls_int1) << " count=" << bg::num_points(mls_int1)
<< " or: len=" << bg::length(mls_int2) << " count=" << bg::num_points(mls_int2)
<< " Detected: len=" << bg::length(mls_output) << " count=" << bg::num_points(mls_output)
<< " wkt=" << bg::wkt(mls_output)
);
}
template
@ -76,13 +76,18 @@ private:
// Check normal behaviour
bg::intersection(geometry1, geometry2, mls_output);
#ifdef TEST_WITH_SVG
to_svg(geometry1, geometry2, mls_output, case_id);
#endif
check_result(geometry1, geometry2, mls_output, mls_int1, mls_int2, case_id, tolerance);
// Check strategy passed explicitly
typedef typename bg::strategy::relate::services::default_strategy
using strategy_type
= typename bg::strategy::relate::services::default_strategy
<
Geometry1, Geometry2
>::type strategy_type;
>::type ;
bg::clear(mls_output);
bg::intersection(geometry1, geometry2, mls_output, strategy_type());
@ -198,11 +203,6 @@ public:
{
#ifdef BOOST_GEOMETRY_TEST_DEBUG
std::cout << "test case: " << case_id << std::endl;
std::stringstream sstr;
sstr << "svgs/" << case_id << ".svg";
#ifdef TEST_WITH_SVG
to_svg(geometry1, geometry2, sstr.str());
#endif
#endif
Geometry1 rg1(geometry1);

View File

@ -309,7 +309,7 @@ void set_operation_output(std::string const& set_op_id,
mapper.map(g2, "stroke-opacity:1;stroke:rgb(153,204,0);stroke-width:4");
mapper.map(g1, "stroke-opacity:1;stroke:rgb(51,51,153);stroke-width:2");
BOOST_AUTO_TPL(it, output.begin());
auto it = output.begin();
for (; it != output.end(); ++it)
{
if ( boost::size(*it) == 2

View File

@ -12,7 +12,6 @@
#include <from_wkt.hpp>
#include <to_svg.hpp>
#include <algorithm>
#include <fstream>

View File

@ -26,6 +26,7 @@
#include <boost/geometry/io/svg/svg_mapper.hpp>
#include <boost/geometry/io/wkt/read.hpp>
#include <string_from_type.hpp>
template <typename G, typename Turns, typename Mapper>
inline void turns_to_svg(Turns const& turns, Mapper & mapper, bool /*enrich*/ = false)
@ -281,12 +282,10 @@ inline void to_svg(G const& g, std::string const& filename, bool /*sort*/ = true
mapper.map(g, "fill-opacity:0.5;fill:rgb(153,204,0);"
"stroke:rgb(153,204,0);stroke-width:3");
// GET TURNS
typedef bg::segment_ratio<double> sr;
typedef bg::detail::overlay::traversal_turn_info<P, sr> turn_info;
typedef bg::detail::overlay::assign_null_policy AssignPolicy;
//typedef to_svg_assign_policy AssignPolicy;
//typedef to_svg_assign_policy AssignPolicy;
typedef std::deque<turn_info> Turns;
typedef bg::detail::self_get_turn_points::no_interrupt_policy InterruptPolicy;
@ -304,58 +303,76 @@ inline void to_svg(G const& g, std::string const& filename, bool /*sort*/ = true
turns_to_svg<G>(turns, mapper);
}
template <typename G1, typename G2>
inline void to_svg(G1 const& g1, G2 const& g2, std::string const& filename, bool sort = true, bool use_old_turns_policy = false, bool enrich = false)
template <typename G1, typename G2, typename G3>
inline void to_svg(G1 const& g1, G2 const& g2, G3 const& g3,
std::string const& caseid, bool sort = true, bool use_old_turns_policy = false, bool enrich = false)
{
namespace bg = boost::geometry;
typedef typename bg::point_type<G1>::type mapper_point_type;
using point_type = typename bg::point_type<G1>::type;
using coordinate_type = typename bg::coordinate_type<point_type>::type;
std::ofstream svg(filename.c_str(), std::ios::trunc);
std::ostringstream filename;
filename << "union_"
<< caseid << "_"
<< string_from_type<coordinate_type>::name()
#if defined(BOOST_GEOMETRY_USE_RESCALING)
<< "_rescaled"
#endif
<< ".svg";
bg::svg_mapper<mapper_point_type> mapper(svg, 500, 500);
std::ofstream svg(filename.str());
bg::svg_mapper<point_type> mapper(svg, 500, 500);
mapper.add(g1);
mapper.add(g2);
mapper.add(g3);
mapper.map(g1, "fill-opacity:0.5;fill:rgb(153,204,0);"
"stroke:rgb(153,204,0);stroke-width:3");
mapper.map(g2, "fill-opacity:0.3;fill:rgb(51,51,153);"
"stroke:rgb(51,51,153);stroke-width:3");
mapper.map(g1, "fill-opacity:0.5;fill:rgb(153,204,0);stroke:rgb(153,204,0);stroke-width:1;stroke-opacity:0.7;");
mapper.map(g2, "fill-opacity:0.3;fill:rgb(51,51,153);stroke:rgb(51,51,153);stroke-width:1;stroke-opacity:0.7;");
mapper.map(g3, "fill-opacity:0.5;fill:rgb(255,0,0);stroke:rgb(255,0,0);stroke-width:1;stroke-opacity:0.7;");
// GET TURNS
typedef typename bg::detail::relate::turns::get_turns<G1, G2>::turn_info turn_info;
//typedef bg::detail::overlay::traversal_turn_info<P1> turn_info;
//typedef bg::detail::overlay::assign_null_policy AssignPolicy;
typedef to_svg_assign_policy AssignPolicy;
using strategy_type
= typename bg::strategies::relate::services::default_strategy
<G1, G2>::type;
typedef std::deque<turn_info> Turns;
typedef bg::detail::get_turns::no_interrupt_policy InterruptPolicy;
static const bool Reverse1 = bg::detail::overlay::do_reverse<bg::point_order<G1>::value>::value;
static const bool Reverse2 = bg::detail::overlay::do_reverse<bg::point_order<G2>::value>::value;
using ratio_type = bg::segment_ratio<coordinate_type>;
Turns turns;
InterruptPolicy interrupt_policy;
using turn_type = bg::detail::overlay::turn_info
<
point_type,
ratio_type,
bg::detail::overlay::turn_operation_linear<point_type, ratio_type>
>;
if ( use_old_turns_policy )
strategy_type strategy;
std::deque<turn_type> turns;
bg::detail::get_turns::no_interrupt_policy interrupt_policy;
if (use_old_turns_policy)
{
boost::geometry::get_turns
static const bool Reverse1 = bg::detail::overlay::do_reverse<bg::point_order<G1>::value>::value;
static const bool Reverse2 = bg::detail::overlay::do_reverse<bg::point_order<G2>::value>::value;
bg::get_turns
<
Reverse1, Reverse2, AssignPolicy
>(g1, g2, bg::detail::no_rescale_policy(), turns, interrupt_policy);
Reverse1, Reverse2, to_svg_assign_policy
>(g1, g2, strategy, bg::detail::no_rescale_policy(), turns, interrupt_policy);
}
else
{
typedef bg::detail::get_turns::get_turn_info_type
<
G1, G2, AssignPolicy
G1, G2, to_svg_assign_policy
> TurnPolicy;
bg::detail::relate::turns::get_turns
<
G1, G2, TurnPolicy
>::apply(turns, g1, g2);
>::apply(turns, g1, g2, interrupt_policy, strategy);
}
if ( sort )
@ -387,7 +404,7 @@ inline void to_svg(G1 const& g1, G2 const& g2, std::string const& filename, bool
side_strategy_type());
}*/
turns_to_svg<G1>(turns, mapper, enrich);
turns_to_svg<G1>(turns, mapper, enrich);
}
template <typename G>