1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: SketchSolver_Storage.cpp
4 // Created: 18 Mar 2015
5 // Author: Artem ZHIDKOV
7 #include <SketchSolver_Storage.h>
11 /** \brief Search the entity/parameter with specified ID in the list of elements
12 * \param[in] theEntityID unique ID of the element
13 * \param[in] theEntities list of elements
14 * \return position of the found element or -1 if the element is not found
17 static int Search(const uint32_t& theEntityID, const std::vector<T>& theEntities);
19 /// \brief Compare two parameters to be different
20 static bool IsNotEqual(const Slvs_Param& theParam1, const Slvs_Param& theParam2);
21 /// \brief Compare two entities to be different
22 static bool IsNotEqual(const Slvs_Entity& theEntity1, const Slvs_Entity& theEntity2);
23 /// \brief Compare two constriants to be different
24 static bool IsNotEqual(const Slvs_Constraint& theConstraint1, const Slvs_Constraint& theConstraint2);
27 SketchSolver_Storage::SketchSolver_Storage()
28 : myParamMaxID(SLVS_E_UNKNOWN),
29 myEntityMaxID(SLVS_E_UNKNOWN),
30 myConstrMaxID(SLVS_C_UNKNOWN),
31 myFixed(SLVS_E_UNKNOWN),
32 myNeedToResolve(false)
36 Slvs_hParam SketchSolver_Storage::addParameter(const Slvs_Param& theParam)
38 if (theParam.h > 0 && theParam.h <= myParamMaxID) {
39 // parameter is already used, rewrite it
40 return updateParameter(theParam);
43 Slvs_Param aParam = theParam;
44 if (aParam.h > myParamMaxID)
45 myParamMaxID = aParam.h;
47 aParam.h = ++myParamMaxID;
48 myParameters.push_back(aParam);
49 myNeedToResolve = true;
53 Slvs_hParam SketchSolver_Storage::updateParameter(const Slvs_Param& theParam)
55 if (theParam.h > 0 && theParam.h <= myParamMaxID) {
56 // parameter already used, rewrite it
57 int aPos = Search(theParam.h, myParameters);
58 if (aPos >= 0 && aPos < (int)myParameters.size()) {
59 myNeedToResolve = myNeedToResolve || IsNotEqual(myParameters[aPos], theParam);
60 myParameters[aPos] = theParam;
65 // Parameter is not found, add new one
66 Slvs_Param aParam = theParam;
68 return addParameter(aParam);
71 bool SketchSolver_Storage::removeParameter(const Slvs_hParam& theParamID)
73 int aPos = Search(theParamID, myParameters);
74 if (aPos >= 0 && aPos < (int)myParameters.size()) {
75 // Firstly, search the parametes is not used elsewhere
76 std::vector<Slvs_Entity>::const_iterator anEntIter = myEntities.begin();
77 for (; anEntIter != myEntities.end(); anEntIter++) {
78 for (int i = 0; i < 4; i++)
79 if (anEntIter->param[i] == theParamID)
83 myParameters.erase(myParameters.begin() + aPos);
84 myParamMaxID = myParameters.empty() ? SLVS_E_UNKNOWN : myParameters.back().h;
85 myNeedToResolve = true;
86 myRemovedParameters.insert(theParamID);
92 const Slvs_Param& SketchSolver_Storage::getParameter(const Slvs_hParam& theParamID) const
94 int aPos = Search(theParamID, myParameters);
95 if (aPos >= 0 && aPos < (int)myParameters.size())
96 return myParameters[aPos];
98 // Parameter is not found, return empty object
99 static Slvs_Param aDummy;
105 Slvs_hEntity SketchSolver_Storage::addEntity(const Slvs_Entity& theEntity)
107 if (theEntity.h > 0 && theEntity.h <= myEntityMaxID) {
108 // Entity is already used, rewrite it
109 return updateEntity(theEntity);
112 Slvs_Entity aEntity = theEntity;
113 if (aEntity.h > myEntityMaxID)
114 myEntityMaxID = aEntity.h;
116 aEntity.h = ++myEntityMaxID;
117 myEntities.push_back(aEntity);
118 myNeedToResolve = true;
122 Slvs_hEntity SketchSolver_Storage::updateEntity(const Slvs_Entity& theEntity)
124 if (theEntity.h > 0 && theEntity.h <= myEntityMaxID) {
125 // Entity already used, rewrite it
126 int aPos = Search(theEntity.h, myEntities);
127 if (aPos >= 0 && aPos < (int)myEntities.size()) {
128 myNeedToResolve = myNeedToResolve || IsNotEqual(myEntities[aPos], theEntity);
129 myEntities[aPos] = theEntity;
134 // Entity is not found, add new one
135 Slvs_Entity aEntity = theEntity;
137 return addEntity(aEntity);
140 bool SketchSolver_Storage::removeEntity(const Slvs_hEntity& theEntityID)
143 int aPos = Search(theEntityID, myEntities);
144 if (aPos >= 0 && aPos < (int)myEntities.size()) {
145 // Firstly, check the entity and its attributes is not used elsewhere
146 std::set<Slvs_hEntity> anEntAndSubs;
147 anEntAndSubs.insert(theEntityID);
148 for (int i = 0; i < 4; i++)
149 if (myEntities[aPos].point[i] != SLVS_E_UNKNOWN)
150 anEntAndSubs.insert(myEntities[aPos].point[i]);
152 std::vector<Slvs_Entity>::const_iterator anEntIter = myEntities.begin();
153 for (; anEntIter != myEntities.end(); anEntIter++) {
154 for (int i = 0; i < 4; i++)
155 if (anEntAndSubs.find(anEntIter->point[i]) != anEntAndSubs.end())
157 if (anEntAndSubs.find(anEntIter->distance) != anEntAndSubs.end())
160 std::vector<Slvs_Constraint>::const_iterator aConstrIter = myConstraints.begin();
161 for (; aConstrIter != myConstraints.end(); aConstrIter++) {
162 Slvs_hEntity anEntIDs[6] = {aConstrIter->ptA, aConstrIter->ptB,
163 aConstrIter->entityA, aConstrIter->entityB,
164 aConstrIter->entityC, aConstrIter->entityD};
165 for (int i = 0; i < 6; i++)
166 if (anEntAndSubs.find(anEntIDs[i]) != anEntAndSubs.end())
169 // The entity is not used, remove it and its parameters
170 Slvs_Entity anEntity = myEntities[aPos];
171 myEntities.erase(myEntities.begin() + aPos);
172 myEntityMaxID = myEntities.empty() ? SLVS_E_UNKNOWN : myEntities.back().h;
173 if (anEntity.distance != SLVS_E_UNKNOWN)
174 aResult = aResult && removeParameter(anEntity.distance);
175 for (int i = 0; i < 4; i++)
176 if (anEntity.param[i] != SLVS_E_UNKNOWN)
177 aResult = removeParameter(anEntity.param[i]) && aResult;
178 for (int i = 0; i < 4; i++)
179 if (anEntity.point[i] != SLVS_E_UNKNOWN)
180 aResult = removeEntity(anEntity.point[i]) && aResult;
181 myNeedToResolve = true;
182 myRemovedEntities.insert(theEntityID);
183 if (anEntity.type == SLVS_E_POINT_IN_2D || anEntity.type == SLVS_E_POINT_IN_3D)
184 removeCoincidentPoint(theEntityID);
189 const Slvs_Entity& SketchSolver_Storage::getEntity(const Slvs_hEntity& theEntityID) const
191 int aPos = Search(theEntityID, myEntities);
192 if (aPos >= 0 && aPos < (int)myEntities.size())
193 return myEntities[aPos];
195 // Entity is not found, return empty object
196 static Slvs_Entity aDummy;
197 aDummy.h = SLVS_E_UNKNOWN;
201 Slvs_hEntity SketchSolver_Storage::copyEntity(const Slvs_hEntity& theCopied)
203 int aPos = Search(theCopied, myEntities);
204 if (aPos < 0 || aPos >= (int)myEntities.size())
205 return SLVS_E_UNKNOWN;
207 Slvs_Entity aCopy = myEntities[aPos];
208 aCopy.h = SLVS_E_UNKNOWN;
210 while (aCopy.point[i] != SLVS_E_UNKNOWN) {
211 aCopy.point[i] = copyEntity(aCopy.point[i]);
214 if (aCopy.param[0] != SLVS_E_UNKNOWN) {
215 aPos = Search(aCopy.param[0], myParameters);
217 while (aCopy.param[i] != SLVS_E_UNKNOWN) {
218 Slvs_Param aNewParam = myParameters[aPos];
219 aNewParam.h = SLVS_E_UNKNOWN;
220 aCopy.param[i] = addParameter(aNewParam);
225 return addEntity(aCopy);
228 void SketchSolver_Storage::copyEntity(const Slvs_hEntity& theFrom, const Slvs_hEntity& theTo)
230 int aPosFrom = Search(theFrom, myEntities);
231 int aPosTo = Search(theTo, myEntities);
232 if (aPosFrom < 0 || aPosFrom >= (int)myEntities.size() ||
233 aPosTo < 0 || aPosTo >= (int)myEntities.size())
236 Slvs_Entity aEntFrom = myEntities[aPosFrom];
237 Slvs_Entity aEntTo = myEntities[aPosTo];
239 while (aEntFrom.point[i] != SLVS_E_UNKNOWN) {
240 copyEntity(aEntFrom.point[i], aEntTo.point[i]);
243 if (aEntFrom.param[0] != SLVS_E_UNKNOWN) {
244 aPosFrom = Search(aEntFrom.param[0], myParameters);
245 aPosTo = Search(aEntTo.param[0], myParameters);
247 while (aEntFrom.param[i] != SLVS_E_UNKNOWN) {
248 myParameters[aPosTo++].val = myParameters[aPosFrom++].val;
255 bool SketchSolver_Storage::isPointFixed(
256 const Slvs_hEntity& thePointID, Slvs_hConstraint& theFixed, bool theAccurate) const
258 // Search the set of coincident points
259 std::set<Slvs_hEntity> aCoincident;
260 aCoincident.insert(thePointID);
261 std::vector< std::set<Slvs_hEntity> >::const_iterator aCPIter = myCoincidentPoints.begin();
262 for (; aCPIter != myCoincidentPoints.end(); aCPIter++)
263 if (aCPIter->find(thePointID) != aCPIter->end()) {
264 aCoincident = *aCPIter;
268 // Search the Rigid constraint
269 std::vector<Slvs_Constraint>::const_iterator aConstrIter = myConstraints.begin();
270 for (; aConstrIter != myConstraints.end(); aConstrIter++)
271 if (aConstrIter->type == SLVS_C_WHERE_DRAGGED &&
272 aCoincident.find(aConstrIter->ptA) != aCoincident.end()) {
273 theFixed = aConstrIter->h;
278 // Try to find the fixed entity which uses such point or its coincidence
279 std::vector<Slvs_Entity>::const_iterator anEntIter = myEntities.begin();
280 for (; anEntIter != myEntities.end(); anEntIter++) {
281 for (int i = 0; i < 4; i++) {
282 Slvs_hEntity aPt = anEntIter->point[i];
283 if (aPt != SLVS_E_UNKNOWN &&
284 (aPt == thePointID || aCoincident.find(aPt) != aCoincident.end())) {
285 if (isEntityFixed(anEntIter->h, true))
291 return SLVS_E_UNKNOWN;
294 bool SketchSolver_Storage::isEntityFixed(const Slvs_hEntity& theEntityID, bool theAccurate) const
296 int aPos = Search(theEntityID, myEntities);
297 if (aPos < 0 || aPos >= (int)myEntities.size())
300 // Firstly, find how many points are under Rigid constraint
302 for (int i = 0; i < 4; i++) {
303 Slvs_hEntity aPoint = myEntities[aPos].point[i];
304 if (aPoint == SLVS_E_UNKNOWN)
307 std::set<Slvs_hEntity> aCoincident;
308 aCoincident.insert(aPoint);
309 std::vector< std::set<Slvs_hEntity> >::const_iterator aCPIter = myCoincidentPoints.begin();
310 for (; aCPIter != myCoincidentPoints.end(); aCPIter++)
311 if (aCPIter->find(aPoint) != aCPIter->end()) {
312 aCoincident = *aCPIter;
316 // Search the Rigid constraint
317 std::vector<Slvs_Constraint>::const_iterator aConstrIter = myConstraints.begin();
318 for (; aConstrIter != myConstraints.end(); aConstrIter++)
319 if (aConstrIter->type == SLVS_C_WHERE_DRAGGED &&
320 aCoincident.find(aConstrIter->ptA) != aCoincident.end())
324 std::list<Slvs_Constraint> aList;
325 std::list<Slvs_Constraint>::iterator anIt;
326 Slvs_hConstraint aTempID; // used in isPointFixed() method
328 if (myEntities[aPos].type == SLVS_E_LINE_SEGMENT) {
331 else if (aNbFixed == 0 || !theAccurate)
333 // Additional check (the line may be fixed if it is used by different constraints):
334 // 1. The line is used in Equal constraint, another entity is fixed and there is a fixed point on line
335 aList = getConstraintsByType(SLVS_C_PT_ON_LINE);
336 for (anIt = aList.begin(); anIt != aList.end(); anIt++)
337 if (anIt->entityA == theEntityID && isPointFixed(anIt->ptA, aTempID))
339 if (anIt != aList.end()) {
340 aList = getConstraintsByType(SLVS_C_EQUAL_LENGTH_LINES);
341 aList.splice(aList.end(), getConstraintsByType(SLVS_C_EQUAL_LINE_ARC_LEN));
342 for (anIt = aList.begin(); anIt != aList.end(); anIt++)
343 if (anIt->entityA == theEntityID || anIt->entityB == theEntityID) {
344 Slvs_hEntity anOther = anIt->entityA == theEntityID ? anIt->entityB : anIt->entityA;
345 if (isEntityFixed(anOther, false))
349 // 2. The line is used in Parallel/Perpendicular and Length constraints
350 aList = getConstraintsByType(SLVS_C_PARALLEL);
351 aList.splice(aList.end(), getConstraintsByType(SLVS_C_PERPENDICULAR));
352 for (anIt = aList.begin(); anIt != aList.end(); anIt++)
353 if (anIt->entityA == theEntityID || anIt->entityB == theEntityID) {
354 Slvs_hEntity anOther = anIt->entityA == theEntityID ? anIt->entityB : anIt->entityA;
355 if (isEntityFixed(anOther, false))
358 if (anIt != aList.end()) {
359 aList = getConstraintsByType(SLVS_C_PT_PT_DISTANCE);
360 for (anIt = aList.begin(); anIt != aList.end(); anIt++)
361 if ((anIt->ptA == myEntities[aPos].point[0] && anIt->ptB == myEntities[aPos].point[1]) ||
362 (anIt->ptA == myEntities[aPos].point[1] && anIt->ptB == myEntities[aPos].point[0]))
365 // 3. Another verifiers ...
366 } else if (myEntities[aPos].type == SLVS_E_CIRCLE) {
369 // Search for Diameter constraint
370 aList = getConstraintsByType(SLVS_C_DIAMETER);
371 for (anIt = aList.begin(); anIt != aList.end(); anIt++)
372 if (anIt->entityA == theEntityID)
376 // Additional check (the circle may be fixed if it is used by different constraints):
377 // 1. The circle is used in Equal constraint and another entity is fixed
378 aList = getConstraintsByType(SLVS_C_EQUAL_RADIUS);
379 for (anIt = aList.begin(); anIt != aList.end(); anIt++)
380 if (anIt->entityA == theEntityID || anIt->entityB == theEntityID) {
381 Slvs_hEntity anOther = anIt->entityA == theEntityID ? anIt->entityB : anIt->entityA;
382 if (isEntityFixed(anOther, false))
385 // 2. Another verifiers ...
386 } else if (myEntities[aPos].type == SLVS_E_ARC_OF_CIRCLE) {
389 else if (aNbFixed <= 1)
391 // Search for Diameter constraint
392 aList = getConstraintsByType(SLVS_C_DIAMETER);
393 for (anIt = aList.begin(); anIt != aList.end(); anIt++)
394 if (anIt->entityA == theEntityID)
398 // Additional check (the arc may be fixed if it is used by different constraints):
399 // 1. The arc is used in Equal constraint and another entity is fixed
400 aList = getConstraintsByType(SLVS_C_EQUAL_RADIUS);
401 aList.splice(aList.end(), getConstraintsByType(SLVS_C_EQUAL_LINE_ARC_LEN));
402 for (anIt = aList.begin(); anIt != aList.end(); anIt++)
403 if (anIt->entityA == theEntityID || anIt->entityB == theEntityID) {
404 Slvs_hEntity anOther = anIt->entityA == theEntityID ? anIt->entityB : anIt->entityA;
405 if (isEntityFixed(anOther, false))
408 // 2. Another verifiers ...
414 Slvs_hConstraint SketchSolver_Storage::addConstraint(const Slvs_Constraint& theConstraint)
416 if (theConstraint.h > 0 && theConstraint.h <= myConstrMaxID) {
417 // Constraint is already used, rewrite it
418 return updateConstraint(theConstraint);
421 Slvs_Constraint aConstraint = theConstraint;
423 // Find a constraint with same type uses same arguments
424 std::vector<Slvs_Constraint>::iterator aCIt = myConstraints.begin();
425 for (; aCIt != myConstraints.end(); aCIt++) {
426 if (aConstraint.type != aCIt->type)
428 if (aConstraint.ptA == aCIt->ptA && aConstraint.ptB == aCIt->ptB &&
429 aConstraint.entityA == aCIt->entityA && aConstraint.entityB == aCIt->entityB &&
430 aConstraint.entityC == aCIt->entityC && aConstraint.entityD == aCIt->entityD) {
431 aConstraint.h = aCIt->h;
432 return updateConstraint(aConstraint);
436 if (aConstraint.h > myConstrMaxID)
437 myConstrMaxID = aConstraint.h;
439 aConstraint.h = ++myConstrMaxID;
440 myConstraints.push_back(aConstraint);
441 myNeedToResolve = true;
442 if (aConstraint.type == SLVS_C_POINTS_COINCIDENT)
443 addCoincidentPoints(aConstraint.ptA, aConstraint.ptB);
444 return aConstraint.h;
447 Slvs_hConstraint SketchSolver_Storage::updateConstraint(const Slvs_Constraint& theConstraint)
449 if (theConstraint.h > 0 && theConstraint.h <= myConstrMaxID) {
450 // Constraint already used, rewrite it
451 int aPos = Search(theConstraint.h, myConstraints);
452 if (aPos >= 0 && aPos < (int)myConstraints.size()) {
453 myNeedToResolve = myNeedToResolve || IsNotEqual(myConstraints[aPos], theConstraint);
454 myConstraints[aPos] = theConstraint;
455 if (theConstraint.type == SLVS_C_POINTS_COINCIDENT)
456 addCoincidentPoints(theConstraint.ptA, theConstraint.ptB);
457 return theConstraint.h;
461 // Constraint is not found, add new one
462 Slvs_Constraint aConstraint = theConstraint;
464 return addConstraint(aConstraint);
467 bool SketchSolver_Storage::removeConstraint(const Slvs_hConstraint& theConstraintID)
470 int aPos = Search(theConstraintID, myConstraints);
471 if (aPos >= 0 && aPos < (int)myConstraints.size()) {
472 Slvs_Constraint aConstraint = myConstraints[aPos];
473 myConstraints.erase(myConstraints.begin() + aPos);
474 myConstrMaxID = myConstraints.empty() ? SLVS_E_UNKNOWN : myConstraints.back().h;
475 myNeedToResolve = true;
476 myRemovedConstraints.insert(theConstraintID);
477 // Remove all entities
478 Slvs_hEntity anEntities[6] = {aConstraint.ptA, aConstraint.ptB,
479 aConstraint.entityA, aConstraint.entityB,
480 aConstraint.entityC, aConstraint.entityD};
481 for (int i = 0; i < 6; i++)
482 if (anEntities[i] != SLVS_E_UNKNOWN)
483 aResult = removeEntity(anEntities[i]) && aResult;
484 // remove temporary fixed point, if available
485 if (myFixed == theConstraintID)
486 myFixed = SLVS_E_UNKNOWN;
491 const Slvs_Constraint& SketchSolver_Storage::getConstraint(const Slvs_hConstraint& theConstraintID) const
493 int aPos = Search(theConstraintID, myConstraints);
494 if (aPos >= 0 && aPos < (int)myConstraints.size())
495 return myConstraints[aPos];
497 // Constraint is not found, return empty object
498 static Slvs_Constraint aDummy;
503 std::list<Slvs_Constraint> SketchSolver_Storage::getConstraintsByType(int theConstraintType) const
505 std::list<Slvs_Constraint> aResult;
506 std::vector<Slvs_Constraint>::const_iterator aCIter = myConstraints.begin();
507 for (; aCIter != myConstraints.end(); aCIter++)
508 if (aCIter->type == theConstraintType)
509 aResult.push_back(*aCIter);
514 void SketchSolver_Storage::addConstraintWhereDragged(const Slvs_hConstraint& theConstraintID)
516 if (myFixed != SLVS_E_UNKNOWN)
517 return; // the point is already fixed
518 int aPos = Search(theConstraintID, myConstraints);
519 if (aPos >= 0 && aPos < (int)myConstraints.size())
520 myFixed = theConstraintID;
523 void SketchSolver_Storage::addTemporaryConstraint(const Slvs_hConstraint& theConstraintID)
525 myTemporaryConstraints.insert(theConstraintID);
528 void SketchSolver_Storage::removeTemporaryConstraints()
530 myTemporaryConstraints.clear();
533 bool SketchSolver_Storage::isTemporary(const Slvs_hConstraint& theConstraintID) const
535 return myTemporaryConstraints.find(theConstraintID) != myTemporaryConstraints.end();
539 void SketchSolver_Storage::getRemoved(
540 std::set<Slvs_hParam>& theParameters,
541 std::set<Slvs_hEntity>& theEntities,
542 std::set<Slvs_hConstraint>& theConstraints)
544 theParameters = myRemovedParameters;
545 theEntities = myRemovedEntities;
546 theConstraints = myRemovedConstraints;
548 myRemovedParameters.clear();
549 myRemovedEntities.clear();
550 myRemovedConstraints.clear();
553 void SketchSolver_Storage::initializeSolver(SketchSolver_Solver& theSolver)
555 theSolver.setParameters(myParameters.data(), (int)myParameters.size());
556 theSolver.setEntities(myEntities.data(), (int)myEntities.size());
558 // Copy constraints excluding the fixed one
559 std::vector<Slvs_Constraint> aConstraints = myConstraints;
560 if (myFixed != SLVS_E_UNKNOWN) {
561 Slvs_hEntity aFixedPoint = SLVS_E_UNKNOWN;
562 std::vector<Slvs_Constraint>::iterator anIt = aConstraints.begin();
563 for (; anIt != aConstraints.end(); anIt++)
564 if (anIt->h == myFixed) {
565 aFixedPoint = anIt->ptA;
566 aConstraints.erase(anIt);
569 // set dragged parameters
570 int aPos = Search(aFixedPoint, myEntities);
571 theSolver.setDraggedParameters(myEntities[aPos].param);
573 theSolver.setConstraints(aConstraints.data(), (int)aConstraints.size());
576 void SketchSolver_Storage::addCoincidentPoints(
577 const Slvs_hEntity& thePoint1, const Slvs_hEntity& thePoint2)
579 std::vector< std::set<Slvs_hEntity> >::iterator aCIter = myCoincidentPoints.begin();
580 std::vector< std::set<Slvs_hEntity> >::iterator aFoundIter = myCoincidentPoints.end(); // already found coincidence
581 bool isFound = false;
582 for (; aCIter != myCoincidentPoints.end(); aCIter++) {
583 bool isFirstFound = aCIter->find(thePoint1) != aCIter->end();
584 bool isSecondFound = aCIter->find(thePoint2) != aCIter->end();
585 isFound = isFound || isFirstFound || isSecondFound;
586 if (isFirstFound && isSecondFound)
587 break; // already coincident
588 else if (isFirstFound || isSecondFound) {
589 if (aFoundIter != myCoincidentPoints.end()) {
591 aFoundIter->insert(aCIter->begin(), aCIter->end());
592 myCoincidentPoints.erase(aCIter);
595 aCIter->insert(thePoint1);
596 aCIter->insert(thePoint2);
599 // coincident points not found
601 std::set<Slvs_hEntity> aNewSet;
602 aNewSet.insert(thePoint1);
603 aNewSet.insert(thePoint2);
604 myCoincidentPoints.push_back(aNewSet);
608 void SketchSolver_Storage::removeCoincidentPoint(const Slvs_hEntity& thePoint)
610 std::vector< std::set<Slvs_hEntity> >::iterator aCIter = myCoincidentPoints.begin();
611 for (; aCIter != myCoincidentPoints.end(); aCIter++)
612 if (aCIter->find(thePoint) != aCIter->end()) {
613 aCIter->erase(thePoint);
614 if (aCIter->size() <= 1)
615 myCoincidentPoints.erase(aCIter);
620 bool SketchSolver_Storage::isCoincident(
621 const Slvs_hEntity& thePoint1, const Slvs_hEntity& thePoint2) const
623 std::vector< std::set<Slvs_hEntity> >::const_iterator aCIter = myCoincidentPoints.begin();
624 for (; aCIter != myCoincidentPoints.end(); aCIter++)
625 if (aCIter->find(thePoint1) != aCIter->end() && aCIter->find(thePoint2) != aCIter->end())
633 // ========================================================
634 // ========= Auxiliary functions ===============
635 // ========================================================
638 int Search(const uint32_t& theEntityID, const std::vector<T>& theEntities)
640 int aResIndex = theEntityID <= theEntities.size() ? theEntityID - 1 : 0;
641 int aVecSize = theEntities.size();
642 if (theEntities.empty())
644 while (aResIndex >= 0 && theEntities[aResIndex].h > theEntityID)
646 while (aResIndex < aVecSize && aResIndex >= 0 && theEntities[aResIndex].h < theEntityID)
648 if (aResIndex == -1 || (aResIndex < aVecSize && theEntities[aResIndex].h != theEntityID))
649 aResIndex = aVecSize;
653 bool IsNotEqual(const Slvs_Param& theParam1, const Slvs_Param& theParam2)
655 return fabs(theParam1.val - theParam2.val) > tolerance;
658 bool IsNotEqual(const Slvs_Entity& theEntity1, const Slvs_Entity& theEntity2)
661 for (; theEntity1.param[i] != 0 && i < 4; i++)
662 if (theEntity1.param[i] != theEntity2.param[i])
665 for (; theEntity1.point[i] != 0 && i < 4; i++)
666 if (theEntity1.point[i] != theEntity2.point[i])
671 bool IsNotEqual(const Slvs_Constraint& theConstraint1, const Slvs_Constraint& theConstraint2)
673 return theConstraint1.ptA != theConstraint2.ptA ||
674 theConstraint1.ptB != theConstraint2.ptB ||
675 theConstraint1.entityA != theConstraint2.entityA ||
676 theConstraint1.entityB != theConstraint2.entityB ||
677 theConstraint1.entityC != theConstraint2.entityC ||
678 theConstraint1.entityD != theConstraint2.entityD ||
679 fabs(theConstraint1.valA - theConstraint2.valA) > tolerance;