diff --git a/README.md b/README.md index 4c689e1a..fd02dabf 100644 --- a/README.md +++ b/README.md @@ -125,6 +125,7 @@ QGIS contains internal copy of MDAL library in following versions: | 3.30.0 | 1.0.2 | | | 3.36.0 | 1.1.0 | Mike21 format support read/write | | 3.38.0 | 1.2.0 | Groundwater / surface water meshes for 3Di format | +| 3.42.0 | 1.3.0 | Fix 2dm format coordinates saving | versions `X.Y.9Z` are development versions or alpha/beta releases (e.g. `0.4.90`, `0.4.91`, ...) diff --git a/mdal/frmts/mdal_2dm.cpp b/mdal/frmts/mdal_2dm.cpp index 35b73bfb..243cb12c 100644 --- a/mdal/frmts/mdal_2dm.cpp +++ b/mdal/frmts/mdal_2dm.cpp @@ -402,7 +402,7 @@ void MDAL::Driver2dm::save( const std::string &fileName, const std::string &, MD for ( size_t j = 0; j < 2; ++j ) { line.append( " " ); - line.append( MDAL::coordinateToString( vertex[j] ) ); + line.append( MDAL::doubleToString( vertex[j], 8, true ) ); } line.append( " " ); line.append( MDAL::doubleToString( vertex[2] ) ); diff --git a/mdal/mdal.cpp b/mdal/mdal.cpp index c1c2ed1e..5ab0756a 100644 --- a/mdal/mdal.cpp +++ b/mdal/mdal.cpp @@ -21,7 +21,7 @@ static const char *EMPTY_STR = ""; const char *MDAL_Version() { - return "1.2.0"; + return "1.3.0"; } MDAL_Status MDAL_LastStatus() diff --git a/mdal/mdal_utils.cpp b/mdal/mdal_utils.cpp index 29dabcc0..c7c6725a 100644 --- a/mdal/mdal_utils.cpp +++ b/mdal/mdal_utils.cpp @@ -837,10 +837,14 @@ std::string MDAL::coordinateToString( double coordinate, int precision ) return returnString; } -std::string MDAL::doubleToString( double value, int precision ) +std::string MDAL::doubleToString( double value, int precision, bool forceScientific ) { std::ostringstream oss; oss.precision( precision ); + if ( forceScientific ) + { + oss.setf( std::ios::scientific ); + } oss << value; return oss.str(); } diff --git a/mdal/mdal_utils.hpp b/mdal/mdal_utils.hpp index 9997c947..db9e56d9 100644 --- a/mdal/mdal_utils.hpp +++ b/mdal/mdal_utils.hpp @@ -117,7 +117,8 @@ namespace MDAL //! Returns a string with scientific format //! precision is the number of signifiant digits - std::string doubleToString( double value, int precision = 6 ); + //! forceScientific forces the scientific notation of the number even if not necessary + std::string doubleToString( double value, int precision = 6, bool forceScientific = false ); /** * Splits by deliminer and skips empty parts. diff --git a/tests/data/2dm/quad_and_triangle_scientific.2dm b/tests/data/2dm/quad_and_triangle_scientific.2dm new file mode 100644 index 00000000..6691a5a7 --- /dev/null +++ b/tests/data/2dm/quad_and_triangle_scientific.2dm @@ -0,0 +1,8 @@ +MESH2D +ND 1 1.00000000e+03 2.00000000e+03 20 +ND 2 2.00000000e+03 2.00000000e+03 30 +ND 3 3.00000000e+03 2.00000000e+03 40 +ND 4 2.00000000e+03 3.00000000e+03 50 +ND 5 1.00000000e+03 3.00000000e+03 10 +E4Q 1 1 2 4 5 +E3T 2 2 3 4 diff --git a/tests/test_2dm.cpp b/tests/test_2dm.cpp index 80380ec9..ee9be542 100644 --- a/tests/test_2dm.cpp +++ b/tests/test_2dm.cpp @@ -764,6 +764,31 @@ TEST( Mesh2DMTest, Save1DMeshToFile ) ); } +TEST( Mesh2DMTest, QuadAndTriangleScientificNotationFile ) +{ + std::string path = test_file( "/2dm/quad_and_triangle_scientific.2dm" ); + EXPECT_EQ( MDAL_MeshNames( path.c_str() ), "2DM:\"" + path + "\"" ); + MDAL_MeshH m_scientific = MDAL_LoadMesh( path.c_str() ); + EXPECT_NE( m_scientific, nullptr ); + MDAL_Status s = MDAL_LastStatus(); + EXPECT_EQ( MDAL_Status::None, s ); + + int v_count = MDAL_M_vertexCount( m_scientific ); + EXPECT_EQ( v_count, 5 ); + + int f_count = MDAL_M_faceCount( m_scientific ); + EXPECT_EQ( 2, f_count ); + + path = test_file( "/2dm/quad_and_triangle.2dm" ); + EXPECT_EQ( MDAL_MeshNames( path.c_str() ), "2DM:\"" + path + "\"" ); + MDAL_MeshH m_not_scientific = MDAL_LoadMesh( path.c_str() ); + + compareMeshFrames( m_scientific, m_not_scientific ); + + MDAL_CloseMesh( m_scientific ); + MDAL_CloseMesh( m_not_scientific ); +} + int main( int argc, char **argv ) { testing::InitGoogleTest( &argc, argv );