Skip to content

Commit

Permalink
Sketcher: small asserts cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
DeepSOIC authored and wwmayer committed Mar 28, 2015
1 parent 94c2662 commit 3e6eb43
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 23 deletions.
28 changes: 10 additions & 18 deletions src/Mod/Sketcher/App/Sketch.cpp
Expand Up @@ -594,8 +594,9 @@ Py::Tuple Sketch::getPyGeometry(void) const
int Sketch::checkGeoId(int geoId)
{
if (geoId < 0)
geoId += Geoms.size();
assert(geoId >= 0 && geoId < int(Geoms.size()));
geoId += Geoms.size();//convert negative external-geometry index to index into Geoms
if(!( geoId >= 0 && geoId < int(Geoms.size()) ))
throw Base::Exception("Sketch::checkGeoId. GeoId index out range.");
return geoId;
}

Expand All @@ -619,7 +620,6 @@ GCS::Curve* Sketch::getGCSCurveByGeoId(int geoId)
return &ArcsOfEllipse[Geoms[geoId].index];
break;
default:
assert(0);
return 0;
};
}
Expand All @@ -628,8 +628,8 @@ GCS::Curve* Sketch::getGCSCurveByGeoId(int geoId)

int Sketch::addConstraint(const Constraint *constraint)
{
// constraints on nothing makes no sense
assert(int(Geoms.size()) > 0);
if(int(Geoms.size()) <= 0)
throw Base::Exception("Sketch::addConstraint. Can't add constraint to a sketch with no geometry!");
int rtn = -1;
switch (constraint->Type) {
case DistanceX:
Expand Down Expand Up @@ -767,7 +767,7 @@ int Sketch::addConstraint(const Constraint *constraint)
}
break;
case SnellsLaw:
assert(constraint->ThirdPos==none);
//assert(constraint->ThirdPos==none); //will work anyway...
rtn = addSnellsLawConstraint(constraint->First, constraint->FirstPos,
constraint->Second, constraint->SecondPos,
constraint->Third,
Expand All @@ -781,9 +781,6 @@ int Sketch::addConstraint(const Constraint *constraint)

int Sketch::addConstraints(const std::vector<Constraint *> &ConstraintList)
{
// constraints on nothing makes no sense
assert(!Geoms.empty() || ConstraintList.empty());

int rtn = -1;
for (std::vector<Constraint *>::const_iterator it = ConstraintList.begin();it!=ConstraintList.end();++it)
rtn = addConstraint (*it);
Expand Down Expand Up @@ -1157,7 +1154,7 @@ int Sketch::addAngleAtPointConstraint(
{

if(!(cTyp == Angle || cTyp == Tangent || cTyp == Perpendicular)) {
assert(0);//none of the three types. Why are we here??
//assert(0);//none of the three types. Why are we here??
return -1;
}

Expand All @@ -1166,7 +1163,7 @@ int Sketch::addAngleAtPointConstraint(
bool e2e = pos2 != none && pos1 != none;//is endpoint-to-endpoint?

if (!( avp || e2c || e2e )) {
assert(0);//none of the three types. Why are we here??
//assert(0);//none of the three types. Why are we here??
return -1;
}

Expand All @@ -1177,14 +1174,13 @@ int Sketch::addAngleAtPointConstraint(

if (Geoms[geoId1].type == Point ||
Geoms[geoId2].type == Point){
assert(0);//point is not a curve. No tangency/whatever!
Base::Console().Error("addAngleAtPointConstraint: one of the curves is a point!\n");
return -1;
}

GCS::Curve* crv1 =getGCSCurveByGeoId(geoId1);
GCS::Curve* crv2 =getGCSCurveByGeoId(geoId2);
if (!crv1 || !crv2) {
assert(0);
Base::Console().Error("addAngleAtPointConstraint: getGCSCurveByGeoId returned NULL!\n");
return -1;
}
Expand All @@ -1196,7 +1192,6 @@ int Sketch::addAngleAtPointConstraint(
pointId = getPointId(geoId1, pos1);

if (pointId < 0 || pointId >= int(Points.size())){
assert(0);
Base::Console().Error("addAngleAtPointConstraint: point index out of range.\n");
return -1;
}
Expand All @@ -1205,7 +1200,6 @@ int Sketch::addAngleAtPointConstraint(
if(e2e){//we need second point
int pointId = getPointId(geoId2, pos2);
if (pointId < 0 || pointId >= int(Points.size())){
assert(0);
Base::Console().Error("addAngleAtPointConstraint: point index out of range.\n");
return -1;
}
Expand Down Expand Up @@ -1660,15 +1654,14 @@ int Sketch::addSnellsLawConstraint(int geoIdRay1, PointPos posRay1,

if (Geoms[geoIdRay1].type == Point ||
Geoms[geoIdRay2].type == Point){
assert(0);//point is not a curve. Not applicable!
Base::Console().Error("addSnellsLawConstraint: point is not a curve. Not applicable!\n");
return -1;
}

GCS::Curve* ray1 =getGCSCurveByGeoId(geoIdRay1);
GCS::Curve* ray2 =getGCSCurveByGeoId(geoIdRay2);
GCS::Curve* boundary =getGCSCurveByGeoId(geoIdBnd);
if (!ray1 || !ray2 || !boundary) {
assert(0);
Base::Console().Error("addSnellsLawConstraint: getGCSCurveByGeoId returned NULL!\n");
return -1;
}
Expand All @@ -1677,7 +1670,6 @@ int Sketch::addSnellsLawConstraint(int geoIdRay1, PointPos posRay1,
int pointId2 = getPointId(geoIdRay2, posRay2);
if ( pointId1 < 0 || pointId1 >= int(Points.size()) ||
pointId2 < 0 || pointId2 >= int(Points.size()) ){
assert(0);
Base::Console().Error("addSnellsLawConstraint: point index out of range.\n");
return -1;
}
Expand Down
10 changes: 5 additions & 5 deletions src/Mod/Sketcher/App/SketchObject.cpp
Expand Up @@ -245,8 +245,9 @@ int SketchObject::movePoint(int GeoId, PointPos PosId, const Base::Vector3d& toP

Base::Vector3d SketchObject::getPoint(int GeoId, PointPos PosId) const
{
assert(GeoId == H_Axis || GeoId == V_Axis ||
(GeoId <= getHighestCurveIndex() && GeoId >= -getExternalGeometryCount()) );
if(!(GeoId == H_Axis || GeoId == V_Axis
|| (GeoId <= getHighestCurveIndex() && GeoId >= -getExternalGeometryCount()) ))
throw Base::Exception("SketchObject::getPoint. Invalid GeoId was supplied.");
const Part::Geometry *geo = getGeometry(GeoId);
if (geo->getTypeId() == Part::GeomPoint::getClassTypeId()) {
const Part::GeomPoint *p = dynamic_cast<const Part::GeomPoint*>(geo);
Expand Down Expand Up @@ -1731,7 +1732,7 @@ int SketchObject::delExternal(int ExtGeoId)
if (copiedConstr->Third < GeoId &&
copiedConstr->Third != Constraint::GeoUndef)
copiedConstr->Third += 1;


newConstraints.push_back(copiedConstr);
}
}
Expand Down Expand Up @@ -2638,7 +2639,7 @@ int SketchObject::port_reversedExternalArcs(bool justAnalyze)
bool SketchObject::AutoLockTangencyAndPerpty(Constraint *cstr, bool bForce, bool bLock)
{
try{
assert ( cstr->Type == Tangent || cstr->Type == Perpendicular);
//assert ( cstr->Type == Tangent || cstr->Type == Perpendicular);
if(cstr->Value != 0.0 && ! bForce) /*tangency type already set. If not bForce - don't touch.*/
return true;
if(!bLock){
Expand Down Expand Up @@ -2683,7 +2684,6 @@ bool SketchObject::AutoLockTangencyAndPerpty(Constraint *cstr, bool bForce, bool
}
} catch (Base::Exception& e){
//failure to determine tangency type is not a big deal, so a warning.
assert(0);//but it shouldn't happen (failure to determine tangency type)!
Base::Console().Warning("Error in AutoLockTangency. %s \n", e.what());
return false;
}
Expand Down

0 comments on commit 3e6eb43

Please sign in to comment.