Planar graph vertex clumping does not work as expected
Hello there, I happen to be using this library for a project of my own. I know planar-graph.h
is an internal header but I exposed it anyways because it was useful to me. I then discovered that it was creating separate vertices for two points as close as (-2.7755575615628914e-17, 0.6000000052154064)
and (0, 0.6000000052154064)
.
I looked into the issue and found that in this function, only the two vertices lexicographically next to the new vertex were examined. This is not guaranteed to cover the existing vertex. For example, in my case it was comparing (-2.7755575615628914e-17, 0.6000000052154064)
with another vertex at (0, 0)
only (there was no vertex lexicographically preceding (-2.7755575615628914e-17, 0.6000000052154064)
).
For now I changed the code to
auto it = std::find_if(_vertices.begin(), _vertices.end(), [&](Vertex const &v) -> bool {
return are_near(pos, v._position, _precision);
});
if (it != _vertices.end()) {
return &(*it);
}
it = std::find_if(_vertices.begin(), _vertices.end(), [&](Vertex const &v) -> bool {
return Vertex::_cmp(pos, v._position); // existing vertex position > pos.
});
if (it == _vertices.begin()) {
return insert_at_front();
}
return &(*(_vertices.emplace(it, pos)));
which seems to work.