Skip to content

Commit 934d23a

Browse files
committed
Use CPU texture in contains methods
1 parent c32b09e commit 934d23a

File tree

2 files changed

+13
-26
lines changed

2 files changed

+13
-26
lines changed

src/renderedtarget.cpp

+1-14
Original file line numberDiff line numberDiff line change
@@ -814,20 +814,7 @@ void RenderedTarget::updateHullPoints()
814814

815815
bool RenderedTarget::containsLocalPoint(const QPointF &point) const
816816
{
817-
if (!boundingRect().contains(point))
818-
return false;
819-
820-
const std::vector<QPoint> &points = hullPoints();
821-
QPoint intPoint = point.toPoint();
822-
auto it = std::lower_bound(points.begin(), points.end(), intPoint, [](const QPointF &lhs, const QPointF &rhs) { return (lhs.y() < rhs.y()) || (lhs.y() == rhs.y() && lhs.x() < rhs.x()); });
823-
824-
if (it == points.end()) {
825-
// The point is beyond the last point in the convex hull
826-
return false;
827-
}
828-
829-
// Check if the point is equal to the one found
830-
return *it == intPoint;
817+
return textureManager()->textureContainsPoint(m_cpuTexture, point);
831818
}
832819

833820
QPointF RenderedTarget::transformPoint(double scratchX, double scratchY, double originX, double originY, double rot) const

test/renderedtarget/renderedtarget_test.cpp

+12-12
Original file line numberDiff line numberDiff line change
@@ -394,12 +394,12 @@ TEST_F(RenderedTargetTest, CpuRendering)
394394
ASSERT_TRUE(target.contains({ 1, 2 }));
395395
ASSERT_FALSE(target.contains({ 2, 2 }));
396396
ASSERT_TRUE(target.contains({ 3, 2 }));
397-
ASSERT_FALSE(target.contains({ 3.5, 2.1 }));
397+
ASSERT_TRUE(target.contains({ 3.5, 2.1 }));
398398

399399
ASSERT_TRUE(target.contains({ 1, 3 }));
400400
ASSERT_TRUE(target.contains({ 2, 3 }));
401401
ASSERT_TRUE(target.contains({ 3, 3 }));
402-
ASSERT_FALSE(target.contains({ 3.3, 3.5 }));
402+
ASSERT_TRUE(target.contains({ 3.3, 3.5 }));
403403

404404
// Test contains() with horizontal mirroring
405405
target.updateRotationStyle(Sprite::RotationStyle::LeftRight);
@@ -408,9 +408,9 @@ TEST_F(RenderedTargetTest, CpuRendering)
408408
ASSERT_TRUE(target.contains({ -1, 1 }));
409409
ASSERT_FALSE(target.contains({ -2, 2 }));
410410
ASSERT_TRUE(target.contains({ -3, 2 }));
411-
ASSERT_FALSE(target.contains({ -3.5, 2.1 }));
411+
ASSERT_TRUE(target.contains({ -3.5, 2.1 }));
412412
ASSERT_TRUE(target.contains({ -2, 3 }));
413-
ASSERT_FALSE(target.contains({ -3.3, 3.5 }));
413+
ASSERT_TRUE(target.contains({ -3.3, 3.5 }));
414414

415415
// Test containsScratchPoint()
416416
target.updateDirection(0);
@@ -425,15 +425,15 @@ TEST_F(RenderedTargetTest, CpuRendering)
425425
ASSERT_TRUE(target.containsScratchPoint(-226, 164)); // [2, 1]
426426
ASSERT_TRUE(target.containsScratchPoint(-225, 164)); // [3, 1]
427427

428-
ASSERT_TRUE(target.containsScratchPoint(-227, 163)); // [1, 2]
429-
ASSERT_FALSE(target.containsScratchPoint(-226, 163)); // [2, 2]
430-
ASSERT_TRUE(target.containsScratchPoint(-225, 163)); // [3, 2]
431-
ASSERT_FALSE(target.containsScratchPoint(-224.5, 162.9)); // [3.5, 2.1]
428+
ASSERT_TRUE(target.containsScratchPoint(-227, 163)); // [1, 2]
429+
ASSERT_FALSE(target.containsScratchPoint(-226, 163)); // [2, 2]
430+
ASSERT_TRUE(target.containsScratchPoint(-225, 163)); // [3, 2]
431+
ASSERT_TRUE(target.containsScratchPoint(-224.5, 162.9)); // [3.5, 2.1]
432432

433-
ASSERT_TRUE(target.containsScratchPoint(-227, 162)); // [1, 3]
434-
ASSERT_TRUE(target.containsScratchPoint(-226, 162)); // [2, 3]
435-
ASSERT_TRUE(target.containsScratchPoint(-225, 162)); // [3, 3]
436-
ASSERT_FALSE(target.containsScratchPoint(-224.7, 161.5)); // [3.3, 3.5]
433+
ASSERT_TRUE(target.containsScratchPoint(-227, 162)); // [1, 3]
434+
ASSERT_TRUE(target.containsScratchPoint(-226, 162)); // [2, 3]
435+
ASSERT_TRUE(target.containsScratchPoint(-225, 162)); // [3, 3]
436+
ASSERT_TRUE(target.containsScratchPoint(-224.7, 161.5)); // [3.3, 3.5]
437437

438438
// Test colorAtScratchPoint()
439439
ASSERT_EQ(target.colorAtScratchPoint(-228, 165), 0); // [0, 0]

0 commit comments

Comments
 (0)