Skip to content
Snippets Groups Projects
Commit 2e84c1dc authored by Norihiro Watanabe's avatar Norihiro Watanabe
Browse files

use boost::optional as a return value of getMeshNodeIDForPoint()

parent 3e3fe345
No related branches found
No related tags found
No related merge requests found
......@@ -75,9 +75,13 @@ MeshNodeSearcher::~MeshNodeSearcher()
}
}
std::size_t MeshNodeSearcher::getMeshNodeIDForPoint(GeoLib::Point const& pnt) const
boost::optional<std::size_t> MeshNodeSearcher::getMeshNodeIDForPoint(GeoLib::Point const& pnt) const
{
return (_mesh_grid.getNearestPoint(pnt.getCoords()))->getID();
auto* found = _mesh_grid.getNearestPoint(pnt.getCoords());
if (found)
return found->getID();
else
return boost::none;
}
std::vector<std::size_t> const& MeshNodeSearcher::getMeshNodeIDsAlongPolyline(
......
......@@ -14,6 +14,8 @@
#include <vector>
#include "boost/optional.hpp"
// GeoLib
#include "Point.h"
#include "Polyline.h"
......@@ -57,7 +59,7 @@ public:
* @param pnt a GeoLib::Point the nearest mesh node is searched for
* @return the id of the nearest mesh node
*/
std::size_t getMeshNodeIDForPoint(GeoLib::Point const& pnt) const;
boost::optional<std::size_t> getMeshNodeIDForPoint(GeoLib::Point const& pnt) const;
/**
* Searches for the nearest mesh nodes along a GeoLib::Polyline.
......
......@@ -69,27 +69,27 @@ TEST_F(MeshLibMeshNodeSearchInSimpleQuadMesh, PointSearch)
MeshGeoToolsLib::MeshNodeSearcher mesh_node_searcher(*_quad_mesh);
// find ORIGIN
ASSERT_EQ(0u, mesh_node_searcher.getMeshNodeIDForPoint(pnt));
ASSERT_EQ(0u, *mesh_node_searcher.getMeshNodeIDForPoint(pnt));
pnt[0] = 0.049;
pnt[1] = 0.049;
ASSERT_EQ(0u, mesh_node_searcher.getMeshNodeIDForPoint(pnt));
ASSERT_EQ(0u, *mesh_node_searcher.getMeshNodeIDForPoint(pnt));
pnt[0] = 0.051;
pnt[1] = 0.049;
ASSERT_EQ(1u, mesh_node_searcher.getMeshNodeIDForPoint(pnt));
ASSERT_EQ(1u, *mesh_node_searcher.getMeshNodeIDForPoint(pnt));
pnt[0] = 0.049;
pnt[1] = 0.051;
ASSERT_EQ(100u, mesh_node_searcher.getMeshNodeIDForPoint(pnt));
ASSERT_EQ(100u, *mesh_node_searcher.getMeshNodeIDForPoint(pnt));
pnt[0] = 0.051;
pnt[1] = 0.051;
ASSERT_EQ(101u, mesh_node_searcher.getMeshNodeIDForPoint(pnt));
ASSERT_EQ(101u, *mesh_node_searcher.getMeshNodeIDForPoint(pnt));
pnt[0] = 9.951;
pnt[1] = 9.951;
ASSERT_EQ((_number_of_subdivisions_per_direction+1) * (_number_of_subdivisions_per_direction+1) - 1, mesh_node_searcher.getMeshNodeIDForPoint(pnt));
ASSERT_EQ((_number_of_subdivisions_per_direction+1) * (_number_of_subdivisions_per_direction+1) - 1, *mesh_node_searcher.getMeshNodeIDForPoint(pnt));
}
TEST_F(MeshLibMeshNodeSearchInSimpleQuadMesh, PolylineSearch)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment