Sketcher: [skip ci] add function to sketch validation panel to remove degenerated geometry
This commit is contained in:
@@ -822,3 +822,49 @@ std::vector<Base::Vector3d> SketchAnalysis::getOpenVertices(void) const
|
||||
|
||||
return points;
|
||||
}
|
||||
|
||||
int SketchAnalysis::detectDegeneratedGeometries(double tolerance)
|
||||
{
|
||||
int countDegenerated = 0;
|
||||
const std::vector<Part::Geometry *>& geom = sketch->getInternalGeometry();
|
||||
for (std::size_t i=0; i<geom.size(); i++) {
|
||||
Part::Geometry* g = geom[i];
|
||||
|
||||
if (g->Construction)
|
||||
continue;
|
||||
|
||||
if (g->getTypeId().isDerivedFrom(Part::GeomCurve::getClassTypeId())) {
|
||||
Part::GeomCurve* curve = static_cast<Part::GeomCurve*>(g);
|
||||
double len = curve->length(curve->getFirstParameter(), curve->getLastParameter());
|
||||
if (len < tolerance)
|
||||
countDegenerated++;
|
||||
}
|
||||
}
|
||||
|
||||
return countDegenerated;
|
||||
}
|
||||
|
||||
int SketchAnalysis::removeDegeneratedGeometries(double tolerance)
|
||||
{
|
||||
std::set<int> delInternalGeometries;
|
||||
const std::vector<Part::Geometry *>& geom = sketch->getInternalGeometry();
|
||||
for (std::size_t i=0; i<geom.size(); i++) {
|
||||
Part::Geometry* g = geom[i];
|
||||
|
||||
if (g->Construction)
|
||||
continue;
|
||||
|
||||
if (g->getTypeId().isDerivedFrom(Part::GeomCurve::getClassTypeId())) {
|
||||
Part::GeomCurve* curve = static_cast<Part::GeomCurve*>(g);
|
||||
double len = curve->length(curve->getFirstParameter(), curve->getLastParameter());
|
||||
if (len < tolerance)
|
||||
delInternalGeometries.insert(static_cast<int>(i));
|
||||
}
|
||||
}
|
||||
|
||||
for (auto it = delInternalGeometries.rbegin(); it != delInternalGeometries.rend(); ++it) {
|
||||
sketch->delGeometry(*it);
|
||||
}
|
||||
|
||||
return static_cast<int>(delInternalGeometries.size());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user