Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3e111a0

Browse files
committed
[turns] without rescaling, include start turns in calculation
1 parent 1243579 commit 3e111a0

File tree

11 files changed

+140
-9
lines changed

11 files changed

+140
-9
lines changed

include/boost/geometry/algorithms/detail/buffer/get_piece_turns.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ class piece_turn_visitor
266266

267267
typedef detail::overlay::get_turn_info
268268
<
269-
detail::overlay::assign_null_policy
269+
detail::overlay::assign_policy_only_start_turns
270270
> turn_policy;
271271

272272
turn_policy::apply(unique_sub_range1, unique_sub_range2,

include/boost/geometry/algorithms/detail/disjoint/linear_linear.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ struct assign_disjoint_policy
7979
static bool const include_no_turn = true;
8080
static bool const include_degenerate = true;
8181
static bool const include_opposite = true;
82+
static bool const include_start_turn = false;
8283
};
8384

8485

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -491,8 +491,8 @@ inline void enrich_intersection_points(Turns& turns,
491491
{
492492
detail::overlay::discard_closed_turns
493493
<
494-
OverlayType,
495-
target_operation
494+
OverlayType,
495+
target_operation
496496
>::apply(turns, clusters, geometry1, geometry2,
497497
strategy);
498498
detail::overlay::discard_open_turns

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

Lines changed: 85 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -830,6 +830,65 @@ struct equal : public base_turn_handler
830830
}
831831
};
832832

833+
template
834+
<
835+
typename TurnInfo
836+
>
837+
struct start : public base_turn_handler
838+
{
839+
template
840+
<
841+
typename UniqueSubRange1,
842+
typename UniqueSubRange2,
843+
typename IntersectionInfo,
844+
typename DirInfo,
845+
typename SideCalculator,
846+
typename UmbrellaStrategy
847+
>
848+
static inline bool apply(UniqueSubRange1 const& /*range_p*/,
849+
UniqueSubRange2 const& /*range_q*/,
850+
TurnInfo& ti,
851+
IntersectionInfo const& info,
852+
DirInfo const& dir_info,
853+
SideCalculator const& side,
854+
UmbrellaStrategy const& )
855+
{
856+
#if defined(BOOST_GEOMETRY_USE_RESCALING)
857+
// With rescaling, start turns are not needed.
858+
return false;
859+
#endif
860+
861+
// Start turns have either how_a = -1, or how_b = -1 (either p leaves or q leaves)
862+
BOOST_GEOMETRY_ASSERT(dir_info.how_a != dir_info.how_b);
863+
BOOST_GEOMETRY_ASSERT(dir_info.how_a == -1 || dir_info.how_b == -1);
864+
BOOST_GEOMETRY_ASSERT(dir_info.how_a == 0 || dir_info.how_b == 0);
865+
866+
if (dir_info.how_b == -1)
867+
{
868+
// p --------------->
869+
// |
870+
// | q q leaves
871+
// v
872+
//
873+
874+
int const side_qj_p1 = side.qj_wrt_p1();
875+
ui_else_iu(side_qj_p1 == -1, ti);
876+
}
877+
else if (dir_info.how_a == -1)
878+
{
879+
// p leaves
880+
int const side_pj_q1 = side.pj_wrt_q1();
881+
ui_else_iu(side_pj_q1 == 1, ti);
882+
}
883+
884+
// Copy intersection point
885+
assign_point(ti, method_start, info, 0);
886+
return true;
887+
}
888+
889+
};
890+
891+
833892
template
834893
<
835894
typename TurnInfo,
@@ -1194,6 +1253,15 @@ struct assign_null_policy
11941253
static bool const include_no_turn = false;
11951254
static bool const include_degenerate = false;
11961255
static bool const include_opposite = false;
1256+
static bool const include_start_turn = false;
1257+
};
1258+
1259+
struct assign_policy_only_start_turns
1260+
{
1261+
static bool const include_no_turn = false;
1262+
static bool const include_degenerate = false;
1263+
static bool const include_opposite = false;
1264+
static bool const include_start_turn = true;
11971265
};
11981266

