Bug with drawing round rectangles

I filed a bug tonight:

https://tracker.xojo.com/xojoinc/xojo/-/issues/74347

where Graphics.FillRoundRectangle and Graphics.DrawRoundRectangle produce different results on desktop (macOS) and iOS:

Dim r As Double = 50 - .000001 // BYO epsilon to prevent crash in iOS (until 2023 R3)
g.FillRoundRectangle(100,100,200,100,r,r)

Desktop (macOS):
Screenshot 2023-10-08 at 10.41.28 PM

Mobile:
Screenshot 2023-10-08 at 10.41.33 PM

I’m not posting this to get people to sign on—I’m sure it will be fixed. But my question is, it looks like the desktop (macOS) version is wrong. Given that the desktop implementation has been around a lot longer than the iOS version, I’m curious how people feel about how this gets fixed—which version is the “correct” one? And if you have an opinion, please leave a comment on the feedback! :slight_smile:

I’m in favor (and hope XOJO is too) of fixing the desktop version, even if it means breaking people’s code. The desktop version is clearly wrong, constructing a radius based on half the height and width values.

Documentation:

x and y are the coordinates of the top-left corner. width and height specify the size of the round rectangle. arcWidth and arcHeightcontrol the shape of the corners in the horizontal and vertical axes, respectively. They are the distance (in points) from the corner at which the arc begins. Setting them to zero results in a rectangle with sharp corners.

This example (in the [Paint] event of a [DesktopCanvas] draws a rounded rectangle with a red fill and 30 pixel rounded corners.

g.DrawingColor = &cff0000
g.FillRoundRectangle(10, 10, 100, 60, 30, 30)

Let’s run this and measure the radii. I’m using an internal picture so I don’t have to worry about points ≠ pixels:

Dim p As Picture = New Picture(200,200)
p.Graphics.DrawingColor = &cff0000
p.Graphics.FillRoundRectangle(10, 10, 100, 60, 30, 30)

Dim c As New Clipboard
c.Picture = p

Paste the output into PhotoShop and we see that the example code actually draws 15 px x 15 px corners instead of 30px x 30px:

1 Like

While it may not be consistent between iOS and macOS, the behavior is consistent for the target types (or, I guess I should say, Mobile is different from everything else).

macOS/Windows/Linux/Web have a common result, while iOS/Android have a common result. I think this is more of a time-induced inconsistency. It behaves the same way it always has for the older targets, but the naming and documentation have made that inconsistent with expectations and the newer platforms implemented it differently, possibly because of this ambiguity.

Considering that the impact of making this change everywhere else would be significantly greater than the impact of changing it for Mobile targets, I’d prefer any change happen to the Mobile targets rather than all of the other targets, and the API naming be corrected everywhere for the function parameters (which shouldn’t break much anywhere, if at all).

It is worth noting that another inconsistency exists between Graphics and WebGraphics where the Draw/FillRoundRectangle methods need only one radius parameter while everywhere else it’s two.

IIRC, that’s because the underlying API only has one. Honestly I’m surprised that there’s two on iOS though. I don’t think there’s two radii there either.