From 0087911841d34cea23c3ed6b8c2d4eb4c8c00cb8 Mon Sep 17 00:00:00 2001 From: ferhatb Date: Wed, 28 Oct 2020 11:45:02 -0700 Subject: [PATCH 1/2] Fix transform not invalidating path bounds causing debugValidate failure --- lib/web_ui/lib/src/engine/html/path/path_ref.dart | 3 +++ lib/web_ui/test/path_test.dart | 14 ++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/lib/web_ui/lib/src/engine/html/path/path_ref.dart b/lib/web_ui/lib/src/engine/html/path/path_ref.dart index 2b9c9f094ca09..970158db673f3 100644 --- a/lib/web_ui/lib/src/engine/html/path/path_ref.dart +++ b/lib/web_ui/lib/src/engine/html/path/path_ref.dart @@ -42,7 +42,9 @@ class PathRef { static const int kInitialPointsCapacity = 8; static const int kInitialVerbsCapacity = 8; + /// Bounds of points that define path. ui.Rect? fBounds; + /// Computed tight bounds of path (may exclude curve control points). ui.Rect? cachedBounds; int _fPointsCapacity = 0; int _fPointsLength = 0; @@ -730,6 +732,7 @@ class PathRef { fIsRRect = false; fIsRect = false; cachedBounds = null; + fBoundsIsDirty = true; } void setIsOval(bool isOval, bool isCCW, int start) { diff --git a/lib/web_ui/test/path_test.dart b/lib/web_ui/test/path_test.dart index 6f19c9cc8f439..97cc942e72491 100644 --- a/lib/web_ui/test/path_test.dart +++ b/lib/web_ui/test/path_test.dart @@ -536,5 +536,19 @@ void testMain() { end = iter.skipToNextContour(); expect(start, end); }); + + /// Regression test for https://github.com/flutter/flutter/issues/68702. + test('Path should return correct bounds after transform', () { + final Path path1 = Path() + ..moveTo(100, 100) + ..lineTo(200, 100) + ..lineTo(150, 200) + ..close(); + final SurfacePath path2 = Path.from(path1) as SurfacePath; + Rect bounds = path2.pathRef.getBounds(); + SurfacePath transformedPath = path2.transform( + Matrix4.identity().scaled(0.5, 0.5).toFloat64()); + expect(bounds != transformedPath.pathRef.getBounds(), isTrue); + }); }); } From 2294e2dee4aa51a841de876bf9110cc29ca2a1d0 Mon Sep 17 00:00:00 2001 From: ferhatb Date: Wed, 28 Oct 2020 13:58:18 -0700 Subject: [PATCH 2/2] address reviewer comment --- lib/web_ui/test/path_test.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/web_ui/test/path_test.dart b/lib/web_ui/test/path_test.dart index 97cc942e72491..b466f87856bfa 100644 --- a/lib/web_ui/test/path_test.dart +++ b/lib/web_ui/test/path_test.dart @@ -548,7 +548,7 @@ void testMain() { Rect bounds = path2.pathRef.getBounds(); SurfacePath transformedPath = path2.transform( Matrix4.identity().scaled(0.5, 0.5).toFloat64()); - expect(bounds != transformedPath.pathRef.getBounds(), isTrue); + expect(transformedPath.pathRef.getBounds(), isNot(bounds)); }); }); }