Skip to content

Commit 59e0840

Browse files
committed
[sort_by_side] walk forward for point_to
(similarly to walking backwards for point_from)
1 parent 4e8ff81 commit 59e0840

File tree

2 files changed

+19
-10
lines changed

2 files changed

+19
-10
lines changed

include/boost/geometry/algorithms/detail/overlay/sort_by_side.hpp

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ public :
316316
}
317317

318318
template <typename Operation, typename Geometry1, typename Geometry2>
319-
static Point walk_back(Operation const& op, int offset,
319+
static Point walk_over_ring(Operation const& op, int offset,
320320
Geometry1 const& geometry1,
321321
Geometry2 const& geometry2)
322322
{
@@ -331,25 +331,32 @@ public :
331331
Geometry2 const& geometry2,
332332
bool is_origin)
333333
{
334-
Point point1, point2, point3;
334+
Point point_from, point2, point3;
335335
geometry::copy_segment_points<Reverse1, Reverse2>(geometry1, geometry2,
336-
op.seg_id, point1, point2, point3);
337-
Point const& point_to = op.fraction.is_one() ? point3 : point2;
336+
op.seg_id, point_from, point2, point3);
337+
Point point_to = op.fraction.is_one() ? point3 : point2;
338338

339-
int offset = 0;
340339

341340
// If the point is in the neighbourhood (the limit itself is not important),
342341
// then take a point (or more) further back.
343342
// The limit of offset avoids theoretical infinite loops. In practice it currently
344343
// walks max 1 point back in all cases.
345-
while (approximately_equals(point1, turn.point, 1.0) && offset > -10)
344+
int offset = 0;
345+
while (approximately_equals(point_from, turn.point, 1.0) && offset > -10)
346+
{
347+
point_from = walk_over_ring(op, --offset, geometry1, geometry2);
348+
}
349+
350+
// Similarly for the point to, walk forward
351+
offset = 0;
352+
while (approximately_equals(point_to, turn.point, 1.0) && offset < 10)
346353
{
347-
point1 = walk_back(op, --offset, geometry1, geometry2);
354+
point_to = walk_over_ring(op, ++offset, geometry1, geometry2);
348355
}
349356

350-
add_segment(turn_index, op_index, point1, point_to, op, is_origin);
357+
add_segment(turn_index, op_index, point_from, point_to, op, is_origin);
351358

352-
return point1;
359+
return point_from;
353360
}
354361

355362
template <typename Turn, typename Operation, typename Geometry1, typename Geometry2>

test/algorithms/buffer/buffer_multi_polygon.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,8 @@ static std::string const nores_wn_2
346346
// Other cases with wrong turn information
347347
static std::string const nores_wt_1
348348
= "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)))";
349-
349+
static std::string const nores_wt_2
350+
= "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)))";
350351

351352
static std::string const neighbouring
352353
= "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()
569570
test_one<multi_polygon_type, polygon_type>("nores_wn_2", nores_wn_2, join_round32, end_flat, 18.2669, 1.0);
570571

571572
test_one<multi_polygon_type, polygon_type>("nores_wt_1", nores_wt_1, join_round32, end_flat, 80.1609, 1.0);
573+
test_one<multi_polygon_type, polygon_type>("nores_wt_2", nores_wt_2, join_round32, end_flat, 22.1102, 1.0);
572574

573575
test_one<multi_polygon_type, polygon_type>("neighbouring_small",
574576
neighbouring,

0 commit comments

Comments
 (0)