From 32cb2ee72043aa325b1847c18bc7bafc5d56aa12 Mon Sep 17 00:00:00 2001 From: Carlos Garnacho Date: Tue, 25 Jun 2024 01:38:10 +0200 Subject: [PATCH] mtk: Add mtk_rectangle_contains_pointf() This variant works on floating point coordinates, in order to avoid undesired effects with rounding. Part-of: --- mtk/mtk/mtk-rectangle.c | 16 ++++++++++++++++ mtk/mtk/mtk-rectangle.h | 4 ++++ 2 files changed, 20 insertions(+) diff --git a/mtk/mtk/mtk-rectangle.c b/mtk/mtk/mtk-rectangle.c index 3c837af8c..404d407a1 100644 --- a/mtk/mtk/mtk-rectangle.c +++ b/mtk/mtk/mtk-rectangle.c @@ -297,6 +297,22 @@ gboolean mtk_rectangle_contains_point (const MtkRectangle *rect, int x, int y) +{ + return mtk_rectangle_contains_pointf (rect, x, y); +} + +/** + * mtk_rectangle_contains_pointf: + * @rect: A rectangle + * @x: X coordinate of the point + * @y: Y coordinate of the point + * + * Returns: Whether the rectangle contains the point + */ +gboolean +mtk_rectangle_contains_pointf (const MtkRectangle *rect, + float x, + float y) { return (x >= rect->x && x < (rect->x + rect->width) && diff --git a/mtk/mtk/mtk-rectangle.h b/mtk/mtk/mtk-rectangle.h index 02fee6e3e..57076eb92 100644 --- a/mtk/mtk/mtk-rectangle.h +++ b/mtk/mtk/mtk-rectangle.h @@ -131,6 +131,10 @@ MTK_EXPORT gboolean mtk_rectangle_contains_point (const MtkRectangle *rect, int x, int y); +MTK_EXPORT +gboolean mtk_rectangle_contains_pointf (const MtkRectangle *rect, + float x, + float y); MTK_EXPORT graphene_rect_t mtk_rectangle_to_graphene_rect (const MtkRectangle *rect);