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

Go to the documentation of this file.
00001 /* $Id: voronoi.c,v 1.2 2005/02/24 00:57:33 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 #include "mem.h"
00018 #include "geometry.h"
00019 #include "edges.h"
00020 #include "hedges.h"
00021 #include "heap.h"
00022 #include "voronoi.h"
00023 
00024 
00025 void voronoi(int triangulate, Site * (*nextsite) (void))
00026 {
00027     Site *newsite, *bot, *top, *temp, *p;
00028     Site *v;
00029     Point newintstar;
00030     char pm;
00031     Halfedge *lbnd, *rbnd, *llbnd, *rrbnd, *bisector;
00032     Edge *e;
00033 
00034     edgeinit();
00035     siteinit();
00036     PQinitialize();
00037     bottomsite = (*nextsite) ();
00038 #ifdef STANDALONE
00039     out_site(bottomsite);
00040 #endif
00041     ELinitialize();
00042 
00043     newsite = (*nextsite) ();
00044     while (1) {
00045         if (!PQempty())
00046             newintstar = PQ_min();
00047 
00048         if (newsite != (struct Site *) NULL && (PQempty()
00049                                                 || newsite->coord.y <
00050                                                 newintstar.y
00051                                                 || (newsite->coord.y ==
00052                                                     newintstar.y
00053                                                     && newsite->coord.x <
00054                                                     newintstar.x))) {
00055             /* new site is smallest */
00056 #ifdef STANDALONE
00057             out_site(newsite);
00058 #endif
00059             lbnd = ELleftbnd(&(newsite->coord));
00060             rbnd = ELright(lbnd);
00061             bot = rightreg(lbnd);
00062             e = bisect(bot, newsite);
00063             bisector = HEcreate(e, le);
00064             ELinsert(lbnd, bisector);
00065             if ((p = hintersect(lbnd, bisector)) != (struct Site *) NULL) {
00066                 PQdelete(lbnd);
00067                 PQinsert(lbnd, p, dist(p, newsite));
00068             }
00069             lbnd = bisector;
00070             bisector = HEcreate(e, re);
00071             ELinsert(lbnd, bisector);
00072             if ((p = hintersect(bisector, rbnd)) != (struct Site *) NULL)
00073                 PQinsert(bisector, p, dist(p, newsite));
00074             newsite = (*nextsite) ();
00075         } else if (!PQempty()) {
00076             /* intersection is smallest */
00077             lbnd = PQextractmin();
00078             llbnd = ELleft(lbnd);
00079             rbnd = ELright(lbnd);
00080             rrbnd = ELright(rbnd);
00081             bot = leftreg(lbnd);
00082             top = rightreg(rbnd);
00083 #ifdef STANDALONE
00084             out_triple(bot, top, rightreg(lbnd));
00085 #endif
00086             v = lbnd->vertex;
00087             makevertex(v);
00088             endpoint(lbnd->ELedge, lbnd->ELpm, v);
00089             endpoint(rbnd->ELedge, rbnd->ELpm, v);
00090             ELdelete(lbnd);
00091             PQdelete(rbnd);
00092             ELdelete(rbnd);
00093             pm = le;
00094             if (bot->coord.y > top->coord.y) {
00095                 temp = bot;
00096                 bot = top;
00097                 top = temp;
00098                 pm = re;
00099             }
00100             e = bisect(bot, top);
00101             bisector = HEcreate(e, pm);
00102             ELinsert(llbnd, bisector);
00103             endpoint(e, re - pm, v);
00104             deref(v);
00105             if ((p = hintersect(llbnd, bisector)) != (struct Site *) NULL) {
00106                 PQdelete(llbnd);
00107                 PQinsert(llbnd, p, dist(p, bot));
00108             }
00109             if ((p = hintersect(bisector, rrbnd)) != (struct Site *) NULL) {
00110                 PQinsert(bisector, p, dist(p, bot));
00111             }
00112         } else
00113             break;
00114     }
00115 
00116     for (lbnd = ELright(ELleftend); lbnd != ELrightend;
00117          lbnd = ELright(lbnd)) {
00118         e = lbnd->ELedge;
00119         clip_line(e);
00120 #ifdef STANDALONE
00121         out_ep(e);
00122 #endif
00123     }
00124 }

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