maui
maui copied to clipboard
Disallow `NaN`s in `Rect` sizes
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
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.
/azp run MAUI-UITests-public
Azure Pipelines successfully started running 1 pipeline(s).
/rebase
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.