[Sketcher] Add some utility functions to Sketcher::Constraint

`involvesGeoId`, `invovesGeoIdAndPosId`, `substituteIndexAndPos`
This commit is contained in:
Ajinkya Dahale
2024-08-29 09:48:46 +05:30
parent 680b4bdb2e
commit ed59a23778
2 changed files with 34 additions and 0 deletions

View File

@@ -239,6 +239,25 @@ void Constraint::substituteIndex(int fromGeoId, int toGeoId)
}
}
void Constraint::substituteIndexAndPos(int fromGeoId,
PointPos fromPosId,
int toGeoId,
PointPos toPosId)
{
if (this->First == fromGeoId && this->FirstPos == fromPosId) {
this->First = toGeoId;
this->FirstPos = toPosId;
}
if (this->Second == fromGeoId && this->SecondPos == fromPosId) {
this->Second = toGeoId;
this->SecondPos = toPosId;
}
if (this->Third == fromGeoId && this->ThirdPos == fromPosId) {
this->Third = toGeoId;
this->ThirdPos = toPosId;
}
}
std::string Constraint::typeToString(ConstraintType type)
{
return type2str[type];

View File

@@ -132,6 +132,21 @@ public:
/// utility function to swap the index in First/Second/Third of the provided constraint from the
/// fromGeoId GeoId to toGeoId
void substituteIndex(int fromGeoId, int toGeoId);
/// utility function to swap the index and position in First/Second/Third of the provided
/// constraint from {fromGeoId, fromPosId} to {toGeoId, toPosId}.
void substituteIndexAndPos(int fromGeoId, PointPos fromPosId, int toGeoId, PointPos toPosId);
/// utility function to check if `geoId` is one of the geometries
bool involvesGeoId(int geoId) const
{
return First == geoId || Second == geoId || Third == geoId;
}
/// utility function to check if (`geoId`, `posId`) is one of the points/curves
bool involvesGeoIdAndPosId(int geoId, PointPos posId) const
{
return (First == geoId && FirstPos == posId) || (Second == geoId && SecondPos == posId)
|| (Third == geoId && ThirdPos == posId);
}
std::string typeToString() const
{