1 #include<test_HYDROData_BSplineOperation.h>
3 #include <HYDROData_BSplineOperation.h>
7 const double LOCAL_SELECTION_TOLERANCE = 0.0001;
9 void test_HYDROData_BSplineOperation::testCurve()
11 // prepare points: function of sin(x)
12 NCollection_Sequence<gp_XYZ> aPoints;
13 for ( double x = 0; x < 6.28; x += 0.1 )
15 gp_XYZ aPoint( x, sin( x ), 0.0 );
16 aPoints.Append( aPoint );
19 HYDROData_BSplineOperation aBSpline( aPoints, false, LOCAL_SELECTION_TOLERANCE );
21 Handle(Geom_BSplineCurve) aBS = aBSpline.Curve();
22 CPPUNIT_ASSERT( !aBS.IsNull() );
23 CPPUNIT_ASSERT( !aBS->IsClosed() );
24 CPPUNIT_ASSERT_EQUAL( aBS->Continuity(), GeomAbs_C2 );
26 // check that values of BSpline are not far from original "sin" function
27 // in all points of the curve
28 for ( double x = 0; x < 6.29; x += 0.001 )
30 double aDiff = aBS->Value( x ).Y() - sin( aBS->Value( x ).X() );
31 if ( aDiff < 0 ) aDiff = -aDiff;
32 CPPUNIT_ASSERT( aDiff < 3.e-6 ); // this number is found manually
36 void test_HYDROData_BSplineOperation::testPath()
38 // prepare points: function of sin(x)
39 static const double aScale = 10000000.;
41 NCollection_Sequence<gp_XYZ> aPoints;
42 for ( double x = 0; x < 6.28; x += 0.1 )
44 gp_XYZ aPoint( x * aScale, sin( x ) * aScale, 0.0 );
45 aPoints.Append( aPoint );
48 // convert to QPainterPath
49 HYDROData_BSplineOperation aBSpline( aPoints, false, LOCAL_SELECTION_TOLERANCE );
51 CPPUNIT_ASSERT( !aBSpline.Curve().IsNull() );
54 aBSpline.ComputePath( aPath );
55 CPPUNIT_ASSERT( !aPath.isEmpty() );
58 QImage aPic(1300, 600, QImage::Format_RGB32);
59 QPainter aPainter(&aPic);
60 aPainter.setBrush(QBrush(Qt::white));
61 aPainter.drawPath(aPath);
65 // check that values of Path are not far from original "sin" function
66 // in all points of the curve
67 QList<QPolygonF> aPolyF = aPath.toSubpathPolygons( QTransform() );
68 QList<QPolygonF>::iterator aFIter = aPolyF.begin();
69 for(; aFIter != aPolyF.end();aFIter++) {
70 QPolygon aPoly = aFIter->toPolygon();
71 QPolygon::iterator aPoints = aPoly.begin();
72 for(; aPoints != aPoly.end(); aPoints++) {
73 double aDiff = aPoints->y() / aScale - sin(aPoints->x() / aScale);
74 if (aDiff < 0) aDiff = -aDiff;
75 CPPUNIT_ASSERT(aDiff < 4.e-6); // this number is found manually