SixLabors / ImageSharp.Drawing

:pen: Extensions to ImageSharp containing a cross-platform 2D polygon manipulation API and drawing operations.
https://sixlabors.com/products/imagesharp-drawing/
Other
282 stars 38 forks source link

Flattening the result of a Clip gives different results for horizontal and vertical lines #250

Closed chris-steema closed 1 year ago

chris-steema commented 1 year ago

Description

Flattening the result of a Clip gives different results for horizontal and vertical lines.

Steps to Reproduce

        private static void Problem()
        {
            var clip = new PathCollection(new RectangularPolygon(new PointF(24, 16), new PointF(777, 385)));

            var vert = new SixLabors.ImageSharp.Drawing.Path(new LinearLineSegment(new PointF(26, 384), new PointF(26, 163)));
            var horiz = new SixLabors.ImageSharp.Drawing.Path(new LinearLineSegment(new PointF(26, 163), new PointF(176, 163)));

            IPath reverse =  vert.Clip(clip);
            var result1 = vert.Clip(reverse).Flatten().Select(x => x.Points);

            reverse = horiz.Clip(clip);
            var result2 = horiz.Clip(reverse).Flatten().Select(x => x.Points);

            var same = result1.Count() == result2.Count();
        }

I expect the Count of both result1 and result2 to be identical.

System Configuration