diff --git a/libweston/vertex-clipping.c b/libweston/vertex-clipping.c index 7f659e189..4de172e4e 100644 --- a/libweston/vertex-clipping.c +++ b/libweston/vertex-clipping.c @@ -374,7 +374,7 @@ clipper_quad_clip(struct clipper_quad *quad, vertices[i].y = CLIP(quad->polygon[i].y, box[0].y, box[1].y); } - if ((vertices[0].x != vertices[1].x) && + if ((vertices[0].x != vertices[2].x) && (vertices[0].y != vertices[2].y)) return 4; else diff --git a/tests/vertex-clip-test.c b/tests/vertex-clip-test.c index 543143eb7..0c0be6769 100644 --- a/tests/vertex-clip-test.c +++ b/tests/vertex-clip-test.c @@ -583,17 +583,99 @@ static const struct vertex_clip_test_data quad_clip_expected_data[] = { .clipped_n = 5, }, - /* Miscellaneous cases: */ + /* Box intersects entire smaller aligned quad of different winding + * orders and first edge orientations: */ - /* Box intersects entire smaller aligned quad. */ + /* Clockwise winding and top/left initial vertex. */ { .aligned = true, - .box = BOX (-0.50f, -0.50f, 0.50f, 0.50f), - .polygon = QUAD(-0.25f, -0.25f, 0.25f, 0.25f), - .clipped = QUAD(-0.25f, -0.25f, 0.25f, 0.25f), + .box = BOX(-0.50f, -0.50f, 0.50f, 0.50f), + .polygon = {{-0.25f, -0.25f}, { 0.25f, -0.25f}, + { 0.25f, 0.25f}, {-0.25f, 0.25f}}, + .clipped = {{-0.25f, -0.25f}, { 0.25f, -0.25f}, + { 0.25f, 0.25f}, {-0.25f, 0.25f}}, .clipped_n = 4, }, + /* Clockwise winding and top/right initial vertex. */ + { + .aligned = true, + .box = BOX(-0.50f, -0.50f, 0.50f, 0.50f), + .polygon = {{ 0.25f, -0.25f}, { 0.25f, 0.25f}, + {-0.25f, 0.25f}, {-0.25f, -0.25f}}, + .clipped = {{ 0.25f, -0.25f}, { 0.25f, 0.25f}, + {-0.25f, 0.25f}, {-0.25f, -0.25f}}, + .clipped_n = 4, + }, + + /* Clockwise winding and bottom/right initial vertex. */ + { + .aligned = true, + .box = BOX(-0.50f, -0.50f, 0.50f, 0.50f), + .polygon = {{ 0.25f, 0.25f}, {-0.25f, 0.25f}, + {-0.25f, -0.25f}, { 0.25f, -0.25f}}, + .clipped = {{ 0.25f, 0.25f}, {-0.25f, 0.25f}, + {-0.25f, -0.25f}, { 0.25f, -0.25f}}, + .clipped_n = 4, + }, + + /* Clockwise winding and bottom/left initial vertex. */ + { + .aligned = true, + .box = BOX(-0.50f, -0.50f, 0.50f, 0.50f), + .polygon = {{-0.25f, 0.25f}, {-0.25f, -0.25f}, + { 0.25f, -0.25f}, { 0.25f, 0.25f}}, + .clipped = {{-0.25f, 0.25f}, {-0.25f, -0.25f}, + { 0.25f, -0.25f}, { 0.25f, 0.25f}}, + .clipped_n = 4, + }, + + /* Counter-clockwise winding and top/left initial vertex. */ + { + .aligned = true, + .box = BOX(-0.50f, -0.50f, 0.50f, 0.50f), + .polygon = {{-0.25f, -0.25f}, {-0.25f, 0.25f}, + { 0.25f, 0.25f}, { 0.25f, -0.25f}}, + .clipped = {{-0.25f, -0.25f}, {-0.25f, 0.25f}, + { 0.25f, 0.25f}, { 0.25f, -0.25f}}, + .clipped_n = 4, + }, + + /* Counter-clockwise winding and top/right initial vertex. */ + { + .aligned = true, + .box = BOX(-0.50f, -0.50f, 0.50f, 0.50f), + .polygon = {{ 0.25f, -0.25f}, {-0.25f, -0.25f}, + {-0.25f, 0.25f}, { 0.25f, 0.25f}}, + .clipped = {{ 0.25f, -0.25f}, {-0.25f, -0.25f}, + {-0.25f, 0.25f}, { 0.25f, 0.25f}}, + .clipped_n = 4, + }, + + /* Counter-clockwise winding and bottom/right initial vertex. */ + { + .aligned = true, + .box = BOX(-0.50f, -0.50f, 0.50f, 0.50f), + .polygon = {{ 0.25f, 0.25f}, { 0.25f, -0.25f}, + {-0.25f, -0.25f}, {-0.25f, 0.25f}}, + .clipped = {{ 0.25f, 0.25f}, { 0.25f, -0.25f}, + {-0.25f, -0.25f}, {-0.25f, 0.25f}}, + .clipped_n = 4, + }, + + /* Counter-clockwise winding and bottom/left initial vertex. */ + { + .aligned = true, + .box = BOX(-0.50f, -0.50f, 0.50f, 0.50f), + .polygon = {{-0.25f, 0.25f}, { 0.25f, 0.25f}, + { 0.25f, -0.25f}, {-0.25f, -0.25f}}, + .clipped = {{-0.25f, 0.25f}, { 0.25f, 0.25f}, + { 0.25f, -0.25f}, {-0.25f, -0.25f}}, + .clipped_n = 4, + }, + + /* Miscellaneous cases: */ + /* Box intersects entire same size aligned quad. */ { .aligned = true,