Graphviz  2.29.20120524.0446
lib/common/geomprocs.h
Go to the documentation of this file.
00001 /* $Id$ $Revision$ */
00002 /* vim:set shiftwidth=4 ts=8: */
00003 
00004 /*************************************************************************
00005  * Copyright (c) 2011 AT&T Intellectual Property 
00006  * All rights reserved. This program and the accompanying materials
00007  * are made available under the terms of the Eclipse Public License v1.0
00008  * which accompanies this distribution, and is available at
00009  * http://www.eclipse.org/legal/epl-v10.html
00010  *
00011  * Contributors: See CVS logs. Details at http://www.graphviz.org/
00012  *************************************************************************/
00013 
00014 /* geometric functions (e.g. on points and boxes) with application to, but
00015  * no specific dependance on graphs */
00016 
00017 #ifndef GV_GEOMPROCS_H
00018 #define GV_GEOMPROCS_H
00019 
00020 #ifdef __cplusplus
00021 extern "C" {
00022 #endif
00023 
00024 
00025 #include "geom.h"
00026 
00027 #ifdef WIN32
00028 #ifdef GVDLL
00029 #define extern __declspec(dllexport)
00030 #else
00031 #define extern __declspec(dllimport)
00032 #endif
00033 #endif  
00034 
00035 extern box mkbox(point p, point q);
00036 extern boxf mkboxf(pointf p, pointf q);
00037 
00038 extern box flip_rec_box(box b, point p);
00039 extern boxf flip_rec_boxf(boxf b, pointf p);
00040 
00041 extern double ptToLine2 (pointf l1, pointf l2, pointf p);
00042 
00043 extern int lineToBox(pointf p1, pointf p2, boxf b);
00044 
00045 extern point ccwrotatep(point p, int ccwrot);
00046 extern pointf ccwrotatepf(pointf p, int ccwrot);
00047 
00048 extern point cwrotatep(point p, int cwrot);
00049 extern pointf cwrotatepf(pointf p, int cwrot);
00050 
00051 extern void rect2poly(pointf *p);
00052 
00053 extern int line_intersect (pointf a, pointf b, pointf c, pointf d, pointf* p);
00054 
00055 #if defined(MSWIN32) || defined(WIN32)
00056 #define inline __inline
00057 #endif
00058 
00059 
00060 static inline point pointof(int x, int y)
00061 {
00062     point r;
00063 
00064     r.x = x;
00065     r.y = y;
00066     return r;
00067 }
00068 
00069 static inline pointf pointfof(double x, double y)
00070 {
00071     pointf r;
00072 
00073     r.x = x;
00074     r.y = y;
00075     return r;
00076 }
00077 
00078 static inline box boxof(int llx, int lly, int urx, int ury)
00079 {
00080     box b;
00081 
00082     b.LL.x = llx, b.LL.y = lly;
00083     b.UR.x = urx, b.UR.y = ury;
00084     return b;
00085 }
00086 
00087 static inline boxf boxfof(double llx, double lly, double urx, double ury)
00088 {
00089     boxf b;
00090 
00091     b.LL.x = llx, b.LL.y = lly;
00092     b.UR.x = urx, b.UR.y = ury;
00093     return b;
00094 }
00095 
00096 static inline point add_point(point p, point q)
00097 {
00098     point r;
00099 
00100     r.x = p.x + q.x;
00101     r.y = p.y + q.y;
00102     return r;
00103 }
00104 
00105 static inline pointf add_pointf(pointf p, pointf q)
00106 {
00107     pointf r;
00108 
00109     r.x = p.x + q.x;
00110     r.y = p.y + q.y;
00111     return r;
00112 }
00113 
00114 static inline point sub_point(point p, point q)
00115 {
00116     point r;
00117 
00118     r.x = p.x - q.x;
00119     r.y = p.y - q.y;
00120     return r;
00121 }
00122 
00123 static inline pointf sub_pointf(pointf p, pointf q)
00124 {
00125     pointf r;
00126 
00127     r.x = p.x - q.x;
00128     r.y = p.y - q.y;
00129     return r;
00130 }
00131 
00132 /* for +ve coord values, this rounds towards p */
00133 static inline point mid_point(point p, point q)
00134 {
00135     point r;
00136 
00137     r.x = (p.x + q.x) / 2;
00138     r.y = (p.y + q.y) / 2;
00139     return r;
00140 }
00141 
00142 static inline pointf mid_pointf(pointf p, pointf q)
00143 {
00144     pointf r;
00145 
00146     r.x = (p.x + q.x) / 2.;
00147     r.y = (p.y + q.y) / 2.;
00148     return r;
00149 }
00150 
00151 static inline pointf interpolate_pointf(double t, pointf p, pointf q)
00152 {
00153     pointf r; 
00154 
00155     r.x = p.x + t * (q.x - p.x);
00156     r.y = p.y + t * (q.y - p.y);
00157     return r;
00158 }
00159 
00160 static inline point exch_xy(point p)
00161 {
00162     point r;
00163 
00164     r.x = p.y;
00165     r.y = p.x;
00166     return r;
00167 }
00168 
00169 static inline pointf exch_xyf(pointf p)
00170 {
00171     pointf r;
00172 
00173     r.x = p.y;
00174     r.y = p.x;
00175     return r;
00176 }
00177 
00178 static inline box box_bb(box b0, box b1)
00179 {
00180     box b;
00181 
00182     b.LL.x = MIN(b0.LL.x, b1.LL.x);
00183     b.LL.y = MIN(b0.LL.y, b1.LL.y);
00184     b.UR.x = MAX(b0.UR.x, b1.UR.x);
00185     b.UR.y = MAX(b0.UR.y, b1.UR.y);
00186 
00187     return b;
00188 }
00189 
00190 static inline boxf boxf_bb(boxf b0, boxf b1)
00191 {
00192     boxf b;
00193 
00194     b.LL.x = MIN(b0.LL.x, b1.LL.x);
00195     b.LL.y = MIN(b0.LL.y, b1.LL.y);
00196     b.UR.x = MAX(b0.UR.x, b1.UR.x);
00197     b.UR.y = MAX(b0.UR.y, b1.UR.y);
00198 
00199     return b;
00200 }
00201 
00202 static inline box box_intersect(box b0, box b1)
00203 {
00204     box b;
00205 
00206     b.LL.x = MAX(b0.LL.x, b1.LL.x);
00207     b.LL.y = MAX(b0.LL.y, b1.LL.y);
00208     b.UR.x = MIN(b0.UR.x, b1.UR.x);
00209     b.UR.y = MIN(b0.UR.y, b1.UR.y);
00210 
00211     return b;
00212 }
00213 
00214 static inline boxf boxf_intersect(boxf b0, boxf b1)
00215 {
00216     boxf b;
00217 
00218     b.LL.x = MAX(b0.LL.x, b1.LL.x);
00219     b.LL.y = MAX(b0.LL.y, b1.LL.y);
00220     b.UR.x = MIN(b0.UR.x, b1.UR.x);
00221     b.UR.y = MIN(b0.UR.y, b1.UR.y);
00222 
00223     return b;
00224 }
00225 
00226 static inline int box_overlap(box b0, box b1)
00227 {
00228     return OVERLAP(b0, b1);
00229 }
00230 
00231 static inline int boxf_overlap(boxf b0, boxf b1)
00232 {
00233     return OVERLAP(b0, b1);
00234 }
00235 
00236 static inline int box_contains(box b0, box b1)
00237 {
00238     return CONTAINS(b0, b1);
00239 }
00240 
00241 static inline int boxf_contains(boxf b0, boxf b1)
00242 {
00243     return CONTAINS(b0, b1);
00244 }
00245 
00246 static inline pointf perp (pointf p)
00247 {
00248     pointf r;
00249 
00250     r.x = -p.y;
00251     r.y = p.x;
00252     return r;
00253 }
00254 
00255 static inline pointf scale (double c, pointf p)
00256 {
00257     pointf r;
00258 
00259     r.x = c * p.x;
00260     r.y = c * p.y;
00261     return r;
00262 }
00263 #ifdef WIN32_STATIC
00264 #undef inline
00265 #endif
00266 
00267 #undef extern
00268 #ifdef __cplusplus
00269 }
00270 #endif
00271 
00272 #endif