Test and document extents of degenerate "dots"

It's a common idiom to stroke degenerate sub-paths made with
cairo_move_to(x,y);cairo_rel_line_to(0,0) to draw dots. Test
that we get the desired extents from cairo_fill_extents,
cairo_stroke_extents, and cairo_path_extents for these cases.

Also document that the cairo_path_extents result is equivalent
to the limit of stroking with CAIRO_LINE_CAP_ROUND, (so that
these "dot" points are included), as the line width
approaches 0.0 .
This commit is contained in:
Carl Worth 2008-01-21 14:56:21 -08:00
parent 55e0dddf04
commit c480eedbb5
2 changed files with 31 additions and 3 deletions

View file

@ -1887,9 +1887,9 @@ slim_hidden_def(cairo_close_path);
* the corresponding drawing operations.
*
* The result of cairo_path_extents() is defined as equivalent to the
* limit of cairo_stroke_extents() as the line width approaches 0.0,
* (but never reaching the empty-rectangle returned by
* cairo_stroke_extents() for a line width of 0.0).
* limit of cairo_stroke_extents() with CAIRO_LINE_CAP_ROUND as the
* line width approaches 0.0, (but never reaching the empty-rectangle
* returned by cairo_stroke_extents() for a line width of 0.0).
*
* Specifically, this means that zero-area sub-paths such as
* cairo_move_to();cairo_line_to() segments, (even degenerate cases

View file

@ -166,6 +166,34 @@ draw (cairo_t *cr, int width, int height)
cairo_new_path (cr2);
cairo_restore (cr2);
/* Test that with CAIRO_LINE_CAP_ROUND, we get "dots" from
* cairo_move_to; cairo_rel_line_to(0,0) */
cairo_save (cr2);
cairo_set_line_cap (cr2, CAIRO_LINE_CAP_ROUND);
cairo_set_line_width (cr2, 20);
cairo_move_to (cr2, 200, 400);
cairo_rel_line_to (cr2, 0, 0);
phase = "Single 'dot'";
if (!check_extents (phase, cr2, FILL, EQUALS, 0, 0, 0, 0) ||
!check_extents (phase, cr2, STROKE, EQUALS, 190, 390, 20, 20) ||
!check_extents (phase, cr2, PATH, EQUALS, 200, 400, 0, 0))
ret = CAIRO_TEST_FAILURE;
/* Add another dot without starting a new path */
cairo_move_to (cr2, 100, 500);
cairo_rel_line_to (cr2, 0, 0);
phase = "Multiple 'dots'";
if (!check_extents (phase, cr2, FILL, EQUALS, 0, 0, 0, 0) ||
!check_extents (phase, cr2, STROKE, EQUALS, 90, 390, 120, 120) ||
!check_extents (phase, cr2, PATH, EQUALS, 100, 400, 100, 100))
ret = CAIRO_TEST_FAILURE;
cairo_new_path (cr2);
cairo_restore (cr2);
/* http://bugs.freedesktop.org/show_bug.cgi?id=7965 */
phase = "A vertical, open path";
cairo_save (cr2);