tests: Add box32 quad clipper tests

Add a few tests ensuring the box32 quad clipping wrapper works as
expected.

Signed-off-by: Loïc Molinari <loic.molinari@collabora.com>
This commit is contained in:
Loïc Molinari 2023-08-09 17:27:22 +02:00 committed by Pekka Paalanen
parent e82ce8032c
commit 5516527f2b
2 changed files with 59 additions and 2 deletions

View File

@ -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)

View File

@ -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)