home *** CD-ROM | disk | FTP | other *** search
- /*
- * queue.c -- the implements a simple depth queue, needed for CSG and
- * clips. Up to now, I no one has ever explained me how to do prioqs, so
- * I've put this together myself.
- *
- * (c) Han-Wen Nienhuys 1993, <hanwen@stack.urc.tue.nl>
- *
- * This program is free software; you can redistribute it and/or modify it
- * under; the terms of the GNU General Public License as published by the
- * Free Software Foundation;
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 675 Mass Ave, Cambridge, MA 02139, USA.
- */
-
- #include "ray.h"
- #include "proto.h"
- #include "extern.h"
-
- /*
- * insert an intersection into the queue. This is kept sorted by insertion
- * sort
- */
-
- PUBLIC void
- add_to_queue(dqueue * root, dqueue q)
- {
- dqueue *p,
- *new,
- *last;
-
-
- assert(root != NULL);
-
-
- for (p = root; p != NULL && q.t >= p->t; p = p->next)
- last = p;
-
- if (p == NULL) { /* we're at the tail of the queue */
- p = last->next = get_new_queue();
- *p = q;
- p->next = NULL;
- } else { /* insert entry before p. */
-
- /*
- * actually, we're moving the info of p to a new node, and copy
- * intersection i into p->i
- */
- new = get_new_queue();
- *new = *p;
- new->next = p->next;
- *p = q;
- p->next = new;
- }
- }
-
- PUBLIC dqueue *
- get_new_queue(void)
- {
- dqueue *p;
-
- p = ALLOC(dqueue);
-
- CHECK_MEM(p, "queue entry");
-
- p->obj = p->obj2 = NULL;
- p->t = INFTY;
- p->next = NULL;
- p->entering = FALSE;
-
- return p;
- }
-
- PUBLIC void
- free_queue(dqueue * root)
- {
- dqueue *p,
- *next;
-
- for (p = root; p != NULL; p = next) {
- next = p->next;
- free((void *) p);
- }
- }
-
- PUBLIC void
- print_queue(dqueue * root)
- {
- #ifdef DEBUG
- printf("\nQUEUE\n");
- for (; root != NULL; root = root->next) {
- printf("param t %lf, entering %d\n", root->t, root->entering);
- if (root->obj != NULL)
- print_object(root->obj);
- }
- #endif
- }
-