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

Go to the documentation of this file.
00001 /* $Id: legal.c,v 1.2 2005/02/17 15:34:31 erg 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 #include "neato.h"
00018 #include "simple.h"
00019 
00020 
00021 extern void
00022 find_ints(struct vertex vertex_list[],
00023           struct polygon polygon_list[],
00024           struct data *input, struct intersection ilist[]);
00025 int Plegal_arrangement(Ppoly_t ** polys, int n_polys)
00026 {
00027 
00028     int i, j, vno, nverts, rv;
00029 
00030     struct vertex *vertex_list;
00031     struct polygon *polygon_list;
00032     struct data input;
00033     struct intersection ilist[MAXINTS];
00034 
00035     polygon_list = N_GNEW(n_polys, struct polygon);
00036 
00037     for (i = nverts = 0; i < n_polys; i++)
00038         nverts += polys[i]->pn;
00039 
00040     vertex_list = N_GNEW(nverts, struct vertex);
00041 
00042     for (i = vno = 0; i < n_polys; i++) {
00043         polygon_list[i].start = &vertex_list[vno];
00044         for (j = 0; j < polys[i]->pn; j++) {
00045             vertex_list[vno].pos.x = polys[i]->ps[j].x;
00046             vertex_list[vno].pos.y = polys[i]->ps[j].y;
00047             vertex_list[vno].poly = &polygon_list[i];
00048             vertex_list[vno].active = 0;
00049             vno++;
00050         }
00051         polygon_list[i].finish = &vertex_list[vno - 1];
00052     }
00053 
00054     input.nvertices = nverts;
00055     input.npolygons = n_polys;
00056 
00057     find_ints(vertex_list, polygon_list, &input, ilist);
00058 
00059 
00060 #define EQ_PT(v,w) (((v).x == (w).x) && ((v).y == (w).y))
00061     rv = 1;
00062     {
00063         int i;
00064         struct position vft, vsd, avft, avsd;
00065         for (i = 0; i < input.ninters; i++) {
00066             vft = ilist[i].firstv->pos;
00067             avft = after(ilist[i].firstv)->pos;
00068             vsd = ilist[i].secondv->pos;
00069             avsd = after(ilist[i].secondv)->pos;
00070             if (((vft.x != avft.x) && (vsd.x != avsd.x)) ||
00071                 ((vft.x == avft.x) &&
00072                  !EQ_PT(vft, ilist[i]) &&
00073                  !EQ_PT(avft, ilist[i])) ||
00074                 ((vsd.x == avsd.x) &&
00075                  !EQ_PT(vsd, ilist[i]) && !EQ_PT(avsd, ilist[i]))) {
00076                 rv = 0;
00077                 if (Verbose > 1) {
00078                     fprintf(stderr, "\nintersection %d at %.3f %.3f\n",
00079                             i, ilist[i].x, ilist[i].y);
00080                     fprintf(stderr, "seg#1 : (%.3f, %.3f) (%.3f, %.3f)\n",
00081                             (double) (ilist[i].firstv->pos.x)
00082                             , (double) (ilist[i].firstv->pos.y)
00083                             , (double) (after(ilist[i].firstv)->pos.x)
00084                             , (double) (after(ilist[i].firstv)->pos.y));
00085                     fprintf(stderr, "seg#2 : (%.3f, %.3f) (%.3f, %.3f)\n",
00086                             (double) (ilist[i].secondv->pos.x)
00087                             , (double) (ilist[i].secondv->pos.y)
00088                             , (double) (after(ilist[i].secondv)->pos.x)
00089                             , (double) (after(ilist[i].secondv)->pos.y));
00090                 }
00091             }
00092         }
00093     }
00094     free(polygon_list);
00095     free(vertex_list);
00096     return rv;
00097 }

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