API 2.0: GraphicsPath Bug?


I am very happy that API 2.0 has introduced the ability to draw paths. However, I’m encountering a strange behavior and I’m not sure if it’s a bug in the GraphicsPath class.
I have taken the example code from the documentation for GraphicsPath.AddRoundRectangle in Window1.Paint:

[code]’ New Style
Var rect As New GraphicsPath
rect.AddRoundRectangle(0, 0, 100, 150, 10, 10)

’ Old Style
g.DrawRoundRectangle(0, 0, 100, 150, 10, 10)[/code]
However, unlike Graphics.DrawRoundRectangle, GraphicPath does not draw the rounded rectangle at the position 0, 0. Is this a bug? The same is true for GraphicsPath.DrawRectangle.

There is also a visible difference in the corner radius, but this is 10 in both the new and the old method. It looks like GraphicsPath.AddRoundRectangle will double the CornerRadius.

Add: If you call rect.MoveToPoint(0, 0) before, the position will unfortunately not change!

Retina monitor ?

Yes, Retina monitor.

Look like a bug. Try the following code to see the difference better:

[code]’ New Style
g.PenSize = 5
Var rect As New GraphicsPath
g.DrawingColor = rgb(255,0,0)
rect.AddRoundRectangle(10, 10, 100, 150, 10, 10)

’ Old Style
g.DrawingColor = rgb(0, 255, 0)
g.DrawRoundRectangle(10, 10, 100, 150, 10, 10)[/code]

Screen res is 144dpi ?

The GraphicsPath system needs to be drawn down the center of the pixel, so change your 0,0 to 0.5,0.5 and everything will look crisp again. The Graphics version either used pixel based drawing or compensated for this internally while the GraphicsPath system is vector/coordinate based and not pixel based.

If you think about it, you’re asking a 1 pixel wide line to be drawn on the left edge of the 0 pixel which will put half the line off the edge of the window and only half a line on the window. But if you ask for the 1 pixel wide line to be placed down the center of the pixel it will fill that entire pixel. This is in contradiction to the old method which would draw to the right and below the coordinate provided and would make things more complicated when scaling happens.

As for the corner radius size, that might be a bug or a side effect of using the new routines behind the scenes.

Julian, old version uses Doubles, so it can be located at 0.5, isn’t it ?

Graphics.DrawRoundRectangle(x As Double, y As Double, width As Double, height As Double, arcWidth As Double, arcHeight As Double)

Yes it uses doubles but internally it draws right/down probably because it either uses “older” pixel drawing routines rather than coordinate based drawing routines or the framework internally transposes everything down/right 0.5 to account for the offset required. Let me edit the post to clarify.