mirror of
https://github.com/boostorg/polygon.git
synced 2026-02-02 09:02:13 +00:00
Merge branch 'develop'
This commit is contained in:
@@ -1129,17 +1129,33 @@ namespace boost { namespace polygon{
|
||||
|
||||
template <typename T, typename input_point_type>
|
||||
typename enable_if<
|
||||
typename gtl_and< typename is_polygon_90_type<T>::type,
|
||||
typename gtl_same_type<typename geometry_concept<input_point_type>::type, point_concept>::type>::type,
|
||||
bool>::type
|
||||
contains(const T& polygon, const input_point_type& point, bool consider_touch = true) {
|
||||
typename gtl_and<
|
||||
typename is_polygon_90_type<T>::type,
|
||||
typename gtl_same_type<
|
||||
typename geometry_concept<input_point_type>::type,
|
||||
point_concept
|
||||
>::type
|
||||
>::type,
|
||||
bool
|
||||
>::type contains(
|
||||
const T& polygon,
|
||||
const input_point_type& point,
|
||||
bool consider_touch = true) {
|
||||
typedef T polygon_type;
|
||||
typedef typename polygon_traits<polygon_type>::coordinate_type coordinate_type;
|
||||
typedef typename polygon_traits<polygon_type>::iterator_type iterator;
|
||||
typedef typename std::iterator_traits<iterator>::value_type point_type;
|
||||
coordinate_type point_x = x(point);
|
||||
coordinate_type point_y = y(point);
|
||||
bool inside = false;
|
||||
// Check how many intersections has the ray extended from the given
|
||||
// point in the x-axis negative direction with the polygon edges.
|
||||
// If the number is odd the point is within the polygon, otherwise not.
|
||||
// We can safely ignore horizontal edges, however intersections with
|
||||
// end points of the vertical edges require special handling. We should
|
||||
// add one intersection in case horizontal edges that extend vertical edge
|
||||
// point in the same direction.
|
||||
int num_full_intersections = 0;
|
||||
int num_half_intersections = 0;
|
||||
for (iterator iter = begin_points(polygon); iter != end_points(polygon);) {
|
||||
point_type curr_point = *iter;
|
||||
++iter;
|
||||
@@ -1154,7 +1170,10 @@ namespace boost { namespace polygon{
|
||||
if (x(curr_point) == point_x) {
|
||||
return consider_touch;
|
||||
}
|
||||
inside ^= true;
|
||||
++num_full_intersections;
|
||||
}
|
||||
if (point_y == min_y || point_y == max_y) {
|
||||
num_half_intersections += (y(curr_point) < y(next_point) ? 1 : -1);
|
||||
}
|
||||
} else {
|
||||
coordinate_type min_x = (std::min)(x(curr_point), x(next_point));
|
||||
@@ -1166,7 +1185,8 @@ namespace boost { namespace polygon{
|
||||
}
|
||||
}
|
||||
}
|
||||
return inside;
|
||||
int total_intersections = num_full_intersections + (num_half_intersections >> 1);
|
||||
return total_intersections & 1;
|
||||
}
|
||||
|
||||
//TODO: refactor to expose as user APIs
|
||||
|
||||
Reference in New Issue
Block a user