- // Check the lengths of auxiliary lines are zero.
- // If they become zero, remove corresponding Angle constraints.
- // It they become non-zero (but were zero recently), add Angle constraint.
- std::vector<Slvs_hConstraint>::iterator aConstr = mySlvsConstraints.begin();
- std::map<Slvs_hEntity, Slvs_hEntity> anEqualLines;
- bool isFirstRemoved = false;
- for (; aConstr != mySlvsConstraints.end();
- isFirstRemoved ? aConstr = mySlvsConstraints.begin() : ++aConstr) {
- isFirstRemoved = false;
- Slvs_Constraint aConstraint = myStorage->getConstraint(*aConstr);
- if (aConstraint.type == SLVS_C_ANGLE || aConstraint.type == SLVS_C_EQUAL_LENGTH_LINES) {
- Slvs_Entity aLine = myStorage->getEntity(aConstraint.entityA);
- // Line length became zero => remove constraint
- if (squareDistance(myStorage, aLine.point[0], aLine.point[1]) < tolerance * tolerance) {
- myStorage->removeConstraint(aConstraint.h);
- isFirstRemoved = aConstr == mySlvsConstraints.begin();
- std::vector<Slvs_hConstraint>::iterator aTmpIter = aConstr;
- if (!isFirstRemoved)
- --aConstr;
- mySlvsConstraints.erase(aTmpIter);
- }
- // Store the lines into the map
- anEqualLines[aConstraint.entityB] = aConstraint.entityA;
- }
- }
- // Create Angle and Equal constraints for non-degenerated lines
- AuxLinesList::iterator anIt = myAuxLines.begin();
- for (; anIt != myAuxLines.end(); ++anIt) {
- if (anEqualLines.find(anIt->back()) != anEqualLines.end())
- continue;
-
- std::vector<Slvs_hEntity>::iterator anEqLinesIt = anIt->begin();
- Slvs_hEntity aPrevLine = (*anEqLinesIt);
- // Check the length of the line
- Slvs_Entity aLine = myStorage->getEntity(aPrevLine);
- if (squareDistance(myStorage, aLine.point[0], aLine.point[1]) < tolerance * tolerance)
- continue;
-
- for (++anEqLinesIt; anEqLinesIt != anIt->end(); ++anEqLinesIt) {
- Slvs_hEntity aLine = (*anEqLinesIt);
- // Equal length constraint
- Slvs_Constraint aConstraint = Slvs_MakeConstraint(SLVS_E_UNKNOWN, myGroup->getId(),
- SLVS_C_EQUAL_LENGTH_LINES, myGroup->getWorkplaneId(), 0.0,
- SLVS_E_UNKNOWN, SLVS_E_UNKNOWN, aPrevLine, aLine);
- aConstraint.h = myStorage->addConstraint(aConstraint);
- mySlvsConstraints.push_back(aConstraint.h);
- // Angle constraint
- aConstraint = Slvs_MakeConstraint(SLVS_E_UNKNOWN, myGroup->getId(),
- SLVS_C_ANGLE, myGroup->getWorkplaneId(), fabs(myAngle), SLVS_E_UNKNOWN, SLVS_E_UNKNOWN,
- aPrevLine, aLine);
- if (myAngle < 0.0) // clockwise rotation
- aConstraint.other = true;
- aConstraint.h = myStorage->addConstraint(aConstraint);
- mySlvsConstraints.push_back(aConstraint.h);
-
- aPrevLine = aLine;
- }
- }