From bef1f5fd7dea92070896688a1e66e6de8292ee8a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Molinari?= Date: Mon, 15 Apr 2024 15:34:47 +0200 Subject: [PATCH] gl-renderer: Remove support for non-quad polygons from clipper MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The added complexity is unnecessary, it is limited to polygons of length less than or equal to 8, there is currently no use for that feature nor any plans to use it and tests are non-existent. Signed-off-by: Loïc Molinari --- libweston/vertex-clipping.c | 12 ++++-------- libweston/vertex-clipping.h | 13 ++++++------- tests/vertex-clip-test.c | 19 +------------------ 3 files changed, 11 insertions(+), 33 deletions(-) diff --git a/libweston/vertex-clipping.c b/libweston/vertex-clipping.c index 5aa26b4b..1ef840b9 100644 --- a/libweston/vertex-clipping.c +++ b/libweston/vertex-clipping.c @@ -295,8 +295,7 @@ clip_polygon_bottom(struct clip_context *ctx, const struct polygon8 *src, * https://www.codeguru.com/cplusplus/polygon-clipping/ */ WESTON_EXPORT_FOR_TESTS int -clipper_clip(const struct clipper_vertex *polygon, - size_t polygon_len, +clipper_clip(const struct clipper_vertex polygon[4], const struct clipper_vertex box[2], struct clipper_vertex *restrict vertices) { @@ -304,12 +303,9 @@ clipper_clip(const struct clipper_vertex *polygon, struct polygon8 p, tmp; int i, n; - if (polygon_len > 8) - return -1; - memcpy(ctx.box, box, 2 * sizeof *box); - memcpy(p.pos, polygon, polygon_len * sizeof *polygon); - p.n = polygon_len; + memcpy(p.pos, polygon, 4 * sizeof *polygon); + p.n = 4; tmp.n = clip_polygon_left(&ctx, &p, tmp.pos); p.n = clip_polygon_right(&ctx, &tmp, p.pos); tmp.n = clip_polygon_top(&ctx, &p, tmp.pos); @@ -390,7 +386,7 @@ clipper_quad_clip(struct clipper_quad *quad, /* Then use our general purpose clipping algorithm: */ - n = clipper_clip(quad->polygon, 4, box, vertices); + n = clipper_clip(quad->polygon, box, vertices); if (n < 3) return 0; diff --git a/libweston/vertex-clipping.h b/libweston/vertex-clipping.h index 5e63cf6f..1308fecc 100644 --- a/libweston/vertex-clipping.h +++ b/libweston/vertex-clipping.h @@ -42,15 +42,14 @@ struct clipper_quad { /* * General purpose clipping function. Compute the boundary vertices of the * intersection of a 'polygon' and a clipping 'box'. 'polygon' points to an - * array of 'polygon_len' vertices, less than or equal to 8, defining a convex - * polygon of any winding order. 'box' points to an array of 2 vertices where - * the values of the 1st vertex are less than or equal to the values of the 2nd - * vertex. Up to 16 resulting vertices, using 'polygon' winding order, are - * written to 'vertices'. The return value is the number of vertices created. + * array of 4 vertices defining a convex polygon of any winding order. 'box' + * points to an array of 2 vertices where the values of the 1st vertex are less + * than or equal to the values of the 2nd vertex. Up to 8 resulting vertices, + * using 'polygon' winding order, are written to 'vertices'. The return value is + * the number of vertices created. */ int -clipper_clip(const struct clipper_vertex *polygon, - size_t polygon_len, +clipper_clip(const struct clipper_vertex polygon[4], const struct clipper_vertex box[2], struct clipper_vertex *restrict vertices); diff --git a/tests/vertex-clip-test.c b/tests/vertex-clip-test.c index 53f1883a..bea3be30 100644 --- a/tests/vertex-clip-test.c +++ b/tests/vertex-clip-test.c @@ -44,7 +44,6 @@ struct vertex_clip_test_data { }; struct clipper_vertex polygon[8]; struct clipper_vertex clipped[8]; - int polygon_n; int clipped_n; bool aligned; }; @@ -86,7 +85,6 @@ static const struct vertex_clip_test_data clip_expected_data[] = { .box = BOX (50.0f, 50.0f, 100.0f, 100.0f), .polygon = QUAD(51.0f, 51.0f, 99.0f, 99.0f), .clipped = QUAD(51.0f, 51.0f, 99.0f, 99.0f), - .polygon_n = 4, .clipped_n = 4, }, @@ -95,7 +93,6 @@ static const struct vertex_clip_test_data clip_expected_data[] = { .box = BOX (50.0f, 50.0f, 100.0f, 100.0f), .polygon = QUAD(51.0f, 51.0f, 99.0f, 101.0f), .clipped = QUAD(51.0f, 51.0f, 99.0f, 100.0f), - .polygon_n = 4, .clipped_n = 4, }, @@ -104,7 +101,6 @@ static const struct vertex_clip_test_data clip_expected_data[] = { .box = BOX (50.0f, 50.0f, 100.0f, 100.0f), .polygon = QUAD(51.0f, 49.0f, 99.0f, 99.0f), .clipped = QUAD(51.0f, 50.0f, 99.0f, 99.0f), - .polygon_n = 4, .clipped_n = 4, }, @@ -113,7 +109,6 @@ static const struct vertex_clip_test_data clip_expected_data[] = { .box = BOX (50.0f, 50.0f, 100.0f, 100.0f), .polygon = QUAD(49.0f, 51.0f, 99.0f, 99.0f), .clipped = QUAD(50.0f, 51.0f, 99.0f, 99.0f), - .polygon_n = 4, .clipped_n = 4, }, @@ -122,7 +117,6 @@ static const struct vertex_clip_test_data clip_expected_data[] = { .box = BOX (50.0f, 50.0f, 100.0f, 100.0f), .polygon = QUAD(51.0f, 51.0f, 101.0f, 99.0f), .clipped = QUAD(51.0f, 51.0f, 100.0f, 99.0f), - .polygon_n = 4, .clipped_n = 4, }, @@ -132,7 +126,6 @@ static const struct vertex_clip_test_data clip_expected_data[] = { .polygon = {{ 25.0f, 75.0f}, {75.0f, 25.0f}, {125.0f, 75.0f}, {75.0f, 125.0f}}, .clipped = QUAD(50.0f, 50.0f, 100.0f, 100.0f), - .polygon_n = 4, .clipped_n = 4, }, @@ -145,7 +138,6 @@ static const struct vertex_clip_test_data clip_expected_data[] = { {100.0f, 62.5f}, {100.0f, 87.5f}, { 87.5f, 100.0f}, { 62.5f, 100.0f}, { 50.0f, 87.5f}, { 50.0f, 62.5f}}, - .polygon_n = 4, .clipped_n = 8, }, @@ -158,7 +150,6 @@ static const struct vertex_clip_test_data clip_expected_data[] = { { 50.0f, 87.5f}, { 62.5f, 100.0f}, { 87.5f, 100.0f}, {100.0f, 87.5f}, {100.0f, 62.5f}, { 87.5f, 50.0f}}, - .polygon_n = 4, .clipped_n = 8, }, }; @@ -169,19 +160,11 @@ TEST_P(clip_expected, clip_expected_data) struct clipper_vertex clipped[8]; int clipped_n; - clipped_n = clipper_clip(tdata->polygon, tdata->polygon_n, tdata->box, - clipped); + clipped_n = clipper_clip(tdata->polygon, tdata->box, clipped); assert_vertices(clipped, clipped_n, tdata->clipped, tdata->clipped_n); } -TEST(clip_size_too_high) -{ - struct clipper_vertex polygon[8] = {}, box[2] = {}; - - assert(clipper_clip(polygon, 9, box, NULL) == -1); -} - /* clipper_quad_clip() tests: */ static const struct vertex_clip_test_data quad_clip_expected_data[] = {