Use standard std::count_if. NFC.

This commit is contained in:
Ryan Pavlik 2019-08-20 14:53:54 -05:00 committed by whitequark
parent 8c750cef9c
commit 93184c54ac
3 changed files with 10 additions and 25 deletions

View File

@ -480,11 +480,6 @@ public:
const T *cbegin() const { return begin(); } const T *cbegin() const { return begin(); }
const T *cend() const { return end(); } const T *cend() const { return end(); }
template<typename F>
size_t CountIf(F &&predicate) const {
return std::count_if(begin(), end(), std::forward<F&&>(predicate));
}
void ClearTags() { void ClearTags() {
for(auto &elt : *this) { elt.tag = 0; } for(auto &elt : *this) { elt.tag = 0; }
} }

View File

@ -50,7 +50,8 @@ bool Group::IsVisible() {
} }
size_t Group::GetNumConstraints() { size_t Group::GetNumConstraints() {
return SK.constraint.CountIf([&](Constraint const & c) { return c.group == h; }); return std::count_if(SK.constraint.begin(), SK.constraint.end(),
[&](Constraint const &c) { return c.group == h; });
} }
Vector Group::ExtrusionGetVector() { Vector Group::ExtrusionGetVector() {

View File

@ -302,16 +302,10 @@ bool SEdgeList::AssemblePolygon(SPolygon *dest, SEdge *errorAt, bool keepDir) co
// but they are considered to cross if they are coincident and overlapping. // but they are considered to cross if they are coincident and overlapping.
// If pi is not NULL, then a crossing is returned in that. // If pi is not NULL, then a crossing is returned in that.
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
int SEdgeList::AnyEdgeCrossings(Vector a, Vector b, int SEdgeList::AnyEdgeCrossings(Vector a, Vector b, Vector *ppi, SPointList *spl) const {
Vector *ppi, SPointList *spl) const auto cnt = std::count_if(l.begin(), l.end(),
{ [&](SEdge const &se) { return se.EdgeCrosses(a, b, ppi, spl); });
int cnt = 0; return static_cast<int>(cnt);
for(const SEdge *se = l.First(); se; se = l.NextAfter(se)) {
if(se->EdgeCrosses(a, b, ppi, spl)) {
cnt++;
}
}
return cnt;
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@ -707,15 +701,10 @@ bool SPolygon::ContainsPoint(Vector p) const {
} }
int SPolygon::WindingNumberForPoint(Vector p) const { int SPolygon::WindingNumberForPoint(Vector p) const {
int winding = 0; auto winding = std::count_if(l.begin(), l.end(), [&](const SContour &sc) {
int i; return sc.ContainsPointProjdToNormal(normal, p);
for(i = 0; i < l.n; i++) { });
const SContour *sc = &(l[i]); return static_cast<int>(winding);
if(sc->ContainsPointProjdToNormal(normal, p)) {
winding++;
}
}
return winding;
} }
void SPolygon::FixContourDirections() { void SPolygon::FixContourDirections() {