如何对段C 进行分类
How to sort the segments c++
本文关键字:分类 更新时间:2023-10-16
i具有边缘的向量。我需要按y坐标的Y级横穿垂直线x ==(a b(/2和那些边缘的点进行分类。问题在于A和B不是恒定的,他们必须从一个edgges变为另一个。如何将A和B参数发送到比较器?
struct vertex
{
double x,y;
bool operator==(const vertex &o)const {
return x == o.x && y == o.y;
}
bool operator<(const vertex &o) const{
return x < o.x || (x == o.x && y < o.y);
}
};
typedef vector<vertex> vertList;
typedef vector <pair<vertex,vertex>> Edge;
您可以定义一个将a
和b
作为构造函数参数的比较类别:
struct EdgeComparator {
int a;
int b;
EdgeComparator(int a, int b): a(a), b(b) {}
bool operator<(const Edge& lhs, const Edge& rhs) const {
// You can compare lhs and rhs using a and b here
}
};
然后以后将其实例传递给排序函数:
std::sort(v.begin(), v.end(), EdgeComparator(some_value_of_a, some_value_of_b));
相关文章:
- 为我的 c++ 类介绍制作一个三角形分类器.我有几个问题
- 更改 C++ 中的组合分类变量
- 只有级联分类器会发出未定义的引用错误
- 分类还是划分枚举?
- 如何删除部分类?
- 使用 SVM 进行分类,使用来自 Bag of Word 的词汇构建
- 如何读取文件并将该文件分类为不同类型的数据,这些数据都存储在结构中的特定数组中
- 将svm分类器设置为HOG检测器
- 使用类型特征的部分类专用化
- 将 CRTP 与部分类专用化结合使用?
- 为什么 C++17 标准没有带来部分类模板参数扣除?
- 神经网络和图像分类
- C++17 中的部分类模板参数推导
- 如何在这两个分类的链接列表之间获得开关的位置
- QTREEWIDGET子分类,停止下降指示器显示给定有不必要的DropIndicatorPosition
- 链接的列表字符串分类问题
- 在C /OBJ-C 中运行Tensorflow分类器模型与Python的结果不同
- 如何找到分类容器的匹配元素的索引
- 在给定的整数数组中,可以找到在给定位置之间分类数组的整数之和
- 以分类方式插入节点时遇到麻烦