Skip to content

Commit

Permalink
[strategies] prevent integer overflow during segment touch ratio calc…
Browse files Browse the repository at this point in the history
…ulation
  • Loading branch information
Anton Kovalev committed Jul 26, 2016
1 parent b3515fc commit 36d8a40
Showing 1 changed file with 37 additions and 11 deletions.
48 changes: 37 additions & 11 deletions include/boost/geometry/strategies/cartesian/cart_intersect.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ struct relate_cartesian_segments

sides.set<1>(side::apply(robust_a1, robust_a2, robust_b1),
side::apply(robust_a1, robust_a2, robust_b2));

if (sides.same<1>())
{
// Both points are at same side of other segment, we can leave
Expand Down Expand Up @@ -258,15 +258,41 @@ struct relate_cartesian_segments
robust_coordinate_type robust_da0, robust_da;
robust_coordinate_type robust_db0, robust_db;

cramers_rule(robust_dx_a, robust_dy_a, robust_dx_b, robust_dy_b,
get<0>(robust_a1) - get<0>(robust_b1),
get<1>(robust_a1) - get<1>(robust_b1),
robust_da0, robust_da);
if (sides.get<0, 0>() == 0)
{
robust_da0 = 1;
robust_da = 0;
}
else if (sides.get<0, 1>() == 0)
{
robust_da0 = 1;
robust_da = 1;
}
else
{
cramers_rule(robust_dx_a, robust_dy_a, robust_dx_b, robust_dy_b,
get<0>(robust_a1) - get<0>(robust_b1),
get<1>(robust_a1) - get<1>(robust_b1),
robust_da0, robust_da);
}

cramers_rule(robust_dx_b, robust_dy_b, robust_dx_a, robust_dy_a,
get<0>(robust_b1) - get<0>(robust_a1),
get<1>(robust_b1) - get<1>(robust_a1),
robust_db0, robust_db);
if (sides.get<1, 0>() == 0)
{
robust_db0 = 1;
robust_db = 0;
}
else if (sides.get<1, 1>() == 0)
{
robust_db0 = 1;
robust_db = 1;
}
else
{
cramers_rule(robust_dx_b, robust_dy_b, robust_dx_a, robust_dy_a,
get<0>(robust_b1) - get<0>(robust_a1),
get<1>(robust_b1) - get<1>(robust_a1),
robust_db0, robust_db);
}

math::detail::equals_factor_policy<robust_coordinate_type>
policy(robust_dx_a, robust_dy_a, robust_dx_b, robust_dy_b);
Expand Down Expand Up @@ -450,7 +476,7 @@ struct relate_cartesian_segments
int const a2_wrt_b = position_value(oa_2, ob_1, ob_2);
int const b1_wrt_a = position_value(ob_1, oa_1, oa_2);
int const b2_wrt_a = position_value(ob_2, oa_1, oa_2);

// fix the ratios if necessary
// CONSIDER: fixing ratios also in other cases, if they're inconsistent
// e.g. if ratio == 1 or 0 (so IP at the endpoint)
Expand All @@ -467,7 +493,7 @@ struct relate_cartesian_segments
{
ra_from.assign(1, 1);
rb_to.assign(0, 1);
}
}

if (a2_wrt_b == 1)
{
Expand Down

0 comments on commit 36d8a40

Please sign in to comment.