/misc/src/release/graphviz-2.18-1/src/graphviz-2.18/lib/neatogen/find_ints.c

Go to the documentation of this file.
00001 /* $Id: find_ints.c,v 1.2 2005/02/23 18:58:12 ellson Exp $ $Revision: 1.2 $ */
00002 /* vim:set shiftwidth=4 ts=8: */
00003 
00004 /**********************************************************
00005 *      This software is part of the graphviz package      *
00006 *                http://www.graphviz.org/                 *
00007 *                                                         *
00008 *            Copyright (c) 1994-2004 AT&T Corp.           *
00009 *                and is licensed under the                *
00010 *            Common Public License, Version 1.0           *
00011 *                      by AT&T Corp.                      *
00012 *                                                         *
00013 *        Information and Software Systems Research        *
00014 *              AT&T Research, Florham Park NJ             *
00015 **********************************************************/
00016 
00017 
00018 #include <render.h>
00019 #include "simple.h"
00020 #include <stdlib.h>
00021 
00022 extern void
00023 find_intersection(struct vertex *l,
00024                   struct vertex *m,
00025                   struct intersection ilist[], struct data *input);
00026 static int gt(struct vertex **i, struct vertex **j);
00027 
00028 void
00029 find_ints(struct vertex vertex_list[],
00030           struct polygon polygon_list[],
00031           struct data *input, struct intersection ilist[])
00032 {
00033     int i, j, k;
00034     struct active_edge_list all;
00035     struct active_edge *new, *tempa;
00036     struct vertex *pt1, *pt2, *templ, **pvertex;
00037 
00038     input->ninters = 0;
00039     all.first = all.final = 0;
00040     all.number = 0;
00041 
00042     pvertex = N_GNEW(input->nvertices, struct vertex *);
00043 
00044     for (i = 0; i < input->nvertices; i++)
00045         pvertex[i] = vertex_list + i;
00046 
00047 /* sort vertices by x coordinate        */
00048     qsort(pvertex, input->nvertices, sizeof(struct vertex *),
00049           (int (*)(const void *, const void *))gt);
00050 
00051 /* walk through the vertices in order of increasing x coordinate        */
00052     for (i = 0; i < input->nvertices; i++) {
00053         pt1 = pvertex[i];
00054         templ = pt2 = prior(pvertex[i]);
00055         for (k = 0; k < 2; k++) {       /* each vertex has 2 edges */
00056             switch (gt(&pt1, &pt2)) {
00057 
00058             case -1:            /* forward edge, test and insert      */
00059 
00060                 for (tempa = all.first, j = 0; j < all.number;
00061                      j++, tempa = tempa->next)
00062                     find_intersection(tempa->name, templ, ilist, input);        /* test */
00063 
00064                 new = GNEW(struct active_edge);
00065                 if (all.number == 0) {
00066                     all.first = new;
00067                     new->last = 0;
00068                 } /* insert */
00069                 else {
00070                     all.final->next = new;
00071                     new->last = all.final;
00072                 }
00073 
00074                 new->name = templ;
00075                 new->next = 0;
00076                 templ->active = new;
00077                 all.final = new;
00078                 all.number++;
00079 
00080                 break;          /* end of case -1       */
00081 
00082             case 1:             /* backward edge, delete        */
00083 
00084                 if ((tempa = templ->active) == 0) {
00085                     agerr(AGERR, "trying to delete a non line\n");
00086                     exit(1);
00087                 }
00088                 if (all.number == 1)
00089                     all.final = all.first = 0;  /* delete the line */
00090                 else if (tempa == all.first) {
00091                     all.first = all.first->next;
00092                     all.first->last = 0;
00093                 } else if (tempa == all.final) {
00094                     all.final = all.final->last;
00095                     all.final->next = 0;
00096                 } else {
00097                     tempa->last->next = tempa->next;
00098                     tempa->next->last = tempa->last;
00099                 }
00100                 free((char *) tempa);
00101                 all.number--;
00102                 templ->active = 0;
00103                 break;          /* end of case 1        */
00104 
00105             }                   /* end switch   */
00106 
00107             pt2 = after(pvertex[i]);
00108             templ = pvertex[i]; /*second neighbor */
00109         }                       /* end k for loop       */
00110     }                           /* end i for loop       */
00111 }
00112 
00113 static int gt(struct vertex **i, struct vertex **j)
00114 {                               /* i > j if i.x > j.x or i.x = j.x and i.y > j.y  */
00115     double t;
00116     if ((t = (*i)->pos.x - (*j)->pos.x) != 0.)
00117         return ((t > 0.) ? 1 : -1);
00118     if ((t = (*i)->pos.y - (*j)->pos.y) == 0.)
00119         return (0);
00120     else
00121         return ((t > 0.) ? 1 : -1);
00122 }

Generated on Mon Mar 31 19:03:27 2008 for Graphviz by  doxygen 1.5.1