@@ -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,86 @@ 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
+ united = united.united (candidateIntersection (targetRect, target));
822
+
823
+ if (target)
824
+ dst.push_back (target);
825
+ }
826
+
827
+ return united;
828
+ }
829
+
830
+ QRectF RenderedTarget::candidatesBounds (const QRectF &targetRect, const std::vector<libscratchcpp::Sprite *> &candidates, std::vector<IRenderedTarget *> &dst)
831
+ {
832
+ QRectF united;
833
+ dst.clear ();
834
+
835
+ for (auto candidate : candidates) {
836
+ Q_ASSERT (candidate);
837
+
838
+ if (!candidate)
839
+ continue ;
840
+
841
+ IRenderedTarget *target = nullptr ;
842
+ SpriteModel *model = static_cast <SpriteModel *>(candidate->getInterface ());
843
+ Q_ASSERT (model);
844
+
845
+ if (model)
846
+ target = model->renderedTarget ();
847
+
848
+ united = united.united (candidateIntersection (targetRect, target));
849
+
850
+ if (target)
851
+ dst.push_back (target);
852
+ }
853
+
854
+ return united;
855
+ }
856
+
857
+ QRectF RenderedTarget::candidateIntersection (const QRectF &targetRect, IRenderedTarget *target)
858
+ {
859
+ Q_ASSERT (target);
860
+
861
+ if (target) {
862
+ // Calculate the intersection of the bounding rectangles
863
+ Rect scratchRect = target->getFastBounds ();
864
+ // TODO: Use Rect::snapToInt()
865
+ QRect rect (QPoint (scratchRect.left (), scratchRect.bottom ()), QPoint (scratchRect.right (), scratchRect.top ()));
866
+ return targetRect.intersected (rect);
867
+ }
868
+
869
+ return QRectF ();
870
+ }
871
+
816
872
void RenderedTarget::clampRect (Rect &rect, double left, double right, double bottom, double top)
817
873
{
818
874
// TODO: Use Rect::clamp()
0 commit comments