diff options
| author | Marc Jeanmougin <marc@jeanmougin.fr> | 2019-01-02 09:41:30 +0000 |
|---|---|---|
| committer | Marc Jeanmougin <marc@jeanmougin.fr> | 2019-01-02 09:41:30 +0000 |
| commit | 169dff19d4da8d76e69b8e896aa25b0013639c03 (patch) | |
| tree | a0c070fa95188b5cde708ac285e6a2db9df4a83f /src/live_effects | |
| parent | Avoid creating a new document before opening an old document. (diff) | |
| download | inkscape-169dff19d4da8d76e69b8e896aa25b0013639c03.tar.gz inkscape-169dff19d4da8d76e69b8e896aa25b0013639c03.zip | |
modernize loops
Diffstat (limited to 'src/live_effects')
40 files changed, 365 insertions, 388 deletions
diff --git a/src/live_effects/effect.cpp b/src/live_effects/effect.cpp index d55f777e5..92f5a781a 100644 --- a/src/live_effects/effect.cpp +++ b/src/live_effects/effect.cpp @@ -446,9 +446,7 @@ Effect::isNodePointSelected(Geom::Point const &nodePoint) const if (selectedNodesPoints.size() > 0) { using Geom::X; using Geom::Y; - for (std::vector<Geom::Point>::const_iterator i = selectedNodesPoints.begin(); - i != selectedNodesPoints.end(); ++i) { - Geom::Point p = *i; + for (auto p : selectedNodesPoints) { Geom::Affine transformCoordinate = sp_lpe_item->i2dt_affine(); Geom::Point p2(nodePoint[X],nodePoint[Y]); p2 *= transformCoordinate; @@ -467,9 +465,7 @@ Effect::processObjects(LPEAction lpe_action) if (!document) { return; } - for (std::vector<Glib::ustring>::iterator el_it = items.begin(); - el_it != items.end(); ++el_it) { - Glib::ustring id = *el_it; + for (auto id : items) { if (id.empty()) { return; } @@ -621,20 +617,20 @@ Effect::doEffect_path (Geom::PathVector const & path_in) if ( !concatenate_before_pwd2 ) { // default behavior - for (unsigned int i=0; i < path_in.size(); i++) { - Geom::Piecewise<Geom::D2<Geom::SBasis> > pwd2_in = path_in[i].toPwSb(); + for (const auto & i : path_in) { + Geom::Piecewise<Geom::D2<Geom::SBasis> > pwd2_in = i.toPwSb(); Geom::Piecewise<Geom::D2<Geom::SBasis> > pwd2_out = doEffect_pwd2(pwd2_in); Geom::PathVector path = Geom::path_from_piecewise( pwd2_out, LPE_CONVERSION_TOLERANCE); // add the output path vector to the already accumulated vector: - for (unsigned int j=0; j < path.size(); j++) { - path_out.push_back(path[j]); + for (const auto & j : path) { + path_out.push_back(j); } } } else { // concatenate the path into possibly discontinuous pwd2 Geom::Piecewise<Geom::D2<Geom::SBasis> > pwd2_in; - for (unsigned int i=0; i < path_in.size(); i++) { - pwd2_in.concat( path_in[i].toPwSb() ); + for (const auto & i : path_in) { + pwd2_in.concat( i.toPwSb() ); } Geom::Piecewise<Geom::D2<Geom::SBasis> > pwd2_out = doEffect_pwd2(pwd2_in); path_out = Geom::path_from_piecewise( pwd2_out, LPE_CONVERSION_TOLERANCE); @@ -716,8 +712,8 @@ Effect::addHandles(KnotHolder *knotholder, SPItem *item) { addKnotHolderEntities(knotholder, item); // add handles provided by the effect's parameters (if any) - for (std::vector<Parameter *>::iterator p = param_vector.begin(); p != param_vector.end(); ++p) { - (*p)->addKnotHolderEntities(knotholder, item); + for (auto & p : param_vector) { + p->addKnotHolderEntities(knotholder, item); } } @@ -736,8 +732,8 @@ Effect::getCanvasIndicators(SPLPEItem const* lpeitem) addCanvasIndicators(lpeitem, hp_vec); // add indicators provided by the effect's parameters - for (std::vector<Parameter *>::iterator p = param_vector.begin(); p != param_vector.end(); ++p) { - (*p)->addCanvasIndicators(lpeitem, hp_vec); + for (auto & p : param_vector) { + p->addCanvasIndicators(lpeitem, hp_vec); } return hp_vec; @@ -1006,8 +1002,8 @@ Effect::providesKnotholder() const } // otherwise: are there any parameters that have knotholderentities? - for (std::vector<Parameter *>::const_iterator p = param_vector.begin(); p != param_vector.end(); ++p) { - if ((*p)->providesKnotHolderEntities()) { + for (auto p : param_vector) { + if (p->providesKnotHolderEntities()) { return true; } } diff --git a/src/live_effects/lpe-bool.cpp b/src/live_effects/lpe-bool.cpp index 6ff27b0aa..7644f3b8e 100644 --- a/src/live_effects/lpe-bool.cpp +++ b/src/live_effects/lpe-bool.cpp @@ -254,11 +254,11 @@ sp_pathvector_boolop_slice_intersect(Geom::PathVector const &pathva, Geom::PathV // Create an array of bools which states which pieces are in std::vector<bool> inside_flags(result_path->descr_cmd.size(), false); - for (std::vector<Path::cut_position>::iterator itPiece = inside_pieces.begin(); itPiece != inside_pieces.end(); ++itPiece) { - inside_flags[ itPiece->piece ] = true; + for (auto & inside_piece : inside_pieces) { + inside_flags[ inside_piece.piece ] = true; // also enable the element -1 to get the MoveTo - if (itPiece->piece >= 1) { - inside_flags[ itPiece->piece - 1 ] = true; + if (inside_piece.piece >= 1) { + inside_flags[ inside_piece.piece - 1 ] = true; } } diff --git a/src/live_effects/lpe-bspline.cpp b/src/live_effects/lpe-bspline.cpp index e6d4315e3..a3f8dbc30 100644 --- a/src/live_effects/lpe-bspline.cpp +++ b/src/live_effects/lpe-bspline.cpp @@ -189,17 +189,16 @@ void sp_bspline_do_effect(SPCurve *curve, double helper_size) Geom::PathVector const original_pathv = curve->get_pathvector(); curve->reset(); Inkscape::Preferences *prefs = Inkscape::Preferences::get(); - for (Geom::PathVector::const_iterator path_it = original_pathv.begin(); - path_it != original_pathv.end(); ++path_it) { - if (path_it->empty()) { + for (const auto & path_it : original_pathv) { + if (path_it.empty()) { continue; } if (!prefs->getBool("/tools/nodes/show_outline", true)){ - hp.push_back(*path_it); + hp.push_back(path_it); } - Geom::Path::const_iterator curve_it1 = path_it->begin(); - Geom::Path::const_iterator curve_it2 = ++(path_it->begin()); - Geom::Path::const_iterator curve_endit = path_it->end_default(); + Geom::Path::const_iterator curve_it1 = path_it.begin(); + Geom::Path::const_iterator curve_it2 = ++(path_it.begin()); + Geom::Path::const_iterator curve_endit = path_it.end_default(); SPCurve *curve_n = new SPCurve(); Geom::Point previousNode(0, 0); Geom::Point node(0, 0); @@ -211,8 +210,8 @@ void sp_bspline_do_effect(SPCurve *curve, double helper_size) Geom::D2<Geom::SBasis> sbasis_helper; Geom::CubicBezier const *cubic = nullptr; curve_n->moveto(curve_it1->initialPoint()); - if (path_it->closed()) { - const Geom::Curve &closingline = path_it->back_closed(); + if (path_it.closed()) { + const Geom::Curve &closingline = path_it.back_closed(); // the closing line segment is always of type // Geom::LineSegment. if (are_near(closingline.initialPoint(), closingline.finalPoint())) { @@ -220,7 +219,7 @@ void sp_bspline_do_effect(SPCurve *curve, double helper_size) // *exact* zero length, which goes wrong for relative coordinates and // rounding errors... // the closing line segment has zero-length. So stop before that one! - curve_endit = path_it->end_open(); + curve_endit = path_it.end_open(); } } while (curve_it1 != curve_endit) { @@ -264,13 +263,13 @@ void sp_bspline_do_effect(SPCurve *curve, double helper_size) out->reset(); delete out; } - if (path_it->closed() && curve_it2 == curve_endit) { + if (path_it.closed() && curve_it2 == curve_endit) { SPCurve *start = new SPCurve(); - start->moveto(path_it->begin()->initialPoint()); - start->lineto(path_it->begin()->finalPoint()); + start->moveto(path_it.begin()->initialPoint()); + start->lineto(path_it.begin()->finalPoint()); Geom::D2<Geom::SBasis> sbasis_start = start->first_segment()->toSBasis(); SPCurve *line_helper = new SPCurve(); - cubic = dynamic_cast<Geom::CubicBezier const *>(&*path_it->begin()); + cubic = dynamic_cast<Geom::CubicBezier const *>(&*path_it.begin()); if (cubic) { line_helper->moveto(sbasis_start.valueAt( Geom::nearest_time((*cubic)[1], *start->first_segment()))); @@ -301,7 +300,7 @@ void sp_bspline_do_effect(SPCurve *curve, double helper_size) curve_n->move_endpoints(node, node); } else if ( curve_it2 == curve_endit) { curve_n->curveto(point_at1, point_at2, curve_it1->finalPoint()); - curve_n->move_endpoints(path_it->begin()->initialPoint(), curve_it1->finalPoint()); + curve_n->move_endpoints(path_it.begin()->initialPoint(), curve_it1->finalPoint()); } else { SPCurve *line_helper = new SPCurve(); line_helper->moveto(point_at2); @@ -323,7 +322,7 @@ void sp_bspline_do_effect(SPCurve *curve, double helper_size) ++curve_it1; ++curve_it2; } - if (path_it->closed()) { + if (path_it.closed()) { curve_n->closepath_current(); } curve->append(curve_n, false); @@ -359,15 +358,14 @@ void LPEBSpline::doBSplineFromWidget(SPCurve *curve, double weight_ammount) Geom::PathVector const original_pathv = curve->get_pathvector(); curve->reset(); - for (Geom::PathVector::const_iterator path_it = original_pathv.begin(); - path_it != original_pathv.end(); ++path_it) { + for (const auto & path_it : original_pathv) { - if (path_it->empty()) { + if (path_it.empty()) { continue; } - Geom::Path::const_iterator curve_it1 = path_it->begin(); - Geom::Path::const_iterator curve_it2 = ++(path_it->begin()); - Geom::Path::const_iterator curve_endit = path_it->end_default(); + Geom::Path::const_iterator curve_it1 = path_it.begin(); + Geom::Path::const_iterator curve_it2 = ++(path_it.begin()); + Geom::Path::const_iterator curve_endit = path_it.end_default(); SPCurve *curve_n = new SPCurve(); Geom::Point point_at0(0, 0); @@ -378,8 +376,8 @@ void LPEBSpline::doBSplineFromWidget(SPCurve *curve, double weight_ammount) Geom::D2<Geom::SBasis> sbasis_out; Geom::CubicBezier const *cubic = nullptr; curve_n->moveto(curve_it1->initialPoint()); - if (path_it->closed()) { - const Geom::Curve &closingline = path_it->back_closed(); + if (path_it.closed()) { + const Geom::Curve &closingline = path_it.back_closed(); // the closing line segment is always of type // Geom::LineSegment. if (are_near(closingline.initialPoint(), closingline.finalPoint())) { @@ -387,7 +385,7 @@ void LPEBSpline::doBSplineFromWidget(SPCurve *curve, double weight_ammount) // *exact* zero length, which goes wrong for relative coordinates and // rounding errors... // the closing line segment has zero-length. So stop before that one! - curve_endit = path_it->end_open(); + curve_endit = path_it.end_open(); } } while (curve_it1 != curve_endit) { @@ -461,13 +459,13 @@ void LPEBSpline::doBSplineFromWidget(SPCurve *curve, double weight_ammount) ++curve_it1; ++curve_it2; } - if (path_it->closed()) { - curve_n->move_endpoints(path_it->begin()->initialPoint(), - path_it->begin()->initialPoint()); + if (path_it.closed()) { + curve_n->move_endpoints(path_it.begin()->initialPoint(), + path_it.begin()->initialPoint()); } else { - curve_n->move_endpoints(path_it->begin()->initialPoint(), point_at3); + curve_n->move_endpoints(path_it.begin()->initialPoint(), point_at3); } - if (path_it->closed()) { + if (path_it.closed()) { curve_n->closepath_current(); } curve->append(curve_n, false); diff --git a/src/live_effects/lpe-clone-original.cpp b/src/live_effects/lpe-clone-original.cpp index 2ce860061..1ea2770ba 100644 --- a/src/live_effects/lpe-clone-original.cpp +++ b/src/live_effects/lpe-clone-original.cpp @@ -74,10 +74,9 @@ LPECloneOriginal::cloneAttrbutes(SPObject *origin, SPObject *dest, const gchar * if ( SP_IS_GROUP(origin) && SP_IS_GROUP(dest) && SP_GROUP(origin)->getItemCount() == SP_GROUP(dest)->getItemCount() ) { std::vector< SPObject * > childs = origin->childList(true); size_t index = 0; - for (std::vector<SPObject * >::iterator obj_it = childs.begin(); - obj_it != childs.end(); ++obj_it) { + for (auto & child : childs) { SPObject *dest_child = dest->nthChild(index); - cloneAttrbutes((*obj_it), dest_child, attributes, style_attributes); + cloneAttrbutes(child, dest_child, attributes, style_attributes); index++; } } diff --git a/src/live_effects/lpe-copy_rotate.cpp b/src/live_effects/lpe-copy_rotate.cpp index 3632d3a62..be0165776 100644 --- a/src/live_effects/lpe-copy_rotate.cpp +++ b/src/live_effects/lpe-copy_rotate.cpp @@ -200,10 +200,9 @@ LPECopyRotate::cloneD(SPObject *orig, SPObject *dest, Geom::Affine transform, bo if ( SP_IS_GROUP(orig) && SP_IS_GROUP(dest) && SP_GROUP(orig)->getItemCount() == SP_GROUP(dest)->getItemCount() ) { std::vector< SPObject * > childs = orig->childList(true); size_t index = 0; - for (std::vector<SPObject * >::iterator obj_it = childs.begin(); - obj_it != childs.end(); ++obj_it) { + for (auto & child : childs) { SPObject *dest_child = dest->nthChild(index); - cloneD(*obj_it, dest_child, transform, reset); + cloneD(child, dest_child, transform, reset); index++; } return; @@ -251,8 +250,7 @@ LPECopyRotate::createPathBase(SPObject *elemref) { container->setAttribute("transform", prev->attribute("transform")); std::vector<SPItem*> const item_list = sp_item_group_item_list(group); Inkscape::XML::Node *previous = nullptr; - for ( std::vector<SPItem*>::const_iterator iter=item_list.begin();iter!=item_list.end();++iter) { - SPObject *sub_item = *iter; + for (auto sub_item : item_list) { Inkscape::XML::Node *resultnode = createPathBase(sub_item); container->addChild(resultnode, previous); previous = resultnode; @@ -427,12 +425,11 @@ LPECopyRotate::split(Geom::PathVector &path_on, Geom::Path const ÷r) int position = 0; Geom::Crossings cs = crossings(original,divider); std::vector<double> crossed; - for(unsigned int i = 0; i < cs.size(); i++) { - crossed.push_back(cs[i].ta); + for(auto & c : cs) { + crossed.push_back(c.ta); } std::sort(crossed.begin(), crossed.end()); - for (unsigned int i = 0; i < crossed.size(); i++) { - double time_end = crossed[i]; + for (double time_end : crossed) { if (time_start == time_end || time_end - time_start < Geom::EPSILON) { continue; } diff --git a/src/live_effects/lpe-curvestitch.cpp b/src/live_effects/lpe-curvestitch.cpp index 254065da8..aa7a39b77 100644 --- a/src/live_effects/lpe-curvestitch.cpp +++ b/src/live_effects/lpe-curvestitch.cpp @@ -159,8 +159,8 @@ LPECurveStitch::resetDefaults(SPItem const* item) // calculate bounding box: (isn't there a simpler way?) Piecewise<D2<SBasis> > pwd2; Geom::PathVector temppath = sp_svg_read_pathv( item->getRepr()->attribute("inkscape:original-d")); - for (unsigned int i=0; i < temppath.size(); i++) { - pwd2.concat( temppath[i].toPwSb() ); + for (const auto & i : temppath) { + pwd2.concat( i.toPwSb() ); } D2<Piecewise<SBasis> > d2pw = make_cuts_independent(pwd2); OptInterval bndsX = bounds_exact(d2pw[0]); diff --git a/src/live_effects/lpe-dash-stroke.cpp b/src/live_effects/lpe-dash-stroke.cpp index e55fdae7f..1972b583c 100644 --- a/src/live_effects/lpe-dash-stroke.cpp +++ b/src/live_effects/lpe-dash-stroke.cpp @@ -77,15 +77,15 @@ Geom::PathVector LPEDashStroke::doEffect_path(Geom::PathVector const & path_in){ Geom::PathVector const pv = pathv_to_linear_and_cubic_beziers(path_in); Geom::PathVector result; - for (Geom::PathVector::const_iterator path_it = pv.begin(); path_it != pv.end(); ++path_it) { - if (path_it->empty()) { + for (const auto & path_it : pv) { + if (path_it.empty()) { continue; } - Geom::Path::const_iterator curve_it1 = path_it->begin(); - Geom::Path::const_iterator curve_it2 = ++(path_it->begin()); - Geom::Path::const_iterator curve_endit = path_it->end_default(); - if (path_it->closed()) { - const Geom::Curve &closingline = path_it->back_closed(); + Geom::Path::const_iterator curve_it1 = path_it.begin(); + Geom::Path::const_iterator curve_it2 = ++(path_it.begin()); + Geom::Path::const_iterator curve_endit = path_it.end_default(); + if (path_it.closed()) { + const Geom::Curve &closingline = path_it.back_closed(); // the closing line segment is always of type // Geom::LineSegment. if (are_near(closingline.initialPoint(), closingline.finalPoint())) { @@ -93,7 +93,7 @@ LPEDashStroke::doEffect_path(Geom::PathVector const & path_in){ // *exact* zero length, which goes wrong for relative coordinates and // rounding errors... // the closing line segment has zero-length. So stop before that one! - curve_endit = path_it->end_open(); + curve_endit = path_it.end_open(); } } size_t numberdashes_fixed = numberdashes; @@ -118,7 +118,7 @@ LPEDashStroke::doEffect_path(Geom::PathVector const & path_in){ double holepercent = globalhole/numberholes; double dashsize_fixed = 0; double holesize_fixed = 0; - Geom::Piecewise<Geom::D2<Geom::SBasis> > pwd2 = (*path_it).toPwSb(); + Geom::Piecewise<Geom::D2<Geom::SBasis> > pwd2 = path_it.toPwSb(); double lenght_pwd2 = length (pwd2); double minlenght = lenght_pwd2; if(unifysegment) { @@ -132,15 +132,15 @@ LPEDashStroke::doEffect_path(Geom::PathVector const & path_in){ ++curve_it1; ++curve_it2; } - curve_it1 = path_it->begin(); - curve_it2 = ++(path_it->begin()); - curve_endit = path_it->end_default(); + curve_it1 = path_it.begin(); + curve_it2 = ++(path_it.begin()); + curve_endit = path_it.end_default(); } size_t p_index = 0; size_t start_index = result.size(); if(splitsegments) { while (curve_it1 != curve_endit) { - Geom::Path segment = (*path_it).portion(p_index, p_index + 1); + Geom::Path segment = path_it.portion(p_index, p_index + 1); if(unifysegment) { double integral; double fractional = modf((*curve_it1).length()/(dashsize_fixed + holesize_fixed), &integral); @@ -222,7 +222,7 @@ LPEDashStroke::doEffect_path(Geom::PathVector const & path_in){ } } if (curve_it2 == curve_endit) { - if (path_it->closed()) { + if (path_it.closed()) { Geom::Path end = result[result.size()-1]; end.setFinal(result[start_index].initialPoint()); end.append(result[start_index]); @@ -243,7 +243,7 @@ LPEDashStroke::doEffect_path(Geom::PathVector const & path_in){ } else { end = timeAtLength(dashsize,pwd2); } - result.push_back((*path_it).portion(start, end)); + result.push_back(path_it.portion(start, end)); double startsize = dashsize + holesize; if (halfextreme) { startsize = (dashsize/2.0) + holesize; @@ -251,14 +251,14 @@ LPEDashStroke::doEffect_path(Geom::PathVector const & path_in){ double endsize = startsize + dashsize; start = timeAtLength(startsize,pwd2); end = timeAtLength(endsize,pwd2); - while (start < (*path_it).size() && start > 0) { - result.push_back((*path_it).portion(start, end)); + while (start < path_it.size() && start > 0) { + result.push_back(path_it.portion(start, end)); startsize = endsize + holesize; endsize = startsize + dashsize; start = timeAtLength(startsize,pwd2); end = timeAtLength(endsize,pwd2); } - if (path_it->closed()) { + if (path_it.closed()) { Geom::Path end = result[result.size()-1]; end.setFinal(result[start_index].initialPoint()); end.append(result[start_index]); diff --git a/src/live_effects/lpe-embrodery-stitch-ordering.cpp b/src/live_effects/lpe-embrodery-stitch-ordering.cpp index 5761c4701..1c3548420 100644 --- a/src/live_effects/lpe-embrodery-stitch-ordering.cpp +++ b/src/live_effects/lpe-embrodery-stitch-ordering.cpp @@ -175,8 +175,8 @@ void OrderingOriginal(std::vector<OrderingInfo> &infos) void OrderingZigZag(std::vector<OrderingInfo> &infos, bool revfirst) { - for (std::vector<OrderingInfo>::iterator it = infos.begin(); it != infos.end(); ++it) { - it->reverse = (it->index & 1) == (revfirst ? 0 : 1); + for (auto & info : infos) { + info.reverse = (info.index & 1) == (revfirst ? 0 : 1); } } @@ -260,32 +260,32 @@ void OrderingPoint::FindNearest2(const std::vector<OrderingInfoEx *> &infos) nearest[0] = nullptr; nearest[1] = nullptr; - for (std::vector<OrderingInfoEx *>::const_iterator it = infos.begin(); it != infos.end(); ++it) { - Coord dist = distance(point, (*it)->beg.point); + for (auto info : infos) { + Coord dist = distance(point, info->beg.point); if (dist < dist1) { - if (&(*it)->beg != this && &(*it)->end != this) { + if (&info->beg != this && &info->end != this) { if (dist < dist0) { nearest[1] = nearest[0]; - nearest[0] = &(*it)->beg; + nearest[0] = &info->beg; dist1 = dist0; dist0 = dist; } else { - nearest[1] = &(*it)->beg; + nearest[1] = &info->beg; dist1 = dist; } } } - dist = distance(point, (*it)->end.point); + dist = distance(point, info->end.point); if (dist < dist1) { - if (&(*it)->beg != this && &(*it)->end != this) { + if (&info->beg != this && &info->end != this) { if (dist < dist0) { nearest[1] = nearest[0]; - nearest[0] = &(*it)->end; + nearest[0] = &info->end; dist1 = dist0; dist0 = dist; } else { - nearest[1] = &(*it)->end; + nearest[1] = &info->end; dist1 = dist; } } @@ -403,14 +403,14 @@ bool OrderingGroupNeighbor::Compare(const OrderingGroupNeighbor &a, const Orderi OrderingGroupNeighbor *OrderingGroupPoint::FindNearestUnused() { - for (std::vector<OrderingGroupNeighbor>::iterator it = nearest.begin(); it != nearest.end(); ++it) { - if (!it->point->used) { + for (auto & it : nearest) { + if (!it.point->used) { DebugTrace1TSP(("Nearest: group %d, size %d, point %d, nghb %d, xFrom %.4lf, yFrom %.4lf, xTo %.4lf, yTo %.4lf, dist %.4lf", it->point->group->index, it->point->group->items.size(), it->point->indexInGroup, it - nearest.begin(), point.x(), 297 - point.y(), it->point->point.x(), 297 - it->point->point.y(), it->distance)); - return &*it; + return ⁢ } } @@ -641,11 +641,11 @@ bool FindShortestReconnect(std::vector<OrderingSegment> &segments, std::vector<O if (contains(connections, *longestConnect)) { // The longest connection is inside the active set, so we need to search for the longest outside Coord length = 0.0; - for (std::vector<OrderingGroupConnection *>::iterator it = allconnections.begin(); it != allconnections.end(); it++) { - if ((*it)->Distance() > length) { - if (!contains(connections, *it)) { - longestOutside = *it; - length = (*it)->Distance(); + for (auto & allconnection : allconnections) { + if (allconnection->Distance() > length) { + if (!contains(connections, allconnection)) { + longestOutside = allconnection; + length = allconnection->Distance(); } } } @@ -662,13 +662,13 @@ bool FindShortestReconnect(std::vector<OrderingSegment> &segments, std::vector<O // Assign a swap bit and end bit to each active connection int nEndBits = 0; int nSwapBits = 0; - for (std::vector<OrderingSegment>::iterator it = segments.begin(); it != segments.end(); it++) { - it->endbit = nEndBits++; - if (it->nEndPoints == 4) { - it->swapbit = nSwapBits++; + for (auto & segment : segments) { + segment.endbit = nEndBits++; + if (segment.nEndPoints == 4) { + segment.swapbit = nSwapBits++; } else { // bit 32 should always be 0 - it->swapbit = 31; + segment.swapbit = 31; } } @@ -702,14 +702,14 @@ bool FindShortestReconnect(std::vector<OrderingSegment> &segments, std::vector<O // Close the loop with the end point of the last segment OrderingGroupPoint *prevend = segments[permutation.back()].GetEndPoint(iSwap, iEnd); - for (std::vector<int>::iterator it = permutation.begin(); it != permutation.end(); it++) { - OrderingGroupPoint *thisbeg = segments[*it].GetBeginPoint(iSwap, iEnd); + for (int & it : permutation) { + OrderingGroupPoint *thisbeg = segments[it].GetBeginPoint(iSwap, iEnd); Coord length = Geom::distance(thisbeg->point, prevend->point); lengthTotal += length; if (length > lengthLongest) { lengthLongest = length; } - prevend = segments[*it].GetEndPoint(iSwap, iEnd); + prevend = segments[it].GetEndPoint(iSwap, iEnd); } lengthTotal -= lengthLongest; @@ -723,11 +723,11 @@ bool FindShortestReconnect(std::vector<OrderingSegment> &segments, std::vector<O // Just debug printing OrderingGroupPoint *prevend = segments[permutation.back()].GetEndPoint(iSwap, iEnd); - for (std::vector<int>::iterator it = permutation.begin(); it != permutation.end(); it++) { - OrderingGroupPoint *thisbeg = segments[*it].GetBeginPoint(iSwap, iEnd); + for (int & it : permutation) { + OrderingGroupPoint *thisbeg = segments[it].GetBeginPoint(iSwap, iEnd); DebugTrace2TSP(("IMP 0F=%d %d %.6lf", thisbeg->group->index, thisbeg->indexInGroup, Geom::distance(thisbeg->point, prevend->point))); DebugTrace2TSP(("IMP 0T=%d %d %.6lf", prevend->group->index, prevend->indexInGroup, Geom::distance(thisbeg->point, prevend->point))); - prevend = segments[*it].GetEndPoint(iSwap, iEnd); + prevend = segments[it].GetEndPoint(iSwap, iEnd); } } @@ -768,9 +768,9 @@ bool FindShortestReconnect(std::vector<OrderingSegment> &segments, std::vector<O } (*longestConnect) = longestOutside; - for (std::vector<OrderingGroupConnection *>::iterator it = connections.begin(); it != connections.end(); ++it) { - if ((*it)->Distance() > (*longestConnect)->Distance()) { - *longestConnect = *it; + for (auto & connection : connections) { + if (connection->Distance() > (*longestConnect)->Distance()) { + *longestConnect = connection; } } DebugTrace2TSP(("LONG =%d %d %.6lf", (*longestConnect)->points[0]->group->index, (*longestConnect)->points[0]->indexInGroup, (*longestConnect)->Distance())); @@ -783,10 +783,10 @@ bool FindShortestReconnect(std::vector<OrderingSegment> &segments, std::vector<O // Check if connections form a tour void AssertIsTour(std::vector<OrderingGroup *> &groups, std::vector<OrderingGroupConnection *> &connections, OrderingGroupConnection *longestConnection) { - for (std::vector<OrderingGroupConnection *>::iterator it = connections.begin(); it != connections.end(); it++) { + for (auto & connection : connections) { for (int i = 0; i < 2; i++) { - OrderingGroupPoint *pnt = (*it)->points[i]; - assert(pnt->connection == *it); + OrderingGroupPoint *pnt = connection->points[i]; + assert(pnt->connection == connection); assert(pnt->connection->points[pnt->indexInConnection] == pnt); assert(pnt->group->endpoints[pnt->indexInGroup] == pnt); } @@ -872,8 +872,8 @@ void OrderGroups(std::vector<OrderingGroup *> *groups, const int nDims) } // Initialize the endpoints for all groups - for (std::vector<OrderingGroup *>::iterator it = groups->begin(); it != groups->end(); ++it) { - (*it)->SetEndpoints(); + for (auto & group : *groups) { + group->SetEndpoints(); } // Find the neighboring points for all end points of all groups and sort by distance @@ -1048,9 +1048,9 @@ void OrderingAdvanced(std::vector<OrderingInfo> &infos, int nDims) ) // Make sure the nearest points are mutual - for (std::vector<OrderingInfoEx *>::iterator it = infoex.begin(); it != infoex.end(); ++it) { - (*it)->beg.EnforceMutual(); - (*it)->end.EnforceMutual(); + for (auto & it : infoex) { + it->beg.EnforceMutual(); + it->end.EnforceMutual(); } DebugTraceGrouping( @@ -1062,9 +1062,9 @@ void OrderingAdvanced(std::vector<OrderingInfo> &infos, int nDims) ) // Make sure the nearest points for begin and end lead to the same sub-path (same index) - for (std::vector<OrderingInfoEx *>::iterator it = infoex.begin(); it != infoex.end(); ++it) { - (*it)->beg.EnforceSymmetric((*it)->end); - (*it)->end.EnforceSymmetric((*it)->beg); + for (auto & it : infoex) { + it->beg.EnforceSymmetric(it->end); + it->end.EnforceSymmetric(it->beg); } DebugTraceGrouping( @@ -1085,10 +1085,10 @@ void OrderingAdvanced(std::vector<OrderingInfo> &infos, int nDims) std::vector<OrderingInfo> result; result.reserve(infos.size()); int nUngrouped = 0; - for (std::vector<OrderingInfoEx *>::iterator it = infoex.begin(); it != infoex.end(); ++it) { - if (!(*it)->grouped) { + for (auto & it : infoex) { + if (!it->grouped) { groups.push_back(new OrderingGroup(groups.size())); - groups.back()->items.push_back(*it); + groups.back()->items.push_back(it); nUngrouped++; } } @@ -1105,17 +1105,17 @@ void OrderingAdvanced(std::vector<OrderingInfo> &infos, int nDims) OrderGroups(&groups, nDims); // Copy grouped lines to output - for (std::vector<OrderingGroup *>::iterator itGroup = groups.begin(); itGroup != groups.end(); ++itGroup) { - for (unsigned int iItem = 0; iItem < (*itGroup)->items.size(); iItem++) { - unsigned int iItemRev = (*itGroup)->revItemList ? (*itGroup)->items.size() - 1 - iItem : iItem; - OrderingInfoEx *item = (*itGroup)->items[iItemRev]; + for (auto & group : groups) { + for (unsigned int iItem = 0; iItem < group->items.size(); iItem++) { + unsigned int iItemRev = group->revItemList ? group->items.size() - 1 - iItem : iItem; + OrderingInfoEx *item = group->items[iItemRev]; // If revItems is false, even items shall have reverse=false // In this case ( ( iItem & 1 ) == 0 )== true, revItems=false, (true==false) == false - bool reverse = ((iItem & 1) == 0) == (*itGroup)->revItems; + bool reverse = ((iItem & 1) == 0) == group->revItems; if (!reverse) { - for (std::vector<int>::iterator itOrig = item->origIndices.begin(); itOrig != item->origIndices.end(); ++itOrig) { - result.push_back(infos[*itOrig]); + for (int & origIndice : item->origIndices) { + result.push_back(infos[origIndice]); result.back().reverse = false; } } else { diff --git a/src/live_effects/lpe-embrodery-stitch.cpp b/src/live_effects/lpe-embrodery-stitch.cpp index a0350fec5..4435c3463 100644 --- a/src/live_effects/lpe-embrodery-stitch.cpp +++ b/src/live_effects/lpe-embrodery-stitch.cpp @@ -333,11 +333,11 @@ PathVector LPEEmbroderyStitch::doEffect_path(PathVector const &path_in) } if (show_stitches) { - for (std::vector< D2<SBasis> >::iterator it = pwStitch.segs.begin(); it != pwStitch.segs.end(); ++it) { + for (auto & seg : pwStitch.segs) { // Create anew piecewise with just one segment Piecewise<D2<SBasis> > pwOne; pwOne.push_cut(0); - pwOne.push_seg(*it); + pwOne.push_seg(seg); pwOne.push_cut(1); // make piecewise equidistant in time @@ -360,11 +360,11 @@ PathVector LPEEmbroderyStitch::doEffect_path(PathVector const &path_in) } } else { PathVector pathv = path_from_piecewise(pwStitch, LPE_CONVERSION_TOLERANCE); - for (size_t ipv = 0; ipv < pathv.size(); ipv++) { + for (const auto & ipv : pathv) { if (connect_with_previous) { - path_out.back().append(pathv[ipv]); + path_out.back().append(ipv); } else { - path_out.push_back(pathv[ipv]); + path_out.push_back(ipv); } } } diff --git a/src/live_effects/lpe-extrude.cpp b/src/live_effects/lpe-extrude.cpp index 8cc9b7468..57e5ca2ce 100644 --- a/src/live_effects/lpe-extrude.cpp +++ b/src/live_effects/lpe-extrude.cpp @@ -83,13 +83,13 @@ LPEExtrude::doEffect_pwd2 (Geom::Piecewise<Geom::D2<Geom::SBasis> > const & pwd2 // connecting lines should be put at cusps Piecewise<D2<SBasis> > deriv = derivative(pwd2_in); std::vector<double> cusps; // = roots(deriv); - for (unsigned i = 0; i < cusps.size() ; ++i) { - pwd2_out.concat( connector + pwd2_in.valueAt(cusps[i]) ); + for (double cusp : cusps) { + pwd2_out.concat( connector + pwd2_in.valueAt(cusp) ); } // connecting lines should be put where the tangent of the path equals the extrude_vector in direction std::vector<double> rts = roots(dot(deriv, rot90(extrude_vector.getVector()))); - for (unsigned i = 0; i < rts.size() ; ++i) { - pwd2_out.concat( connector + pwd2_in.valueAt(rts[i]) ); + for (double rt : rts) { + pwd2_out.concat( connector + pwd2_in.valueAt(rt) ); } return pwd2_out; } diff --git a/src/live_effects/lpe-fill-between-many.cpp b/src/live_effects/lpe-fill-between-many.cpp index 6eb5750f0..c5121c37a 100644 --- a/src/live_effects/lpe-fill-between-many.cpp +++ b/src/live_effects/lpe-fill-between-many.cpp @@ -80,22 +80,21 @@ void LPEFillBetweenMany::doEffect (SPCurve * curve) selection = desktop->selection; } if (!autoreverse) { - for (std::vector<PathAndDirectionAndVisible *>::iterator iter = linked_paths._vector.begin(); - iter != linked_paths._vector.end(); ++iter) { + for (auto & iter : linked_paths._vector) { SPObject *obj; - if ((*iter)->ref.isAttached() && (obj = (*iter)->ref.getObject()) && SP_IS_ITEM(obj) && - !(*iter)->_pathvector.empty() && (*iter)->visibled) { + if (iter->ref.isAttached() && (obj = iter->ref.getObject()) && SP_IS_ITEM(obj) && + !iter->_pathvector.empty() && iter->visibled) { Geom::Path linked_path; - if ((*iter)->_pathvector.front().closed() && linked_paths._vector.size() > 1) { + if (iter->_pathvector.front().closed() && linked_paths._vector.size() > 1) { continue; } if (obj && transf != Geom::identity() && selection && !selection->includes(obj->getRepr())) { SP_ITEM(obj)->doWriteTransform(transf); } - if ((*iter)->reversed) { - linked_path = (*iter)->_pathvector.front().reversed(); + if (iter->reversed) { + linked_path = iter->_pathvector.front().reversed(); } else { - linked_path = (*iter)->_pathvector.front(); + linked_path = iter->_pathvector.front(); } if (!res_pathv.empty() && join) { if (!are_near(res_pathv.front().finalPoint(), linked_path.initialPoint(), 0.01) || !fuse) { @@ -142,26 +141,25 @@ void LPEFillBetweenMany::doEffect (SPCurve * curve) unsigned int counter2 = 0; unsigned int added = 0; PathAndDirectionAndVisible *nearest = nullptr; - for (std::vector<PathAndDirectionAndVisible *>::iterator iter2 = linked_paths._vector.begin(); - iter2 != linked_paths._vector.end(); ++iter2) { + for (auto & iter2 : linked_paths._vector) { SPObject *obj2; - if ((*iter2)->ref.isAttached() && (obj2 = (*iter2)->ref.getObject()) && SP_IS_ITEM(obj2) && - !(*iter2)->_pathvector.empty() && (*iter2)->visibled) { + if (iter2->ref.isAttached() && (obj2 = iter2->ref.getObject()) && SP_IS_ITEM(obj2) && + !iter2->_pathvector.empty() && iter2->visibled) { if (obj == obj2 || std::find(done.begin(), done.end(), counter2) != done.end()) { counter2++; continue; } - if ((*iter2)->_pathvector.front().closed() && linked_paths._vector.size() > 1) { + if (iter2->_pathvector.front().closed() && linked_paths._vector.size() > 1) { counter2++; continue; } - Geom::Point start = (*iter2)->_pathvector.front().initialPoint(); - Geom::Point end = (*iter2)->_pathvector.front().finalPoint(); + Geom::Point start = iter2->_pathvector.front().initialPoint(); + Geom::Point end = iter2->_pathvector.front().finalPoint(); Geom::Coord distance_iter = std::min(Geom::distance(current, end), Geom::distance(current, start)); if (distance > distance_iter) { distance = distance_iter; - nearest = (*iter2); + nearest = iter2; added = counter2; } counter2++; diff --git a/src/live_effects/lpe-fill-between-strokes.cpp b/src/live_effects/lpe-fill-between-strokes.cpp index 3b00b2d03..262a5f9d0 100644 --- a/src/live_effects/lpe-fill-between-strokes.cpp +++ b/src/live_effects/lpe-fill-between-strokes.cpp @@ -60,13 +60,13 @@ void LPEFillBetweenStrokes::doEffect (SPCurve * curve) Geom::PathVector second_pathv = second_path.get_pathvector(); Geom::PathVector result_linked_pathv; Geom::PathVector result_second_pathv; - for (Geom::PathVector::iterator iter = linked_pathv.begin(); iter != linked_pathv.end(); ++iter) + for (auto & iter : linked_pathv) { - result_linked_pathv.push_back((*iter)); + result_linked_pathv.push_back(iter); } - for (Geom::PathVector::iterator iter = second_pathv.begin(); iter != second_pathv.end(); ++iter) + for (auto & iter : second_pathv) { - result_second_pathv.push_back((*iter)); + result_second_pathv.push_back(iter); } if ( !result_linked_pathv.empty() && !result_second_pathv.empty() && !result_linked_pathv.front().closed() ) { @@ -104,9 +104,9 @@ void LPEFillBetweenStrokes::doEffect (SPCurve * curve) } Geom::PathVector linked_pathv = linked_path.get_pathvector(); Geom::PathVector result_pathv; - for (Geom::PathVector::iterator iter = linked_pathv.begin(); iter != linked_pathv.end(); ++iter) + for (auto & iter : linked_pathv) { - result_pathv.push_back((*iter)); + result_pathv.push_back(iter); } if ( !result_pathv.empty() ) { if (close) { @@ -122,9 +122,9 @@ void LPEFillBetweenStrokes::doEffect (SPCurve * curve) } Geom::PathVector second_pathv = second_path.get_pathvector(); Geom::PathVector result_pathv; - for (Geom::PathVector::iterator iter = second_pathv.begin(); iter != second_pathv.end(); ++iter) + for (auto & iter : second_pathv) { - result_pathv.push_back((*iter)); + result_pathv.push_back(iter); } if ( !result_pathv.empty() ) { if (close) { diff --git a/src/live_effects/lpe-fillet-chamfer.cpp b/src/live_effects/lpe-fillet-chamfer.cpp index 0574b5b4b..e0aada95b 100644 --- a/src/live_effects/lpe-fillet-chamfer.cpp +++ b/src/live_effects/lpe-fillet-chamfer.cpp @@ -109,12 +109,12 @@ void LPEFilletChamfer::doOnApply(SPLPEItem const *lpeItem) if (it != gchar_map_to_satellite_type.end()) { satellite_type = it->second; } - for (Geom::PathVector::const_iterator path_it = pathv.begin(); path_it != pathv.end(); ++path_it) { - if (path_it->empty()) { + for (const auto & path_it : pathv) { + if (path_it.empty()) { continue; } std::vector<Satellite> subpath_satellites; - for (Geom::Path::const_iterator curve_it = path_it->begin(); curve_it != path_it->end(); ++curve_it) { + for (Geom::Path::const_iterator curve_it = path_it.begin(); curve_it != path_it.end(); ++curve_it) { //Maybe we want this satellites... //if (curve_it->isDegenerate()) { // continue @@ -131,7 +131,7 @@ void LPEFilletChamfer::doOnApply(SPLPEItem const *lpeItem) //so maybe in the future we can need this last satellite in other effects //don't remove for this effect because _pathvector_satellites class has methods when the path is modified //and we want one method for all uses - if (!path_it->closed()) { + if (!path_it.closed()) { Satellite satellite(satellite_type); satellite.setSteps(chamfer_steps); satellite.setAmount(power); diff --git a/src/live_effects/lpe-interpolate_points.cpp b/src/live_effects/lpe-interpolate_points.cpp index d1e94a392..6748aae37 100644 --- a/src/live_effects/lpe-interpolate_points.cpp +++ b/src/live_effects/lpe-interpolate_points.cpp @@ -53,18 +53,18 @@ LPEInterpolatePoints::doEffect_path (Geom::PathVector const & path_in) Geom::PathVector path_out; std::unique_ptr<Geom::Interpolate::Interpolator> interpolator( Geom::Interpolate::Interpolator::create(static_cast<Geom::Interpolate::InterpolatorType>(interpolator_type.get_value())) ); - for(Geom::PathVector::const_iterator path_it = path_in.begin(); path_it != path_in.end(); ++path_it) { - if (path_it->empty()) + for(const auto & path_it : path_in) { + if (path_it.empty()) continue; - if (path_it->closed()) { + if (path_it.closed()) { g_warning("Interpolate points LPE currently ignores whether path is closed or not."); } std::vector<Geom::Point> pts; - pts.push_back(path_it->initialPoint()); + pts.push_back(path_it.initialPoint()); - for (Geom::Path::const_iterator it = path_it->begin(), e = path_it->end_default(); it != e; ++it) { + for (Geom::Path::const_iterator it = path_it.begin(), e = path_it.end_default(); it != e; ++it) { pts.push_back((*it).finalPoint()); } diff --git a/src/live_effects/lpe-jointype.cpp b/src/live_effects/lpe-jointype.cpp index ad3fcb9f6..df39fe0d0 100644 --- a/src/live_effects/lpe-jointype.cpp +++ b/src/live_effects/lpe-jointype.cpp @@ -168,8 +168,8 @@ void LPEJoinType::doOnRemove(SPLPEItem const* lpeitem) Geom::PathVector LPEJoinType::doEffect_path(Geom::PathVector const & path_in) { Geom::PathVector ret; - for (size_t i = 0; i < path_in.size(); ++i) { - Geom::PathVector tmp = Inkscape::outline(path_in[i], line_width, + for (const auto & i : path_in) { + Geom::PathVector tmp = Inkscape::outline(i, line_width, (attempt_force_join ? std::numeric_limits<double>::max() : miter_limit), static_cast<LineJoinType>(linejoin_type.get_value()), static_cast<LineCapType>(linecap_type.get_value())); diff --git a/src/live_effects/lpe-knot.cpp b/src/live_effects/lpe-knot.cpp index f16c11bb2..d48dbd765 100644 --- a/src/live_effects/lpe-knot.cpp +++ b/src/live_effects/lpe-knot.cpp @@ -79,10 +79,10 @@ std::vector<Geom::Interval> complementOf(Geom::Interval I, std::vector<Geom::Int Geom::Interval I1 = Geom::Interval(min,I.min()); Geom::Interval I2 = Geom::Interval(I.max(),max); - for (unsigned i = 0; i<domain.size(); i++){ - boost::optional<Geom::Interval> I1i = intersect(domain.at(i),I1); + for (auto i : domain){ + boost::optional<Geom::Interval> I1i = intersect(i,I1); if (I1i && !I1i->isSingular()) ret.push_back(I1i.get()); - boost::optional<Geom::Interval> I2i = intersect(domain.at(i),I2); + boost::optional<Geom::Interval> I2i = intersect(i,I2); if (I2i && !I2i->isSingular()) ret.push_back(I2i.get()); } } @@ -119,8 +119,8 @@ findShadowedTime(Geom::Path const &patha, std::vector<Geom::Point> const &pt_and times_i.insert(times_i.end(), temptimes.begin(), temptimes.end() ); temptimes = roots(f[X]+3*width); times_i.insert(times_i.end(), temptimes.begin(), temptimes.end() ); - for (unsigned k=0; k<times_i.size(); k++){ - times_i[k]+=i; + for (double & k : times_i){ + k+=i; } times.insert(times.end(), times_i.begin(), times_i.end() ); } @@ -180,29 +180,29 @@ CrossingPoints::CrossingPoints(Geom::PathVector const &paths) : std::vector<Cros find_intersections( times, paths[i][ii].toSBasis(), paths[j][jj].toSBasis() ); } - for (unsigned k=0; k<times.size(); k++){ + for (auto & time : times){ //std::cout<<"intersection "<<i<<"["<<ii<<"]("<<times[k].first<<")= "<<j<<"["<<jj<<"]("<<times[k].second<<")\n"; - if ( !IS_NAN(times[k].first) && !IS_NAN(times[k].second) ){ + if ( !IS_NAN(time.first) && !IS_NAN(time.second) ){ double zero = 1e-4; - if ( (i==j) && (fabs(times[k].first+ii - times[k].second-jj) <= zero) ) + if ( (i==j) && (fabs(time.first+ii - time.second-jj) <= zero) ) { //this is just end=start of successive curves in a path. continue; } if ( (i==j) && (ii == 0) && (jj == size_nondegenerate(paths[i])-1) && paths[i].closed() - && (fabs(times[k].first) <= zero) - && (fabs(times[k].second - 1) <= zero) ) + && (fabs(time.first) <= zero) + && (fabs(time.second - 1) <= zero) ) {//this is just end=start of a closed path. continue; } CrossingPoint cp; - cp.pt = paths[i][ii].pointAt(times[k].first); + cp.pt = paths[i][ii].pointAt(time.first); cp.sign = 1; cp.i = i; cp.j = j; cp.ni = 0; cp.nj=0;//not set yet - cp.ti = times[k].first + ii; - cp.tj = times[k].second + jj; + cp.ti = time.first + ii; + cp.tj = time.second + jj; push_back(cp); }else{ std::cout<<"ooops: find_(self)_intersections returned NaN:" << std::endl; @@ -221,11 +221,11 @@ CrossingPoints::CrossingPoints(Geom::PathVector const &paths) : std::vector<Cros if (cp.j == i) cuts[cp.tj] = k; } unsigned count = 0; - for ( std::map < double, unsigned >::iterator m=cuts.begin(); m!=cuts.end(); ++m ){ - if ( ((*this)[m->second].i == i) && ((*this)[m->second].ti == m->first) ){ - (*this)[m->second].ni = count; + for (auto & cut : cuts){ + if ( ((*this)[cut.second].i == i) && ((*this)[cut.second].ti == cut.first) ){ + (*this)[cut.second].ni = count; }else{ - (*this)[m->second].nj = count; + (*this)[cut.second].nj = count; } count++; } @@ -412,7 +412,7 @@ LPEKnot::doEffect_path (Geom::PathVector const &path_in) return path_in; } Geom::PathVector const original_pathv = pathv_to_linear_and_cubic_beziers(path_in); - for (unsigned comp=0; comp<original_pathv.size(); comp++){ + for (const auto & comp : original_pathv){ //find the relevant path component in gpaths (required to allow groups!) //Q: do we always receive the group members in the same order? can we rest on that? @@ -421,7 +421,7 @@ LPEKnot::doEffect_path (Geom::PathVector const &path_in) gint precision = prefs->getInt("/options/svgoutput/numericprecision"); prefs->setInt("/options/svgoutput/numericprecision", 4); // I think this is enough for minor differences for (i0=0; i0<gpaths.size(); i0++){ - if (!strcmp(sp_svg_write_path(original_pathv[comp]), sp_svg_write_path(gpaths[i0]))) + if (!strcmp(sp_svg_write_path(comp), sp_svg_write_path(gpaths[i0]))) break; } prefs->setInt("/options/svgoutput/numericprecision", precision); @@ -556,8 +556,8 @@ collectPathsAndWidths (SPLPEItem const *lpeitem, Geom::PathVector &paths, std::v SPCurve * c = SP_SHAPE(lpeitem)->getCurve(); if (c) { Geom::PathVector subpaths = pathv_to_linear_and_cubic_beziers(c->get_pathvector()); - for (unsigned i=0; i<subpaths.size(); i++){ - paths.push_back(subpaths[i]); + for (const auto & subpath : subpaths){ + paths.push_back(subpath); //FIXME: do we have to be more careful when trying to access stroke width? stroke_widths.push_back(lpeitem->style->stroke_width.computed); } diff --git a/src/live_effects/lpe-measure-segments.cpp b/src/live_effects/lpe-measure-segments.cpp index 827f4b5ac..8768547e8 100644 --- a/src/live_effects/lpe-measure-segments.cpp +++ b/src/live_effects/lpe-measure-segments.cpp @@ -740,8 +740,8 @@ std::vector< Point > transformNodes(std::vector< Point > nodes, Geom::Affine transform) { std::vector< Point > result; - for ( std::vector<Point>::iterator iter = nodes.begin(); iter != nodes.end(); ++iter ) { - Geom::Point point = (*iter); + for (auto & node : nodes) { + Geom::Point point = node; result.push_back(point * transform); } return result; @@ -758,8 +758,7 @@ getNodes(SPItem * item, Geom::Affine transform, bool onbbox, bool centers, bool //TODO handle clones/use if (group) { std::vector<SPItem*> const item_list = sp_item_group_item_list(group); - for ( std::vector<SPItem*>::const_iterator iter=item_list.begin();iter!=item_list.end();++iter) { - SPItem *sub_item = *iter; + for (auto sub_item : item_list) { std::vector< Point > nodes = transformNodes(getNodes(sub_item, sub_item->transform, onbbox, centers, bboxonly), transform); current_nodes.insert(current_nodes.end(), nodes.begin(), nodes.end()); } @@ -849,8 +848,8 @@ LPEMeasureSegments::doBeforeEffect (SPLPEItem const* lpeitem) Geom::OptRect bbox = sp_lpe_item->geometricBounds(sp_lpe_item->transform); Geom::Point pojpoint = Geom::Point(); double maxdistance = -std::numeric_limits<double>::max(); - for ( std::vector<Point>::iterator iter = nodes.begin(); iter != nodes.end(); ++iter ) { - Geom::Point point = (*iter); + for (auto & node : nodes) { + Geom::Point point = node; point *= Geom::Translate(mid).inverse(); point *= Geom::Rotate(angle).inverse(); point *= Geom::Translate(mid); @@ -858,9 +857,9 @@ LPEMeasureSegments::doBeforeEffect (SPLPEItem const* lpeitem) maxdistance = point[Geom::X]; } } - for (std::vector<ItemAndActive*>::iterator iter = linked_items._vector.begin(); iter != linked_items._vector.end(); ++iter) { + for (auto & iter : linked_items._vector) { SPObject *obj; - if ((*iter)->ref.isAttached() && (*iter)->actived && (obj = (*iter)->ref.getObject()) && SP_IS_ITEM(obj)) { + if (iter->ref.isAttached() && iter->actived && (obj = iter->ref.getObject()) && SP_IS_ITEM(obj)) { SPItem * item = dynamic_cast<SPItem *>(obj); if (item) { Geom::Affine affinetransform_sub = i2anc_affine(SP_OBJECT(item), SP_OBJECT(document->getRoot())); @@ -874,8 +873,8 @@ LPEMeasureSegments::doBeforeEffect (SPLPEItem const* lpeitem) } } - for ( std::vector<Point>::iterator iter = nodes.begin(); iter != nodes.end(); ++iter ) { - Geom::Point point = (*iter); + for (auto & node : nodes) { + Geom::Point point = node; double dproj = Inkscape::Util::Quantity::convert(distance_projection, display_unit.c_str(), unit.get_abbreviation()); Geom::Coord xpos = maxdistance + dproj; result.emplace_back(xpos, point[Geom::Y]); @@ -885,8 +884,8 @@ LPEMeasureSegments::doBeforeEffect (SPLPEItem const* lpeitem) Geom::Point prevpoint(0,0); size_t counter = 0; bool started = false; - for ( std::vector<Point>::iterator iter = result.begin(); iter != result.end(); ++iter ) { - Geom::Point point = (*iter); + for (auto & iter : result) { + Geom::Point point = iter; if (Geom::are_near(prevpoint, point)){ continue; } diff --git a/src/live_effects/lpe-mirror_symmetry.cpp b/src/live_effects/lpe-mirror_symmetry.cpp index f5359ab85..55565adb4 100644 --- a/src/live_effects/lpe-mirror_symmetry.cpp +++ b/src/live_effects/lpe-mirror_symmetry.cpp @@ -282,10 +282,9 @@ LPEMirrorSymmetry::cloneD(SPObject *orig, SPObject *dest, bool reset) if ( SP_IS_GROUP(orig) && SP_IS_GROUP(dest) && SP_GROUP(orig)->getItemCount() == SP_GROUP(dest)->getItemCount() ) { std::vector< SPObject * > childs = orig->childList(true); size_t index = 0; - for (std::vector<SPObject * >::iterator obj_it = childs.begin(); - obj_it != childs.end(); ++obj_it) { + for (auto & child : childs) { SPObject *dest_child = dest->nthChild(index); - cloneD(*obj_it, dest_child, reset); + cloneD(child, dest_child, reset); index++; } return; @@ -322,8 +321,7 @@ LPEMirrorSymmetry::createPathBase(SPObject *elemref) { container->setAttribute("transform", prev->attribute("transform")); std::vector<SPItem*> const item_list = sp_item_group_item_list(group); Inkscape::XML::Node *previous = nullptr; - for ( std::vector<SPItem*>::const_iterator iter=item_list.begin();iter!=item_list.end();++iter) { - SPObject *sub_item = *iter; + for (auto sub_item : item_list) { Inkscape::XML::Node *resultnode = createPathBase(sub_item); container->addChild(resultnode, previous); previous = resultnode; @@ -471,24 +469,23 @@ LPEMirrorSymmetry::doEffect_path (Geom::PathVector const & path_in) Geom::Point gap = dir * split_gap; path_out *= Geom::Translate(gap); } else if (fuse_paths && !discard_orig_path) { - for (Geom::PathVector::const_iterator path_it = original_pathv.begin(); - path_it != original_pathv.end(); ++path_it) + for (const auto & path_it : original_pathv) { - if (path_it->empty()) { + if (path_it.empty()) { continue; } Geom::PathVector tmp_pathvector; double time_start = 0.0; int position = 0; bool end_open = false; - if (path_it->closed()) { - const Geom::Curve &closingline = path_it->back_closed(); + if (path_it.closed()) { + const Geom::Curve &closingline = path_it.back_closed(); if (!are_near(closingline.initialPoint(), closingline.finalPoint())) { end_open = true; } } - Geom::Path original = *path_it; - if (end_open && path_it->closed()) { + Geom::Path original = path_it; + if (end_open && path_it.closed()) { original.close(false); original.appendNew<Geom::LineSegment>( original.initialPoint() ); original.close(true); @@ -505,8 +502,8 @@ LPEMirrorSymmetry::doEffect_path (Geom::PathVector const & path_in) divider.appendNew<Geom::LineSegment>(e); Geom::Crossings cs = crossings(original, divider); std::vector<double> crossed; - for(unsigned int i = 0; i < cs.size(); i++) { - crossed.push_back(cs[i].ta); + for(auto & c : cs) { + crossed.push_back(c.ta); } std::sort(crossed.begin(), crossed.end()); for (unsigned int i = 0; i < crossed.size(); i++) { @@ -571,8 +568,8 @@ LPEMirrorSymmetry::doEffect_path (Geom::PathVector const & path_in) tmp_pathvector.clear(); } } else if (!fuse_paths || discard_orig_path) { - for (size_t i = 0; i < original_pathv.size(); ++i) { - path_out.push_back(original_pathv[i] * m); + for (const auto & i : original_pathv) { + path_out.push_back(i * m); } } return path_out; diff --git a/src/live_effects/lpe-offset.cpp b/src/live_effects/lpe-offset.cpp index e8a1e7df7..b67ff49e8 100644 --- a/src/live_effects/lpe-offset.cpp +++ b/src/live_effects/lpe-offset.cpp @@ -132,8 +132,8 @@ sp_get_outer(Geom::PathVector pathvector) Geom::OptRect bbox; Geom::Path ret; Geom::PathVector ret_pv; - for (Geom::PathVector::iterator path_it = pathvector.begin(); path_it != pathvector.end(); ++path_it) { - Geom::Path iter = (*path_it); + for (auto & path_it : pathvector) { + Geom::Path iter = path_it; if (iter.empty()) { continue; } @@ -157,8 +157,8 @@ sp_get_inner(Geom::PathVector pathvector) Geom::PathVector ret_pv; Geom::PathVector outer = sp_get_outer(pathvector); Geom::OptRect bbox = outer.boundsFast(); - for (Geom::PathVector::iterator path_it = pathvector.begin(); path_it != pathvector.end(); ++path_it) { - Geom::Path iter = (*path_it); + for (auto & path_it : pathvector) { + Geom::Path iter = path_it; if (iter.empty()) { continue; } diff --git a/src/live_effects/lpe-patternalongpath.cpp b/src/live_effects/lpe-patternalongpath.cpp index 57a3c3875..081c87990 100644 --- a/src/live_effects/lpe-patternalongpath.cpp +++ b/src/live_effects/lpe-patternalongpath.cpp @@ -184,8 +184,7 @@ LPEPatternAlongPath::doEffect_pwd2 (Geom::Piecewise<Geom::D2<Geom::SBasis> > con std::vector<Geom::Piecewise<Geom::D2<Geom::SBasis> > > paths_in; paths_in = split_at_discontinuities(pwd2_in); - for (unsigned idx = 0; idx < paths_in.size(); idx++){ - Geom::Piecewise<Geom::D2<Geom::SBasis> > path_i = paths_in[idx]; + for (auto path_i : paths_in){ Piecewise<SBasis> x = x0; Piecewise<SBasis> y = y0; Piecewise<D2<SBasis> > uskeleton = arc_length_parametrization(path_i,2, 0.1); @@ -257,8 +256,8 @@ LPEPatternAlongPath::doEffect_pwd2 (Geom::Piecewise<Geom::D2<Geom::SBasis> > con } if (fuse_tolerance > 0){ pre_output = fuse_nearby_ends(pre_output, fuse_tolerance); - for (unsigned i=0; i<pre_output.size(); i++){ - output.concat(pre_output[i]); + for (const auto & i : pre_output){ + output.concat(i); } } return output; diff --git a/src/live_effects/lpe-perspective-envelope.cpp b/src/live_effects/lpe-perspective-envelope.cpp index b0ca8e521..6d0cd707f 100644 --- a/src/live_effects/lpe-perspective-envelope.cpp +++ b/src/live_effects/lpe-perspective-envelope.cpp @@ -204,9 +204,9 @@ void LPEPerspectiveEnvelope::doEffect(SPCurve *curve) free_term[i+4] = handles[i][Y]; } int h = 0; - for( int i = 0; i < 8; i++ ) { + for(auto & i : solmatrix) { for( int j = 0; j < 8; j++ ) { - gslSolmatrix[h] = solmatrix[i][j]; + gslSolmatrix[h] = i[j]; h++; } } @@ -220,13 +220,13 @@ void LPEPerspectiveEnvelope::doEffect(SPCurve *curve) gsl_linalg_LU_decomp (&m.matrix, p, &s); gsl_linalg_LU_solve (&m.matrix, p, &b.vector, x); h = 0; - for( int i = 0; i < 3; i++ ) { + for(auto & i : projmatrix) { for( int j = 0; j < 3; j++ ) { if(h==8) { projmatrix[2][2] = 1.0; continue; } - projmatrix[i][j] = gsl_vector_get(x, h); + i[j] = gsl_vector_get(x, h); h++; } } @@ -239,21 +239,21 @@ void LPEPerspectiveEnvelope::doEffect(SPCurve *curve) Geom::Point point_at1(0, 0); Geom::Point point_at2(0, 0); Geom::Point point_at3(0, 0); - for (Geom::PathVector::const_iterator path_it = original_pathv.begin(); path_it != original_pathv.end(); ++path_it) { + for (const auto & path_it : original_pathv) { //Si está vacío... - if (path_it->empty()) + if (path_it.empty()) continue; //Itreadores SPCurve *nCurve = new SPCurve(); - Geom::Path::const_iterator curve_it1 = path_it->begin(); - Geom::Path::const_iterator curve_it2 = ++(path_it->begin()); - Geom::Path::const_iterator curve_endit = path_it->end_default(); + Geom::Path::const_iterator curve_it1 = path_it.begin(); + Geom::Path::const_iterator curve_it2 = ++(path_it.begin()); + Geom::Path::const_iterator curve_endit = path_it.end_default(); - if (path_it->closed()) { + if (path_it.closed()) { const Geom::Curve &closingline = - path_it->back_closed(); + path_it.back_closed(); if (are_near(closingline.initialPoint(), closingline.finalPoint())) { - curve_endit = path_it->end_open(); + curve_endit = path_it.end_open(); } } if(deform_type == DEFORMATION_PERSPECTIVE) { @@ -287,7 +287,7 @@ void LPEPerspectiveEnvelope::doEffect(SPCurve *curve) } } //y cerramos la curva - if (path_it->closed()) { + if (path_it.closed()) { nCurve->move_endpoints(point_at3, point_at3); nCurve->closepath_current(); } diff --git a/src/live_effects/lpe-powerstroke.cpp b/src/live_effects/lpe-powerstroke.cpp index 37e91ab42..79d147a69 100644 --- a/src/live_effects/lpe-powerstroke.cpp +++ b/src/live_effects/lpe-powerstroke.cpp @@ -593,8 +593,8 @@ LPEPowerStroke::doEffect_path (Geom::PathVector const & path_in) return path_out; } std::vector<Geom::Point> ts; - for (std::vector<Geom::Point>::iterator tsp = ts_no_scale.begin(); tsp != ts_no_scale.end(); ++tsp) { - Geom::Point p = Geom::Point((*tsp)[Geom::X], (*tsp)[Geom::Y] * scale_width); + for (auto & tsp : ts_no_scale) { + Geom::Point p = Geom::Point(tsp[Geom::X], tsp[Geom::Y] * scale_width); ts.push_back(p); } if (sort_points) { @@ -640,8 +640,8 @@ LPEPowerStroke::doEffect_path (Geom::PathVector const & path_in) // instead of the heavily compressed coordinate system of (segment_no offset, Y) in which the knots are stored double pwd2_in_arclength = length(pwd2_in); double xcoord_scaling = pwd2_in_arclength / ts.back()[Geom::X]; - for (std::size_t i = 0, e = ts.size(); i < e; ++i) { - ts[i][Geom::X] *= xcoord_scaling; + for (auto & t : ts) { + t[Geom::X] *= xcoord_scaling; } Geom::Path strokepath = interpolator->interpolateToPath(ts); diff --git a/src/live_effects/lpe-pts2ellipse.cpp b/src/live_effects/lpe-pts2ellipse.cpp index e1c87f2dd..0d3f70314 100644 --- a/src/live_effects/lpe-pts2ellipse.cpp +++ b/src/live_effects/lpe-pts2ellipse.cpp @@ -261,11 +261,11 @@ LPEPts2Ellipse::doEffect_path (Geom::PathVector const & path_in) // from: extension/internal/odf.cpp // get all points std::vector<Point> pts; - for(PathVector::const_iterator pit = path_in.begin(); pit!= path_in.end(); ++pit) { + for(const auto & pit : path_in) { // extract first point of this path - pts.push_back(pit->initialPoint()); + pts.push_back(pit.initialPoint()); // iterate over all curves - for (Geom::Path::const_iterator cit = pit->begin(); cit != pit->end(); ++cit) { + for (Geom::Path::const_iterator cit = pit.begin(); cit != pit.end(); ++cit) { pts.push_back(cit->finalPoint()); } } diff --git a/src/live_effects/lpe-recursiveskeleton.cpp b/src/live_effects/lpe-recursiveskeleton.cpp index b21738855..0a67cdbbc 100644 --- a/src/live_effects/lpe-recursiveskeleton.cpp +++ b/src/live_effects/lpe-recursiveskeleton.cpp @@ -73,8 +73,7 @@ LPERecursiveSkeleton::doEffect_pwd2 (Geom::Piecewise<Geom::D2<Geom::SBasis> > co std::vector<Piecewise<D2<SBasis> > > skeleton = split_at_discontinuities(output); output.clear(); - for (unsigned idx = 0; idx < skeleton.size(); idx++){ - Piecewise<D2<SBasis> > path_i = skeleton[idx]; + for (auto path_i : skeleton){ Piecewise<SBasis> x = x0; Piecewise<SBasis> y = y0; Piecewise<D2<SBasis> > uskeleton = arc_length_parametrization(path_i,2,.1); diff --git a/src/live_effects/lpe-rough-hatches.cpp b/src/live_effects/lpe-rough-hatches.cpp index de62b263d..b93e0a94e 100644 --- a/src/live_effects/lpe-rough-hatches.cpp +++ b/src/live_effects/lpe-rough-hatches.cpp @@ -88,13 +88,13 @@ public: Piecewise<D2<SBasis> > const &f, Piecewise<SBasis> const &dx){ - for (unsigned i=0; i<times.size(); i++){ + for (const auto & time : times){ LevelCrossings lcs; - for (unsigned j=0; j<times[i].size(); j++){ + for (unsigned j=0; j<time.size(); j++){ LevelCrossing lc; - lc.pt = f.valueAt(times[i][j]); - lc.t = times[i][j]; - lc.sign = ( dx.valueAt(times[i][j])>0 ); + lc.pt = f.valueAt(time[j]); + lc.t = time[j]; + lc.sign = ( dx.valueAt(time[j])>0 ); lc.used = false; lcs.push_back(lc); } @@ -429,24 +429,24 @@ Piecewise<D2<SBasis> > LPERoughHatches::smoothSnake(std::vector<std::vector<Point> > const &linearSnake){ Piecewise<D2<SBasis> > result; - for (unsigned comp=0; comp<linearSnake.size(); comp++){ - if (linearSnake[comp].size()>=2){ - Point last_pt = linearSnake[comp][0]; + for (const auto & comp : linearSnake){ + if (comp.size()>=2){ + Point last_pt = comp[0]; //Point last_top = linearSnake[comp][0]; //Point last_bot = linearSnake[comp][0]; - Point last_hdle = linearSnake[comp][0]; - Point last_top_hdle = linearSnake[comp][0]; - Point last_bot_hdle = linearSnake[comp][0]; + Point last_hdle = comp[0]; + Point last_top_hdle = comp[0]; + Point last_bot_hdle = comp[0]; Geom::Path res_comp(last_pt); Geom::Path res_comp_top(last_pt); Geom::Path res_comp_bot(last_pt); unsigned i=1; //bool is_top = true;//Inversion here; due to downward y? - bool is_top = ( linearSnake[comp][0][Y] < linearSnake[comp][1][Y] ); + bool is_top = ( comp[0][Y] < comp[1][Y] ); - while( i+1<linearSnake[comp].size() ){ - Point pt0 = linearSnake[comp][i]; - Point pt1 = linearSnake[comp][i+1]; + while( i+1<comp.size() ){ + Point pt0 = comp[i]; + Point pt1 = comp[i+1]; Point new_pt = (pt0+pt1)/2; double scale_in = (is_top ? scale_tf : scale_bf ); double scale_out = (is_top ? scale_tb : scale_bb ); @@ -511,12 +511,12 @@ LPERoughHatches::smoothSnake(std::vector<std::vector<Point> > const &linearSnake i+=2; is_top = !is_top; } - if ( i<linearSnake[comp].size() ){ + if ( i<comp.size() ){ if ( fat_output.get_value() ){ - res_comp_top.appendNew<CubicBezier>(last_top_hdle,linearSnake[comp][i],linearSnake[comp][i]); - res_comp_bot.appendNew<CubicBezier>(last_bot_hdle,linearSnake[comp][i],linearSnake[comp][i]); + res_comp_top.appendNew<CubicBezier>(last_top_hdle,comp[i],comp[i]); + res_comp_bot.appendNew<CubicBezier>(last_bot_hdle,comp[i],comp[i]); }else{ - res_comp.appendNew<CubicBezier>(last_hdle,linearSnake[comp][i],linearSnake[comp][i]); + res_comp.appendNew<CubicBezier>(last_hdle,comp[i],comp[i]); } } if ( fat_output.get_value() ){ diff --git a/src/live_effects/lpe-roughen.cpp b/src/live_effects/lpe-roughen.cpp index 9008230d4..14c95ca45 100644 --- a/src/live_effects/lpe-roughen.cpp +++ b/src/live_effects/lpe-roughen.cpp @@ -198,20 +198,19 @@ void LPERoughen::doEffect(SPCurve *curve) { Geom::PathVector const original_pathv = pathv_to_linear_and_cubic_beziers(curve->get_pathvector()); curve->reset(); - for (Geom::PathVector::const_iterator path_it = original_pathv.begin(); - path_it != original_pathv.end(); ++path_it) { - if (path_it->empty()) + for (const auto & path_it : original_pathv) { + if (path_it.empty()) continue; - Geom::Path::const_iterator curve_it1 = path_it->begin(); - Geom::Path::const_iterator curve_it2 = ++(path_it->begin()); - Geom::Path::const_iterator curve_endit = path_it->end_default(); + Geom::Path::const_iterator curve_it1 = path_it.begin(); + Geom::Path::const_iterator curve_it2 = ++(path_it.begin()); + Geom::Path::const_iterator curve_endit = path_it.end_default(); SPCurve *nCurve = new SPCurve(); Geom::Point prev(0, 0); Geom::Point last_move(0, 0); nCurve->moveto(curve_it1->initialPoint()); - if (path_it->closed()) { - const Geom::Curve &closingline = path_it->back_closed(); + if (path_it.closed()) { + const Geom::Curve &closingline = path_it.back_closed(); // the closing line segment is always of type // Geom::LineSegment. if (are_near(closingline.initialPoint(), closingline.finalPoint())) { @@ -219,7 +218,7 @@ void LPERoughen::doEffect(SPCurve *curve) // *exact* zero length, which goes wrong for relative coordinates and // rounding errors... // the closing line segment has zero-length. So stop before that one! - curve_endit = path_it->end_open(); + curve_endit = path_it.end_open(); } } while (curve_it1 != curve_endit) { @@ -265,7 +264,7 @@ void LPERoughen::doEffect(SPCurve *curve) ++curve_it1; ++curve_it2; } - if (path_it->closed()) { + if (path_it.closed()) { if(handles == HM_SMOOTH && curve_it1 == curve_endit){ SPCurve *out = new SPCurve(); nCurve = nCurve->create_reverse(); diff --git a/src/live_effects/lpe-ruler.cpp b/src/live_effects/lpe-ruler.cpp index 0b7443de2..75052ad33 100644 --- a/src/live_effects/lpe-ruler.cpp +++ b/src/live_effects/lpe-ruler.cpp @@ -146,11 +146,11 @@ LPERuler::doEffect_pwd2 (Geom::Piecewise<Geom::D2<Geom::SBasis> > const & pwd2_i } std::vector<std::vector<double> > roots = multi_roots(arclength, s_cuts); std::vector<double> t_cuts; - for (unsigned v=0; v<roots.size();v++){ + for (auto & root : roots){ //FIXME: 2geom multi_roots solver seem to sometimes "repeat" solutions. //Here, we are supposed to have one and only one solution for each s. - if(roots[v].size()>0) - t_cuts.push_back(roots[v][0]); + if(root.size()>0) + t_cuts.push_back(root[0]); } //draw the marks for (size_t i = 0; i < t_cuts.size(); i++) { diff --git a/src/live_effects/lpe-show_handles.cpp b/src/live_effects/lpe-show_handles.cpp index ccf0f80dd..c40f07501 100644 --- a/src/live_effects/lpe-show_handles.cpp +++ b/src/live_effects/lpe-show_handles.cpp @@ -88,8 +88,8 @@ Geom::PathVector LPEShowHandles::doEffect_path (Geom::PathVector const & path_in Geom::PathVector path_out; Geom::PathVector original_pathv = pathv_to_linear_and_cubic_beziers(path_in); if(original_path) { - for (unsigned int i=0; i < path_in.size(); i++) { - path_out.push_back(path_in[i]); + for (const auto & i : path_in) { + path_out.push_back(i); } } if(!outline_path.empty()) { @@ -100,8 +100,8 @@ Geom::PathVector LPEShowHandles::doEffect_path (Geom::PathVector const & path_in if (shape_curve) { Geom::PathVector original_curve = shape_curve->get_pathvector(); if(original_path) { - for (unsigned int i=0; i < original_curve.size(); i++) { - path_out.push_back(original_curve[i]); + for (const auto & i : original_curve) { + path_out.push_back(i); } } original_pathv.insert(original_pathv.end(), original_curve.begin(), original_curve.end()); @@ -111,8 +111,8 @@ Geom::PathVector LPEShowHandles::doEffect_path (Geom::PathVector const & path_in } else { generateHelperPath(original_pathv); } - for (unsigned int i=0; i < outline_path.size(); i++) { - path_out.push_back(outline_path[i]); + for (const auto & i : outline_path) { + path_out.push_back(i); } return path_out; @@ -126,33 +126,33 @@ LPEShowHandles::generateHelperPath(Geom::PathVector result) } Geom::CubicBezier const *cubic = nullptr; - for (Geom::PathVector::iterator path_it = result.begin(); path_it != result.end(); ++path_it) { + for (auto & path_it : result) { //Si está vacío... - if (path_it->empty()) { + if (path_it.empty()) { continue; } //Itreadores - Geom::Path::iterator curve_it1 = path_it->begin(); // incoming curve - Geom::Path::iterator curve_it2 = ++(path_it->begin()); // outgoing curve - Geom::Path::iterator curve_endit = path_it->end_default(); // this determines when the loop has to stop + Geom::Path::iterator curve_it1 = path_it.begin(); // incoming curve + Geom::Path::iterator curve_it2 = ++(path_it.begin()); // outgoing curve + Geom::Path::iterator curve_endit = path_it.end_default(); // this determines when the loop has to stop - if (path_it->closed()) { + if (path_it.closed()) { // if the path is closed, maybe we have to stop a bit earlier because the // closing line segment has zerolength. - Geom::Curve const &closingline = path_it->back_closed(); // the closing line segment is always of type + Geom::Curve const &closingline = path_it.back_closed(); // the closing line segment is always of type // Geom::LineSegment. if (are_near(closingline.initialPoint(), closingline.finalPoint())) { // closingline.isDegenerate() did not work, because it only checks for // *exact* zero length, which goes wrong for relative coordinates and // rounding errors... // the closing line segment has zero-length. So stop before that one! - curve_endit = path_it->end_open(); + curve_endit = path_it.end_open(); } } if(nodes) { Geom::NodeType nodetype = Geom::NODE_CUSP; - if(path_it->closed()) { - nodetype = Geom::get_nodetype(path_it->finalCurve(), *curve_it1); + if(path_it.closed()) { + nodetype = Geom::get_nodetype(path_it.finalCurve(), *curve_it1); } drawNode(curve_it1->initialPoint(), nodetype); } @@ -170,7 +170,7 @@ LPEShowHandles::generateHelperPath(Geom::PathVector result) } } } - if(nodes && (curve_it2 != curve_endit || !path_it->closed())) { + if(nodes && (curve_it2 != curve_endit || !path_it.closed())) { Geom::NodeType nodetype = Geom::get_nodetype(*curve_it1, *curve_it2); drawNode(curve_it1->finalPoint(), nodetype); } diff --git a/src/live_effects/lpe-simplify.cpp b/src/live_effects/lpe-simplify.cpp index d589f16d1..56647e4e2 100644 --- a/src/live_effects/lpe-simplify.cpp +++ b/src/live_effects/lpe-simplify.cpp @@ -155,27 +155,27 @@ LPESimplify::generateHelperPathAndSmooth(Geom::PathVector &result) } Geom::PathVector tmp_path; Geom::CubicBezier const *cubic = nullptr; - for (Geom::PathVector::iterator path_it = result.begin(); path_it != result.end(); ++path_it) { - if (path_it->empty()) { + for (auto & path_it : result) { + if (path_it.empty()) { continue; } - Geom::Path::iterator curve_it1 = path_it->begin(); // incoming curve - Geom::Path::iterator curve_it2 = ++(path_it->begin());// outgoing curve - Geom::Path::iterator curve_endit = path_it->end_default(); // this determines when the loop has to stop + Geom::Path::iterator curve_it1 = path_it.begin(); // incoming curve + Geom::Path::iterator curve_it2 = ++(path_it.begin());// outgoing curve + Geom::Path::iterator curve_endit = path_it.end_default(); // this determines when the loop has to stop SPCurve *nCurve = new SPCurve(); - if (path_it->closed()) { + if (path_it.closed()) { // if the path is closed, maybe we have to stop a bit earlier because the // closing line segment has zerolength. const Geom::Curve &closingline = - path_it->back_closed(); // the closing line segment is always of type + path_it.back_closed(); // the closing line segment is always of type // Geom::LineSegment. if (are_near(closingline.initialPoint(), closingline.finalPoint())) { // closingline.isDegenerate() did not work, because it only checks for // *exact* zero length, which goes wrong for relative coordinates and // rounding errors... // the closing line segment has zero-length. So stop before that one! - curve_endit = path_it->end_open(); + curve_endit = path_it.end_open(); } } if(helper_size > 0) { @@ -199,7 +199,7 @@ LPESimplify::generateHelperPathAndSmooth(Geom::PathVector &result) point_at2 = (*cubic)[2]; } - if(path_it->closed() && curve_it2 == curve_endit) { + if(path_it.closed() && curve_it2 == curve_endit) { point_at4 = start; } if(curve_it2 != curve_endit) { @@ -240,7 +240,7 @@ LPESimplify::generateHelperPathAndSmooth(Geom::PathVector &result) ++curve_it1; ++curve_it2; } - if (path_it->closed()) { + if (path_it.closed()) { nCurve->closepath_current(); } tmp_path.push_back(nCurve->get_pathvector()[0]); diff --git a/src/live_effects/lpe-sketch.cpp b/src/live_effects/lpe-sketch.cpp index 7d0a4a505..594751967 100644 --- a/src/live_effects/lpe-sketch.cpp +++ b/src/live_effects/lpe-sketch.cpp @@ -214,9 +214,8 @@ LPESketch::doEffect_pwd2 (Geom::Piecewise<Geom::D2<Geom::SBasis> > const & pwd2_ std::vector<Piecewise<D2<SBasis> > > pieces_in = split_at_discontinuities (pwd2_in); //work separately on each component. - for (unsigned pieceidx = 0; pieceidx < pieces_in.size(); pieceidx++){ + for (auto piece : pieces_in){ - Piecewise<D2<SBasis> > piece = pieces_in[pieceidx]; Piecewise<SBasis> piecelength = arcLengthSb(piece,.1); double piece_total_length = piecelength.segs.back().at1()-piecelength.segs.front().at0(); pathlength.concat(piecelength + total_length); diff --git a/src/live_effects/lpe-spiro.cpp b/src/live_effects/lpe-spiro.cpp index 06173d011..e0464a2a0 100644 --- a/src/live_effects/lpe-spiro.cpp +++ b/src/live_effects/lpe-spiro.cpp @@ -47,13 +47,13 @@ void sp_spiro_do_effect(SPCurve *curve){ Spiro::spiro_cp *path = g_new (Spiro::spiro_cp, len); int ip = 0; - for(Geom::PathVector::const_iterator path_it = original_pathv.begin(); path_it != original_pathv.end(); ++path_it) { - if (path_it->empty()) + for(const auto & path_it : original_pathv) { + if (path_it.empty()) continue; // start of path { - Geom::Point p = path_it->initialPoint(); + Geom::Point p = path_it.initialPoint(); path[ip].x = p[X]; path[ip].y = p[Y]; path[ip].ty = '{' ; // for closed paths, this is overwritten @@ -61,9 +61,9 @@ void sp_spiro_do_effect(SPCurve *curve){ } // midpoints - Geom::Path::const_iterator curve_it1 = path_it->begin(); // incoming curve - Geom::Path::const_iterator curve_it2 = ++(path_it->begin()); // outgoing curve - Geom::Path::const_iterator curve_endit = path_it->end_default(); // this determines when the loop has to stop + Geom::Path::const_iterator curve_it1 = path_it.begin(); // incoming curve + Geom::Path::const_iterator curve_it2 = ++(path_it.begin()); // outgoing curve + Geom::Path::const_iterator curve_endit = path_it.end_default(); // this determines when the loop has to stop while ( curve_it2 != curve_endit ) { @@ -103,9 +103,9 @@ void sp_spiro_do_effect(SPCurve *curve){ Geom::Point p = curve_it1->finalPoint(); path[ip].x = p[X]; path[ip].y = p[Y]; - if (path_it->closed()) { + if (path_it.closed()) { // curve_it1 points to the (visually) closing segment. determine the match between first and this last segment (the closing node) - Geom::NodeType nodetype = Geom::get_nodetype(*curve_it1, path_it->front()); + Geom::NodeType nodetype = Geom::get_nodetype(*curve_it1, path_it.front()); switch (nodetype) { case Geom::NODE_NONE: // can't happen! but if it does, it means the path isn't closed :-) path[ip].ty = '}'; diff --git a/src/live_effects/lpe-taperstroke.cpp b/src/live_effects/lpe-taperstroke.cpp index db1d36cbb..cc8e21014 100644 --- a/src/live_effects/lpe-taperstroke.cpp +++ b/src/live_effects/lpe-taperstroke.cpp @@ -405,8 +405,7 @@ Piecewise<D2<SBasis> > stretch_along(Piecewise<D2<SBasis> > pwd2_in, Geom::Path std::vector<Piecewise<D2<SBasis> > > paths_in; paths_in = split_at_discontinuities(pwd2_in); - for (unsigned idx = 0; idx < paths_in.size(); idx++) { - Piecewise<D2<SBasis> > path_i = paths_in[idx]; + for (auto path_i : paths_in) { Piecewise<SBasis> x = x0; Piecewise<SBasis> y = y0; Piecewise<D2<SBasis> > uskeleton = arc_length_parametrization(path_i,2,.1); diff --git a/src/live_effects/lpe-transform_2pts.cpp b/src/live_effects/lpe-transform_2pts.cpp index 640e1b146..adb3d6fd4 100644 --- a/src/live_effects/lpe-transform_2pts.cpp +++ b/src/live_effects/lpe-transform_2pts.cpp @@ -207,8 +207,8 @@ size_t LPETransform2Pts::nodeCount(Geom::PathVector pathvector) const { size_t n = 0; - for (Geom::PathVector::iterator it = pathvector.begin(); it != pathvector.end(); ++it) { - n += it->size_closed(); + for (auto & it : pathvector) { + n += it.size_closed(); } return n; } @@ -217,8 +217,8 @@ Geom::Point LPETransform2Pts::pointAtNodeIndex(Geom::PathVector pathvector, size_t index) const { size_t n = 0; - for (Geom::PathVector::iterator pv_it = pathvector.begin(); pv_it != pathvector.end(); ++pv_it) { - for (Geom::Path::iterator curve_it = pv_it->begin(); curve_it != pv_it->end_closed(); ++curve_it) { + for (auto & pv_it : pathvector) { + for (Geom::Path::iterator curve_it = pv_it.begin(); curve_it != pv_it.end_closed(); ++curve_it) { if(index == n) { return curve_it->initialPoint(); } @@ -232,10 +232,10 @@ Geom::Path LPETransform2Pts::pathAtNodeIndex(Geom::PathVector pathvector, size_t index) const { size_t n = 0; - for (Geom::PathVector::iterator pv_it = pathvector.begin(); pv_it != pathvector.end(); ++pv_it) { - for (Geom::Path::iterator curve_it = pv_it->begin(); curve_it != pv_it->end_closed(); ++curve_it) { + for (auto & pv_it : pathvector) { + for (Geom::Path::iterator curve_it = pv_it.begin(); curve_it != pv_it.end_closed(); ++curve_it) { if(index == n) { - return *pv_it; + return pv_it; } n++; } diff --git a/src/live_effects/lpe-vonkoch.cpp b/src/live_effects/lpe-vonkoch.cpp index f52645849..aa0f46ecc 100644 --- a/src/live_effects/lpe-vonkoch.cpp +++ b/src/live_effects/lpe-vonkoch.cpp @@ -98,18 +98,18 @@ LPEVonKoch::doEffect_path (Geom::PathVector const & path_in) m0 = m0.inverse(); std::vector<Affine> transforms; - for (unsigned i=0; i<generating_path.size(); i++){ + for (const auto & i : generating_path){ Affine m; - if(generating_path[i].size()==1){ - Point p = generating_path[i].pointAt(0); - Point u = generating_path[i].pointAt(1)-p; + if(i.size()==1){ + Point p = i.pointAt(0); + Point u = i.pointAt(1)-p; m = Affine(u[X], u[Y],-u[Y], u[X], p[X], p[Y]); m = m0*m; transforms.push_back(m); - }else if(generating_path[i].size()>=2){ - Point p = generating_path[i].pointAt(1); - Point u = generating_path[i].pointAt(2)-p; - Point v = p-generating_path[i].pointAt(0); + }else if(i.size()>=2){ + Point p = i.pointAt(1); + Point u = i.pointAt(2)-p; + Point v = p-i.pointAt(0); if (similar_only.get_value()){ int sign = (u[X]*v[Y]-u[Y]*v[X]>=0?1:-1); v[X] = -u[Y]*sign; @@ -127,8 +127,8 @@ LPEVonKoch::doEffect_path (Geom::PathVector const & path_in) //Do nothing if the output is too complex... int path_in_complexity = 0; - for (unsigned k = 0; k < path_in.size(); k++){ - path_in_complexity+=path_in[k].size(); + for (const auto & k : path_in){ + path_in_complexity+=k.size(); } double complexity = std::pow(transforms.size(), nbgenerations) * path_in_complexity; if (drawall.get_value()){ @@ -156,9 +156,9 @@ LPEVonKoch::doEffect_path (Geom::PathVector const & path_in) path_out = Geom::PathVector(); complexity = 0; } - for (unsigned j = 0; j<transforms.size(); j++){ + for (const auto & transform : transforms){ for (unsigned k = 0; k<pathi.size() && complexity < maxComplexity; k++){ - path_out.push_back(pathi[k]*transforms[j]); + path_out.push_back(pathi[k]*transform); complexity+=pathi[k].size(); } } diff --git a/src/live_effects/parameter/originalitemarray.cpp b/src/live_effects/parameter/originalitemarray.cpp index 8182b0d9c..1b826c888 100644 --- a/src/live_effects/parameter/originalitemarray.cpp +++ b/src/live_effects/parameter/originalitemarray.cpp @@ -293,8 +293,7 @@ OriginalItemArrayParam::on_link_button_click() } os << (*iter)->href << "," << ((*iter)->actived ? "1" : "0"); } - for (auto i=itemsid.begin();i!=itemsid.end();++i) { - Glib::ustring itemid = *i; + for (auto itemid : itemsid) { // add '#' at start to make it an uri. itemid.insert(itemid.begin(), '#'); @@ -423,13 +422,13 @@ gchar * OriginalItemArrayParam::param_getSVGValue() const { Inkscape::SVGOStringStream os; bool foundOne = false; - for (std::vector<ItemAndActive*>::const_iterator iter = _vector.begin(); iter != _vector.end(); ++iter) { + for (auto iter : _vector) { if (foundOne) { os << "|"; } else { foundOne = true; } - os << (*iter)->href << "," << ((*iter)->actived ? "1" : "0"); + os << iter->href << "," << (iter->actived ? "1" : "0"); } return g_strdup(os.str().c_str()); } @@ -441,9 +440,9 @@ gchar * OriginalItemArrayParam::param_getDefaultSVGValue() const void OriginalItemArrayParam::update() { - for (std::vector<ItemAndActive*>::iterator iter = _vector.begin(); iter != _vector.end(); ++iter) { - SPObject *linked_obj = (*iter)->ref.getObject(); - linked_modified(linked_obj, SP_OBJECT_MODIFIED_FLAG, *iter); + for (auto & iter : _vector) { + SPObject *linked_obj = iter->ref.getObject(); + linked_modified(linked_obj, SP_OBJECT_MODIFIED_FLAG, iter); } } diff --git a/src/live_effects/parameter/originalpatharray.cpp b/src/live_effects/parameter/originalpatharray.cpp index 21b02cc7c..0f62ed5f9 100644 --- a/src/live_effects/parameter/originalpatharray.cpp +++ b/src/live_effects/parameter/originalpatharray.cpp @@ -333,8 +333,7 @@ OriginalPathArrayParam::on_link_button_click() } os << (*iter)->href << "," << ((*iter)->reversed ? "1" : "0") << "," << ((*iter)->visibled ? "1" : "0"); } - for (auto i=pathsid.begin();i!=pathsid.end();++i) { - Glib::ustring pathid = *i; + for (auto pathid : pathsid) { // add '#' at start to make it an uri. pathid.insert(pathid.begin(), '#'); @@ -512,13 +511,13 @@ gchar * OriginalPathArrayParam::param_getSVGValue() const { Inkscape::SVGOStringStream os; bool foundOne = false; - for (std::vector<PathAndDirectionAndVisible*>::const_iterator iter = _vector.begin(); iter != _vector.end(); ++iter) { + for (auto iter : _vector) { if (foundOne) { os << "|"; } else { foundOne = true; } - os << (*iter)->href << "," << ((*iter)->reversed ? "1" : "0") << "," << ((*iter)->visibled ? "1" : "0"); + os << iter->href << "," << (iter->reversed ? "1" : "0") << "," << (iter->visibled ? "1" : "0"); } return g_strdup(os.str().c_str()); } @@ -530,9 +529,9 @@ gchar * OriginalPathArrayParam::param_getDefaultSVGValue() const void OriginalPathArrayParam::update() { - for (std::vector<PathAndDirectionAndVisible*>::iterator iter = _vector.begin(); iter != _vector.end(); ++iter) { - SPObject *linked_obj = (*iter)->ref.getObject(); - linked_modified(linked_obj, SP_OBJECT_MODIFIED_FLAG, *iter); + for (auto & iter : _vector) { + SPObject *linked_obj = iter->ref.getObject(); + linked_modified(linked_obj, SP_OBJECT_MODIFIED_FLAG, iter); } } diff --git a/src/live_effects/parameter/path.cpp b/src/live_effects/parameter/path.cpp index 788c8b288..b8d2f4476 100644 --- a/src/live_effects/parameter/path.cpp +++ b/src/live_effects/parameter/path.cpp @@ -385,8 +385,8 @@ PathParam::ensure_pwd2() { if (must_recalculate_pwd2) { _pwd2.clear(); - for (unsigned int i=0; i < _pathvector.size(); i++) { - _pwd2.concat( _pathvector[i].toPwSb() ); + for (const auto & i : _pathvector) { + _pwd2.concat( i.toPwSb() ); } must_recalculate_pwd2 = false; diff --git a/src/live_effects/parameter/powerstrokepointarray.cpp b/src/live_effects/parameter/powerstrokepointarray.cpp index 08e17ed93..a39c872cd 100644 --- a/src/live_effects/parameter/powerstrokepointarray.cpp +++ b/src/live_effects/parameter/powerstrokepointarray.cpp @@ -69,19 +69,19 @@ PowerStrokePointArrayParam::recalculate_controlpoints_for_new_pwd2(Geom::Piecewi if (last_pwd2.size() > pwd2_in.size()) { // Path has become shorter: rescale offsets double factor = (double)pwd2_in.size() / (double)last_pwd2.size(); - for (unsigned int i = 0; i < _vector.size(); ++i) { - _vector[i][Geom::X] *= factor; + for (auto & i : _vector) { + i[Geom::X] *= factor; } } else if (last_pwd2.size() < pwd2_in.size()) { // Path has become longer: probably node added, maintain position of knots Geom::Piecewise<Geom::D2<Geom::SBasis> > normal = rot90(unitVector(derivative(pwd2_in))); - for (unsigned int i = 0; i < _vector.size(); ++i) { - Geom::Point pt = _vector[i]; + for (auto & i : _vector) { + Geom::Point pt = i; Geom::Point position = last_pwd2.valueAt(pt[Geom::X]) + pt[Geom::Y] * last_pwd2_normal.valueAt(pt[Geom::X]); double t = nearest_time(position, pwd2_in); double offset = dot(position - pwd2_in.valueAt(t), normal.valueAt(t)); - _vector[i] = Geom::Point(t, offset); + i = Geom::Point(t, offset); } } @@ -96,11 +96,11 @@ PowerStrokePointArrayParam::reverse_controlpoints(bool write) std::vector<Geom::Point> controlpoints; if (!last_pwd2.empty()) { Geom::Piecewise<Geom::D2<Geom::SBasis> > const & pwd2_in_reverse = reverse(last_pwd2); - for (unsigned int i = 0; i < _vector.size(); ++i) { - Geom::Point control_pos = last_pwd2.valueAt(_vector[i][Geom::X]); + for (auto & i : _vector) { + Geom::Point control_pos = last_pwd2.valueAt(i[Geom::X]); double new_pos = Geom::nearest_time(control_pos, pwd2_in_reverse); - controlpoints.emplace_back(new_pos,_vector[i][Geom::Y]); - _vector[i][Geom::X] = new_pos; + controlpoints.emplace_back(new_pos,i[Geom::Y]); + i[Geom::X] = new_pos; } if (write) { write_to_SVG(); @@ -235,8 +235,8 @@ PowerStrokePointArrayParamKnotHolderEntity::knot_click(guint state) vec.erase(vec.begin() + _index); _pparam->param_set_and_write_new_value(vec); // shift knots down one index - for(std::list<KnotHolderEntity *>::iterator ent = parent_holder->entity.begin(); ent != parent_holder->entity.end(); ++ent) { - PowerStrokePointArrayParamKnotHolderEntity *pspa_ent = dynamic_cast<PowerStrokePointArrayParamKnotHolderEntity *>(*ent); + for(auto & ent : parent_holder->entity) { + PowerStrokePointArrayParamKnotHolderEntity *pspa_ent = dynamic_cast<PowerStrokePointArrayParamKnotHolderEntity *>(ent); if ( pspa_ent && pspa_ent->_pparam == this->_pparam ) { // check if the knotentity belongs to this powerstrokepointarray parameter if (pspa_ent->_index > this->_index) { --pspa_ent->_index; @@ -254,8 +254,8 @@ PowerStrokePointArrayParamKnotHolderEntity::knot_click(guint state) _pparam->param_set_and_write_new_value(vec); // shift knots up one index - for(std::list<KnotHolderEntity *>::iterator ent = parent_holder->entity.begin(); ent != parent_holder->entity.end(); ++ent) { - PowerStrokePointArrayParamKnotHolderEntity *pspa_ent = dynamic_cast<PowerStrokePointArrayParamKnotHolderEntity *>(*ent); + for(auto & ent : parent_holder->entity) { + PowerStrokePointArrayParamKnotHolderEntity *pspa_ent = dynamic_cast<PowerStrokePointArrayParamKnotHolderEntity *>(ent); if ( pspa_ent && pspa_ent->_pparam == this->_pparam ) { // check if the knotentity belongs to this powerstrokepointarray parameter if (pspa_ent->_index > this->_index) { ++pspa_ent->_index; diff --git a/src/live_effects/parameter/satellitesarray.cpp b/src/live_effects/parameter/satellitesarray.cpp index aa1644597..a82df2d27 100644 --- a/src/live_effects/parameter/satellitesarray.cpp +++ b/src/live_effects/parameter/satellitesarray.cpp @@ -158,10 +158,10 @@ void SatellitesArrayParam::param_transform_multiply(Geom::Affine const &postmul, Inkscape::Preferences *prefs = Inkscape::Preferences::get(); if (prefs->getBool("/options/transform/rectcorners", true)) { - for (size_t i = 0; i < _vector.size(); ++i) { - for (size_t j = 0; j < _vector[i].size(); ++j) { - if (!_vector[i][j].is_time && _vector[i][j].amount > 0) { - _vector[i][j].amount = _vector[i][j].amount * ((postmul.expansionX() + postmul.expansionY()) / 2); + for (auto & i : _vector) { + for (size_t j = 0; j < i.size(); ++j) { + if (!i[j].is_time && i[j].amount > 0) { + i[j].amount = i[j].amount * ((postmul.expansionX() + postmul.expansionY()) / 2); } } } diff --git a/src/live_effects/spiro.cpp b/src/live_effects/spiro.cpp index 54bc021c7..4c129bafd 100644 --- a/src/live_effects/spiro.cpp +++ b/src/live_effects/spiro.cpp @@ -672,11 +672,11 @@ spiro_iter(spiro_seg *s, bandmat *m, int *perm, double *v, const int n) for (int i = 0; i < nmat; i++) { v[i] = 0.; - for (int j = 0; j < 11; j++) { - m[i].a[j] = 0.; + for (double & j : m[i].a) { + j = 0.; } - for (int j = 0; j < 5; j++) { - m[i].al[j] = 0.; + for (double & j : m[i].al) { + j = 0.; } } |
