From 5516527f2b1199383ee414227977cd40c9679ce3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Molinari?= Date: Wed, 9 Aug 2023 17:27:22 +0200 Subject: [PATCH] tests: Add box32 quad clipper tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add a few tests ensuring the box32 quad clipping wrapper works as expected. Signed-off-by: Loïc Molinari --- libweston/vertex-clipping.c | 2 +- tests/vertex-clip-test.c | 59 ++++++++++++++++++++++++++++++++++++- 2 files changed, 59 insertions(+), 2 deletions(-) diff --git a/libweston/vertex-clipping.c b/libweston/vertex-clipping.c index 4de172e4..5aa26b4b 100644 --- a/libweston/vertex-clipping.c +++ b/libweston/vertex-clipping.c @@ -398,7 +398,7 @@ clipper_quad_clip(struct clipper_quad *quad, return n; } -int +WESTON_EXPORT_FOR_TESTS int clipper_quad_clip_box32(struct clipper_quad *quad, const struct pixman_box32 *box, struct clipper_vertex *restrict vertices) diff --git a/tests/vertex-clip-test.c b/tests/vertex-clip-test.c index 0c0be676..53f1883a 100644 --- a/tests/vertex-clip-test.c +++ b/tests/vertex-clip-test.c @@ -34,10 +34,14 @@ #include "vertex-clipping.h" #define BOX(x1,y1,x2,y2) { { x1, y1 }, { x2, y2 } } +#define BOX32(x1,y1,x2,y2) { x1, y1, x2, y2 } #define QUAD(x1,y1,x2,y2) { { x1, y1 }, { x2, y1 }, { x2, y2 }, { x1, y2 } } struct vertex_clip_test_data { - struct clipper_vertex box[2]; + union { + struct clipper_vertex box[2]; /* Common clipping API. */ + struct pixman_box32 box32; /* Pixman clipping API. */ + }; struct clipper_vertex polygon[8]; struct clipper_vertex clipped[8]; int polygon_n; @@ -723,6 +727,59 @@ TEST_P(quad_clip_expected, quad_clip_expected_data) assert_vertices(clipped, clipped_n, tdata->clipped, tdata->clipped_n); } +/* clipper_quad_clip_box32() tests: */ + +static const struct vertex_clip_test_data quad_clip_box32_expected_data[] = { + /* Box bottom/right corner intersects polygon top/left corner. */ + { + .aligned = true, + .box32 = BOX32(-3, -3, -1, -1), + .polygon = QUAD (-2.5f, -2.5f, 2.5f, 2.5f), + .clipped = QUAD (-2.5f, -2.5f, -1.0f, -1.0f), + .clipped_n = 4, + }, + + /* Box bottom/left corner intersects polygon top/right corner. */ + { + .aligned = true, + .box32 = BOX32( 1, -3, 3, -1), + .polygon = QUAD (-2.5f, -2.5f, 2.5f, 2.5f), + .clipped = QUAD ( 1.0f, -2.5f, 2.5f, -1.0f), + .clipped_n = 4, + }, + + /* Box top/right corner intersects polygon bottom/left corner. */ + { + .aligned = true, + .box32 = BOX32(-3, 1, -1, 3), + .polygon = QUAD (-2.5f, -2.5f, 2.5f, 2.5f), + .clipped = QUAD (-2.5f, 1.0f, -1.0f, 2.5f), + .clipped_n = 4, + }, + + /* Box top/left corner intersects polygon bottom/right corner. */ + { + .aligned = true, + .box32 = BOX32( 1, 1, 3, 3), + .polygon = QUAD (-2.5f, -2.5f, 2.5f, 2.5f), + .clipped = QUAD ( 1.0f, 1.0f, 2.5f, 2.5f), + .clipped_n = 4, + }, +}; + +TEST_P(quad_clip_box32_expected, quad_clip_box32_expected_data) +{ + struct vertex_clip_test_data *tdata = data; + struct clipper_vertex clipped[8]; + struct clipper_quad quad; + int clipped_n; + + clipper_quad_init(&quad, tdata->polygon, tdata->aligned); + clipped_n = clipper_quad_clip_box32(&quad, &tdata->box32, clipped); + + assert_vertices(clipped, clipped_n, tdata->clipped, tdata->clipped_n); +} + /* clipper_float_difference() tests: */ TEST(float_difference_different)