From 8bc51aa5eec379455cc5030faab8f043312caf20 Mon Sep 17 00:00:00 2001 From: Ajinkya Dahale Date: Mon, 30 Dec 2024 09:24:18 +0530 Subject: [PATCH] [Sketcher] Incorporate review of #18665 by kadet 1. Replace `find_if` with `any_of` when the iterator is not used. 2. Use PascalCase for templated class. --- src/Mod/Sketcher/App/SketchObject.cpp | 60 +++++++++++++-------------- src/Mod/Sketcher/App/SketchObject.h | 4 +- 2 files changed, 30 insertions(+), 34 deletions(-) diff --git a/src/Mod/Sketcher/App/SketchObject.cpp b/src/Mod/Sketcher/App/SketchObject.cpp index f6203dadf8..bb67d49fd3 100644 --- a/src/Mod/Sketcher/App/SketchObject.cpp +++ b/src/Mod/Sketcher/App/SketchObject.cpp @@ -6381,11 +6381,10 @@ int SketchObject::exposeInternalGeometryForType(const in } if (controlpointgeoids[0] != GeoEnum::GeoUndef) { - // search for first pole weight constraint - auto it = std::find_if(vals.begin(), - vals.end(), - [&controlpointgeoids](const auto& constr) {return (constr->Type == Sketcher::Weight && constr->First == controlpointgeoids[0]);}); - isfirstweightconstrained = (it != vals.end()); + isfirstweightconstrained = + std::any_of(vals.begin(), vals.end(), [&controlpointgeoids](const auto& constr) { + return (constr->Type == Sketcher::Weight && constr->First == controlpointgeoids[0]); + }); } int currentgeoid = getHighestCurveIndex(); @@ -6739,21 +6738,19 @@ int SketchObject::deleteUnusedInternalGeometryWhenBSpline(int GeoId, bool delgeo if (constr->Type != Sketcher::Equal) { continue; } - - bool firstIsInCPGeoIds = std::find_if(poleGeoIdsAndConstraints.begin(), + bool firstIsInCPGeoIds = std::any_of(poleGeoIdsAndConstraints.begin(), + poleGeoIdsAndConstraints.end(), + [&constr](const auto& _pair) { + return _pair.first == constr->First; + }); + bool secondIsInCPGeoIds = std::any_of(poleGeoIdsAndConstraints.begin(), poleGeoIdsAndConstraints.end(), [&constr](const auto& _pair) { - return _pair.first == constr->First; - }) != poleGeoIdsAndConstraints.end(); - bool secondIsInCPGeoIds = std::find_if(poleGeoIdsAndConstraints.begin(), - poleGeoIdsAndConstraints.end(), - [&constr](const auto& _pair){ - return _pair.first == constr->Second; - }) != poleGeoIdsAndConstraints.end(); - + return _pair.first == constr->Second; + }); // the equality constraint constrains a pole but it is not interpole if (firstIsInCPGeoIds != secondIsInCPGeoIds) { - numConstr++; + ++numConstr; } // We do not ignore weight constraints as we did with radius constraints, // because the radius magnitude no longer makes sense without the B-Spline. @@ -10707,20 +10704,19 @@ void SketchObject::migrateSketch() auto constraints = Constraints.getValues(); auto geometries = getInternalGeometry(); - auto parabolafound = std::find_if(geometries.begin(), geometries.end(), [](Part::Geometry* g) { + bool parabolaFound = std::any_of(geometries.begin(), geometries.end(), [](Part::Geometry* g) { return g->is(); }); - if (parabolafound != geometries.end()) { + if (parabolaFound) { - auto focalaxisfound = std::find_if(constraints.begin(), constraints.end(), [](auto c) { + bool focalaxisfound = std::any_of(constraints.begin(), constraints.end(), [](auto c) { return c->Type == InternalAlignment && c->AlignmentType == ParabolaFocalAxis; }); // There are parabolas and there isn't an IA axis. (1) there are no axis or (2) there is a // legacy construction line - if (focalaxisfound == constraints.end()) { - + if (!focalaxisfound) { // maps parabola geoid to focusgeoid std::map parabolageoid2focusgeoid; @@ -10771,18 +10767,18 @@ void SketchObject::migrateSketch() } else { auto axismajorcoincidentfound = - std::find_if(axisgeoid2parabolageoid.begin(), - axisgeoid2parabolageoid.end(), - [&](const auto& pair) { - auto parabolageoid = pair.second; - auto axisgeoid = pair.first; - return (c->First == axisgeoid && c->Second == parabolageoid - && c->SecondPos == PointPos::mid) - || (c->Second == axisgeoid && c->First == parabolageoid - && c->FirstPos == PointPos::mid); - }); + std::any_of(axisgeoid2parabolageoid.begin(), + axisgeoid2parabolageoid.end(), + [&](const auto& pair) { + auto parabolageoid = pair.second; + auto axisgeoid = pair.first; + return (c->First == axisgeoid && c->Second == parabolageoid + && c->SecondPos == PointPos::mid) + || (c->Second == axisgeoid && c->First == parabolageoid + && c->FirstPos == PointPos::mid); + }); - if (axismajorcoincidentfound != axisgeoid2parabolageoid.end()) { + if (axismajorcoincidentfound) { // we skip this coincident, the other coincident on axis will be substituted // by internal geometry constraint continue; diff --git a/src/Mod/Sketcher/App/SketchObject.h b/src/Mod/Sketcher/App/SketchObject.h index 09aca4d269..7eaf8b0ba6 100644 --- a/src/Mod/Sketcher/App/SketchObject.h +++ b/src/Mod/Sketcher/App/SketchObject.h @@ -370,8 +370,8 @@ public: /// retrieves the coordinates of a point static Base::Vector3d getPoint(const Part::Geometry* geo, PointPos PosId); Base::Vector3d getPoint(int GeoId, PointPos PosId) const; - template - static Base::Vector3d getPointForGeometry(const geomType* geo, PointPos PosId) + template + static Base::Vector3d getPointForGeometry(const GeomType* geo, PointPos PosId) { (void)geo; (void)PosId;