Skip to content

Commit ed6a33b

Browse files
committed
Implement RenderedTarget::contains()
1 parent 477d468 commit ed6a33b

File tree

4 files changed

+38
-0
lines changed

4 files changed

+38
-0
lines changed

ScratchCPPGui/renderedtarget.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,19 @@ const std::vector<QPointF> &RenderedTarget::hullPoints() const
363363
return m_hullPoints;
364364
}
365365

366+
bool RenderedTarget::contains(const QPointF &point) const
367+
{
368+
if (m_stageModel)
369+
return true; // the stage contains any point within the scene
370+
371+
for (const auto &hullPoint : m_hullPoints) {
372+
if (point.toPoint() == hullPoint.toPoint())
373+
return true;
374+
}
375+
376+
return false;
377+
}
378+
366379
void RenderedTarget::calculateSize(Target *target, double costumeWidth, double costumeHeight)
367380
{
368381
if (m_costume) {

ScratchCPPGui/renderedtarget.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ class RenderedTarget : public IRenderedTarget
6262
void updateHullPoints(QOpenGLFramebufferObject *fbo) override;
6363
const std::vector<QPointF> &hullPoints() const override;
6464

65+
Q_INVOKABLE bool contains(const QPointF &point) const override;
66+
6567
signals:
6668
void engineChanged();
6769
void stageModelChanged();

test/mocks/renderedtargetmock.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ class RenderedTargetMock : public IRenderedTarget
4747
MOCK_METHOD(void, updateHullPoints, (QOpenGLFramebufferObject *), (override));
4848
MOCK_METHOD(const std::vector<QPointF> &, hullPoints, (), (const, override));
4949

50+
MOCK_METHOD(bool, contains, (const QPointF &), (const, override));
5051
MOCK_METHOD(QNanoQuickItemPainter *, createItemPainter, (), (const, override));
5152
};
5253

test/renderedtarget/renderedtarget_test.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -520,6 +520,28 @@ TEST_F(RenderedTargetTest, HullPoints)
520520
// Release
521521
fbo.release();
522522
context.doneCurrent();
523+
524+
// Test contains()
525+
ASSERT_FALSE(target.contains({ 0, 0 }));
526+
ASSERT_FALSE(target.contains({ 1, 0 }));
527+
ASSERT_FALSE(target.contains({ 2, 0 }));
528+
ASSERT_FALSE(target.contains({ 3, 0 }));
529+
530+
ASSERT_FALSE(target.contains({ 0, 1 }));
531+
ASSERT_TRUE(target.contains({ 1, 1 }));
532+
ASSERT_TRUE(target.contains({ 1.4, 1.25 }));
533+
ASSERT_TRUE(target.contains({ 2, 1 }));
534+
ASSERT_TRUE(target.contains({ 3, 1 }));
535+
536+
ASSERT_TRUE(target.contains({ 1, 2 }));
537+
ASSERT_FALSE(target.contains({ 2, 2 }));
538+
ASSERT_TRUE(target.contains({ 3, 2 }));
539+
ASSERT_FALSE(target.contains({ 3.5, 2.1 }));
540+
541+
ASSERT_TRUE(target.contains({ 1, 3 }));
542+
ASSERT_TRUE(target.contains({ 2, 3 }));
543+
ASSERT_TRUE(target.contains({ 3, 3 }));
544+
ASSERT_FALSE(target.contains({ 3.3, 3.5 }));
523545
}
524546

525547
TEST_F(RenderedTargetTest, Engine)

0 commit comments

Comments
 (0)