maui icon indicating copy to clipboard operation
maui copied to clipboard

Disallow `NaN`s in `Rect` sizes

Open BioTurboNick opened this issue 2 years ago • 3 comments

Description of Change

Rect has a Size property that returns a Size object that wraps the Width and Height properties. However, Size objects do not allow construction with NaN values. This means that Rects can be created that have a property getter that throws an exception, which is against .Net design guidelines: https://learn.microsoft.com/en-us/dotnet/standard/design-guidelines/property

Apart from just being against guidelines, a downstream issue is that exceptions are thrown at the point of access, rather than the point of creation, inhibiting the ability to troubleshoot where these NaNs are coming from.

This change found one location in MAUI that was creating Rects with NaNs, and includes a fix. There may well be more locations that require adjustment. This would potentially be a breaking change in Graphics.

Alternatively, if a breaking change is not desired, documenting the issue and ensuring any location that consumes the Size property guards against the Rect containing NaN values could be pursued. That would be tricky because of instances like Element.Bounds.Size.ToSizeF() being used.

Issues Fixed

Fixes #16571

BioTurboNick avatar Nov 23 '23 00:11 BioTurboNick

Hey there @BioTurboNick! Thank you so much for your PR! Someone from the team will get assigned to your PR shortly and we'll get it reviewed.

ghost avatar Nov 23 '23 00:11 ghost

/azp run MAUI-UITests-public

rmarinho avatar Nov 23 '23 11:11 rmarinho

Azure Pipelines successfully started running 1 pipeline(s).

azure-pipelines[bot] avatar Nov 23 '23 11:11 azure-pipelines[bot]

/rebase

jfversluis avatar Mar 30 '24 10:03 jfversluis

I am going to close this PR because I am not sure that we should do this. I would rather go back to the issue and have a discussion on whether we should do this or even change Point and/or Size instead. Or everything.

mattleibow avatar Jun 06 '24 17:06 mattleibow