Skip to content

Check if a double is NaN before converting to it int - #61940

Merged
fluttergithubbot merged 4 commits into
flutter:masterfrom
LongCatIsLooong:handle-zero-transform
Jul 23, 2020
Merged

fluttergithubbot merged 4 commits into
flutter:masterfrom
LongCatIsLooong:handle-zero-transform

Conversation

@LongCatIsLooong

@LongCatIsLooong LongCatIsLooong commented Jul 21, 2020 •

Copy link
Copy Markdown
Contributor

Description

RenderObject.localToGlobal may return (NaN, NaN) when (x, y, 0, 1) is transformed to a point at infinity. This is generally not a problem, as painting is usually skipped when the transform is set to zero. But trying to convert the point's coordinates to int or json will throw.

Related Issues

#9344

Tests

I added the following tests:

  • getLocalRectForCaret does not throw when it sees an infinite point

Checklist

Before you create this PR confirm that it meets all requirements listed below by checking the relevant checkboxes ([x]). This will ensure a smooth and quick review process.

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I signed the CLA.
  • I read and followed the Flutter Style Guide, including Features we expect every widget to implement.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I updated/added relevant documentation (doc comments with ///).
  • All existing and new tests are passing.
  • The analyzer (flutter analyze --flutter-repo) does not report any problems on my PR.
  • I am willing to follow-up on review comments in a timely manner.

Breaking Change

Did any tests fail when you ran them? Please read Handling breaking changes.

@fluttergithubbot fluttergithubbot added the framework flutter/packages/flutter repository. See also f: labels. label Jul 21, 2020

@Piinks Piinks left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

/// This function assumes the given point has a z-coordinate of 0.0. The
/// z-coordinate of the result is ignored.
///
/// While not common, this method may return (NaN, NaN), iff the given `point`

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just checking - 'iff' as in 'if and only if', or typo?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I meant "if and only if".

@justinmc justinmc left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

I ran into something vaguely similar but not quite the same while working with matrix math in InteractiveViewer. Some Matrix4 methods would fail in strange ways when given infinite numbers. I'm glad this will handle things in a more sane way now at least 👍

@LongCatIsLooong LongCatIsLooong mentioned this pull request Jul 21, 2020
13 tasks
@fluttergithubbot
fluttergithubbot merged commit 64173f7 into flutter:master Jul 23, 2020
@LongCatIsLooong
LongCatIsLooong deleted the handle-zero-transform branch July 23, 2020 17:07
Pragya007 pushed a commit to Pragya007/flutter that referenced this pull request Aug 11, 2020
mingwandroid pushed a commit to mingwandroid/flutter that referenced this pull request Sep 6, 2020
@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Jul 30, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

framework flutter/packages/flutter repository. See also f: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants