You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
AddLine creates zigzag pattern instead of separate parallel lines when StartFigure is called #396
When calling StartFigure() followed by AddLine() multiple times, the resulting path creates a connected zigzag pattern instead of separate parallel lines.
Expected Behavior
Each call to StartFigure() should begin a new independent figure. Subsequent AddLine() calls should draw isolated line segments that don't connect to previous figures.
Current Behavior
The lines are being connected together, creating a zigzag pattern that connects all the line segments sequentially.
Expected Result: Four separate horizontal parallel lines Actual Result: A connected zigzag pattern
Root Cause Analysis
The issue is in the AddLine(double x1, double y1, double x2, double y2) method (lines 276-306). The WPF implementation has problematic logic:
#if WPFPathFigurefigure=CurrentPathFigure;if(figure.Segments.Count==0){figure.StartPoint=newSysPoint(x1,y1);varlineSegment=newLineSegment(newSysPoint(x2,y2),true);figure.Segments.Add(lineSegment);}else{// This branch connects to the previous point!varlineSegment1=newLineSegment(newSysPoint(x1,y1),true);varlineSegment2=newLineSegment(newSysPoint(x2,y2),true);figure.Segments.Add(lineSegment1);figure.Segments.Add(lineSegment2);}
#endif
The Problem:
When figure.Segments.Count > 0 (i.e., the figure already has segments), the code adds TWO line segments:
A line from the current position to (x1, y1) - this connects to the previous line's endpoint
A line from (x1, y1) to (x2, y2) - the intended line
This causes unwanted connections between figures that should be independent after StartFigure() is called.
Expected Implementation
After StartFigure() creates a new figure, the figure should be empty, and the next AddLine() call should behave as if it's the first line (setting StartPoint to x1, y1 and adding a single segment to x2, y2), not connecting to previous figures.
Copilot maybe points out the wrong location for the bug. For my understanding the code in AddLine looks goods. But I still see the zigzag when I run the example code.
Since StartFigure() leaves nothing behind for this check to see, the start point of each new line becomes a LineTo from the previous line's end. The content stream comes out as m l l l l l l l S, which is the zigzag.
We fixed this in a fork by having StartFigure set a flag that MoveOrLineTo checks. The first point added after it clears the flag:
The copy constructor should carry _startNewFigure across as well. Anything else that begins a subpath without going through MoveTo has to clear the flag too.
With this change, the repro above gives four separate lines (m l m l m l m l S). Without StartFigure(), consecutive AddLine calls still join into one figure, as in GDI+:
Activity
RonHeck commentedon Sep 28, 2026
Copilot maybe points out the wrong location for the bug. For my understanding the code in AddLine looks goods. But I still see the zigzag when I run the example code.
RonHeck commentedon Sep 28, 2026
Also happens with 7 preview version
jafin commentedon Sep 28, 2026
I think the root cause is in the Core build, not the WPF branch the analysis above points at.
In Core, XGraphicsPath.StartFigure() does nothing:
AddLine then calls CorePath.MoveOrLineTo(x1, y1), which only makes a MoveTo if the path is empty or the last subpath was closed:
Since StartFigure() leaves nothing behind for this check to see, the start point of each new line becomes a LineTo from the previous line's end. The content stream comes out as m l l l l l l l S, which is the zigzag.
We fixed this in a fork by having StartFigure set a flag that MoveOrLineTo checks. The first point added after it clears the flag:
The copy constructor should carry _startNewFigure across as well. Anything else that begins a subpath without going through MoveTo has to clear the flag too.
With this change, the repro above gives four separate lines (m l m l m l m l S). Without StartFigure(), consecutive AddLine calls still join into one figure, as in GDI+:
RonHeck commentedon Sep 29, 2026
Finally we do not want to rely on a fork so it would be nice if this issue somehow gets fixed on the origin code base.