split sched.c
convert source tree

typedef struct pset_vertex_s
{
    s32_t vertex;
    s32_t edge;
    /* face on the right side of edge or -1 if none */
    s32_t face_on_right; /* FIXME: may be more than one */
}   pset_vertex_t, pset_vertex_p;
    
typedef struct pset_face_s
{
    /* indices of upper and lower brushes or -1 if none */
    s32_t   upper_brush, lower_brush;
    s32_t   num_vertices;
    /* variable-sized counter-clockwise list of vertices */
    pset_vertex_t   vertices;
}   pset_face_t;

/*
 * Returns index of edge or -1 if not found
 */
s32_t polyset_find_edge(s32_stack_p list,s32_t v1,s32_t v2)
{
    s32_t i, cv1, cv2;
    for(i=0;i<s32sCount(list);i+=2)
    {
        if(s32sGet(list,i)==v1 && s32sGet(list,i+1)==v2)
            return (s32_t)(i >> 1);
    }
    return -1;
}

/*
 * Inserts edge (if new), returns its index in list
 */
s32_t insert_new_edge(s32_stack_p list,s32_t v1,s32_t v2)
{
    s32_t pos = polyset_find_edge(list,v1,v2);
    if(pos != -1)
        return pos;
    pos = (s32_t)(s32sCount(list) >> 1);
    s32sPush(list,v1);
    s32sPush(list,v2);
    return pos;
}

/*
 * Builds list of edges, for each face fills .edge array,
 * returns total number of edges
 */
s32_t build_polyset_edge_list(polyset_p pset,s32_stack_p list)
{
    s32_t f,v,v1,v2,t;
    polyset_face_p face;
    s32sClear(list);
    for(f=0;f<pset->num_faces;f++)
    {
        face = &pset->faces[f];
        for(v=0;v<face->num_vertices;v++)
        {
            v1 = face->vertex[i];
            v2 = face->vertex[(i+1) % face->num_vertices];
            if(v1 > v2)
            {
                t = v1;
                v1 = v2;
                v2 = 1;
            }
            face->edge[i] = insert_new_edge(list,v1,v2);
        }
    }
    return s32sCount(list);
}

/*
 * Builds list of brushes, for each face fills 'upper_brush' and 'lower_brush'.
 * Returns number of brushes.
 */

TODO: implement this (very complex) CSG routine !

