add_vertex and new_vertex parameters changed to by value

This commit is contained in:
Jan Möbius
2024-02-22 14:54:20 +01:00
parent fc4545e4fa
commit 49aeab8d3a
4 changed files with 105 additions and 12 deletions

View File

@@ -8,6 +8,11 @@
<tr valign=top><td><b>11.0</b> (?/?/?)</td><td>
<b>Core</b>
<ul>
<li>Changed add_vertex and new_vertex to copy the given position by value instead of by reference. Avoids crash when copying directly inside mesh on reallocation and most compilers optimize that to be faster.</li>
</ul>
<b>Documentation</b>
<ul>
<li>Update Doxygen config format</li>

View File

@@ -206,11 +206,8 @@ public:
*
* \sa new_vertex(), new_vertex_dirty()
*
* \attention Be careful to not use a reference to a point in the mesh itself here.
* as a resize of the underlying vector might invalidate this reference
* and cause a segfault.
*/
inline SmartVertexHandle new_vertex(const Point& _p)
inline SmartVertexHandle new_vertex(const Point _p)
{
VertexHandle vh(Kernel::new_vertex());
this->set_point(vh, _p);
@@ -226,9 +223,9 @@ public:
* new_vertex(const Point &) saves reallocation and reinitialization of
* property memory.
*
* \sa new_vertex(const Point &)
* \sa new_vertex(const Point )
*/
inline SmartVertexHandle new_vertex_dirty(const Point& _p)
inline SmartVertexHandle new_vertex_dirty(const Point _p)
{
VertexHandle vh(Kernel::new_vertex_dirty());
this->set_point(vh, _p);
@@ -237,16 +234,12 @@ public:
/** Alias for new_vertex(const Point&).
*
* \attention Be careful to not use a reference to a point in the mesh itself here.
* as a resize of the underlying vector might invalidate this reference
* and cause a segfault.
*
*/
inline SmartVertexHandle add_vertex(const Point& _p)
inline SmartVertexHandle add_vertex(const Point _p)
{ return new_vertex(_p); }
/// Alias for new_vertex_dirty().
inline SmartVertexHandle add_vertex_dirty(const Point& _p)
inline SmartVertexHandle add_vertex_dirty(const Point _p)
{ return make_smart(new_vertex_dirty(_p), this); }
// --- normal vectors ---

View File

@@ -17,6 +17,7 @@ set(UNITTEST_SRC
unittests_mesh_dual.cc
unittests_mesh_type.cc
unittests_mixed_decimater.cc
unittests_new_vertex.cc
unittests_normal_calculations.cc
unittests_polymesh_collapse.cc
unittests_polymesh_vec2i.cc

View File

@@ -0,0 +1,94 @@
#include <gtest/gtest.h>
#include <Unittests/unittests_common.hh>
#include <iostream>
namespace {
class OpenMeshNewVertexTriangleMesh : public OpenMeshBase {
protected:
// This function is called before each test is run
virtual void SetUp() {
// Do some initial stuff with the member data here...
}
// This function is called after all tests are through
virtual void TearDown() {
// Do some final stuff with the member data here...
}
// Member already defined in OpenMeshBase
//Mesh mesh_;
};
class OpenMeshNewVertexPolyMesh : public OpenMeshBasePoly {
protected:
// This function is called before each test is run
virtual void SetUp() {
// Do some initial stuff with the member data here...
}
// This function is called after all tests are through
virtual void TearDown() {
// Do some final stuff with the member data here...
}
// Member already defined in OpenMeshBase
//Mesh mesh_;
};
/*
* ====================================================================
* Define tests below
* ====================================================================
*/
/* Takes a vertex position directly from the mesh and readds it as a new vertex position
*/
TEST_F(OpenMeshNewVertexTriangleMesh, CopyVertexinsideMeshTriangle) {
mesh_.clear();
// Add some vertices
Mesh::VertexHandle vhandle[4];
vhandle[0] = mesh_.add_vertex(Mesh::Point(0, 0, 0));
vhandle[1] = mesh_.add_vertex(mesh_.point(Mesh::VertexHandle(0)));
vhandle[2] = mesh_.add_vertex(mesh_.point(Mesh::VertexHandle(1)));
vhandle[3] = mesh_.add_vertex(mesh_.point(Mesh::VertexHandle(2)));
// Check setup
EXPECT_EQ(4u, mesh_.n_vertices() ) << "Wrong number of vertices";
EXPECT_EQ(0u, mesh_.n_faces() ) << "Wrong number of faces";
}
/* Takes a vertex position directly from the mesh and readds it as a new vertex position
*/
TEST_F(OpenMeshNewVertexPolyMesh, CopyVertexinsideMeshPoly) {
mesh_.clear();
// Add some vertices
Mesh::VertexHandle vhandle[4];
vhandle[0] = mesh_.add_vertex(Mesh::Point(0, 0, 0));
vhandle[1] = mesh_.add_vertex(mesh_.point(Mesh::VertexHandle(0)));
vhandle[2] = mesh_.add_vertex(mesh_.point(Mesh::VertexHandle(1)));
vhandle[3] = mesh_.add_vertex(mesh_.point(Mesh::VertexHandle(2)));
// Check setup
EXPECT_EQ(4u, mesh_.n_vertices() ) << "Wrong number of vertices";
EXPECT_EQ(0u, mesh_.n_faces() ) << "Wrong number of faces";
}
}