Upgrade test for BSpline is Line
This commit is contained in:
committed by
Yorik van Havre
parent
3ca8eb0989
commit
9f2ad88ded
@@ -30,6 +30,7 @@
|
||||
|
||||
#include <gp_Ax2.hxx>
|
||||
#include <gp_Dir.hxx>
|
||||
#include <gp_Pnt.hxx>
|
||||
#include <gp_Vec.hxx>
|
||||
#include <TopoDS.hxx>
|
||||
#include <TopoDS_Vertex.hxx>
|
||||
@@ -89,6 +90,8 @@ class TechDrawExport DrawUtil {
|
||||
//! find intersection in 2d for 2 lines in point+direction form
|
||||
static Base::Vector3d Intersect2d(Base::Vector3d p1, Base::Vector3d d1,
|
||||
Base::Vector3d p2, Base::Vector3d d2);
|
||||
static Base::Vector3d gpPnt2V3(const gp_Pnt gp) { return Base::Vector3d(gp.X(),gp.Y(),gp.Z()); }
|
||||
static gp_Pnt V32gpPnt(const Base::Vector3d v) { return gp_Pnt(v.x,v.y,v.z); }
|
||||
|
||||
//debugging routines
|
||||
static void dumpVertexes(const char* text, const TopoDS_Shape& s);
|
||||
|
||||
@@ -564,31 +564,39 @@ BSpline::BSpline(const TopoDS_Edge &e)
|
||||
|
||||
|
||||
//! Can this BSpline be represented by a straight line?
|
||||
// if len(first-last) == sum(len(pi - pi+1)) then it is a line
|
||||
bool BSpline::isLine()
|
||||
{
|
||||
bool result = false;
|
||||
BRepAdaptor_Curve c(occEdge);
|
||||
|
||||
Handle(Geom_BSplineCurve) spline = c.BSpline();
|
||||
if (spline->Degree() == 1) {
|
||||
//TODO: this test is a bit sketchy
|
||||
// proper test would be to test each pole for collinearity.
|
||||
|
||||
double splineLength = GCPnts_AbscissaPoint::Length (c);
|
||||
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) {
|
||||
Base::Vector3d startPnt(s.X(), s.Y(), 0.0);
|
||||
Base::Vector3d endPnt(e.X(), e.Y(), 0.0);
|
||||
double endLength = (startPnt - endPnt).Length();
|
||||
if (DrawUtil::fpCompare(splineLength,endLength)) {
|
||||
Base::Vector3d vs = DrawUtil::gpPnt2V3(s);
|
||||
Base::Vector3d ve = DrawUtil::gpPnt2V3(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::gpPnt2V3(p1);
|
||||
gp_Pnt p2 = poles(i+1);
|
||||
Base::Vector3d v2 = DrawUtil::gpPnt2V3(p2);
|
||||
lenTotal += (v2-v1).Length();
|
||||
}
|
||||
|
||||
if (DrawUtil::fpCompare(lenTotal,endLength)) {
|
||||
result = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user