Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix 2dm coordinates saving #491

Merged
merged 5 commits into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`, ...)

Expand Down
2 changes: 1 addition & 1 deletion mdal/frmts/mdal_2dm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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] ) );
Expand Down
2 changes: 1 addition & 1 deletion mdal/mdal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
6 changes: 5 additions & 1 deletion mdal/mdal_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
3 changes: 2 additions & 1 deletion mdal/mdal_utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
8 changes: 8 additions & 0 deletions tests/data/2dm/quad_and_triangle_scientific.2dm
Original file line number Diff line number Diff line change
@@ -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
25 changes: 25 additions & 0 deletions tests/test_2dm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down
Loading