[sort_by_side] walk forward for point_to

(similarly to walking backwards for point_from)
This commit is contained in:
Barend Gehrels 2020-12-16 14:29:15 +01:00
parent 4e8ff81131
commit 59e0840d75
2 changed files with 19 additions and 10 deletions

View File

@ -316,7 +316,7 @@ public :
}
template <typename Operation, typename Geometry1, typename Geometry2>
static Point walk_back(Operation const& op, int offset,
static Point walk_over_ring(Operation const& op, int offset,
Geometry1 const& geometry1,
Geometry2 const& geometry2)
{
@ -331,25 +331,32 @@ public :
Geometry2 const& geometry2,
bool is_origin)
{
Point point1, point2, point3;
Point point_from, point2, point3;
geometry::copy_segment_points<Reverse1, Reverse2>(geometry1, geometry2,
op.seg_id, point1, point2, point3);
Point const& point_to = op.fraction.is_one() ? point3 : point2;
op.seg_id, point_from, point2, point3);
Point point_to = op.fraction.is_one() ? point3 : point2;
int offset = 0;
// If the point is in the neighbourhood (the limit itself is not important),
// then take a point (or more) further back.
// The limit of offset avoids theoretical infinite loops. In practice it currently
// walks max 1 point back in all cases.
while (approximately_equals(point1, turn.point, 1.0) && offset > -10)
int offset = 0;
while (approximately_equals(point_from, turn.point, 1.0) && offset > -10)
{
point1 = walk_back(op, --offset, geometry1, geometry2);
point_from = walk_over_ring(op, --offset, geometry1, geometry2);
}
add_segment(turn_index, op_index, point1, point_to, op, is_origin);
// Similarly for the point to, walk forward
offset = 0;
while (approximately_equals(point_to, turn.point, 1.0) && offset < 10)
{
point_to = walk_over_ring(op, ++offset, geometry1, geometry2);
}
return point1;
add_segment(turn_index, op_index, point_from, point_to, op, is_origin);
return point_from;
}
template <typename Turn, typename Operation, typename Geometry1, typename Geometry2>

View File

@ -346,7 +346,8 @@ static std::string const nores_wn_2
// Other cases with wrong turn information
static std::string const nores_wt_1
= "MULTIPOLYGON(((0 4,0 5,1 4,0 4)),((9 3,9 4,10 4,9 3)),((9 7,10 8,10 7,9 7)),((6 7,7 8,7 7,6 7)),((0 7,0 8,1 8,0 7)),((3 6,4 6,4 5,3 4,3 6)),((3 7,2 6,2 7,3 7)),((3 7,3 8,4 8,4 7,3 7)),((3 3,4 4,4 3,3 3)),((3 3,3 2,2 2,2 3,3 3)),((2 6,2 5,1 5,1 6,2 6)),((6 4,6 3,5 3,5 4,6 4)),((6 4,7 5,7 4,6 4)),((5 1,4 0,4 1,5 1)),((5 1,5 2,6 2,6 1,5 1)))";
static std::string const nores_wt_2
= "MULTIPOLYGON(((1 1,2 2,2 1,1 1)),((0 2,0 3,1 3,0 2)),((4 3,5 4,5 3,4 3)),((4 3,3 3,4 4,4 3)))";
static std::string const neighbouring
= "MULTIPOLYGON(((0 0,0 10,10 10,10 0,0 0)),((10 10,10 20,20 20,20 10,10 10)))";
@ -569,6 +570,7 @@ void test_all()
test_one<multi_polygon_type, polygon_type>("nores_wn_2", nores_wn_2, join_round32, end_flat, 18.2669, 1.0);
test_one<multi_polygon_type, polygon_type>("nores_wt_1", nores_wt_1, join_round32, end_flat, 80.1609, 1.0);
test_one<multi_polygon_type, polygon_type>("nores_wt_2", nores_wt_2, join_round32, end_flat, 22.1102, 1.0);
test_one<multi_polygon_type, polygon_type>("neighbouring_small",
neighbouring,