// Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. using System.Numerics; using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Primitives; using SixLabors.ImageSharp.Processing; using SixLabors.ImageSharp.Processing.Processors.Drawing; using SixLabors.ImageSharp.Tests.Processing; using SixLabors.ImageSharp.Tests.TestUtilities; using SixLabors.Shapes; using Xunit; namespace SixLabors.ImageSharp.Tests.Drawing.Paths { public class FillPathCollection : BaseImageOperationsExtensionTest { private static readonly GraphicsOptionsComparer graphicsOptionsComparer = new GraphicsOptionsComparer(); GraphicsOptions nonDefault = new GraphicsOptions { Antialias = false }; Color color = Color.HotPink; SolidBrush brush = Brushes.Solid(Rgba32.HotPink); IPath path1 = new Path(new LinearLineSegment(new SixLabors.Primitives.PointF[] { new Vector2(10,10), new Vector2(20,10), new Vector2(20,10), new Vector2(30,10), })); IPath path2 = new Path(new LinearLineSegment(new SixLabors.Primitives.PointF[] { new Vector2(10,10), new Vector2(20,10), new Vector2(20,10), new Vector2(30,10), })); IPathCollection pathCollection; public FillPathCollection() { this.pathCollection = new PathCollection(this.path1, this.path2); } [Fact] public void CorrectlySetsBrushAndPath() { this.operations.Fill(this.brush, this.pathCollection); for (int i = 0; i < 2; i++) { FillRegionProcessor processor = this.Verify(i); Assert.Equal(new GraphicsOptions(), processor.Options, graphicsOptionsComparer); ShapeRegion region = Assert.IsType(processor.Region); // path is converted to a polygon before filling Polygon polygon = Assert.IsType(region.Shape); Assert.IsType(polygon.LineSegments[0]); Assert.Equal(this.brush, processor.Brush); } } [Fact] public void CorrectlySetsBrushPathOptions() { this.operations.Fill(this.nonDefault, this.brush, this.pathCollection); for (int i = 0; i < 2; i++) { FillRegionProcessor processor = this.Verify(i); Assert.Equal(this.nonDefault, processor.Options, graphicsOptionsComparer); ShapeRegion region = Assert.IsType(processor.Region); Polygon polygon = Assert.IsType(region.Shape); Assert.IsType(polygon.LineSegments[0]); Assert.Equal(this.brush, processor.Brush); } } [Fact] public void CorrectlySetsColorAndPath() { this.operations.Fill(this.color, this.pathCollection); for (int i = 0; i < 2; i++) { FillRegionProcessor processor = this.Verify(i); Assert.Equal(new GraphicsOptions(), processor.Options, graphicsOptionsComparer); ShapeRegion region = Assert.IsType(processor.Region); Polygon polygon = Assert.IsType(region.Shape); Assert.IsType(polygon.LineSegments[0]); SolidBrush brush = Assert.IsType(processor.Brush); Assert.Equal(this.color, brush.Color); } } [Fact] public void CorrectlySetsColorPathAndOptions() { this.operations.Fill(this.nonDefault, this.color, this.pathCollection); for (int i = 0; i < 2; i++) { FillRegionProcessor processor = this.Verify(i); Assert.Equal(this.nonDefault, processor.Options, graphicsOptionsComparer); ShapeRegion region = Assert.IsType(processor.Region); Polygon polygon = Assert.IsType(region.Shape); Assert.IsType(polygon.LineSegments[0]); SolidBrush brush = Assert.IsType(processor.Brush); Assert.Equal(this.color, brush.Color); } } } }