From bdfedcc26f78ea332cdac0ed67590157c82c954e Mon Sep 17 00:00:00 2001 From: Michael Goderbauer Date: Wed, 27 Sep 2017 17:42:44 -0700 Subject: [PATCH] Add overlaps method to Rect (#4150) * Add overlaps method to Rect * review comment --- lib/ui/geometry.dart | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lib/ui/geometry.dart b/lib/ui/geometry.dart index d90a858a60e..9823c25daf3 100644 --- a/lib/ui/geometry.dart +++ b/lib/ui/geometry.dart @@ -653,6 +653,15 @@ class Rect { ); } + /// Whether `other` has a nonzero area of overlap with this rectangle. + bool overlaps(Rect other) { + if (right <= other.left || other.right <= left) + return false; + if (bottom <= other.top || other.bottom <= top) + return false; + return true; + } + /// The lesser of the magnitudes of the width and the height of this /// rectangle. double get shortestSide {