[TD]make BSpline::isLine a general purpose static method

This commit is contained in:
wandererfan
2023-04-22 09:20:55 -04:00
committed by WandererFan
parent ef68b1c020
commit ec1c458907
2 changed files with 39 additions and 33 deletions

View File

@@ -1266,39 +1266,7 @@ BSpline::BSpline(const TopoDS_Edge &e)
// if len(first-last) == sum(len(pi - pi+1)) then it is a line
bool BSpline::isLine()
{
BRepAdaptor_Curve c(occEdge);
Handle(Geom_BSplineCurve) spline = c.BSpline();
double f = c.FirstParameter();
double l = c.LastParameter();
gp_Pnt s = c.Value(f);
gp_Pnt e = c.Value(l);
bool samePnt = s.IsEqual(e, FLT_EPSILON);
if (samePnt) {
return false;
}
Base::Vector3d vs = DrawUtil::toVector3d(s);
Base::Vector3d ve = DrawUtil::toVector3d(e);
double endLength = (vs - ve).Length();
int low = 0;
int high = spline->NbPoles() - 1;
TColgp_Array1OfPnt poles(low, high);
spline->Poles(poles);
double lenTotal = 0.0;
for (int i = 0; i < high; i++) {
gp_Pnt p1 = poles(i);
Base::Vector3d v1 = DrawUtil::toVector3d(p1);
gp_Pnt p2 = poles(i+1);
Base::Vector3d v2 = DrawUtil::toVector3d(p2);
lenTotal += (v2-v1).Length();
}
if (DrawUtil::fpCompare(lenTotal, endLength)) {
return true;
}
return false;
return GeometryUtils::isLine(occEdge);
}
//used by DVDim for approximate dims
@@ -1802,3 +1770,40 @@ TopoDS_Edge GeometryUtils::asCircle(TopoDS_Edge occEdge, bool& arc)
}
return result;
}
bool GeometryUtils::isLine(TopoDS_Edge occEdge)
{
BRepAdaptor_Curve c(occEdge);
Handle(Geom_BSplineCurve) spline = c.BSpline();
double f = c.FirstParameter();
double l = c.LastParameter();
gp_Pnt s = c.Value(f);
gp_Pnt e = c.Value(l);
bool samePnt = s.IsEqual(e, FLT_EPSILON);
if (samePnt) {
return false;
}
Base::Vector3d vs = DrawUtil::toVector3d(s);
Base::Vector3d ve = DrawUtil::toVector3d(e);
double endLength = (vs - ve).Length();
int low = 0;
int high = spline->NbPoles() - 1;
TColgp_Array1OfPnt poles(low, high);
spline->Poles(poles);
double lenTotal = 0.0;
for (int i = 0; i < high; i++) {
gp_Pnt p1 = poles(i);
Base::Vector3d v1 = DrawUtil::toVector3d(p1);
gp_Pnt p2 = poles(i+1);
Base::Vector3d v2 = DrawUtil::toVector3d(p2);
lenTotal += (v2-v1).Length();
}
if (DrawUtil::fpCompare(lenTotal, endLength)) {
return true;
}
return false;
}

View File

@@ -435,6 +435,7 @@ class TechDrawExport GeometryUtils
static bool isCircle(TopoDS_Edge occEdge);
static bool getCircleParms(TopoDS_Edge occEdge, double& radius, Base::Vector3d& center, bool& isArc);
static TopoDS_Edge asCircle(TopoDS_Edge occEdge, bool& arc);
static bool isLine(TopoDS_Edge occEdge);
};
} //end namespace TechDraw