+ //break;
+ }
+ }
+ seg = seg->left;
+ }
+ }
+ segrange_test_segment_min(range, last, y);
+ segrange_test_segment_max(range, first, y);
+}
+
+/* segments ending in the current scanline need xrow treatment like everything else.
+ (consider an intersection taking place just above a nearly horizontal segment
+ ending on the current scanline- the intersection would snap down *below* the
+ ending segment if we don't add the intersection point to the latter right away)
+ we need to treat ending segments seperately, however. we have to delete them from
+ the active list right away to make room for intersect operations (which might
+ still be in the current scanline- consider two 45° polygons and a vertical polygon
+ intersecting on an integer coordinate). but once they're no longer in the active list,
+ we can't use the add_points_to_*_sloped_segments() functions anymore, and re-adding
+ them to the active list just for point snapping would be overkill.
+ (One other option to consider, however, would be to create a new active list only
+ for ending segments)
+*/
+static void add_points_to_ending_segments(status_t*status, int32_t y)
+{
+ segment_t*seg = status->ending_segments;
+ while(seg) {
+ segment_t*next = seg->right;seg->right=0;
+
+ assert(seg->b.y == status->y);
+
+ if(status->xrow->num == 1) {
+ // shortcut
+ assert(seg->b.x == status->xrow->x[0]);
+ point_t p = {status->xrow->x[0], y};
+ insert_point_into_segment(status, seg, p);
+ } else {
+ int t;
+ int start=0,end=status->xrow->num,dir=1;
+ if(seg->delta.x < 0) {
+ start = status->xrow->num-1;
+ end = dir = -1;
+ }
+ for(t=start;t!=end;t+=dir) {
+ box_t box = box_new(status->xrow->x[t], y);
+ double d0 = LINE_EQ(box.left1, seg);
+ double d1 = LINE_EQ(box.left2, seg);
+ double d2 = LINE_EQ(box.right1, seg);
+ double d3 = LINE_EQ(box.right2, seg);
+ if(!(d0>=0 && d1>=0 && d2>=0 && d3>0 ||
+ d0<=0 && d1<=0 && d2<=0 && d3<0)) {
+ insert_point_into_segment(status, seg, box.right2);