GraphicsPath – Why does order of AddLine methods matter

I am drawing a triangle with the following code

When I call DrawPath, it always draws my lines, no matter the order. But when I call FillPath, it does nothing. Only when my order is / _ \ or \ _ / does my triangle actually fill. Why is this?

Asked on April 7, 2016 in C#.
Add Comment
1 Answer(s)

It turns out that the answer I posted originally didn’t really solve the problem and that it worked on my machine because of an additional change I introduced, which is to change the FillMode:

GraphicsPath path = new GraphicsPath(FillMode.Winding);

When you use the Winding mode, the algorithm will detect a closed path even if you didn’t add the lines in order.

Answered on April 7, 2016.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.