self-intersecting.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*
  2. * Copyright © 2005 Red Hat, Inc.
  3. *
  4. * Permission to use, copy, modify, distribute, and sell this software
  5. * and its documentation for any purpose is hereby granted without
  6. * fee, provided that the above copyright notice appear in all copies
  7. * and that both that copyright notice and this permission notice
  8. * appear in supporting documentation, and that the name of
  9. * Red Hat, Inc. not be used in advertising or publicity pertaining to
  10. * distribution of the software without specific, written prior
  11. * permission. Red Hat, Inc. makes no representations about the
  12. * suitability of this software for any purpose. It is provided "as
  13. * is" without express or implied warranty.
  14. *
  15. * RED HAT, INC. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
  16. * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
  17. * FITNESS, IN NO EVENT SHALL RED HAT, INC. BE LIABLE FOR ANY SPECIAL,
  18. * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
  19. * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
  20. * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
  21. * IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  22. *
  23. * Author: Carl D. Worth <cworth@cworth.org>
  24. */
  25. /* Bug history
  26. *
  27. * 2005-06-01 Carl Worth <cworth@cworth.org>
  28. *
  29. * There's a long-standing bug in that self-intersecting paths give
  30. * an incorrect result when stroked. The problem is that the
  31. * trapezoids are generated incrementally along the stroke and as
  32. * such, are not disjoint. The errant intersections of these
  33. * trapezoids then leads to overfilled pixels.
  34. *
  35. * The test belows first creates and fills a path. Then it creates a
  36. * second path which has a stroked boundary identical to the first
  37. * filled path. But the results of the two operations are
  38. * different. The most obvious difference is in the central region
  39. * where the entire path intersects itself. But notice that every
  40. * time the path turns there are also errors on the inside of the
  41. * turn, (since the subsequent trapezoids along the path intersect).
  42. */
  43. #include "cairo-test.h"
  44. static cairo_test_status_t
  45. draw (cairo_t *cr, int width, int height)
  46. {
  47. cairo_set_source_rgb (cr, 1, 1, 1);
  48. cairo_paint (cr);
  49. cairo_translate (cr, 1.0, 1.0);
  50. cairo_set_source_rgb (cr, 1, 0, 0); /* red */
  51. /* First draw the desired shape with a fill */
  52. cairo_rectangle (cr, 0.5, 0.5, 4.0, 4.0);
  53. cairo_rectangle (cr, 3.5, 3.5, 4.0, 4.0);
  54. cairo_rectangle (cr, 3.5, 1.5, -2.0, 2.0);
  55. cairo_rectangle (cr, 6.5, 4.5, -2.0, 2.0);
  56. cairo_fill (cr);
  57. /* Then try the same thing with a stroke */
  58. cairo_translate (cr, 0, 10);
  59. cairo_move_to (cr, 1.0, 1.0);
  60. cairo_rel_line_to (cr, 3.0, 0.0);
  61. cairo_rel_line_to (cr, 0.0, 6.0);
  62. cairo_rel_line_to (cr, 3.0, 0.0);
  63. cairo_rel_line_to (cr, 0.0, -3.0);
  64. cairo_rel_line_to (cr, -6.0, 0.0);
  65. cairo_close_path (cr);
  66. cairo_set_line_width (cr, 1.0);
  67. cairo_stroke (cr);
  68. return CAIRO_TEST_SUCCESS;
  69. }
  70. CAIRO_TEST (self_intersecting,
  71. "Test strokes of self-intersecting paths"
  72. "\nSelf-intersecting strokes are wrong due to incremental trapezoidization.",
  73. "stroke, trap", /* keywords */
  74. NULL, /* requirements */
  75. 10, 20,
  76. NULL, draw)