FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

generate: fix `PruneRequests()` to actually prune requests by iscgar · Pull Request #1587 · solvespace/solvespace · GitHub

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .cpp  (2) .h  (1) All 2 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
118 changes: 68 additions & 50 deletions src/generate.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -30,24 +30,24 @@ void SolveSpaceUI::MarkGroupDirty(hGroup hg, bool onlyThis) {
}

bool SolveSpaceUI::PruneOrphans() {

auto r = std::find_if(SK.request.begin(), SK.request.end(),
[&](Request &r) { return !GroupExists(r.group); });
if(r != SK.request.end()) {
(deleted.requests)++;
SK.request.RemoveById(r->h);
return true;
const int requests = SK.request.n;
for(Request &r : SK.request) {
if(!GroupExists(r.group))
r.tag = 1;
}
SK.request.RemoveTagged();
deleted.requests += requests - SK.request.n;

auto c = std::find_if(SK.constraint.begin(), SK.constraint.end(),
[&](Constraint &c) { return !GroupExists(c.group); });
if(c != SK.constraint.end()) {
(deleted.constraints)++;
(deleted.nonTrivialConstraints)++;
SK.constraint.RemoveById(c->h);
return true;
const int constraints = SK.constraint.n;
for(Constraint &c : SK.constraint) {
if(!GroupExists(c.group))
c.tag = 1;
}
return false;
SK.constraint.RemoveTagged();
deleted.constraints += constraints - SK.constraint.n;
deleted.nonTrivialConstraints += constraints - SK.constraint.n;

return (requests > SK.request.n) || (constraints > SK.constraint.n);
}

bool SolveSpaceUI::GroupsInOrder(hGroup before, hGroup after) {
Expand Down Expand Up @@ -86,46 +86,65 @@ bool SolveSpaceUI::PruneGroups(hGroup hg) {
return true;
}

bool SolveSpaceUI::PruneRequests(hGroup hg) {
auto e = std::find_if(SK.entity.begin(), SK.entity.end(),
[&](Entity &e) { return e.group == hg && !EntityExists(e.workplane); });
if(e != SK.entity.end()) {
(deleted.requests)++;
SK.entity.RemoveById(e->h);
return true;
bool SolveSpaceUI::PruneRequestsAndConstraints(hGroup hg) {
auto entityRequestExists = [](hEntity he, bool checkEntity = false) {
if(he == Entity::NO_ENTITY) {
return true;
}

if(he.isFromRequest()) {
if(SK.request.FindByIdNoOops(he.request()) != nullptr) {
return true;
}
} else if(!checkEntity || SK.entity.FindByIdNoOops(he) != nullptr) {
return true;
}

return false;
};

const int requests = SK.request.n;
for(Request &r : SK.request) {
if(r.group != hg) {
continue;
}

if(entityRequestExists(r.workplane)) {
continue;
}

r.tag = 1;
}
return false;
}
SK.request.RemoveTagged();
deleted.requests += requests - SK.request.n;

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

if(EntityExists(c.workplane) &&
EntityExists(c.ptA) &&
EntityExists(c.ptB) &&
EntityExists(c.entityA) &&
EntityExists(c.entityB) &&
EntityExists(c.entityC) &&
EntityExists(c.entityD)) {
return false;
continue;

if(entityRequestExists(c.workplane, true) &&
entityRequestExists(c.ptA, true) &&
entityRequestExists(c.ptB, true) &&
entityRequestExists(c.entityA, true) &&
entityRequestExists(c.entityB, true) &&
entityRequestExists(c.entityC, true) &&
entityRequestExists(c.entityD, true)) {
continue;
}
return true;
});

if(c != SK.constraint.end()) {
(deleted.constraints)++;
if(c->type != Constraint::Type::POINTS_COINCIDENT &&
c->type != Constraint::Type::HORIZONTAL &&
c->type != Constraint::Type::VERTICAL) {

if(c.type != Constraint::Type::POINTS_COINCIDENT &&
c.type != Constraint::Type::HORIZONTAL &&
c.type != Constraint::Type::VERTICAL) {
(deleted.nonTrivialConstraints)++;
}

SK.constraint.RemoveById(c->h);
return true;
c.tag = 1;
}
return false;
SK.constraint.RemoveTagged();
deleted.constraints += constraints - SK.constraint.n;

return (requests > SK.request.n) || (constraints > SK.constraint.n);
}

void SolveSpaceUI::GenerateAll(Generate type, bool andFindFree, bool genForBBox) {
Expand Down Expand Up @@ -203,8 +222,7 @@ void SolveSpaceUI::GenerateAll(Generate type, bool andFindFree, bool genForBBox)
// Remove any requests or constraints that refer to a nonexistent
// group; can check those immediately, since we know what the list
// of groups should be.
while(PruneOrphans())
;
PruneOrphans();

// Don't lose our numerical guesses when we regenerate.
IdList<Param,hParam> prev = {};
Expand Down Expand Up @@ -242,7 +260,7 @@ void SolveSpaceUI::GenerateAll(Generate type, bool andFindFree, bool genForBBox)

// The requests and constraints depend on stuff in this or the
// previous group, so check them after generating.
if(PruneRequests(hg) || PruneConstraints(hg))
if(PruneRequestsAndConstraints(hg))
goto pruned;

// Use the previous values for params that we've seen before, as
Expand Down
8 changes: 0 additions & 8 deletions src/graphicswin.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -1039,14 +1039,6 @@ void GraphicsWindow::ForceTextWindowShown() {
}

void GraphicsWindow::DeleteTaggedRequests() {
// Delete any requests that were affected by this deletion.
for(Request &r : SK.request) {
if(r.workplane == Entity::FREE_IN_3D) continue;
if(!r.workplane.isFromRequest()) continue;
Request *wrkpl = SK.GetRequest(r.workplane.request());
if(wrkpl->tag)
r.tag = 1;
}
// Rewrite any point-coincident constraints that were affected by this
// deletion.
for(Request &r : SK.request) {
Expand Down
3 changes: 1 addition & 2 deletions src/solvespace.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -765,8 +765,7 @@ class SolveSpaceUI {
bool EntityExists(hEntity he);
bool GroupsInOrder(hGroup before, hGroup after);
bool PruneGroups(hGroup hg);
bool PruneRequests(hGroup hg);
bool PruneConstraints(hGroup hg);
bool PruneRequestsAndConstraints(hGroup hg);
static void ShowNakedEdges(bool reportOnlyWhenNotOkay);

enum class Generate : uint32_t {
Expand Down

Back | FazBrowse Home | New Git URL