PatternPen with a four-value pattern and LineJoin.Miter draws an EllipsePolygon almost solid

未關閉
#430 1 則留言 1 個 reaction 已指派 0 人 在 GitHub 檢視

已經有一個關聯 PR 被合併了。

  • #432 來自 @JimBobSquarePants —— 已合併

評估

難度
4/5
預估耗時
3-5 天
新手友好度
55/100
Issue 類型
缺陷
描述清晰度
描述清楚
活躍度
活躍
技術堆疊
csharp

研究方向

Start by tracing how PatternPen applies the four-value dash pattern while drawing an EllipsePolygon with LineJoin.Miter; compare that path with the reported working two-value pattern and closed square. Reproduce with the supplied C# example and check the ink ratio against the expected 56–60%. The issue does not name source files or tests, so locate the drawing and pattern tests; done means the gaps remain visible and existing join and pattern cases still behave correctly.

由索引模型根據 Issue 內容生成。

描述

bug
Prerequisites
  • I have written a descriptive issue title
  • I have verified that I am running the latest version of ImageSharp.Drawing
  • I have verified if the problem exist in both DEBUG and RELEASE mode
  • I have searched open and closed issues to ensure it has not already been reported
ImageSharp.Drawing version

3.1.3

Other ImageSharp packages and versions

SixLabors.ImageSharp 4.1.3 (SixLabors.Fonts 3.2.0, SixLabors.PolygonClipper 1.0.2 via dependencies)

Environment (Operating system, version and so on)

Windows 11 x64

.NET Framework version

.NET 10 (SDK 10.0.401)

Description

A PatternPen with the four-value pattern [4, 2, 1, 2] and LineJoin.Miter draws an EllipsePolygon as an almost continuous line: the ink is 97 % of a solid pen with the same options, where about 56–60 % is expected. Only one gap remains visible.

The same pattern is correct on a closed square polygon. A two-value pattern [3, 2] is correct on the same ellipse. With the default join (Bevel) the four-value pattern is also correct on the ellipse (60 %), and with LineJoin.Round it is 66 %. So the combination of a short dash/gap pattern on a densely flattened curve with miter (and to a lesser extent round) joins seems to fill the gaps.

In ImageSharp.Drawing 2.1.6 the same drawing (with JointStyle.Miter, EndCapStyle.Butt) was dashed as expected.

Join, cap [3, 2] [4, 2, 1, 2]
default (Bevel, Butt) 60 % 60 %
Miter, Butt 60 % 97 %
Round, Butt 60 % 66 %
Miter, Round 74 % 101 %

(ink as a share of a solid pen with the same StrokeOptions; circle of 200 px diameter, pen width 2, 256 × 256 image)

Steps to Reproduce
using SixLabors.ImageSharp;
using SixLabors.ImageSharp.Drawing;
using SixLabors.ImageSharp.Drawing.Processing;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing;

IPath circle = new EllipsePolygon(128, 128, 200, 200);

double Ink(Pen pen)
{
    using var image = new Image<Rgba32>(256, 256, Color.White.ToPixel<Rgba32>());
    image.Mutate(ctx => ctx.Paint(canvas => canvas.Draw(pen, circle)));
    double ink = 0;
    image.ProcessPixelRows(rows =>
    {
        for (var y = 0; y < rows.Height; y++)
            foreach (var p in rows.GetRowSpan(y))
                ink += (255 - p.R) / 255.0;
    });
    return ink;
}

var stroke = new StrokeOptions { LineJoin = LineJoin.Miter, LineCap = LineCap.Butt };
var solid = Ink(new SolidPen(new PenOptions(Color.Black, 2, []) { StrokeOptions = stroke }));
var dashed = Ink(new PatternPen(new PenOptions(Color.Black, 2, [4f, 2f, 1f, 2f]) { StrokeOptions = stroke }));

Console.WriteLine($"{dashed / solid:P0}"); // 97 %, expected about 56–60 %
Images

The arc is drawn as a continuous line with a single gap, instead of dash, gap, dot, gap.

主要語言
C#
星號
322
分支
49
平均合併
3 小時 27 分鐘
30 天內合併 PR
6

環境準備

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

SixLabors/ImageSharp.Drawing 的其他 Issue

查看 SixLabors/ImageSharp.Drawing 的全部 Issue

相似的 Issue

更多 C# Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。