media: v4l2-rect.h: add enclosed rectangle helper
authorBenoit Parrot <bparrot@ti.com>
Thu, 28 May 2020 13:26:04 +0000 (15:26 +0200)
committerMauro Carvalho Chehab <mchehab+huawei@kernel.org>
Sat, 4 Jul 2020 10:29:38 +0000 (12:29 +0200)
Add a helper function to check if one rectangle is enclosed inside
another.

Signed-off-by: Benoit Parrot <bparrot@ti.com>
Acked-by: Andrzej Pietrasiewicz <andrzejtp2010@gmail.com>
Reviewed-by: Lad Prabhakar <prabhakar.csengg@gmail.com>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
include/media/v4l2-rect.h

index 8800a64..bd587d0 100644 (file)
@@ -184,4 +184,24 @@ static inline bool v4l2_rect_overlap(const struct v4l2_rect *r1,
        return true;
 }
 
+/**
+ * v4l2_rect_enclosed() - is r1 enclosed in r2?
+ * @r1: rectangle.
+ * @r2: rectangle.
+ *
+ * Returns true if @r1 is enclosed in @r2.
+ */
+static inline bool v4l2_rect_enclosed(struct v4l2_rect *r1,
+                                     struct v4l2_rect *r2)
+{
+       if (r1->left < r2->left || r1->top < r2->top)
+               return false;
+       if (r1->left + r1->width > r2->left + r2->width)
+               return false;
+       if (r1->top + r1->height > r2->top + r2->height)
+               return false;
+
+       return true;
+}
+
 #endif