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