@@ -610,34 +610,10 @@ bool RenderedTarget::touchingClones(const std::vector<libscratchcpp::Sprite *> &
610
610
if (myRect.isEmpty ())
611
611
return false ;
612
612
613
- QRectF united;
614
613
std::vector<IRenderedTarget *> candidates;
615
614
616
615
// Calculate the union of the bounding rectangle intersections
617
- for (auto clone : clones) {
618
- Q_ASSERT (clone);
619
-
620
- if (!clone)
621
- continue ;
622
-
623
- SpriteModel *model = static_cast <SpriteModel *>(clone->getInterface ());
624
- Q_ASSERT (model);
625
-
626
- if (model) {
627
- // Calculate the intersection of the bounding rectangles
628
- IRenderedTarget *candidate = model->renderedTarget ();
629
- Q_ASSERT (candidate);
630
- Rect scratchRect = candidate->getFastBounds ();
631
- // TODO: Use Rect::snapToInt()
632
- QRect rect (QPoint (scratchRect.left (), scratchRect.bottom ()), QPoint (scratchRect.right (), scratchRect.top ()));
633
- QRectF intersected = myRect.intersected (rect);
634
-
635
- // Add it to the union
636
- united = united.united (intersected);
637
-
638
- candidates.push_back (candidate);
639
- }
640
- }
616
+ QRectF united = candidatesBounds (myRect, clones, candidates);
641
617
642
618
if (united.isEmpty () || candidates.empty ())
643
619
return false ;
@@ -813,6 +789,39 @@ QRectF RenderedTarget::touchingBounds() const
813
789
return bounds;
814
790
}
815
791
792
+ QRectF RenderedTarget::candidatesBounds (const QRectF &targetRect, const std::vector<Sprite *> &candidates, std::vector<IRenderedTarget *> &dst)
793
+ {
794
+ QRectF united;
795
+ dst.clear ();
796
+
797
+ for (auto candidate : candidates) {
798
+ Q_ASSERT (candidate);
799
+
800
+ if (!candidate)
801
+ continue ;
802
+
803
+ SpriteModel *model = static_cast <SpriteModel *>(candidate->getInterface ());
804
+ Q_ASSERT (model);
805
+
806
+ if (model) {
807
+ // Calculate the intersection of the bounding rectangles
808
+ IRenderedTarget *target = model->renderedTarget ();
809
+ Q_ASSERT (target);
810
+ Rect scratchRect = target->getFastBounds ();
811
+ // TODO: Use Rect::snapToInt()
812
+ QRect rect (QPoint (scratchRect.left (), scratchRect.bottom ()), QPoint (scratchRect.right (), scratchRect.top ()));
813
+ QRectF intersected = targetRect.intersected (rect);
814
+
815
+ // Add it to the union
816
+ united = united.united (intersected);
817
+
818
+ dst.push_back (target);
819
+ }
820
+ }
821
+
822
+ return united;
823
+ }
824
+
816
825
void RenderedTarget::clampRect (Rect &rect, double left, double right, double bottom, double top)
817
826
{
818
827
// TODO: Use Rect::clamp()
0 commit comments