排序屏幕坐标
Sorting screen coordinates
我有一个向量textCommands
,它包含一个名为TextCommand
的结构,包含一个RECT
和一个字符串;并且RECT
的值top
、left
、bottom
和right
都在屏幕坐标中。我想知道如何对这个向量进行排序,这样我就可以调用std::unique
并删除重复的条目。重复条目是具有相同字符串和相同RECT
的条目,其中所有值都相同。
//Location in screen coordinates(pixels)
struct RECT
{
int top;
int left;
int bottom;
int right;
};
//text at location RECT
struct TextCommand
{
std::string text;
RECT pos;
};
std::vector<TextCommand> textCommands;
您需要一个满足严格弱排序的自定义比较器(函子、lambda或重载operator <
),可以将其输入到std::sort
或std::set
中。最简单的是:
#include <tuple>
struct TextCommandCompare
{
bool operator()(TextCommand const& a, TextCommand const& b) const
{
return std::tie(a.text, a.pos.top, a.pos.left, a.pos.bottom, a.pos.right) <
std::tie(b.text, b.pos.top, b.pos.left, b.pos.bottom, b.pos.right);
}
};
std::tie
创建一个std::tuple
,为您实现字典比较。
相关文章:
- UE4-如何在给定4个屏幕坐标的情况下缩放纹理或材质
- 跳转到通过输入坐标定义的控制台屏幕位置
- 使用C++中的链表对与原点的距离、x 和 y 坐标进行排序
- 如何在Openscenegraph中从二维鼠标点击的屏幕坐标点计算三维点(世界坐标)
- 对坐标结构的向量进行排序
- OpenGL屏幕坐标到世界坐标
- 将 2D 屏幕坐标转换为 3D 世界坐标
- 屏幕坐标和设备坐标有什么区别?
- 使用二维屏幕坐标gluUnproject获取三维模型坐标
- 对话框单位到屏幕坐标
- 将文本光标移动到特定的屏幕坐标
- 在 OpenGL 中将 3D 坐标转换为屏幕坐标
- 原点直接到屏幕坐标
- 将屏幕坐标转换为游戏坐标
- 俯仰和偏航至2d屏幕坐标
- 将顶点坐标转换为屏幕坐标"same"
- OpenGL转换在NDC坐标而不是屏幕坐标(2D)
- 在路径跟踪器中查找屏幕坐标背后的数学
- 笛卡尔坐标和屏幕坐标之间的转换
- 排序屏幕坐标