-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Disallow NaN
s in Rect
's Width
and Height
properties
#18971
Conversation
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). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the idea, just needs some minor changes.
Co-authored-by: E.Z. Hart <hartez@users.noreply.github.com>
/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. |
NaN
s in Rect
sizesNaN
s in Rect
's Width
and Height
properties
### Description of Change The other primitives are fine with `NaN`: * `Point` * `PointF` * `Rect` * `RectF` In fact, `Rect.Size` may throw because the `Rect` handles `NaN` but the `Size` instance does not. ### Issues Fixed <!-- Please make sure that there is a bug logged for the issue being fixed. The bug should describe the problem and how to reproduce it. --> Fixes #16571 <!-- Are you targeting main? All PRs should target the main branch unless otherwise noted. --> Possible alternative: - #18971
Description of Change
Rect
has aSize
property that returns aSize
object that wraps theWidth
andHeight
properties. However,Size
objects do not allow construction withNaN
values. This means thatRect
s 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/propertyApart 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
NaN
s are coming from.This change found one location in MAUI that was creating
Rect
s withNaN
s, and includes a fix. There may well be more locations that require adjustment. This would potentially be a breaking change inGraphics
.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 likeElement.Bounds.Size.ToSizeF()
being used.Issues Fixed
Fixes #16571
Possible alternative:
Size
andSizeF
should not throw onNaN
#22890