gpt4 book ai didi

c++ - 删除重复项而不四舍五入,C++

转载 作者:太空宇宙 更新时间:2023-11-04 12:20:36 25 4
gpt4 key购买 nike

我正在尝试使用以下比较器从 vector 中删除重复项

            bool operator() ( const Point * p1, const Point * p2 ) const
{
return ( p1->X() < p2->X() ) || ( ( p1->X() == p2->X() ) && ( p1->Y() < p2-Y() ) );
}

和重载的运算符==

bool Point::operator == ( const Point &p ) const
{
return ( x - p.x ) * ( x - p.x ) + ( y - p.y ) * ( y - p.y ) < DIFF;
}

原理图去除:

std::sort ( it_begin, it_end, Comp );
Points::iterator i_new_end = std::unique ( it_begin, it_end, Uniq);
items.erase ( i_new_end, this->items.end() );

但是数据有问题。根据x坐标排序的点

-0.0000000015   -6281103.8487118632   0.0000000000
-0.0000000011 -5993359.5353725236 0.0000000000
-0.0000000010 -5523510.0253371494 0.0000000000
-0.0000000009 -4885831.4582128422 0.0000000000
-0.0000000009 -4099699.3745807474 0.0000000000
-0.0000000008 -3189000.0000000000 0.0000000000
-0.0000000008 -2181404.4741311157 0.0000000000
-0.0000000008 -1107528.0771596823 0.0000000000 //unique
-0.0000000008 -0.0000000005 0.0000000000
-0.0000000007 1107528.0771596811 0.0000000000 //unique
-0.0000000007 2181404.4741311143 0.0000000000
-0.0000000007 3188999.9999999991 0.0000000000
-0.0000000006 4099699.3745807474 0.0000000000
-0.0000000006 4885831.4582128404 0.0000000000
-0.0000000005 5523510.0253371485 0.0000000000
-0.0000000004 5993359.5353725236 0.0000000000
0.0000000000 -6281103.8487118632 0.0000000000
0.0000000004 5993359.5353725236 0.0000000000
0.0000000005 5523510.0253371485 0.0000000000
0.0000000006 4099699.3745807474 0.0000000000
0.0000000006 4885831.4582128404 0.0000000000
0.0000000007 1107528.0771596811 0.0000000000
0.0000000007 2181404.4741311143 0.0000000000
0.0000000007 3188999.9999999991 0.0000000000
0.0000000008 -3189000.0000000000 0.0000000000
0.0000000008 -2181404.4741311157 0.0000000000
0.0000000008 -1107528.0771596823 0.0000000000
0.0000000008 -0.0000000005 0.0000000000
0.0000000009 -4885831.4582128422 0.0000000000
0.0000000009 -4099699.3745807474 0.0000000000
0.0000000010 -5523510.0253371494 0.0000000000
0.0000000011 -5993359.5353725236 0.0000000000
0.0000000015 -6281103.8487118632 0.0000000000
0.0089638987 -6377999.9999999991 0.0000000000

运算符 == 不会带来任何影响,附近的点不会彼此相邻排序...

是否有可能在不四舍五入的情况下删除此类重复点(例如 diffrenet 比较器)?我知道,坐标有很多小数位...

最佳答案

std::sort 需要运算符 <,而不是运算符 ==

关于c++ - 删除重复项而不四舍五入,C++,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5330203/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com