1 #include<test_HYDROData_BSplineOperation.h>
3 #include <HYDROData_BSplineOperation.h>
7 void test_HYDROData_BSplineOperation::testCurve()
9 // prepare points: function of sin(x)
10 NCollection_Sequence<gp_XYZ> aPoints;
11 for ( double x = 0; x < 6.28; x += 0.1 )
13 gp_XYZ aPoint( x, sin( x ), 0.0 );
14 aPoints.Append( aPoint );
17 HYDROData_BSplineOperation aBSpline( aPoints, false );
19 Handle(Geom_BSplineCurve) aBS = aBSpline.Curve();
20 CPPUNIT_ASSERT( !aBS.IsNull() );
21 CPPUNIT_ASSERT( !aBS->IsClosed() );
22 CPPUNIT_ASSERT_EQUAL( aBS->Continuity(), GeomAbs_C2 );
24 // check that values of BSpline are not far from original "sin" function
25 // in all points of the curve
26 for ( double x = 0; x < 6.29; x += 0.001 )
28 double aDiff = aBS->Value( x ).Y() - sin( aBS->Value( x ).X() );
29 if ( aDiff < 0 ) aDiff = -aDiff;
30 CPPUNIT_ASSERT( aDiff < 3.e-6 ); // this number is found manually
34 void test_HYDROData_BSplineOperation::testPath()
36 // prepare points: function of sin(x)
37 static const double aScale = 10000000.;
39 NCollection_Sequence<gp_XYZ> aPoints;
40 for ( double x = 0; x < 6.28; x += 0.1 )
42 gp_XYZ aPoint( x * aScale, sin( x ) * aScale, 0.0 );
43 aPoints.Append( aPoint );
46 // convert to QPainterPath
47 HYDROData_BSplineOperation aBSpline( aPoints, false );
49 CPPUNIT_ASSERT( !aBSpline.Curve().IsNull() );
51 QPainterPath aPath = aBSpline.ComputePath();
52 CPPUNIT_ASSERT( !aPath.isEmpty() );
55 QImage aPic(1300, 600, QImage::Format_RGB32);
56 QPainter aPainter(&aPic);
57 aPainter.setBrush(QBrush(Qt::white));
58 aPainter.drawPath(aPath);
62 // check that values of Path are not far from original "sin" function
63 // in all points of the curve
64 QList<QPolygonF> aPolyF = aPath.toSubpathPolygons( QTransform() );
65 QList<QPolygonF>::iterator aFIter = aPolyF.begin();
66 for(; aFIter != aPolyF.end();aFIter++) {
67 QPolygon aPoly = aFIter->toPolygon();
68 QPolygon::iterator aPoints = aPoly.begin();
69 for(; aPoints != aPoly.end(); aPoints++) {
70 double aDiff = aPoints->y() / aScale - sin(aPoints->x() / aScale);
71 if (aDiff < 0) aDiff = -aDiff;
72 CPPUNIT_ASSERT(aDiff < 4.e-6); // this number is found manually