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

Go to the documentation of this file.
00001 /* $Id: geometry.c,v 1.1.1.1 2004/12/23 04:05:11 ellson Exp $ $Revision: 1.1.1.1 $ */
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 "geometry.h"
00018 #include <math.h>
00019 
00020 
00021 Point origin = { 0, 0 };
00022 
00023 double xmin, xmax, ymin, ymax;  /* min and max x and y values of sites */
00024 double deltax,                  /* xmax - xmin */
00025  deltay;                        /* ymax - ymin */
00026 
00027 int nsites;
00028 int sqrt_nsites;
00029 
00030 void geominit()
00031 {
00032     double sn;
00033 
00034     sn = nsites + 4;
00035     sqrt_nsites = (int) sqrt(sn);
00036     /* deltay = ymax - ymin; */
00037     /* deltax = xmax - xmin; */
00038 }
00039 
00040 double dist_2(Point * pp, Point * qp)
00041 {
00042     double dx = pp->x - qp->x;
00043     double dy = pp->y - qp->y;
00044 
00045     return (dx * dx + dy * dy);
00046 }
00047 
00048 void subPt(Point * a, Point b, Point c)
00049 {
00050     a->x = b.x - c.x;
00051     a->y = b.y - c.y;
00052 }
00053 
00054 void addPt(Point * c, Point a, Point b)
00055 {
00056     c->x = a.x + b.x;
00057     c->y = a.y + b.y;
00058 }
00059 
00060 double area_2(Point a, Point b, Point c)
00061 {
00062     return ((a.y - b.y) * (c.x - b.x) - (c.y - b.y) * (a.x - b.x));
00063 }
00064 
00065 int leftOf(Point a, Point b, Point c)
00066 {
00067     return (area_2(a, b, c) > 0);
00068 }
00069 
00070 int intersection(Point a, Point b, Point c, Point d, Point * p)
00071 {
00072     double s, t;                /* The two parameters of the parametric eqns. */
00073     double denom;               /* Denominator of solutions. */
00074 
00075     denom =
00076         a.x * (d.y - c.y) +
00077         b.x * (c.y - d.y) + d.x * (b.y - a.y) + c.x * (a.y - b.y);
00078 
00079     /* If denom is zero, then the line segments are parallel. */
00080     /* In this case, return false even though the segments might overlap. */
00081     if (denom == 0.0)
00082         return 0;
00083 
00084     s = (a.x * (d.y - c.y) + c.x * (a.y - d.y) + d.x * (c.y - a.y)
00085         ) / denom;
00086     t = -(a.x * (c.y - b.y) + b.x * (a.y - c.y) + c.x * (b.y - a.y)
00087         ) / denom;
00088 
00089     p->x = a.x + s * (b.x - a.x);
00090     p->y = a.y + s * (b.y - a.y);
00091 
00092     if ((0.0 <= s) && (s <= 1.0) && (0.0 <= t) && (t <= 1.0))
00093         return 1;
00094     else
00095         return 0;
00096 }

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