Skip to content

Commit 9c3f489

Browse files
committed
generate: change PruneOrphans and PruneConstraints to prune all items
...instead of just the first "prunable" one. The same was done for `PruneRequests` in the previous commit. The change in `PruneConstraints` avoids some of the recursive `GenerateAll` calls. The one caused by `PruneGroups` remains. The change in `PruneOrphans` is a NOP.
1 parent 46d7d2b commit 9c3f489

File tree

1 file changed

+27
-28
lines changed

1 file changed

+27
-28
lines changed

src/generate.cpp

Lines changed: 27 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -30,24 +30,24 @@ void SolveSpaceUI::MarkGroupDirty(hGroup hg, bool onlyThis) {
3030
}
3131

3232
bool SolveSpaceUI::PruneOrphans() {
33-
34-
auto r = std::find_if(SK.request.begin(), SK.request.end(),
35-
[&](Request &r) { return !GroupExists(r.group); });
36-
if(r != SK.request.end()) {
37-
(deleted.requests)++;
38-
SK.request.RemoveById(r->h);
39-
return true;
33+
const int requests = SK.request.n;
34+
for(Request &r : SK.request) {
35+
if(!GroupExists(r.group))
36+
r.tag = 1;
4037
}
38+
SK.request.RemoveTagged();
39+
deleted.requests += requests - SK.request.n;
4140

42-
auto c = std::find_if(SK.constraint.begin(), SK.constraint.end(),
43-
[&](Constraint &c) { return !GroupExists(c.group); });
44-
if(c != SK.constraint.end()) {
45-
(deleted.constraints)++;
46-
(deleted.nonTrivialConstraints)++;
47-
SK.constraint.RemoveById(c->h);
48-
return true;
41+
const int constraints = SK.constraint.n;
42+
for(Constraint &c : SK.constraint) {
43+
if(!GroupExists(c.group))
44+
c.tag = 1;
4945
}
50-
return false;
46+
SK.constraint.RemoveTagged();
47+
deleted.constraints += constraints - SK.constraint.n;
48+
deleted.nonTrivialConstraints += constraints - SK.constraint.n;
49+
50+
return (requests > SK.request.n) || (constraints > SK.constraint.n);
5151
}
5252

5353
bool SolveSpaceUI::GroupsInOrder(hGroup before, hGroup after) {
@@ -111,9 +111,9 @@ bool SolveSpaceUI::PruneRequests(hGroup hg) {
111111
}
112112

113113
bool SolveSpaceUI::PruneConstraints(hGroup hg) {
114-
auto c = std::find_if(SK.constraint.begin(), SK.constraint.end(), [&](Constraint &c) {
115-
if(c.group != hg)
116-
return false;
114+
const int constraints = SK.constraint.n;
115+
for(Constraint &c : SK.constraint) {
116+
if(c.group != hg) continue;
117117

118118
if(EntityExists(c.workplane) &&
119119
EntityExists(c.ptA) &&
@@ -122,23 +122,22 @@ bool SolveSpaceUI::PruneConstraints(hGroup hg) {
122122
EntityExists(c.entityB) &&
123123
EntityExists(c.entityC) &&
124124
EntityExists(c.entityD)) {
125-
return false;
125+
continue;
126126
}
127-
return true;
128-
});
129127

130-
if(c != SK.constraint.end()) {
131128
(deleted.constraints)++;
132-
if(c->type != Constraint::Type::POINTS_COINCIDENT &&
133-
c->type != Constraint::Type::HORIZONTAL &&
134-
c->type != Constraint::Type::VERTICAL) {
129+
if(c.type != Constraint::Type::POINTS_COINCIDENT &&
130+
c.type != Constraint::Type::HORIZONTAL &&
131+
c.type != Constraint::Type::VERTICAL) {
135132
(deleted.nonTrivialConstraints)++;
136133
}
137134

138-
SK.constraint.RemoveById(c->h);
139-
return true;
135+
c.tag = 1;
140136
}
141-
return false;
137+
138+
SK.constraint.RemoveTagged();
139+
140+
return constraints > SK.constraint.n;
142141
}
143142

144143
void SolveSpaceUI::GenerateAll(Generate type, bool andFindFree, bool genForBBox) {

0 commit comments

Comments
 (0)