Problem Description
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.
Reproduction Code
XGraphicsPath path = new XGraphicsPath();
path.StartFigure();
path.AddLine(new XPoint(50, 50), new XPoint(100, 50));
path.StartFigure();
path.AddLine(new XPoint(50, 100), new XPoint(100, 100));
path.StartFigure();
path.AddLine(new XPoint(50, 150), new XPoint(100, 150));
path.StartFigure();
path.AddLine(new XPoint(50, 200), new XPoint(100, 200));
gfx.DrawPath(pen, path);
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 WPF
PathFigure figure = CurrentPathFigure;
if (figure.Segments.Count == 0)
{
figure.StartPoint = new SysPoint(x1, y1);
var lineSegment = new LineSegment(new SysPoint(x2, y2), true);
figure.Segments.Add(lineSegment);
}
else
{
// This branch connects to the previous point!
var lineSegment1 = new LineSegment(new SysPoint(x1, y1), true);
var lineSegment2 = new LineSegment(new SysPoint(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.
Problem Description
When calling
StartFigure()followed byAddLine()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. SubsequentAddLine()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.
Reproduction Code
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:The Problem:
When
figure.Segments.Count > 0(i.e., the figure already has segments), the code adds TWO line segments:(x1, y1)- this connects to the previous line's endpoint(x1, y1)to(x2, y2)- the intended lineThis 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 nextAddLine()call should behave as if it's the first line (settingStartPointtox1, y1and adding a single segment tox2, y2), not connecting to previous figures.