1、得到长度
long calculatePerimeter(const ClipperLib::Path& path) {
long perimeter = 0;
for (int i = 0; i < path.size(); ++i) {
ClipperLib::IntPoint p1 = path[i];
ClipperLib::IntPoint p2 = path[(i + 1) % path.size()];
perimeter += std::sqrt((p2.X - p1.X) * (p2.X - p1.X) + (p2.Y - p1.Y) * (p2.Y - p1.Y));
}
return perimeter;
}
2、判定
bool POOP::filterSharpPolygons(ClipperLib::Path& subject, int threshold)
{
long area;
area = static_cast<long>(std::fabs(ClipperLib::Area(*it)));
long perimeter = calculatePerimeter(*it);
double ratio = double(perimeter) / double(area);
if (ratio > threshold)
{
std::cout<<"yes"<<std::endl;
return true;
}
else
{
std::cout<<"no"<<std::endl;
return false;
}
}
如有误,请指出,谢谢!