libweston/vertex-clipping: Use shared helper

And introduced a new helper, CLIP, with it.

Signed-off-by: Marius Vlad <marius.vlad@collabora.com>
This commit is contained in:
Marius Vlad 2023-01-23 23:09:19 +02:00
parent 71e826defd
commit 59ac0a38da
2 changed files with 15 additions and 6 deletions

View File

@ -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;
}

View File

@ -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.
*