- horizontal_t*h = &horiz->data[t];
-#ifdef DEBUG
- fprintf(stderr, "horizontal (y=%.2f): %.2f -> %.2f dir=%s fs=%p\n",
- h->y * status->gridsize,
- h->x1 * status->gridsize,
- h->x2 * status->gridsize,
- h->dir==DIR_UP?"up":"down", h->fs);
-#endif
- assert(h->y == status->y);
- assert(xrow_contains(status->xrow, h->x1));
- assert(xrow_contains(status->xrow, h->x2));
-
- int pos = xrow_find(status->xrow, h->x1);
- int x = h->x1;
- assert(pos <= status->xrow->num);
- assert(pos == status->xrow->num || status->xrow->x[pos] > x);
-
- while(x < h->x2) {
- int next_x = pos < status->xrow->num ? status->xrow->x[pos] : h->x2;
- pos++;
-
- assert(next_x > x);
-
- point_t p1 = {x,h->y};
- point_t p2 = {next_x,h->y};
- segment_t* left = actlist_find(status->actlist, p1, p2);
- assert(!left || left->fs_out_ok);
-#ifdef DEBUG
- fprintf(stderr, " fragment %.2f..%.2f edge=%08x\n",
- x * status->gridsize,
- next_x * status->gridsize,
- h->fs);
- if(left) {
- fprintf(stderr, " segment [%d] (%.2f,%.2f -> %.2f,%2f, at %.2f,%.2f) is to the left\n",
- SEGNR(left),
- left->a.x * status->gridsize,
- left->a.y * status->gridsize,
- left->b.x * status->gridsize,
- left->b.y * status->gridsize,
- left->pos.x * status->gridsize,
- left->pos.y * status->gridsize
- );
- /* this segment might be a distance away from the left point
- of the horizontal line if the horizontal line belongs to a stroke
- with segments that just ended (so this horizontal line appears to
- be "floating in space" from our current point of view)
- assert(left->pos.y == h->y && left->pos.x == h->x1);
- */
- }
-#endif
- windstate_t below = left?left->wind:status->windrule->start(status->context);
- windstate_t above = status->windrule->add(status->context, below, h->fs, h->dir, h->polygon_nr);
- edgestyle_t*fs = status->windrule->diff(&above, &below);
-
- segment_dir_t dir = above.is_filled?DIR_DOWN:DIR_UP;
- if(fs) {
- //append_stroke(status, p1, p2, DIR_INVERT(h->dir), fs);
- append_stroke(status, p1, p2, dir, fs);
- }
+ assert(horiz->data[t].x1 != horiz->data[t].x2);
+ e.events[e.num].x = horiz->data[t].x1;
+ e.events[e.num].h = &horiz->data[t];
+ e.events[e.num].type = hevent_start;
+ e.num++;
+ e.events[e.num].x = horiz->data[t].x2;
+ e.events[e.num].h = &horiz->data[t];
+ e.events[e.num].type = hevent_end;
+ e.num++;
+ }
+ for(t=0;t<xrow->num;t++) {
+ e.events[e.num].x = status->xrow->x[t];
+ e.events[e.num].h = 0;
+ e.events[e.num].type = hevent_hotpixel;
+ e.num++;
+ }
+ qsort(e.events, e.num, sizeof(hevent_t), compare_hevents);
+ return e;
+
+}
+
+static void process_horizontals(status_t*status)
+{
+ horizdata_t*horiz = &status->horiz;
+
+ if(!horiz->num)
+ return;
+
+ hevents_t events = hevents_fill(status);
+ int num_open = 0;
+ horizontal_t**open = malloc(sizeof(horizontal_t*)*horiz->num);
+
+ int s,t;
+ for(t=0;t<events.num;t++) {
+ hevent_t*e = &events.events[t];
+ switch(e->type) {
+ case hevent_start:
+ e->h->pos = num_open;
+ open[num_open++] = e->h;