public void CorrectlySetsColorThicknessAndRectangle()
        {
            img.Draw(color, thickness, rectangle);

            Assert.NotEmpty(img.ProcessorApplications);
            DrawPathProcessor <Color> processor = Assert.IsType <DrawPathProcessor <Color> >(img.ProcessorApplications[0].processor);

            Assert.Equal(GraphicsOptions.Default, processor.Options);

            ShapePath shapepath = Assert.IsType <ShapePath>(processor.Path);

            SixLabors.Shapes.Rectangle rect = Assert.IsType <SixLabors.Shapes.Rectangle>(shapepath.Path);

            Assert.Equal(rect.Location.X, rectangle.X);
            Assert.Equal(rect.Location.Y, rectangle.Y);
            Assert.Equal(rect.Size.Width, rectangle.Width);
            Assert.Equal(rect.Size.Height, rectangle.Height);

            Pen <Color> pen = Assert.IsType <Pen <Color> >(processor.Pen);

            Assert.Equal(thickness, pen.Width);

            SolidBrush <Color> brush = Assert.IsType <SolidBrush <Color> >(pen.Brush);

            Assert.Equal(color, brush.Color);
        }
Esempio n. 2
0
        public void CorrectlySetsBrushThicknessRectangleAndOptions()
        {
            img.Draw(brush, thickness, rectangle, noneDefault);

            Assert.NotEmpty(img.ProcessorApplications);
            DrawPathProcessor <Color> processor = Assert.IsType <DrawPathProcessor <Color> >(img.ProcessorApplications[0].processor);

            Assert.Equal(noneDefault, processor.Options);

            ShapePath shapepath = Assert.IsType <ShapePath>(processor.Path);

            Assert.NotEmpty(shapepath.Paths);

            SixLabors.Shapes.Rectangle rect = Assert.IsType <SixLabors.Shapes.Rectangle>(shapepath.Paths[0].AsShape());

            Assert.Equal(rect.Location.X, rectangle.X);
            Assert.Equal(rect.Location.Y, rectangle.Y);
            Assert.Equal(rect.Size.Width, rectangle.Width);
            Assert.Equal(rect.Size.Height, rectangle.Height);

            Pen <Color> pen = Assert.IsType <Pen <Color> >(processor.Pen);

            Assert.Equal(brush, pen.Brush);
            Assert.Equal(thickness, pen.Width);
        }
Esempio n. 3
0
        public ShapeRegionTests()
        {
            this.pathMock = new Mock <IPath>();

            this.bounds = new SixLabors.Shapes.Rectangle(10.5f, 10, 10, 10);
            pathMock.Setup(x => x.Bounds).Returns(this.bounds);
            // wire up the 2 mocks to reference eachother
            pathMock.Setup(x => x.AsClosedPath()).Returns(() => pathMock.Object);
        }
Esempio n. 4
0
        public void ConvertRectangle(float x, float y, float width, float height, int expectedX, int expectedY, int expectedWidth, int expectedHeight)
        {
            SixLabors.Shapes.Rectangle src    = new SixLabors.Shapes.Rectangle(x, y, width, height);
            ImageSharp.Rectangle       actual = src.Convert();

            Assert.Equal(expectedX, actual.X);
            Assert.Equal(expectedY, actual.Y);
            Assert.Equal(expectedWidth, actual.Width);
            Assert.Equal(expectedHeight, actual.Height);
        }
