@@ -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,54 @@ QRectF RenderedTarget::touchingBounds() const
813
789
return bounds;
814
790
}
815
791
792
+ QRectF RenderedTarget::candidatesBounds (const QRectF &targetRect, const std::vector<Target *> &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
+ IRenderedTarget *target = nullptr ;
804
+
805
+ if (candidate->isStage ()) {
806
+ Stage *stage = static_cast <Stage *>(candidate);
807
+ StageModel *model = static_cast <StageModel *>(stage->getInterface ());
808
+ Q_ASSERT (model);
809
+
810
+ if (model)
811
+ target = model->renderedTarget ();
812
+ } else {
813
+ Sprite *sprite = static_cast <Sprite *>(candidate);
814
+ SpriteModel *model = static_cast <SpriteModel *>(sprite->getInterface ());
815
+ Q_ASSERT (model);
816
+
817
+ if (model)
818
+ target = model->renderedTarget ();
819
+ }
820
+
821
+ Q_ASSERT (target);
822
+
823
+ if (target) {
824
+ // Calculate the intersection of the bounding rectangles
825
+ Rect scratchRect = target->getFastBounds ();
826
+ // TODO: Use Rect::snapToInt()
827
+ QRect rect (QPoint (scratchRect.left (), scratchRect.bottom ()), QPoint (scratchRect.right (), scratchRect.top ()));
828
+ QRectF intersected = targetRect.intersected (rect);
829
+
830
+ // Add it to the union
831
+ united = united.united (intersected);
832
+
833
+ dst.push_back (target);
834
+ }
835
+ }
836
+
837
+ return united;
838
+ }
839
+
816
840
void RenderedTarget::clampRect (Rect &rect, double left, double right, double bottom, double top)
817
841
{
818
842
// TODO: Use Rect::clamp()
0 commit comments