1 // Copyright (C) 2014-2015 EDF-R&D
2 // This library is free software; you can redistribute it and/or
3 // modify it under the terms of the GNU Lesser General Public
4 // License as published by the Free Software Foundation; either
5 // version 2.1 of the License, or (at your option) any later version.
7 // This library is distributed in the hope that it will be useful,
8 // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10 // Lesser General Public License for more details.
12 // You should have received a copy of the GNU Lesser General Public
13 // License along with this library; if not, write to the Free Software
14 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #include<test_HYDROData_BSplineOperation.h>
21 #include <HYDROData_BSplineOperation.h>
25 const double LOCAL_SELECTION_TOLERANCE = 0.0001;
27 void test_HYDROData_BSplineOperation::testCurve()
29 /*// prepare points: function of sin(x)
30 NCollection_Sequence<gp_XYZ> aPoints;
31 for ( double x = 0; x < 6.28; x += 0.1 )
33 gp_XYZ aPoint( x, sin( x ), 0.0 );
34 aPoints.Append( aPoint );
37 HYDROData_BSplineOperation aBSpline( aPoints, false, LOCAL_SELECTION_TOLERANCE );
39 Handle(Geom_BSplineCurve) aBS = aBSpline.Curve();
40 CPPUNIT_ASSERT( !aBS.IsNull() );
41 CPPUNIT_ASSERT( !aBS->IsClosed() );
42 CPPUNIT_ASSERT_EQUAL( aBS->Continuity(), GeomAbs_C2 );
44 // check that values of BSpline are not far from original "sin" function
45 // in all points of the curve
46 for ( double x = 0; x < 6.29; x += 0.001 )
48 double aDiff = aBS->Value( x ).Y() - sin( aBS->Value( x ).X() );
49 if ( aDiff < 0 ) aDiff = -aDiff;
50 CPPUNIT_ASSERT( aDiff < 3.e-6 ); // this number is found manually
54 void test_HYDROData_BSplineOperation::testPath()
56 /*// prepare points: function of sin(x)
57 static const double aScale = 10000000.;
59 NCollection_Sequence<gp_XYZ> aPoints;
60 for ( double x = 0; x < 6.28; x += 0.1 )
62 gp_XYZ aPoint( x * aScale, sin( x ) * aScale, 0.0 );
63 aPoints.Append( aPoint );
66 // convert to QPainterPath
67 HYDROData_BSplineOperation aBSpline( aPoints, false, LOCAL_SELECTION_TOLERANCE );
69 CPPUNIT_ASSERT( !aBSpline.Curve().IsNull() );
72 aBSpline.ComputePath( aPath );
73 CPPUNIT_ASSERT( !aPath.isEmpty() );*/
76 QImage aPic(1300, 600, QImage::Format_RGB32);
77 QPainter aPainter(&aPic);
78 aPainter.setBrush(QBrush(Qt::white));
79 aPainter.drawPath(aPath);
83 /*// check that values of Path are not far from original "sin" function
84 // in all points of the curve
85 QList<QPolygonF> aPolyF = aPath.toSubpathPolygons( QTransform() );
86 QList<QPolygonF>::iterator aFIter = aPolyF.begin();
87 for(; aFIter != aPolyF.end();aFIter++) {
88 QPolygon aPoly = aFIter->toPolygon();
89 QPolygon::iterator aPoints = aPoly.begin();
90 for(; aPoints != aPoly.end(); aPoints++) {
91 double aDiff = aPoints->y() / aScale - sin(aPoints->x() / aScale);
92 if (aDiff < 0) aDiff = -aDiff;
93 CPPUNIT_ASSERT(aDiff < 4.e-6); // this number is found manually