Skip to content

Commit ce20484

Browse files
committed
RenderedTarget: Optimize point parameters
1 parent 0085d55 commit ce20484

File tree

2 files changed

+5
-9
lines changed

2 files changed

+5
-9
lines changed

src/renderedtarget.cpp

+4-8
Original file line numberDiff line numberDiff line change
@@ -665,15 +665,11 @@ bool RenderedTarget::touchingColor(const Value &color) const
665665
return false;
666666
}
667667

668-
QPointF point;
669-
670668
// Loop through the points of the union
671669
for (int y = bounds.top(); y <= bounds.bottom(); y++) {
672670
for (int x = bounds.left(); x <= bounds.right(); x++) {
673671
if (this->containsScratchPoint(x, y)) {
674-
point.setX(x);
675-
point.setY(y);
676-
QRgb pixelColor = sampleColor3b(point, candidates);
672+
QRgb pixelColor = sampleColor3b(x, y, candidates);
677673

678674
if (colorMatches(rgb, pixelColor))
679675
return true;
@@ -1046,7 +1042,7 @@ bool RenderedTarget::colorMatches(QRgb a, QRgb b)
10461042
return (qRed(a) & 0b11111000) == (qRed(b) & 0b11111000) && (qGreen(a) & 0b11111000) == (qGreen(b) & 0b11111000) && (qBlue(a) & 0b11110000) == (qBlue(b) & 0b11110000);
10471043
}
10481044

1049-
QRgb RenderedTarget::sampleColor3b(const QPointF &point, const std::vector<IRenderedTarget *> &targets) const
1045+
QRgb RenderedTarget::sampleColor3b(double x, double y, const std::vector<IRenderedTarget *> &targets) const
10501046
{
10511047
// https://github.com/scratchfoundation/scratch-render/blob/0a04c2fb165f5c20406ec34ab2ea5682ae45d6e0/src/RenderWebGL.js#L1966-L1990
10521048
double blendAlpha = 1;
@@ -1059,7 +1055,7 @@ QRgb RenderedTarget::sampleColor3b(const QPointF &point, const std::vector<IRend
10591055

10601056
if ((i == targets.size() || targets[i]->stageModel()) && !penLayerChecked) {
10611057
if (m_penLayer)
1062-
blendColor = m_penLayer->colorAtScratchPoint(point.x(), point.y());
1058+
blendColor = m_penLayer->colorAtScratchPoint(x, y);
10631059
else
10641060
blendColor = qRgba(0, 0, 0, 0);
10651061

@@ -1070,7 +1066,7 @@ QRgb RenderedTarget::sampleColor3b(const QPointF &point, const std::vector<IRend
10701066
} else if (i == targets.size())
10711067
break;
10721068
else
1073-
blendColor = targets[i]->colorAtScratchPoint(point.x(), point.y());
1069+
blendColor = targets[i]->colorAtScratchPoint(x, y);
10741070

10751071
r += qRed(blendColor) * blendAlpha;
10761072
g += qGreen(blendColor) * blendAlpha;

src/renderedtarget.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ class RenderedTarget : public IRenderedTarget
136136
static void clampRect(libscratchcpp::Rect &rect, double left, double right, double bottom, double top);
137137
static QRgb convertColor(const libscratchcpp::Value &color);
138138
static bool colorMatches(QRgb a, QRgb b);
139-
QRgb sampleColor3b(const QPointF &point, const std::vector<IRenderedTarget *> &targets) const;
139+
QRgb sampleColor3b(double x, double y, const std::vector<IRenderedTarget *> &targets) const;
140140

141141
libscratchcpp::IEngine *m_engine = nullptr;
142142
libscratchcpp::Costume *m_costume = nullptr;

0 commit comments

Comments
 (0)