Solver: Support for Diameter constraint
This commit is contained in:
@@ -1390,6 +1390,19 @@ int Sketch::addConstraint(const Constraint *constraint)
|
||||
rtn = addRadiusConstraint(constraint->First, c.value,c.driving);
|
||||
break;
|
||||
}
|
||||
case Diameter:
|
||||
{
|
||||
c.value = new double(constraint->getValue());
|
||||
if(c.driving)
|
||||
FixParameters.push_back(c.value);
|
||||
else {
|
||||
Parameters.push_back(c.value);
|
||||
DrivenParameters.push_back(c.value);
|
||||
}
|
||||
|
||||
rtn = addDiameterConstraint(constraint->First, c.value,c.driving);
|
||||
break;
|
||||
}
|
||||
case Equal:
|
||||
rtn = addEqualConstraint(constraint->First,constraint->Second);
|
||||
break;
|
||||
@@ -2120,6 +2133,25 @@ int Sketch::addRadiusConstraint(int geoId, double * value, bool driving)
|
||||
return -1;
|
||||
}
|
||||
|
||||
int Sketch::addDiameterConstraint(int geoId, double * value, bool driving)
|
||||
{
|
||||
geoId = checkGeoId(geoId);
|
||||
|
||||
if (Geoms[geoId].type == Circle) {
|
||||
GCS::Circle &c = Circles[Geoms[geoId].index];
|
||||
int tag = ++ConstraintsCounter;
|
||||
GCSsys.addConstraintCircleDiameter(c, value, tag, driving);
|
||||
return ConstraintsCounter;
|
||||
}
|
||||
else if (Geoms[geoId].type == Arc) {
|
||||
GCS::Arc &a = Arcs[Geoms[geoId].index];
|
||||
int tag = ++ConstraintsCounter;
|
||||
GCSsys.addConstraintArcDiameter(a, value, tag, driving);
|
||||
return ConstraintsCounter;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
// line orientation angle constraint
|
||||
int Sketch::addAngleConstraint(int geoId, double * value, bool driving)
|
||||
{
|
||||
@@ -3039,6 +3071,10 @@ bool Sketch::updateNonDrivingConstraints()
|
||||
|
||||
(*it).constr->setValue(std::remainder(*((*it).value), 2.0*M_PI));
|
||||
}
|
||||
else if((*it).constr->Type==Diameter) {
|
||||
|
||||
(*it).constr->setValue(2.0**((*it).value));
|
||||
}
|
||||
else {
|
||||
(*it).constr->setValue(*((*it).value));
|
||||
}
|
||||
|
||||
@@ -261,6 +261,14 @@ public:
|
||||
* Parameters array, as the case may be.
|
||||
*/
|
||||
int addRadiusConstraint(int geoId, double * value, bool driving = true);
|
||||
/**
|
||||
* add a radius constraint on a circle or an arc
|
||||
*
|
||||
* double * value is a pointer to double allocated in the heap, containing the
|
||||
* constraint value and already inserted into either the FixParameters or
|
||||
* Parameters array, as the case may be.
|
||||
*/
|
||||
int addDiameterConstraint(int geoId, double * value, bool driving = true);
|
||||
/**
|
||||
* add an angle constraint on a line or between two lines
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user