public async Task Render_SimpleGeometry()
        {
            await TestUtilities.InitializeWithGraphicsAsync();

            var polygon = new Polygon2D(new Vector2(10, 10), new Vector2(900, 100), new Vector2(800, 924), new Vector2(50, 1014), new Vector2(10, 10));

            using (var solidBrush = new SolidBrushResource(Color4.LightGray))
                using (var solidBrushBorder = new SolidBrushResource(Color4.Gray))
                    using (var polygonGeometry = new PolygonGeometryResource(polygon))
                        using (var memRenderTarget = new MemoryRenderTarget(1024, 1024))
                        {
                            // Perform rendering
                            memRenderTarget.ClearColor = Color4.CornflowerBlue;
                            await memRenderTarget.RenderLoop.Register2DDrawingLayerAsync(graphics =>
                            {
                                // 2D rendering is made here
                                graphics.DrawGeometry(polygonGeometry, solidBrushBorder, 3f);
                                graphics.FillGeometry(polygonGeometry, solidBrush);
                            });

                            await memRenderTarget.AwaitRenderAsync();

                            // Take screenshot
                            var screenshot = await memRenderTarget.RenderLoop.GetScreenshotGdiAsync();

                            // TestUtilities.DumpToDesktop(screenshot, "Blub.png");

                            // Calculate and check difference
                            var diff = BitmapComparison.CalculatePercentageDifference(
                                screenshot, TestUtilities.LoadBitmapFromResource("Drawing2D", "SimpleGeometry2D.png"));
                            Assert.IsTrue(diff < 0.2, "Difference to reference image is to big!");
                        }
        }
Exemple #2
0
        public void Collision_Ellipse_to_Polygon()
        {
            EllipseGeometryResource ellipseGeometry01 = new EllipseGeometryResource(
                new Vector2(50, 50), 10f, 10f);
            EllipseGeometryResource ellipseGeometry02 = new EllipseGeometryResource(
                new Vector2(50, 80), 10f, 10f);

            PolygonGeometryResource polygonGeometry = new PolygonGeometryResource(new Polygon2D(new Vector2[]
            {
                new Vector2(55f, 50f),
                new Vector2(60f, 50f),
                new Vector2(55f, 55f)
            }));

            try
            {
                Assert.True(ellipseGeometry01.IntersectsWith(polygonGeometry));
                Assert.False(ellipseGeometry02.IntersectsWith(polygonGeometry));
            }
            finally
            {
                CommonTools.SafeDispose(ref ellipseGeometry01);
                CommonTools.SafeDispose(ref ellipseGeometry02);
                CommonTools.SafeDispose(ref polygonGeometry);
            }
        }
        public async Task MemoryRenderTarget_2DFallbackRendering()
        {
            await UnitTestHelper.InitializeWithGrahicsAsync();

            using (GraphicsCore.AutomatedTest_NewTestEnviornment())
            {
                GraphicsCore.Initialize(
                    enableDebug: false,
                    force2DFallback: true);
                Assert.True(GraphicsCore.IsInitialized);

                Polygon2D polygon = new Polygon2D(new Vector2[]
                {
                    new Vector2(10, 10),
                    new Vector2(900, 100),
                    new Vector2(800, 924),
                    new Vector2(50, 1014),
                    new Vector2(10, 10)
                });
                using (SolidBrushResource solidBrush = new SolidBrushResource(Color4.LightGray))
                    using (SolidBrushResource solidBrushBorder = new SolidBrushResource(Color4.Gray))
                        using (PolygonGeometryResource polygonGeometry = new PolygonGeometryResource(polygon))
                            using (MemoryRenderTarget memRenderTarget = new MemoryRenderTarget(1024, 1024))
                            {
                                // Perform rendering
                                memRenderTarget.ClearColor = Color4.CornflowerBlue;
                                await memRenderTarget.RenderLoop.Register2DDrawingLayerAsync((graphics) =>
                                {
                                    // 2D rendering is made here
                                    graphics.DrawGeometry(polygonGeometry, solidBrushBorder, 3f);
                                    graphics.FillGeometry(polygonGeometry, solidBrush);
                                });

                                await memRenderTarget.AwaitRenderAsync();

                                // Take screenshot
                                GDI.Bitmap screenshot = await memRenderTarget.RenderLoop.GetScreenshotGdiAsync();

                                //screenshot.DumpToDesktop("Blub.png");

                                // Calculate and check difference
                                float diff = BitmapComparison.CalculatePercentageDifference(
                                    screenshot, Properties.Resources.ReferenceImage_SimpleGeometry2D);
                                Assert.True(diff < 0.2, "Difference to reference image is to big!");
                            }
            }
        }
        public async Task Collision_Ellipse_to_Polygon()
        {
            await TestUtilities.InitializeWithGraphicsAsync();

            var ellipseGeometry01 = new EllipseGeometryResource(
                new Vector2(50, 50), 10f, 10f);
            var ellipseGeometry02 = new EllipseGeometryResource(
                new Vector2(50, 80), 10f, 10f);

            var polygonGeometry = new PolygonGeometryResource(new Polygon2D(new Vector2(55f, 50f), new Vector2(60f, 50f), new Vector2(55f, 55f)));

            try
            {
                Assert.IsTrue(ellipseGeometry01.IntersectsWith(polygonGeometry));
                Assert.IsFalse(ellipseGeometry02.IntersectsWith(polygonGeometry));
            }
            finally
            {
                SeeingSharpUtil.SafeDispose(ref ellipseGeometry01);
                SeeingSharpUtil.SafeDispose(ref ellipseGeometry02);
                SeeingSharpUtil.SafeDispose(ref polygonGeometry);
            }
        }