From 59ac0a38da2c1f1c40bbbbd4e59735b1fa2e9e25 Mon Sep 17 00:00:00 2001 From: Marius Vlad Date: Mon, 23 Jan 2023 23:09:19 +0200 Subject: [PATCH] libweston/vertex-clipping: Use shared helper And introduced a new helper, CLIP, with it. Signed-off-by: Marius Vlad --- libweston/vertex-clipping.c | 8 ++------ shared/helpers.h | 13 +++++++++++++ 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/libweston/vertex-clipping.c b/libweston/vertex-clipping.c index 3a05c7bd..7b471053 100644 --- a/libweston/vertex-clipping.c +++ b/libweston/vertex-clipping.c @@ -279,10 +279,6 @@ clip_polygon_bottom(struct clip_context *ctx, const struct polygon8 *src, return ctx->vertices.x - dst_x; } -#define max(a, b) (((a) > (b)) ? (a) : (b)) -#define min(a, b) (((a) > (b)) ? (b) : (a)) -#define clip(x, a, b) min(max(x, a), b) - WESTON_EXPORT_FOR_TESTS int clip_simple(struct clip_context *ctx, struct polygon8 *surf, @@ -291,8 +287,8 @@ clip_simple(struct clip_context *ctx, { int i; for (i = 0; i < surf->n; i++) { - ex[i] = clip(surf->x[i], ctx->clip.x1, ctx->clip.x2); - ey[i] = clip(surf->y[i], ctx->clip.y1, ctx->clip.y2); + ex[i] = CLIP(surf->x[i], ctx->clip.x1, ctx->clip.x2); + ey[i] = CLIP(surf->y[i], ctx->clip.y1, ctx->clip.y2); } return surf->n; } diff --git a/shared/helpers.h b/shared/helpers.h index 2e7ed2ea..872a78c0 100644 --- a/shared/helpers.h +++ b/shared/helpers.h @@ -82,6 +82,19 @@ do { \ #define MAX(x,y) (((x) > (y)) ? (x) : (y)) #endif +/** + * Clips the value to the maximum to the first item provided. + * + * @param c the first item to compare. + * @param x the second item to compare. + * @param y the third item to compare. + * @return the value that evaluates to lesser than the maximum of + * the two other parameters. + */ +#ifndef CLIP +#define CLIP(c, x, y) MIN(MAX(c, x), y) +#endif + /** * Returns a pointer to the containing struct of a given member item. *