Salome HOME
Debug minor changes.
[modules/hydro.git] / src / HYDROData / test_HYDROData_BSplineOperation.cxx
1 #include<test_HYDROData_BSplineOperation.h>
2
3 #include <HYDROData_BSplineOperation.h>
4 #include <gp_Pnt.hxx>
5 #include <QTransform>
6
7 void test_HYDROData_BSplineOperation::testCurve()
8 {
9   // prepare points: function of sin(x)
10   QList<double> aPoints;
11   double x;
12   for(x = 0; x < 6.28; x += 0.1)
13     aPoints<<x<<sin(x);
14   // compute BSpline
15   HYDROData_BSplineOperation aBSpline(aPoints, 0, false);
16   Handle(Geom_BSplineCurve) aBS = aBSpline.Curve();
17   CPPUNIT_ASSERT(!aBS.IsNull());
18   CPPUNIT_ASSERT(!aBS->IsClosed());
19   CPPUNIT_ASSERT_EQUAL(aBS->Continuity(), GeomAbs_C2);
20   // check that values of BSpline are not far from original "sin" function
21   // in all points of the curve
22   for(x = 0; x < 6.29; x += 0.001) {
23     double aDiff = aBS->Value(x).Y() - sin(aBS->Value(x).X());
24     if (aDiff < 0) aDiff = -aDiff;
25     CPPUNIT_ASSERT(aDiff < 3.e-6); // this number is found manually
26   }
27 }
28
29 void test_HYDROData_BSplineOperation::testPath()
30 {
31   // prepare points: function of sin(x)
32   static const double aScale = 10000000.;
33   QList<double> aPoints;
34   double x;
35   for(x = 0; x < 6.28; x += 0.1)
36     aPoints<<x*aScale<<sin(x) * aScale;
37   // convert to QPainterPath
38   HYDROData_BSplineOperation aBSpline(aPoints, 0, false);
39   CPPUNIT_ASSERT(!aBSpline.Curve().IsNull());
40   QPainterPath aPath = aBSpline.ComputePath();
41   CPPUNIT_ASSERT(!aPath.isEmpty());
42   
43   /*
44   QImage aPic(1300, 600, QImage::Format_RGB32);
45   QPainter aPainter(&aPic);
46   aPainter.setBrush(QBrush(Qt::white));
47   aPainter.drawPath(aPath);
48   aPic.save("pic.bmp");
49   */
50      
51   // check that values of Path are not far from original "sin" function
52   // in all points of the curve
53   QList<QPolygonF> aPolyF = aPath.toSubpathPolygons(QTransform());
54   QList<QPolygonF>::iterator aFIter = aPolyF.begin();
55   for(; aFIter != aPolyF.end();aFIter++) {
56     QPolygon aPoly = aFIter->toPolygon();
57     QPolygon::iterator aPoints = aPoly.begin();
58     for(; aPoints != aPoly.end(); aPoints++) {
59       double aDiff = aPoints->y() / aScale - sin(aPoints->x() / aScale);
60       if (aDiff < 0) aDiff = -aDiff;
61       CPPUNIT_ASSERT(aDiff < 4.e-6); // this number is found manually
62     }
63   }
64 }