Bug 664930 - Handle the case where an edge lies at the left most coordinate and initialize the rest of the data; r=bjacob
authorJeff Muizelaar <jmuizelaar@mozilla.com>
Fri, 12 Aug 2011 15:18:06 -0400
changeset 75262 1fc015db1f6f9d77d2a2192f8cda244809a8ea5f
parent 75261 c974f3df9aceb27062c7ef519d089e40c5fbf2f7
child 75263 55d5d141c68df188cfd0a2b5d2acab6e5936e2e4
push id2
push userbsmedberg@mozilla.com
push dateFri, 19 Aug 2011 14:38:13 +0000
reviewersbjacob
bugs664930
milestone8.0a1
Bug 664930 - Handle the case where an edge lies at the left most coordinate and initialize the rest of the data; r=bjacob
gfx/cairo/cairo/src/cairo-bentley-ottmann-rectangular.c
--- a/gfx/cairo/cairo/src/cairo-bentley-ottmann-rectangular.c
+++ b/gfx/cairo/cairo/src/cairo-bentley-ottmann-rectangular.c
@@ -264,20 +264,27 @@ sweep_line_init (sweep_line_t	 *sweep_li
     _rectangle_sort (rectangles, num_rectangles);
     rectangles[num_rectangles] = NULL;
     sweep_line->rectangles = rectangles;
 
     sweep_line->head.x = INT32_MIN;
     sweep_line->head.right = NULL;
     sweep_line->head.dir = 0;
     sweep_line->head.next = &sweep_line->tail;
+    /* we need to initialize prev so that we can check
+     * if this edge is the left most and make sure
+     * we always insert to the right of it, even if
+     * our x coordinate matches */
+    sweep_line->head.prev = NULL;
+
     sweep_line->tail.x = INT32_MAX;
     sweep_line->tail.right = NULL;
     sweep_line->tail.dir = 0;
     sweep_line->tail.prev = &sweep_line->head;
+    sweep_line->tail.next = NULL;
 
     sweep_line->insert_left = &sweep_line->tail;
     sweep_line->insert_right = &sweep_line->tail;
 
     sweep_line->current_y = INT32_MIN;
     sweep_line->last_y = INT32_MIN;
 
     sweep_line->fill_rule = fill_rule;
@@ -540,21 +547,29 @@ insert_edge (edge_t *edge, edge_t *pos)
 		UNROLL3({
 		    pos = pos->next;
 		    if (pos->x >= edge->x)
 			break;
 		})
 	    } while (TRUE);
 	}
     }
-
-    pos->prev->next = edge;
-    edge->prev = pos->prev;
-    edge->next = pos;
-    pos->prev = edge;
+    if (pos->prev) {
+        pos->prev->next = edge;
+        edge->prev = pos->prev;
+        edge->next = pos;
+        pos->prev = edge;
+    } else {
+        /* we have edge that shares an x coordinate with the left most sentinal.
+         * instead of inserting before pos and ruining our sentinal we insert after pos. */
+        pos->next->prev = edge;
+        edge->next = pos->next;
+        edge->prev = pos;
+        pos->next = edge;
+    }
 }
 
 static inline cairo_bool_t
 sweep_line_insert (sweep_line_t	*sweep,
 		   rectangle_t	*rectangle)
 {
     edge_t *pos;