test-cogl-path: Test sub paths and intersections

This changes the original tests so that it splits the original path
into two sub paths. When adding a new block to the copied path it also
adds another sub path. This further stresses the path copying
mechanism and exposes a bug.

It also tests intersections by drawing a self-intersecting path and a
path with two sub-paths that overlap. Where the path overlaps it
should be inverted.
This commit is contained in:
Neil Roberts 2010-04-21 18:58:18 +01:00
parent abc64a2c67
commit fddd316986

View File

@ -75,10 +75,13 @@ on_paint (ClutterActor *actor, TestState *state)
cogl_set_source_color4ub (255, 255, 255, 255);
/* Create a path filling just a quarter of a block */
/* Create a path filling just a quarter of a block. It will use two
rectangles so that we have a sub path in the path */
cogl_path_new ();
cogl_path_rectangle (BLOCK_SIZE / 2, BLOCK_SIZE / 2,
cogl_path_rectangle (BLOCK_SIZE * 3 / 4, BLOCK_SIZE / 2,
BLOCK_SIZE, BLOCK_SIZE);
cogl_path_rectangle (BLOCK_SIZE / 2, BLOCK_SIZE / 2,
BLOCK_SIZE * 3 / 4, BLOCK_SIZE);
path_a = cogl_handle_ref (cogl_path_get ());
draw_path_at (0, 0);
@ -110,12 +113,15 @@ on_paint (ClutterActor *actor, TestState *state)
cogl_path_set (path_c);
draw_path_at (5, 0);
/* Add another rectangle to path c */
/* Add another rectangle to path c. It will be added in two halves,
one as an extension of the previous path and the other as a new
sub path */
cogl_path_set (path_c);
cogl_path_line_to (BLOCK_SIZE / 2, 0);
cogl_path_line_to (BLOCK_SIZE, 0);
cogl_path_line_to (BLOCK_SIZE, BLOCK_SIZE / 2);
cogl_path_line_to (BLOCK_SIZE * 3 / 4, 0);
cogl_path_line_to (BLOCK_SIZE * 3 / 4, BLOCK_SIZE / 2);
cogl_path_line_to (BLOCK_SIZE / 2, BLOCK_SIZE / 2);
cogl_path_rectangle (BLOCK_SIZE * 3 / 4, 0, BLOCK_SIZE, BLOCK_SIZE / 2);
draw_path_at (6, 0);
/* Draw the original path again. It should not have changed */
@ -126,6 +132,21 @@ on_paint (ClutterActor *actor, TestState *state)
cogl_handle_unref (path_b);
cogl_handle_unref (path_c);
/* Draw a self-intersecting path. The part that intersects should be
inverted */
cogl_path_rectangle (0, 0, BLOCK_SIZE, BLOCK_SIZE);
cogl_path_line_to (0, BLOCK_SIZE / 2);
cogl_path_line_to (BLOCK_SIZE / 2, BLOCK_SIZE / 2);
cogl_path_line_to (BLOCK_SIZE / 2, 0);
cogl_path_close ();
draw_path_at (8, 0);
/* Draw two sub paths. Where the paths intersect it should be
inverted */
cogl_path_rectangle (0, 0, BLOCK_SIZE, BLOCK_SIZE);
cogl_path_rectangle (BLOCK_SIZE / 2, BLOCK_SIZE / 2, BLOCK_SIZE, BLOCK_SIZE);
draw_path_at (9, 0);
verify_block (0, 0, 0x8 /* bottom right */);
verify_block (1, 0, 0xf /* all of them */);
verify_block (2, 0, 0x8 /* bottom right */);
@ -134,6 +155,8 @@ on_paint (ClutterActor *actor, TestState *state)
verify_block (5, 0, 0x8 /* bottom right */);
verify_block (6, 0, 0xa /* bottom right and top right */);
verify_block (7, 0, 0x9 /* top_left and bottom right */);
verify_block (8, 0, 0xe /* all but top left */);
verify_block (9, 0, 0x7 /* all but bottom right */);
/* Comment this out if you want visual feedback of what this test
* paints.