From 8cfbdf2f02ba01d5638a91c9f3f7fc228b402caa Mon Sep 17 00:00:00 2001 From: Chris Wilson Date: Fri, 8 Feb 2013 13:10:25 +0000 Subject: [PATCH] polygon: Only rely on the computed boundary intersections for crossing edges If we need to extrapolate the edge to the boundary, then we run the risk of an overflow for an immaterial result. So if the edge does not cross the boundary, we can simply use the corresponding end-point and not emit the boundary segment. Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=60489 Signed-off-by: Chris Wilson --- src/cairo-polygon.c | 35 +++++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/src/cairo-polygon.c b/src/cairo-polygon.c index c714b32ad..4c5861df4 100644 --- a/src/cairo-polygon.c +++ b/src/cairo-polygon.c @@ -420,11 +420,14 @@ _add_clipped_edge (cairo_polygon_t *polygon, * inside the box if it is clipped to this vertical range. */ - top_left_to_bottom_right = (p1->x < p2->x) == (p1->y < p2->y); - + top_left_to_bottom_right = (p1->x <= p2->x) == (p1->y <= p2->y); if (top_left_to_bottom_right) { - if (_cairo_edge_compute_intersection_x_for_y (p1, p2, left_y) < limits->p1.x) - left_y++; + if (pleft >= limits->p1.x) { + left_y = top_y; + } else { + if (_cairo_edge_compute_intersection_x_for_y (p1, p2, left_y) < limits->p1.x) + left_y++; + } left_y = MIN (left_y, bot_y); if (top_y < left_y) { @@ -434,8 +437,12 @@ _add_clipped_edge (cairo_polygon_t *polygon, top_y = left_y; } - if (_cairo_edge_compute_intersection_x_for_y (p1, p2, right_y) > limits->p1.y) - right_y--; + if (pright <= limits->p2.x) { + right_y = bot_y; + } else { + if (_cairo_edge_compute_intersection_x_for_y (p1, p2, right_y) > limits->p2.x) + right_y--; + } right_y = MAX (right_y, top_y); if (bot_y > right_y) { @@ -445,8 +452,12 @@ _add_clipped_edge (cairo_polygon_t *polygon, bot_y = right_y; } } else { - if (_cairo_edge_compute_intersection_x_for_y (p1, p2, right_y) > limits->p2.x) - right_y++; + if (pright <= limits->p2.x) { + right_y = top_y; + } else { + if (_cairo_edge_compute_intersection_x_for_y (p1, p2, right_y) > limits->p2.x) + right_y++; + } right_y = MIN (right_y, bot_y); if (top_y < right_y) { @@ -456,8 +467,12 @@ _add_clipped_edge (cairo_polygon_t *polygon, top_y = right_y; } - if (_cairo_edge_compute_intersection_x_for_y (p1, p2, left_y) < limits->p1.x) - left_y--; + if (pleft >= limits->p1.x) { + left_y = bot_y; + } else { + if (_cairo_edge_compute_intersection_x_for_y (p1, p2, left_y) < limits->p1.x) + left_y--; + } left_y = MAX (left_y, top_y); if (bot_y > left_y) {