@@ -184,8 +184,9 @@ void ContourLine::push_back(const XY& point)
184
184
void ContourLine::write () const
185
185
{
186
186
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
+ }
189
190
std::cout << std::endl;
190
191
}
191
192
@@ -194,8 +195,9 @@ void ContourLine::write() const
194
195
void write_contour (const Contour& contour)
195
196
{
196
197
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
+ }
199
201
}
200
202
201
203
@@ -264,7 +266,7 @@ void Triangulation::calculate_boundaries()
264
266
// time, initialise the _tri_edge_to_boundary_map.
265
267
while (!boundary_edges.empty ()) {
266
268
// Start of new boundary.
267
- BoundaryEdges::iterator it = boundary_edges.begin ();
269
+ auto it = boundary_edges.cbegin ();
268
270
int tri = it->tri ;
269
271
int edge = it->edge ;
270
272
_boundaries.push_back (Boundary ());
@@ -321,9 +323,9 @@ void Triangulation::calculate_edges()
321
323
auto edges = _edges.mutable_data ();
322
324
323
325
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 ;
327
329
}
328
330
}
329
331
@@ -351,8 +353,7 @@ void Triangulation::calculate_neighbors()
351
353
for (edge = 0 ; edge < 3 ; ++edge) {
352
354
int start = get_triangle_point (tri, edge);
353
355
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));
356
357
if (it == edge_to_tri_edge_map.end ()) {
357
358
// No neighbor edge exists in the edge_to_tri_edge_map, so
358
359
// add this edge to it.
@@ -464,10 +465,8 @@ void Triangulation::get_boundary_edge(const TriEdge& triEdge,
464
465
int & edge) const
465
466
{
466
467
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" );
471
470
boundary = it->second .boundary ;
472
471
edge = it->second .edge ;
473
472
}
@@ -587,13 +586,12 @@ void Triangulation::set_mask(const MaskArray& mask)
587
586
588
587
void Triangulation::write_boundaries () const
589
588
{
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 << " , " ;
597
595
}
598
596
std::cout << std::endl;
599
597
}
@@ -625,18 +623,18 @@ void TriContourGenerator::clear_visited_flags(bool include_boundaries)
625
623
626
624
// Initialise _boundaries_visited.
627
625
_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
+ }
631
629
632
630
// Initialise _boundaries_used.
633
631
_boundaries_used = BoundariesUsed (boundaries.size ());
634
632
}
635
633
636
634
// 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
+ }
640
638
641
639
// Clear _boundaries_used.
642
640
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
672
670
CodeArray codes (codes_dims);
673
671
unsigned char * codes_ptr = codes.mutable_data ();
674
672
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;
680
677
}
678
+ *codes.mutable_data (0 ) = MOVETO;
681
679
682
680
// Closed line loop has identical first and last (x, y) points.
683
681
if (contour_line.size () > 1 &&
@@ -707,13 +705,11 @@ py::tuple TriContourGenerator::contour_to_segs_and_kinds(const Contour& contour)
707
705
// and they are returned in the Python lists vertices_list and codes_list
708
706
// respectively.
709
707
710
- Contour::const_iterator line;
711
- ContourLine::const_iterator point;
712
-
713
708
// Find total number of points in all contour lines.
714
709
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
+ }
717
713
718
714
// Create segs array for point coordinates.
719
715
py::ssize_t segs_dims[2 ] = {n_points, 2 };
@@ -725,15 +721,16 @@ py::tuple TriContourGenerator::contour_to_segs_and_kinds(const Contour& contour)
725
721
CodeArray codes (codes_dims);
726
722
unsigned char * codes_ptr = codes.mutable_data ();
727
723
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++) {
730
726
*segs_ptr++ = point->x ;
731
727
*segs_ptr++ = point->y ;
732
- *codes_ptr++ = (point == line-> begin () ? MOVETO : LINETO);
728
+ *codes_ptr++ = (point == line. cbegin () ? MOVETO : LINETO);
733
729
}
734
730
735
- if (line-> size () > 1 )
731
+ if (line. size () > 1 ) {
736
732
*(codes_ptr-1 ) = CLOSEPOLY;
733
+ }
737
734
}
738
735
739
736
py::list vertices_list (1 );
@@ -787,13 +784,10 @@ void TriContourGenerator::find_boundary_lines(Contour& contour,
787
784
// line to its end before continuing.
788
785
const Triangulation& triang = _triangulation;
789
786
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) {
793
788
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 ())
797
791
startAbove = get_z (triang.get_triangle_point (*itb)) >= level;
798
792
else
799
793
startAbove = endAbove;
@@ -867,9 +861,10 @@ void TriContourGenerator::find_boundary_lines_filled(Contour& contour,
867
861
if (z >= lower_level && z < upper_level) {
868
862
contour.push_back (ContourLine ());
869
863
ContourLine& contour_line = contour.back ();
870
- for (Boundary::size_type j = 0 ; j < boundary. size (); ++j)
864
+ for (auto edge : boundary) {
871
865
contour_line.push_back (triang.get_point_coords (
872
- triang.get_triangle_point (boundary[j])));
866
+ triang.get_triangle_point (edge)));
867
+ }
873
868
874
869
// Close polygon.
875
870
contour_line.push_back (contour_line.front ());
@@ -1638,9 +1633,7 @@ TrapezoidMapTriFinder::Node::assert_valid(bool tree_complete) const
1638
1633
{
1639
1634
#ifndef NDEBUG
1640
1635
// Check parents.
1641
- for (Parents::const_iterator it = _parents.begin ();
1642
- it != _parents.end (); ++it) {
1643
- Node* parent = *it;
1636
+ for (const auto & parent : _parents) {
1644
1637
assert (parent != this && " Cannot be parent of self" );
1645
1638
assert (parent->has_child (this ) && " Parent missing child" );
1646
1639
}
@@ -1779,7 +1772,7 @@ TrapezoidMapTriFinder::Node::remove_parent(Node* parent)
1779
1772
{
1780
1773
assert (parent != 0 && " Null parent" );
1781
1774
assert (parent != this && " Cannot be parent of self" );
1782
- Parents::iterator it = std::find (_parents.begin (), _parents.end (), parent);
1775
+ auto it = std::find (_parents.begin (), _parents.end (), parent);
1783
1776
assert (it != _parents.end () && " Parent not in collection" );
1784
1777
_parents.erase (it);
1785
1778
return _parents.empty ();
0 commit comments