1 /*
2 * vim: ts=4 sw=4 et tw=0 wm=0
3 *
4 * libavoid - Fast, Incremental, Object-avoiding Line Router
5 * Copyright (C) 2004-2006 Michael Wybrow <mjwybrow@users.sourceforge.net>
6 *
7 * --------------------------------------------------------------------
8 * Much of the code in this module is based on code published with
9 * and/or described in "Computational Geometry in C" (Second Edition),
10 * Copyright (C) 1998 Joseph O'Rourke <orourke@cs.smith.edu>
11 * --------------------------------------------------------------------
12 *
13 * This library is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU Lesser General Public
15 * License as published by the Free Software Foundation; either
16 * version 2.1 of the License, or (at your option) any later version.
17 *
18 * This library is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 * Lesser General Public License for more details.
22 *
23 * You should have received a copy of the GNU Lesser General Public
24 * License along with this library; if not, write to the Free Software
25 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 *
27 */
30 #ifndef _GEOMETRY_H
31 #define _GEOMETRY_H
33 #include "libavoid/geomtypes.h"
35 namespace Avoid {
38 extern double dist(const Point& a, const Point& b);
39 extern bool segmentIntersect(const Point& a, const Point& b,
40 const Point& c, const Point& d);
41 extern bool inPoly(const Polygn& poly, const Point& q);
42 extern bool inValidRegion(bool IgnoreRegions, const Point& a0,
43 const Point& a1, const Point& a2, const Point& b);
46 // Direction from vector.
47 // Looks at the position of point c from the directed segment ab and
48 // returns the following:
49 // 1 counterclockwise
50 // 0 collinear
51 // -1 clockwise
52 //
53 // Based on the code of 'AreaSign'.
54 //
55 static inline int vecDir(const Point& a, const Point& b, const Point& c)
56 {
57 double area2 = ((b.x - a.x) * (c.y - a.y)) -
58 ((c.x - a.x) * (b.y - a.y));
60 if (area2 < -0.001)
61 {
62 return -1;
63 }
64 else if (area2 > 0.001)
65 {
66 return 1;
67 }
68 return 0;
69 }
72 }
75 #endif