annotate toolboxes/graph_visualisation/include/graphviz/geom.h @ 0:e9a9cd732c1e tip

first hg version after svn
author wolffd
date Tue, 10 Feb 2015 15:05:51 +0000
parents
children
rev   line source
wolffd@0 1 /* $Id: geom.h,v 1.14 2009/06/03 01:10:52 ellson Exp $ $Revision: 1.14 $ */
wolffd@0 2 /* vim:set shiftwidth=4 ts=8: */
wolffd@0 3
wolffd@0 4 /**********************************************************
wolffd@0 5 * This software is part of the graphviz package *
wolffd@0 6 * http://www.graphviz.org/ *
wolffd@0 7 * *
wolffd@0 8 * Copyright (c) 1994-2004 AT&T Corp. *
wolffd@0 9 * and is licensed under the *
wolffd@0 10 * Common Public License, Version 1.0 *
wolffd@0 11 * by AT&T Corp. *
wolffd@0 12 * *
wolffd@0 13 * Information and Software Systems Research *
wolffd@0 14 * AT&T Research, Florham Park NJ *
wolffd@0 15 **********************************************************/
wolffd@0 16
wolffd@0 17 /* geometric types and macros (e.g. points and boxes) with application to, but
wolffd@0 18 * no specific dependance on graphs */
wolffd@0 19
wolffd@0 20 #ifndef GV_GEOM_H
wolffd@0 21 #define GV_GEOM_H
wolffd@0 22
wolffd@0 23 #ifdef HAVE_CONFIG_H
wolffd@0 24 #include "arith.h"
wolffd@0 25 #endif
wolffd@0 26
wolffd@0 27 #ifdef __cplusplus
wolffd@0 28 extern "C" {
wolffd@0 29 #endif
wolffd@0 30
wolffd@0 31 typedef struct { int x, y; } point;
wolffd@0 32
wolffd@0 33 typedef struct pointf_s { double x, y; } pointf;
wolffd@0 34
wolffd@0 35 /* tell pathplan/pathgeom.h */
wolffd@0 36 #define HAVE_POINTF_S
wolffd@0 37
wolffd@0 38 typedef struct { point LL, UR; } box;
wolffd@0 39
wolffd@0 40 typedef struct { pointf LL, UR; } boxf;
wolffd@0 41
wolffd@0 42 #ifdef HAVE_CONFIG_H
wolffd@0 43
wolffd@0 44 /* true if point p is inside box b */
wolffd@0 45 #define INSIDE(p,b) (BETWEEN((b).LL.x,(p).x,(b).UR.x) && BETWEEN((b).LL.y,(p).y,(b).UR.y))
wolffd@0 46
wolffd@0 47 /* true if boxes b0 and b1 overlap */
wolffd@0 48 #define OVERLAP(b0,b1) (((b0).UR.x >= (b1).LL.x) && ((b1).UR.x >= (b0).LL.x) && ((b0).UR.y >= (b1).LL.y) && ((b1).UR.y >= (b0).LL.y))
wolffd@0 49
wolffd@0 50 /* true if box b0 completely contains b1*/
wolffd@0 51 #define CONTAINS(b0,b1) (((b0).UR.x >= (b1).UR.x) && ((b0).UR.y >= (b1).UR.y) && ((b0).LL.x <= (b1).LL.x) && ((b0).LL.y <= (b1).LL.y))
wolffd@0 52
wolffd@0 53 /* expand box b as needed to enclose point p */
wolffd@0 54 #define EXPANDBP(b, p) ((b).LL.x = MIN((b).LL.x, (p).x), (b).LL.y = MIN((b).LL.y, (p).y), (b).UR.x = MAX((b).UR.x, (p).x), (b).UR.y = MAX((b).UR.y, (p).y))
wolffd@0 55
wolffd@0 56 /* expand box b0 as needed to enclose box b1 */
wolffd@0 57 #define EXPANDBB(b0, b1) ((b0).LL.x = MIN((b0).LL.x, (b1).LL.x), (b0).LL.y = MIN((b0).LL.y, (b1).LL.y), (b0).UR.x = MAX((b0).UR.x, (b1).UR.x), (b0).UR.y = MAX((b0).UR.y, (b1).UR.y))
wolffd@0 58
wolffd@0 59 /* clip box b0 to fit box b1 */
wolffd@0 60 #define CLIPBB(b0, b1) ((b0).LL.x = MAX((b0).LL.x, (b1).LL.x), (b0).LL.y = MAX((b0).LL.y, (b1).LL.y), (b0).UR.x = MIN((b0).UR.x, (b1).UR.x), (b0).UR.y = MIN((b0).UR.y, (b1).UR.y))
wolffd@0 61
wolffd@0 62 #define LEN2(a,b) (SQR(a) + SQR(b))
wolffd@0 63 #define LEN(a,b) (sqrt(LEN2((a),(b))))
wolffd@0 64
wolffd@0 65 #define DIST2(p,q) (LEN2(((p).x - (q).x),((p).y - (q).y)))
wolffd@0 66 #define DIST(p,q) (sqrt(DIST2((p),(q))))
wolffd@0 67
wolffd@0 68 #define POINTS_PER_INCH 72
wolffd@0 69 #define POINTS_PER_PC ((double)POINTS_PER_INCH / 6)
wolffd@0 70 #define POINTS_PER_CM ((double)POINTS_PER_INCH * 0.393700787)
wolffd@0 71 #define POINTS_PER_MM ((double)POINTS_PER_INCH * 0.0393700787)
wolffd@0 72
wolffd@0 73 #define POINTS(a_inches) (ROUND((a_inches)*POINTS_PER_INCH))
wolffd@0 74 #define PS2INCH(a_points) ((a_points)/(double)POINTS_PER_INCH)
wolffd@0 75
wolffd@0 76 #define P2PF(p,pf) ((pf).x = (p).x,(pf).y = (p).y)
wolffd@0 77 #define PF2P(pf,p) ((p).x = ROUND((pf).x),(p).y = ROUND((pf).y))
wolffd@0 78
wolffd@0 79 #define B2BF(b,bf) (P2PF((b).LL,(bf).LL),P2PF((b).UR,(bf).UR))
wolffd@0 80 #define BF2B(bf,b) (PF2P((bf).LL,(b).LL),PF2P((bf).UR,(b).UR))
wolffd@0 81
wolffd@0 82 #define APPROXEQ(a,b,tol) (ABS((a) - (b)) < (tol))
wolffd@0 83 #define APPROXEQPT(p,q,tol) (DIST2((p),(q)) < SQR(tol))
wolffd@0 84
wolffd@0 85 /* some common tolerance values */
wolffd@0 86 #define MILLIPOINT .001
wolffd@0 87 #define MICROPOINT .000001
wolffd@0 88
wolffd@0 89 #endif
wolffd@0 90
wolffd@0 91 #ifdef __cplusplus
wolffd@0 92 }
wolffd@0 93 #endif
wolffd@0 94
wolffd@0 95 #endif