Skip to content
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 NaNs in Rect's Width and Height properties #18971

Closed
wants to merge 5 commits into from

Conversation

BioTurboNick
Copy link
Contributor

@BioTurboNick BioTurboNick commented Nov 23, 2023

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

Possible alternative:

@BioTurboNick BioTurboNick requested a review from a team as a code owner November 23, 2023 00:55
@ghost ghost added the community ✨ Community Contribution label Nov 23, 2023
@ghost
Copy link

ghost commented Nov 23, 2023

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.

@rmarinho
Copy link
Member

/azp run MAUI-UITests-public

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

Copy link
Contributor

@hartez hartez left a 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.

src/Controls/src/Core/Window/Window.cs Outdated Show resolved Hide resolved
src/Graphics/src/Graphics/Rect.cs Outdated Show resolved Hide resolved
src/Graphics/src/Graphics/Rect.cs Outdated Show resolved Hide resolved
src/Graphics/src/Graphics/Rect.cs Outdated Show resolved Hide resolved
@Eilon Eilon added the area-drawing Shapes, Borders, Shadows, Graphics, BoxView, custom drawing label Nov 28, 2023
@BioTurboNick BioTurboNick requested a review from hartez December 10, 2023 04:17
@samhouts samhouts added the stale Indicates a stale issue/pr and will be closed soon label Jan 8, 2024
@jfversluis
Copy link
Member

/rebase

@mattleibow
Copy link
Member

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 mattleibow closed this Jun 6, 2024
@mattleibow mattleibow changed the title Disallow NaNs in Rect sizes Disallow NaNs in Rect's Width and Height properties Jun 6, 2024
@mattleibow mattleibow reopened this Jun 6, 2024
PureWeen added a commit that referenced this pull request Jun 20, 2024
### 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
@PureWeen PureWeen closed this Jun 20, 2024
@github-actions github-actions bot locked and limited conversation to collaborators Jul 21, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-drawing Shapes, Borders, Shadows, Graphics, BoxView, custom drawing community ✨ Community Contribution stale Indicates a stale issue/pr and will be closed soon
Projects
None yet
Development

Successfully merging this pull request may close these issues.

"System.ArgumentException: NaN is not a valid value for height" from Rect.Size getter
8 participants