@@ -184,8 +184,9 @@ void ContourLine::push_back(const XY& point)
184184void ContourLine::write () const
185185{
186186 std::cout << " ContourLine of " << size () << " points:" ;
187- for (const_iterator it = begin (); it != end (); ++it)
188- std::cout << ' ' << *it;
187+ for (const auto & it : *this ) {
188+ std::cout << ' ' << it;
189+ }
189190 std::cout << std::endl;
190191}
191192
@@ -194,8 +195,9 @@ void ContourLine::write() const
194195void write_contour (const Contour& contour)
195196{
196197 std::cout << " Contour of " << contour.size () << " lines." << std::endl;
197- for (Contour::const_iterator it = contour.begin (); it != contour.end (); ++it)
198- it->write ();
198+ for (const auto & it : contour) {
199+ it.write ();
200+ }
199201}
200202
201203
@@ -264,7 +266,7 @@ void Triangulation::calculate_boundaries()
264266 // time, initialise the _tri_edge_to_boundary_map.
265267 while (!boundary_edges.empty ()) {
266268 // Start of new boundary.
267- BoundaryEdges::iterator it = boundary_edges.begin ();
269+ auto it = boundary_edges.cbegin ();
268270 int tri = it->tri ;
269271 int edge = it->edge ;
270272 _boundaries.push_back (Boundary ());
@@ -321,9 +323,9 @@ void Triangulation::calculate_edges()
321323 auto edges = _edges.mutable_data ();
322324
323325 int i = 0 ;
324- for (EdgeSet::const_iterator it = edge_set. begin (); it != edge_set. end (); ++it ) {
325- edges[i++] = it-> start ;
326- edges[i++] = it-> end ;
326+ for (const auto & it : edge_set) {
327+ edges[i++] = it. start ;
328+ edges[i++] = it. end ;
327329 }
328330}
329331
@@ -351,8 +353,7 @@ void Triangulation::calculate_neighbors()
351353 for (edge = 0 ; edge < 3 ; ++edge) {
352354 int start = get_triangle_point (tri, edge);
353355 int end = get_triangle_point (tri, (edge+1 )%3 );
354- EdgeToTriEdgeMap::iterator it =
355- edge_to_tri_edge_map.find (Edge (end,start));
356+ const auto it = edge_to_tri_edge_map.find (Edge (end, start));
356357 if (it == edge_to_tri_edge_map.end ()) {
357358 // No neighbor edge exists in the edge_to_tri_edge_map, so
358359 // add this edge to it.
@@ -464,10 +465,8 @@ void Triangulation::get_boundary_edge(const TriEdge& triEdge,
464465 int & edge) const
465466{
466467 get_boundaries (); // Ensure _tri_edge_to_boundary_map has been created.
467- TriEdgeToBoundaryMap::const_iterator it =
468- _tri_edge_to_boundary_map.find (triEdge);
469- assert (it != _tri_edge_to_boundary_map.end () &&
470- " TriEdge is not on a boundary" );
468+ const auto it = _tri_edge_to_boundary_map.find (triEdge);
469+ assert (it != _tri_edge_to_boundary_map.end () && " TriEdge is not on a boundary" );
471470 boundary = it->second .boundary ;
472471 edge = it->second .edge ;
473472}
@@ -587,13 +586,12 @@ void Triangulation::set_mask(const MaskArray& mask)
587586
588587void Triangulation::write_boundaries () const
589588{
590- const Boundaries& bs = get_boundaries ();
591- std::cout << " Number of boundaries: " << bs.size () << std::endl;
592- for (Boundaries::const_iterator it = bs.begin (); it != bs.end (); ++it) {
593- const Boundary& b = *it;
594- std::cout << " Boundary of " << b.size () << " points: " ;
595- for (Boundary::const_iterator itb = b.begin (); itb != b.end (); ++itb) {
596- std::cout << *itb << " , " ;
589+ const Boundaries& boundaries = get_boundaries ();
590+ std::cout << " Number of boundaries: " << boundaries.size () << std::endl;
591+ for (const auto & boundary : boundaries) {
592+ std::cout << " Boundary of " << boundary.size () << " points: " ;
593+ for (const auto & point : boundary) {
594+ std::cout << point << " , " ;
597595 }
598596 std::cout << std::endl;
599597 }
@@ -625,18 +623,18 @@ void TriContourGenerator::clear_visited_flags(bool include_boundaries)
625623
626624 // Initialise _boundaries_visited.
627625 _boundaries_visited.reserve (boundaries.size ());
628- for (Boundaries::const_iterator it = boundaries. begin ();
629- it != boundaries. end (); ++it)
630- _boundaries_visited. push_back ( BoundaryVisited (it-> size ()));
626+ for (const auto & boundary : boundaries) {
627+ _boundaries_visited. push_back ( BoundaryVisited (boundary. size ()));
628+ }
631629
632630 // Initialise _boundaries_used.
633631 _boundaries_used = BoundariesUsed (boundaries.size ());
634632 }
635633
636634 // Clear _boundaries_visited.
637- for (BoundariesVisited::iterator it = _boundaries_visited. begin ();
638- it != _boundaries_visited .end (); ++it)
639- std::fill (it-> begin (), it-> end (), false );
635+ for (auto & it : _boundaries_visited) {
636+ std::fill (it. begin (), it .end (), false );
637+ }
640638
641639 // Clear _boundaries_used.
642640 std::fill (_boundaries_used.begin (), _boundaries_used.end (), false );
@@ -672,12 +670,12 @@ py::tuple TriContourGenerator::contour_line_to_segs_and_kinds(const Contour& con
672670 CodeArray codes (codes_dims);
673671 unsigned char * codes_ptr = codes.mutable_data ();
674672
675- for (ContourLine::const_iterator it = contour_line.begin ();
676- it != contour_line.end (); ++it) {
677- *segs_ptr++ = it->x ;
678- *segs_ptr++ = it->y ;
679- *codes_ptr++ = (it == contour_line.begin () ? MOVETO : LINETO);
673+ for (const auto & point : contour_line) {
674+ *segs_ptr++ = point.x ;
675+ *segs_ptr++ = point.y ;
676+ *codes_ptr++ = LINETO;
680677 }
678+ *codes.mutable_data (0 ) = MOVETO;
681679
682680 // Closed line loop has identical first and last (x, y) points.
683681 if (contour_line.size () > 1 &&
@@ -707,13 +705,11 @@ py::tuple TriContourGenerator::contour_to_segs_and_kinds(const Contour& contour)
707705 // and they are returned in the Python lists vertices_list and codes_list
708706 // respectively.
709707
710- Contour::const_iterator line;
711- ContourLine::const_iterator point;
712-
713708 // Find total number of points in all contour lines.
714709 py::ssize_t n_points = 0 ;
715- for (line = contour.begin (); line != contour.end (); ++line)
716- n_points += static_cast <py::ssize_t >(line->size ());
710+ for (const auto & line : contour) {
711+ n_points += static_cast <py::ssize_t >(line.size ());
712+ }
717713
718714 // Create segs array for point coordinates.
719715 py::ssize_t segs_dims[2 ] = {n_points, 2 };
@@ -725,15 +721,16 @@ py::tuple TriContourGenerator::contour_to_segs_and_kinds(const Contour& contour)
725721 CodeArray codes (codes_dims);
726722 unsigned char * codes_ptr = codes.mutable_data ();
727723
728- for (line = contour. begin (); line != contour. end (); ++line ) {
729- for (point = line-> begin (); point != line-> end (); point++) {
724+ for (const auto & line : contour) {
725+ for (auto point = line. cbegin (); point != line. cend (); point++) {
730726 *segs_ptr++ = point->x ;
731727 *segs_ptr++ = point->y ;
732- *codes_ptr++ = (point == line-> begin () ? MOVETO : LINETO);
728+ *codes_ptr++ = (point == line. cbegin () ? MOVETO : LINETO);
733729 }
734730
735- if (line-> size () > 1 )
731+ if (line. size () > 1 ) {
736732 *(codes_ptr-1 ) = CLOSEPOLY;
733+ }
737734 }
738735
739736 py::list vertices_list (1 );
@@ -787,13 +784,10 @@ void TriContourGenerator::find_boundary_lines(Contour& contour,
787784 // line to its end before continuing.
788785 const Triangulation& triang = _triangulation;
789786 const Boundaries& boundaries = get_boundaries ();
790- for (Boundaries::const_iterator it = boundaries.begin ();
791- it != boundaries.end (); ++it) {
792- const Boundary& boundary = *it;
787+ for (const auto & boundary : boundaries) {
793788 bool startAbove, endAbove = false ;
794- for (Boundary::const_iterator itb = boundary.begin ();
795- itb != boundary.end (); ++itb) {
796- if (itb == boundary.begin ())
789+ for (auto itb = boundary.cbegin (); itb != boundary.cend (); ++itb) {
790+ if (itb == boundary.cbegin ())
797791 startAbove = get_z (triang.get_triangle_point (*itb)) >= level;
798792 else
799793 startAbove = endAbove;
@@ -867,9 +861,10 @@ void TriContourGenerator::find_boundary_lines_filled(Contour& contour,
867861 if (z >= lower_level && z < upper_level) {
868862 contour.push_back (ContourLine ());
869863 ContourLine& contour_line = contour.back ();
870- for (Boundary::size_type j = 0 ; j < boundary. size (); ++j)
864+ for (auto edge : boundary) {
871865 contour_line.push_back (triang.get_point_coords (
872- triang.get_triangle_point (boundary[j])));
866+ triang.get_triangle_point (edge)));
867+ }
873868
874869 // Close polygon.
875870 contour_line.push_back (contour_line.front ());
@@ -1639,9 +1634,7 @@ TrapezoidMapTriFinder::Node::assert_valid(bool tree_complete) const
16391634{
16401635#ifndef NDEBUG
16411636 // Check parents.
1642- for (Parents::const_iterator it = _parents.begin ();
1643- it != _parents.end (); ++it) {
1644- Node* parent = *it;
1637+ for (const auto & parent : _parents) {
16451638 assert (parent != this && " Cannot be parent of self" );
16461639 assert (parent->has_child (this ) && " Parent missing child" );
16471640 }
@@ -1780,7 +1773,7 @@ TrapezoidMapTriFinder::Node::remove_parent(Node* parent)
17801773{
17811774 assert (parent != 0 && " Null parent" );
17821775 assert (parent != this && " Cannot be parent of self" );
1783- Parents::iterator it = std::find (_parents.begin (), _parents.end (), parent);
1776+ auto it = std::find (_parents.begin (), _parents.end (), parent);
17841777 assert (it != _parents.end () && " Parent not in collection" );
17851778 _parents.erase (it);
17861779 return _parents.empty ();
0 commit comments