假设我有一个std::vector<Point>
其中Point
是struct Point { double x; double y;}
我想这样的载体分成组(存储桶),其中在同一个桶中的所有点具有彼此之间相同欧几里得范数(例如dist(PointA,PointB)== X,其中X是常数)。我已经决定使用std::map
这样的任务自定义排序操作:分区的std :: 2D的矢量指向
struct ClosePoints
{
bool operator()(Point const& A, Point const& B) const
{
bool same = dist(A,B) < x;
//If not close enough use lexical sort
return same ? false : std::tie(A.x, A.y) < std::tie(B.x,);
}
}
分区代码:
std::map<Point, std::list<Point>, ClosePoints> map;
for(const auto& p : pointsVector)
map[p].push_back(p);
经过一番测试,并打印我注意到,有些点是听从了给予桶欧几里得标准限制X
以不同的桶结束。 我不明白为什么这样?
我建议您提供一个完整的,可编译的工作示例,包括测试输入,可以重现您的问题。 – vordhosbn
1)什么是'x'? 2)什么是'dist()'? 3)如果dist(A,B)
PaulMcKenzie
您的操作员不遵循严格的排序规则,因为A <= A + eps'和'A + eps <= A + 2 * eps',但不是'A <= A + 2 * eps'。 – Jarod42