11991267
/*!
@@ -1257,9 +1325,24 @@ struct get_turn_info
12571325
bool handle_as_equal = method == 'e';
12581326
bool const handle_as_collinear = method == 'c';
12591327
bool const handle_as_degenerate = method == '0';
1328+
bool const handle_as_start = method == 's';
12601329

1261-
// (angle, from, start)
1262-
bool const do_only_convert = method == 'a' || method == 'f' || method == 's';
1330+
// (angle, from)
1331+
bool do_only_convert = method == 'a' || method == 'f';
1332+
1333+
if (handle_as_start)
1334+
{
1335+
// It is in some cases necessary to handle a start turn
1336+
if (AssignPolicy::include_start_turn
1337+
&& start<TurnInfo>::apply(range_p, range_q, tp, inters.i_info(), inters.d_info(), inters.sides(), umbrella_strategy))
1338+
{
1339+
*out++ = tp;
1340+
}
1341+
else
1342+
{
1343+
do_only_convert = true;
1344+
}
1345+
}
12631346

12641347
if (handle_as_touch_interior)
12651348
{

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

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,46 @@ inline void discard_interior_exterior_turns(Turns& turns, Clusters& clusters)
507507
}
508508
}
509509

510+
template<typename Turns, typename Clusters>
511+
inline void discard_start_turns(Turns& turns, Clusters& clusters)
512+
{
513+
for (auto& nv : clusters)
514+
{
515+
cluster_info& cinfo = nv.second;
516+
auto& indices = cinfo.turn_indices;
517+
std::size_t start_count{0};
518+
for (signed_size_type index : indices)
519+
{
520+
auto const& turn = turns[index];
521+
if (turn.method == method_start)
522+
{
523+
start_count++;
524+
}
525+
}
526+
if (start_count == 0 && start_count == indices.size())
527+
{
528+
// There are no start turns, or all turns in the cluster are start turns.
529+
continue;
530+
}
531+
532+
// Discard the start turns and simultaneously erase them from the indices
533+
for (auto it = indices.begin(); it != indices.end();)
534+
{
535+
auto& turn = turns[*it];
536+
if (turn.method == method_start)
537+
{
538+
turn.discarded = true;
539+
turn.cluster_id = -1;
540+
it = indices.erase(it);
541+
}
542+
else
543+
{
544+
++it;
545+
}
546+
}
547+
}
548+
}
549+
510550
template <typename Geometry0, typename Geometry1>
511551
inline segment_identifier get_preceding_segment_id(segment_identifier const& id,
512552
Geometry0 const& geometry0, Geometry1 const& geometry1)
@@ -700,6 +740,8 @@ inline bool handle_colocations(Turns& turns, Clusters& clusters,
700740
// on turns which are discarded afterwards
701741
set_colocation<OverlayType>(turns, clusters);
702742

743+
discard_start_turns(turns, clusters);
744+
703745
if (BOOST_GEOMETRY_CONDITION(target_operation == operation_intersection))
704746
{
705747
discard_interior_exterior_turns
@@ -783,7 +825,7 @@ inline bool fill_sbs(Sbs& sbs, Point& turn_point,
783825
{
784826
signed_size_type turn_index = *sit;
785827
turn_type const& turn = turns[turn_index];
786-
if (first )
828+
if (first)
787829
{
788830
turn_point = turn.point;
789831
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ class linear_linear_linestring
138138
static bool const include_no_turn = false;
139139
static bool const include_degenerate = EnableDegenerateTurns;
140140
static bool const include_opposite = false;
141+
static bool const include_start_turn = false;
141142
};
142143

143144

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ std::cout << "get turns" << std::endl;
306306
geometry::get_turns
307307
<
308308
Reverse1, Reverse2,
309-
detail::overlay::assign_null_policy
309+
assign_policy_only_start_turns
310310
>(geometry1, geometry2, strategy, robust_policy, turns, policy);
311311

312312
visitor.visit_turns(1, turns);
@@ -318,12 +318,12 @@ std::cout << "get turns" << std::endl;
318318
// and if necessary (e.g.: multi-geometry, polygon with interior rings)
319319
if (needs_self_turns<Geometry1>::apply(geometry1))
320320
{
321-
self_get_turn_points::self_turns<Reverse1, assign_null_policy>(geometry1,
321+
self_get_turn_points::self_turns<Reverse1, assign_policy_only_start_turns>(geometry1,
322322
strategy, robust_policy, turns, policy, 0);
323323
}
324324
if (needs_self_turns<Geometry2>::apply(geometry2))
325325
{
326-
self_get_turn_points::self_turns<Reverse2, assign_null_policy>(geometry2,
326+
self_get_turn_points::self_turns<Reverse2, assign_policy_only_start_turns>(geometry2,
327327
strategy, robust_policy, turns, policy, 1);
328328
}
329329
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ enum method_type
3434
method_touch_interior,
3535
method_collinear,
3636
method_equal,
37+
method_start,
3738
method_error
3839
};
3940

include/boost/geometry/algorithms/detail/touches/implementation.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ struct areal_interrupt_policy
181181
return true;
182182
}
183183
break;
184+
case overlay::method_start :
184185
case overlay::method_none :
185186
case overlay::method_disjoint :
186187
case overlay::method_error :

test/algorithms/set_operations/check_turn_less.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ struct check_turn_less
5555
static bool const include_no_turn = false;
5656
static bool const include_degenerate = EnableDegenerateTurns;
5757
static bool const include_opposite = false;
58+
static bool const include_start_turn = false;
5859

5960
template
6061
<

test/algorithms/set_operations/test_get_turns_ll_invariance.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ class test_get_turns_ll_invariance
4545
static bool const include_no_turn = false;
4646
static bool const include_degenerate = EnableDegenerateTurns;
4747
static bool const include_opposite = false;
48+
static bool const include_start_turn = false;
4849

4950
template
5051
<

0 commit comments

Comments
 (0)