Skip to content

Commit

Permalink
Add comment on potential impact on divergence
Browse files Browse the repository at this point in the history
  • Loading branch information
isVoid committed Jul 27, 2022
1 parent 047551d commit e3a2134
Showing 1 changed file with 4 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ __device__ inline bool is_point_in_polygon(Cart2d const& test_point,
T rise = b.y - a.y;
T rise_to_point = test_point.y - a.y;

// The divergence here is introduced to avoid a potential division
// of `rise` on the rhs of the comparison operator. The assumption here
// is that the the division instruction costs more cycles than the
// divergence to synchronize.
if (rise > 0 && (test_point.x - a.x) * rise < run * rise_to_point)
point_is_within = not point_is_within;
else if (rise < 0 && (test_point.x - a.x) * rise > run * rise_to_point)
Expand Down

0 comments on commit e3a2134

Please sign in to comment.