#include <gp_Pnt2d.hxx>
+const double EPS = 1E-4;
+extern QString TMP_DIR;
+
void generateOne( QTextStream& theStream,
double theFirstX, double theFirstY,
double theLastX, double theLastY )
{
const int aNbPoints = 50;
-
- double aComDist = gp_Pnt2d( theFirstX, theFirstY ).Distance( gp_Pnt2d( theLastX, theLastY ) );
- double aStep = aComDist / (double)aNbPoints;
-
double aStepZ = -5;
- double aCurDist = 0.0;
- for ( int i = 0; i <= aNbPoints; ++i )
+ const double dt = 1.0 / aNbPoints;
+
+ for( double t=0.0; t<=1.0; t += dt )
{
- double aRatio = ( aCurDist / ( aComDist - aCurDist ) );
-
- double anX = ( theFirstX + aRatio * theLastX ) / ( 1 + aRatio );
- double anY = ( theFirstY + aRatio * theLastY ) / ( 1 + aRatio );
- double aZ = aStepZ * aStepZ + sin( (float)rand() );
+ double anX = theFirstX * (1-t) + theLastX * t;
+ double anY = theFirstY * (1-t) + theLastY * t;
+ double aZ = aStepZ * aStepZ + sin( 10*t );
theStream << anX << " " << anY << " " << aZ << " \n";
- aCurDist += aStep;
aStepZ += 0.2;
}
}
{
QTextStream anOutStream( &aTmpFile );
- srand( 4587 );
generateOne( anOutStream, 0, 5, 0, -5 );
generateOne( anOutStream, 10, 5, 10, -5 );
generateOne( anOutStream, 20, 5, 20, -5 );
Handle(HYDROData_Bathymetry) aBathymetry =
Handle(HYDROData_Bathymetry)::DownCast( aDoc->CreateObject( KIND_BATHYMETRY ) );
- QString aFileName = QDir::tempPath() + QDir::separator() + "test.xyz";
+ QString aFileName = TMP_DIR + QDir::separator() + "test.xyz";
if ( !createTestFile( aFileName ) )
return; // No file has been created
- CPPUNIT_ASSERT( aBathymetry->ImportFromFile( aFileName.toStdString().c_str() ) );
+ CPPUNIT_ASSERT( aBathymetry->ImportFromFiles( QStringList(aFileName)) );
HYDROData_Bathymetry::AltitudePoints anAltitudePoints = aBathymetry->GetAltitudePoints();
- CPPUNIT_ASSERT( anAltitudePoints.Length() == 20 );
+ CPPUNIT_ASSERT_EQUAL( 2300, (int)anAltitudePoints.size() );
gp_XY aTestPoint( 1, 1 );
- double anAltitude = aBathymetry->GetAltitudeForPoint( aTestPoint );
- CPPUNIT_ASSERT( ValuesEquals( anAltitude, 10.0 ) );
+ double anAltitude = aBathymetry->GetAltitudeForPoint( aTestPoint, 1 );
+ CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.2432, anAltitude, EPS );
aTestPoint = gp_XY( 0.5, 0.5 );
- anAltitude = aBathymetry->GetAltitudeForPoint( aTestPoint );
- CPPUNIT_ASSERT( ValuesEquals( anAltitude, 5.0 ) );
+ anAltitude = aBathymetry->GetAltitudeForPoint( aTestPoint, 1 );
+ CPPUNIT_ASSERT_DOUBLES_EQUAL( -0.591602, anAltitude, EPS );
aTestPoint = gp_XY( 1.5, 1 );
- anAltitude = aBathymetry->GetAltitudeForPoint( aTestPoint );
- CPPUNIT_ASSERT( ValuesEquals( anAltitude, 10.0 ) );
+ anAltitude = aBathymetry->GetAltitudeForPoint( aTestPoint, 1 );
+ CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.2432, anAltitude, EPS );
aTestPoint = gp_XY( 1.5, 0.7 );
- anAltitude = aBathymetry->GetAltitudeForPoint( aTestPoint );
- CPPUNIT_ASSERT( ValuesEquals( anAltitude, 7.0 ) );
+ anAltitude = aBathymetry->GetAltitudeForPoint( aTestPoint, 1 );
+ CPPUNIT_ASSERT_DOUBLES_EQUAL( -0.591602, anAltitude, EPS );
aTestPoint = gp_XY( 1.5, -0.7 );
- anAltitude = aBathymetry->GetAltitudeForPoint( aTestPoint );
- CPPUNIT_ASSERT( ValuesEquals( anAltitude, HYDROData_Bathymetry::GetInvalidAltitude() ) );
+ anAltitude = aBathymetry->GetAltitudeForPoint( aTestPoint, 1 );
+ CPPUNIT_ASSERT_DOUBLES_EQUAL( -0.271267, anAltitude, EPS );
aTestPoint = gp_XY( 2, 3.5 );
- anAltitude = aBathymetry->GetAltitudeForPoint( aTestPoint );
- CPPUNIT_ASSERT( ValuesEquals( anAltitude, 35.0 ) );
+ anAltitude = aBathymetry->GetAltitudeForPoint( aTestPoint, 1 );
+ CPPUNIT_ASSERT_DOUBLES_EQUAL( 13.9454, anAltitude, EPS );
aDoc->Close();
}
Handle(HYDROData_Bathymetry) aBathymetry1 =
Handle(HYDROData_Bathymetry)::DownCast( aDoc->CreateObject( KIND_BATHYMETRY ) );
- QString aFileName = QDir::tempPath() + QDir::separator() + "test.xyz";
+ QString aFileName = TMP_DIR + QDir::separator() + "test.xyz";
bool anIsFileCreated = createTestFile( aFileName );
if ( anIsFileCreated )
{
- CPPUNIT_ASSERT( aBathymetry1->ImportFromFile( aFileName.toStdString().c_str() ) );
+ CPPUNIT_ASSERT( aBathymetry1->ImportFromFiles( QStringList(aFileName ) ) );
HYDROData_Bathymetry::AltitudePoints anAltitudePoints = aBathymetry1->GetAltitudePoints();
- CPPUNIT_ASSERT( anAltitudePoints.Length() == 20 );
+ CPPUNIT_ASSERT_EQUAL( 2300, (int)anAltitudePoints.size() );
}
Handle(HYDROData_Bathymetry) aBathymetry2 =
if ( anIsFileCreated )
{
HYDROData_Bathymetry::AltitudePoints anAltitudePoints = aBathymetry2->GetAltitudePoints();
- CPPUNIT_ASSERT( anAltitudePoints.Length() == 20 );
+ CPPUNIT_ASSERT_EQUAL( 2300, (int)anAltitudePoints.size() );
}
aDoc->Close();