Skip to content

Commit ed4ef5b

Browse files
committed
RenderedTarget: Rewrite contains() using binary search
1 parent 29ac674 commit ed4ef5b

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

src/renderedtarget.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -445,12 +445,18 @@ bool RenderedTarget::contains(const QPointF &point) const
445445
if (!boundingRect().contains(point))
446446
return false;
447447

448-
for (const auto &hullPoint : m_hullPoints) {
449-
if (point.toPoint() == hullPoint.toPoint())
450-
return true;
448+
QPoint intPoint = point.toPoint();
449+
auto it = std::lower_bound(m_hullPoints.begin(), m_hullPoints.end(), intPoint, [](const QPointF &lhs, const QPointF &rhs) {
450+
return (lhs.y() < rhs.y()) || (lhs.y() == rhs.y() && lhs.x() < rhs.x());
451+
});
452+
453+
if (it == m_hullPoints.end()) {
454+
// The point is beyond the last point in the convex hull
455+
return false;
451456
}
452457

453-
return false;
458+
// Check if the point is equal to the one found
459+
return *it == intPoint;
454460
}
455461

456462
void RenderedTarget::calculateSize(Target *target, double costumeWidth, double costumeHeight)

0 commit comments

Comments
 (0)