comparison DEPENDENCIES/generic/include/boost/polygon/polygon_traits.hpp @ 101:c530137014c0

Update Boost headers (1.58.0)
author Chris Cannam
date Mon, 07 Sep 2015 11:12:49 +0100
parents 2665513ce2d3
children
comparison
equal deleted inserted replaced
100:793467b5e61c 101:c530137014c0
969 969
970 template <typename iterator_type, typename area_type> 970 template <typename iterator_type, typename area_type>
971 static area_type 971 static area_type
972 point_sequence_area(iterator_type begin_range, iterator_type end_range) { 972 point_sequence_area(iterator_type begin_range, iterator_type end_range) {
973 typedef typename std::iterator_traits<iterator_type>::value_type point_type; 973 typedef typename std::iterator_traits<iterator_type>::value_type point_type;
974 typedef typename point_traits<point_type>::coordinate_type Unit;
975 if(begin_range == end_range) return area_type(0); 974 if(begin_range == end_range) return area_type(0);
976 point_type first = *begin_range; 975 point_type first = *begin_range;
977 point_type previous = first; 976 point_type previous = first;
978 ++begin_range; 977 ++begin_range;
979 // Initialize trapezoid base line 978 // Initialize trapezoid base line
1127 COUNTERCLOCKWISE : CLOCKWISE; 1126 COUNTERCLOCKWISE : CLOCKWISE;
1128 } 1127 }
1129 1128
1130 template <typename T, typename input_point_type> 1129 template <typename T, typename input_point_type>
1131 typename enable_if< 1130 typename enable_if<
1132 typename gtl_and< typename is_polygon_90_type<T>::type, 1131 typename gtl_and<
1133 typename gtl_same_type<typename geometry_concept<input_point_type>::type, point_concept>::type>::type, 1132 typename is_polygon_90_type<T>::type,
1134 bool>::type 1133 typename gtl_same_type<
1135 contains(const T& polygon, const input_point_type& point, bool consider_touch = true) { 1134 typename geometry_concept<input_point_type>::type,
1135 point_concept
1136 >::type
1137 >::type,
1138 bool
1139 >::type contains(
1140 const T& polygon,
1141 const input_point_type& point,
1142 bool consider_touch = true) {
1136 typedef T polygon_type; 1143 typedef T polygon_type;
1137 typedef typename polygon_traits<polygon_type>::coordinate_type coordinate_type; 1144 typedef typename polygon_traits<polygon_type>::coordinate_type coordinate_type;
1138 typedef typename polygon_traits<polygon_type>::iterator_type iterator; 1145 typedef typename polygon_traits<polygon_type>::iterator_type iterator;
1139 typedef typename std::iterator_traits<iterator>::value_type point_type; 1146 typedef typename std::iterator_traits<iterator>::value_type point_type;
1140 coordinate_type point_x = x(point); 1147 coordinate_type point_x = x(point);
1141 coordinate_type point_y = y(point); 1148 coordinate_type point_y = y(point);
1142 bool inside = false; 1149 // Check how many intersections has the ray extended from the given
1150 // point in the x-axis negative direction with the polygon edges.
1151 // If the number is odd the point is within the polygon, otherwise not.
1152 // We can safely ignore horizontal edges, however intersections with
1153 // end points of the vertical edges require special handling. We should
1154 // add one intersection in case horizontal edges that extend vertical edge
1155 // point in the same direction.
1156 int num_full_intersections = 0;
1157 int num_half_intersections = 0;
1143 for (iterator iter = begin_points(polygon); iter != end_points(polygon);) { 1158 for (iterator iter = begin_points(polygon); iter != end_points(polygon);) {
1144 point_type curr_point = *iter; 1159 point_type curr_point = *iter;
1145 ++iter; 1160 ++iter;
1146 point_type next_point = (iter == end_points(polygon)) ? *begin_points(polygon) : *iter; 1161 point_type next_point = (iter == end_points(polygon)) ? *begin_points(polygon) : *iter;
1147 if (x(curr_point) == x(next_point)) { 1162 if (x(curr_point) == x(next_point)) {
1152 coordinate_type max_y = (std::max)(y(curr_point), y(next_point)); 1167 coordinate_type max_y = (std::max)(y(curr_point), y(next_point));
1153 if (point_y > min_y && point_y < max_y) { 1168 if (point_y > min_y && point_y < max_y) {
1154 if (x(curr_point) == point_x) { 1169 if (x(curr_point) == point_x) {
1155 return consider_touch; 1170 return consider_touch;
1156 } 1171 }
1157 inside ^= true; 1172 ++num_full_intersections;
1173 }
1174 if (point_y == min_y || point_y == max_y) {
1175 num_half_intersections += (y(curr_point) < y(next_point) ? 1 : -1);
1158 } 1176 }
1159 } else { 1177 } else {
1160 coordinate_type min_x = (std::min)(x(curr_point), x(next_point)); 1178 coordinate_type min_x = (std::min)(x(curr_point), x(next_point));
1161 coordinate_type max_x = (std::max)(x(curr_point), x(next_point)); 1179 coordinate_type max_x = (std::max)(x(curr_point), x(next_point));
1162 if (point_x >= min_x && point_x <= max_x) { 1180 if (point_x >= min_x && point_x <= max_x) {
1164 return consider_touch; 1182 return consider_touch;
1165 } 1183 }
1166 } 1184 }
1167 } 1185 }
1168 } 1186 }
1169 return inside; 1187 int total_intersections = num_full_intersections + (num_half_intersections >> 1);
1188 return total_intersections & 1;
1170 } 1189 }
1171 1190
1172 //TODO: refactor to expose as user APIs 1191 //TODO: refactor to expose as user APIs
1173 template <typename Unit> 1192 template <typename Unit>
1174 struct edge_utils { 1193 struct edge_utils {
1418 } 1437 }
1419 */ 1438 */
1420 1439
1421 template <typename T1, typename T2> 1440 template <typename T1, typename T2>
1422 typename enable_if< 1441 typename enable_if<
1423 typename gtl_and< typename is_mutable_point_concept<typename geometry_concept<T1>::type>::type,
1424 typename is_polygon_with_holes_type<T2>::type>::type,
1425 bool>::type
1426 center(T1& center_point, const T2& polygon) {
1427 typedef typename polygon_traits<T2>::coordinate_type coordinate_type;
1428 rectangle_data<coordinate_type> bbox;
1429 extents(bbox, polygon);
1430 return center(center_point, bbox);
1431 }
1432
1433 template <typename T1, typename T2>
1434 typename enable_if<
1435 typename gtl_and< typename is_mutable_rectangle_concept<typename geometry_concept<T1>::type>::type, 1442 typename gtl_and< typename is_mutable_rectangle_concept<typename geometry_concept<T1>::type>::type,
1436 typename is_polygon_with_holes_type<T2>::type>::type, 1443 typename is_polygon_with_holes_type<T2>::type>::type,
1437 bool>::type 1444 bool>::type
1438 extents(T1& bounding_box, const T2& polygon) { 1445 extents(T1& bounding_box, const T2& polygon) {
1439 typedef typename polygon_traits<T2>::iterator_type iterator; 1446 typedef typename polygon_traits<T2>::iterator_type iterator;
1447 encompass(bounding_box, *itr); 1454 encompass(bounding_box, *itr);
1448 } 1455 }
1449 } 1456 }
1450 if(first_iteration) return false; 1457 if(first_iteration) return false;
1451 return true; 1458 return true;
1459 }
1460
1461 template <typename T1, typename T2>
1462 typename enable_if<
1463 typename gtl_and< typename is_mutable_point_concept<typename geometry_concept<T1>::type>::type,
1464 typename is_polygon_with_holes_type<T2>::type>::type,
1465 bool>::type
1466 center(T1& center_point, const T2& polygon) {
1467 typedef typename polygon_traits<T2>::coordinate_type coordinate_type;
1468 rectangle_data<coordinate_type> bbox;
1469 extents(bbox, polygon);
1470 return center(center_point, bbox);
1452 } 1471 }
1453 1472
1454 template <class T> 1473 template <class T>
1455 template <class T2> 1474 template <class T2>
1456 polygon_90_data<T>& polygon_90_data<T>::operator=(const T2& rvalue) { 1475 polygon_90_data<T>& polygon_90_data<T>::operator=(const T2& rvalue) {