From d6a9daa7ee8173b47058a9aea1ea6554bcd21988 Mon Sep 17 00:00:00 2001 From: azv Date: Wed, 2 Sep 2015 14:27:22 +0300 Subject: [PATCH] Update the procedure of removing entities not used by constraints (issue #883) --- src/SketchSolver/SketchSolver_Storage.cpp | 28 ++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/src/SketchSolver/SketchSolver_Storage.cpp b/src/SketchSolver/SketchSolver_Storage.cpp index 30d3f5790..6dce96f4c 100644 --- a/src/SketchSolver/SketchSolver_Storage.cpp +++ b/src/SketchSolver/SketchSolver_Storage.cpp @@ -225,7 +225,33 @@ void SketchSolver_Storage::removeUnusedEntities() } std::set::const_iterator anEntIt = anUnusedEntities.begin(); - for (; anEntIt != anUnusedEntities.end(); ++anEntIt) { + while (anEntIt != anUnusedEntities.end()) { + int aPos = Search(*anEntIt, myEntities); + if (aPos < 0 && aPos >= (int)myEntities.size()) + continue; + Slvs_Entity anEntity = myEntities[aPos]; + // Remove entity if and only if all its parameters unused + bool isUsed = false; + if (anEntity.distance != SLVS_E_UNKNOWN && + anUnusedEntities.find(anEntity.distance) == anUnusedEntities.end()) + isUsed = true; + for (int i = 0; i < 4 && !isUsed; i++) + if (anEntity.point[i] != SLVS_E_UNKNOWN && + anUnusedEntities.find(anEntity.point[i]) == anUnusedEntities.end()) + isUsed = true; + if (isUsed) { + anUnusedEntities.erase(anEntity.distance); + for (int i = 0; i < 4; i++) + if (anEntity.point[i] != SLVS_E_UNKNOWN) + anUnusedEntities.erase(anEntity.point[i]); + std::set::iterator aRemoveIt = anEntIt++; + anUnusedEntities.erase(aRemoveIt); + continue; + } + ++anEntIt; + } + + for (anEntIt = anUnusedEntities.begin(); anEntIt != anUnusedEntities.end(); ++anEntIt) { int aPos = Search(*anEntIt, myEntities); if (aPos >= 0 && aPos < (int)myEntities.size()) { // Remove entity and its parameters -- 2.39.2