update
This commit is contained in:
@@ -68,7 +68,23 @@ QImage extractEntityImage(const QImage& bg, const QVector<QPointF>& polyWorld, Q
|
||||
outTopLeftWorld = {};
|
||||
return {};
|
||||
}
|
||||
const QRect bbox = clampRectToImage(path.boundingRect().toAlignedRect(), bg.size());
|
||||
// bbox 必须只由顶点 min/max 推导,不能依赖 QPainterPath::boundingRect():
|
||||
// 在坐标含小数时,boundingRect 的浮点误差会造成稳定的“右下”偏移。
|
||||
double minX = polyWorld.front().x();
|
||||
double minY = polyWorld.front().y();
|
||||
double maxX = polyWorld.front().x();
|
||||
double maxY = polyWorld.front().y();
|
||||
for (const auto& p : polyWorld) {
|
||||
minX = std::min(minX, double(p.x()));
|
||||
minY = std::min(minY, double(p.y()));
|
||||
maxX = std::max(maxX, double(p.x()));
|
||||
maxY = std::max(maxY, double(p.y()));
|
||||
}
|
||||
const int left = std::clamp(int(std::floor(minX)), 0, bg.width());
|
||||
const int top = std::clamp(int(std::floor(minY)), 0, bg.height());
|
||||
const int right = std::clamp(int(std::ceil(maxX)), 0, bg.width() - 1);
|
||||
const int bottom = std::clamp(int(std::ceil(maxY)), 0, bg.height() - 1);
|
||||
const QRect bbox = clampRectToImage(QRect(QPoint(left, top), QPoint(right, bottom)), bg.size());
|
||||
if (bbox.isNull()) {
|
||||
outTopLeftWorld = {};
|
||||
return {};
|
||||
|
||||
Reference in New Issue
Block a user