Esempio n. 5
0
        public ShapeRegionTests()
        {
            this.shapeMock = new Mock <IShape>();
            this.pathMock  = new Mock <IPath>();

            this.bounds = new SixLabors.Shapes.Rectangle(10.5f, 10, 10, 10);
            shapeMock.Setup(x => x.Bounds).Returns(this.bounds);
            // wire up the 2 mocks to reference eachother
            pathMock.Setup(x => x.AsShape()).Returns(() => shapeMock.Object);
            shapeMock.Setup(x => x.Paths).Returns(() => ImmutableArray.Create(pathMock.Object));
        }
        public void CorrectlySetsBrushRectangleAndOptions()
        {
            img.Fill(brush, rectangle, noneDefault);

            Assert.NotEmpty(img.ProcessorApplications);
            FillRegionProcessor <Color> processor = Assert.IsType <FillRegionProcessor <Color> >(img.ProcessorApplications[0].processor);

            Assert.Equal(noneDefault, processor.Options);

            ShapeRegion region = Assert.IsType <ShapeRegion>(processor.Region);

            SixLabors.Shapes.Rectangle rect = Assert.IsType <SixLabors.Shapes.Rectangle>(region.Shape);
            Assert.Equal(rect.Location.X, rectangle.X);
            Assert.Equal(rect.Location.Y, rectangle.Y);
            Assert.Equal(rect.Size.Width, rectangle.Width);
            Assert.Equal(rect.Size.Height, rectangle.Height);

            Assert.Equal(brush, processor.Brush);
        }
        public void CorrectlySetsPenRectangleAndOptions()
        {
            img.Draw(pen, rectangle, noneDefault);

            Assert.NotEmpty(img.ProcessorApplications);
            DrawPathProcessor <Color> processor = Assert.IsType <DrawPathProcessor <Color> >(img.ProcessorApplications[0].processor);

            Assert.Equal(noneDefault, processor.Options);

            ShapePath shapepath = Assert.IsType <ShapePath>(processor.Path);

            SixLabors.Shapes.Rectangle rect = Assert.IsType <SixLabors.Shapes.Rectangle>(shapepath.Path);

            Assert.Equal(rect.Location.X, rectangle.X);
            Assert.Equal(rect.Location.Y, rectangle.Y);
            Assert.Equal(rect.Size.Width, rectangle.Width);
            Assert.Equal(rect.Size.Height, rectangle.Height);

            Assert.Equal(pen, processor.Pen);
        }
        public void CorrectlySetsColorAndRectangle()
        {
            img.Fill(color, rectangle);

            Assert.NotEmpty(img.ProcessorApplications);
            FillRegionProcessor <Color> processor = Assert.IsType <FillRegionProcessor <Color> >(img.ProcessorApplications[0].processor);

            Assert.Equal(GraphicsOptions.Default, processor.Options);

            ShapeRegion region = Assert.IsType <ShapeRegion>(processor.Region);

            SixLabors.Shapes.Rectangle rect = Assert.IsType <SixLabors.Shapes.Rectangle>(region.Shape);
            Assert.Equal(rect.Location.X, rectangle.X);
            Assert.Equal(rect.Location.Y, rectangle.Y);
            Assert.Equal(rect.Size.Width, rectangle.Width);
            Assert.Equal(rect.Size.Height, rectangle.Height);

            SolidBrush <Color> brush = Assert.IsType <SolidBrush <Color> >(processor.Brush);

            Assert.Equal(color, brush.Color);
        }
Esempio n. 9
0
        public static IPathCollection BuildCorners(int imageWidth, int imageHeight, float cornerRadius)
        {
            // first create a square
            var rect = new SixLabors.Shapes.Rectangle(-0.5f, -0.5f, cornerRadius, cornerRadius);

            // then cut out of the square a circle so we are left with a corner
            var cornerToptLeft = rect.Clip(new SixLabors.Shapes.Ellipse(cornerRadius - 0.5f, cornerRadius - 0.5f, cornerRadius));

            // corner is now a corner shape positions top left
            //lets make 3 more positioned correctly, we cando that by translating the orgional artound the center of the image
            var center = new Vector2(imageWidth / 2, imageHeight / 2);
            var angle  = Math.PI / 2f;

            float rightPos  = imageWidth - cornerToptLeft.Bounds.Width + 1;
            float bottomPos = imageHeight - cornerToptLeft.Bounds.Height + 1;

            // move it across the widthof the image - the width of the shape
            var cornerTopRight    = cornerToptLeft.RotateDegree(90).Translate(rightPos, 0);
            var cornerBottomLeft  = cornerToptLeft.RotateDegree(-90).Translate(0, bottomPos);
            var cornerBottomRight = cornerToptLeft.RotateDegree(180).Translate(rightPos, bottomPos);

            return(new PathCollection(cornerToptLeft, cornerBottomLeft, cornerTopRight, cornerBottomRight));
        }