Skip to content

Trap NaN in geometry. #132770

@dnfield

Description

@dnfield

NaN is never a useful value to have in geometry classes (e.g. Rect, Matrix, Path, RRect).

If possible, in debug mode it would be nice to trap NaNs that show up in the geometry. I ran into this today while debugging an issue like this:

  auto rect = impeller_object.GetCoverage().value_or(Rect());
  auto sk_rect = SkRect::MakeXYWH(rect.origin.x, rect.origin.y, rect.bounds.width, rect.bounds.height);
  // Safe version:
  // auto sk_rect = SkRect::MakeLTRB(rect.GetLeft(), rect.GetTop(), rect.GetRight(), rect.GetBottom());

Where rect was {{-Inf, -Inf}, {+Inf, +Inf}} and sk_rect ended up being {{-Inf, -Inf}, {NaN, NaN}} (using the impeller representation of rects), because -Inf + +Inf == NaN.

/cc @flar who is looking at geometry
/cc @bdero @chinmaygarde - this makes me question a little whether Rect::MakeMaximum in Impeller should be returning an infinitely sized rect or the same as the engine's concept of a "giant" rect, but that's a different and probably less serious issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3Issues that are less important to the Flutter projectengineflutter/engine related. See also e: labels.team-engineOwned by Engine teamtriaged-engineTriaged by Engine team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions