gpt4 book ai didi

c++ - 是否可以为裁剪器路径提供 float 值

转载 作者:行者123 更新时间:2023-11-27 23:37:15 24 4
gpt4 key购买 nike

Clipper 采用整数输入,但我想在不丢失精度的情况下传递浮点值。整数和 double 值的 Clipper 结构。

struct IntPoint {
cInt X;
cInt Y;
#ifdef use_xyz
cInt Z;
IntPoint(cInt x = 0, cInt y = 0, cInt z = 0): X(x), Y(y), Z(z) {};
#else
IntPoint(cInt x = 0, cInt y = 0): X(x), Y(y) {};
#endif

friend inline bool operator== (const IntPoint& a, const IntPoint& b)
{
return a.X == b.X && a.Y == b.Y;
}
friend inline bool operator!= (const IntPoint& a, const IntPoint& b)
{
return a.X != b.X || a.Y != b.Y;
}
};

struct DoublePoint
{
double X;
double Y;
DoublePoint(double x = 0, double y = 0) : X(x), Y(y) {}
DoublePoint(IntPoint ip) : X((double)ip.X), Y((double)ip.Y) {}
};

为什么不将 double 值作为输入。

Paths Polygon(2);
Polygon[0] << IntPoint(10, 10) << IntPoint(60, 10) << IntPoint(30, 100) ;
Polygon[1] << IntPoint(20, 20) << IntPoint(50, 20) << IntPoint(30, 80) ; //it Works



Paths Line(1);
line[0] << DoublePoint(40.2, 10.2) << DoublePoint(56.5, 85.45); //Not works

最佳答案

Clipper 仅使用 integer point types .

The IntPoint structure is used to represent all vertices in the Clipper Library. An integer storage type has been deliberately chosen to preserve numerical robustness. (Early versions of the library used floating point coordinates, but it became apparent that floating point imprecision would always cause occasional errors.) [src]

但是,您可以按所需的系数缩放输入坐标。

所以不要想要这个,(它不存在)

line[0] << DoublePoint(40.2, 10.2) << DoublePoint(56.5, 85.45); //Not works

您可以缩放 100。

line[0] << IntPoint(4020, 1020) << IntPoint(5650, 8545); //works

请记住将输出坐标缩放 0.01 以返回到您的坐标系。

关于c++ - 是否可以为裁剪器路径提供 float 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58374181/

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