@@ -740,3 +740,75 @@ TEST_F(RenderedTargetTest, GetBounds)
740740
741741 context.doneCurrent ();
742742}
743+
744+ TEST_F (RenderedTargetTest, GetFastBounds)
745+ {
746+ QOpenGLContext context;
747+ QOffscreenSurface surface;
748+ createContextAndSurface (&context, &surface);
749+ QOpenGLExtraFunctions glF (&context);
750+ glF.initializeOpenGLFunctions ();
751+ RenderedTarget target;
752+
753+ Sprite sprite;
754+ sprite.setX (75.64 );
755+ sprite.setY (-120.3 );
756+ sprite.setDirection (-46.37 );
757+ sprite.setSize (67.98 );
758+ SpriteModel spriteModel;
759+ sprite.setInterface (&spriteModel);
760+ target.setSpriteModel (&spriteModel);
761+ EngineMock engine;
762+ target.setEngine (&engine);
763+ auto costume = std::make_shared<Costume>(" " , " " , " png" );
764+ std::string costumeData = readFileStr (" image.png" );
765+ costume->setData (costumeData.size (), static_cast <void *>(costumeData.data ()));
766+ costume->setRotationCenterX (-15 );
767+ costume->setRotationCenterY (48 );
768+ costume->setBitmapResolution (3.25 );
769+ sprite.addCostume (costume);
770+
771+ EXPECT_CALL (engine, stageWidth ()).WillOnce (Return (480 ));
772+ EXPECT_CALL (engine, stageHeight ()).WillOnce (Return (360 ));
773+ target.loadCostumes ();
774+ target.updateCostume (costume.get ());
775+ target.beforeRedraw ();
776+
777+ Rect bounds = target.getFastBounds ();
778+ ASSERT_EQ (std::round (bounds.left () * 100 ) / 100 , 65.84 );
779+ ASSERT_EQ (std::round (bounds.top () * 100 ) / 100 , -123.92 );
780+ ASSERT_EQ (std::round (bounds.right () * 100 ) / 100 , 67.31 );
781+ ASSERT_EQ (std::round (bounds.bottom () * 100 ) / 100 , -125.4 );
782+
783+ EXPECT_CALL (engine, stageWidth ()).WillOnce (Return (480 ));
784+ EXPECT_CALL (engine, stageHeight ()).WillOnce (Return (360 ));
785+ target.updateRotationStyle (Sprite::RotationStyle::LeftRight);
786+
787+ bounds = target.getFastBounds ();
788+ ASSERT_EQ (std::round (bounds.left () * 100 ) / 100 , 71.67 );
789+ ASSERT_EQ (std::round (bounds.top () * 100 ) / 100 , -110.26 );
790+ ASSERT_EQ (std::round (bounds.right () * 100 ) / 100 , 72.5 );
791+ ASSERT_EQ (std::round (bounds.bottom () * 100 ) / 100 , -111.51 );
792+
793+ EXPECT_CALL (engine, stageWidth ()).WillOnce (Return (480 ));
794+ EXPECT_CALL (engine, stageHeight ()).WillOnce (Return (360 ));
795+ target.setStageScale (20.75 );
796+
797+ bounds = target.getFastBounds ();
798+ ASSERT_EQ (std::round (bounds.left () * 100 ) / 100 , 71.67 );
799+ ASSERT_EQ (std::round (bounds.top () * 100 ) / 100 , -110.26 );
800+ ASSERT_EQ (std::round (bounds.right () * 100 ) / 100 , 72.5 );
801+ ASSERT_EQ (std::round (bounds.bottom () * 100 ) / 100 , -111.51 );
802+
803+ EXPECT_CALL (engine, stageWidth ()).WillOnce (Return (480 ));
804+ EXPECT_CALL (engine, stageHeight ()).WillOnce (Return (360 ));
805+ target.updateSize (9780.6 );
806+
807+ bounds = target.getFastBounds ();
808+ ASSERT_EQ (std::round (bounds.left () * 100 ) / 100 , -496.15 );
809+ ASSERT_EQ (std::round (bounds.top () * 100 ) / 100 , 1324.22 );
810+ ASSERT_EQ (std::round (bounds.right () * 100 ) / 100 , -375.77 );
811+ ASSERT_EQ (std::round (bounds.bottom () * 100 ) / 100 , 1143.65 );
812+
813+ context.doneCurrent ();
814+ }
0 commit comments