circles intersection and tourel beacon
[aversive.git] / modules / base / math / geometry / polygon.h
1 /*
2  *  Copyright Droids Corporation (2009)
3  *
4  *  This program is free software; you can redistribute it and/or modify
5  *  it under the terms of the GNU General Public License as published by
6  *  the Free Software Foundation; either version 2 of the License, or
7  *  (at your option) any later version.
8  *
9  *  This program is distributed in the hope that it will be useful,
10  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  *  GNU General Public License for more details.
13  *
14  *  You should have received a copy of the GNU General Public License
15  *  along with this program; if not, write to the Free Software
16  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17  *
18  *  Revision : $Id: f16.h,v 1.6.4.3 2008-05-10 15:06:26 zer0 Exp $
19  *
20  */
21
22 #ifndef _POLYGON_H_
23 #define _POLYGON_H_
24
25 typedef struct _poly {
26         point_t * pts;
27         uint8_t l;
28 } poly_t;
29
30 /* XXX add const, fix arg order */
31
32 /*
33  * return:
34  *  0 not inside
35  *  1 inside
36  *  2 on edge
37  */
38 uint8_t is_in_poly(const point_t *p, poly_t *pol);
39
40 /*
41  * public wrapper for is_in_poly()
42  *  0 not inside
43  *  1 inside
44  *  2 on edge
45  */
46 uint8_t is_point_in_poly(poly_t *pol, int16_t x, int16_t y);
47
48 /* Is segment crossing polygon? (including edges)
49  *  0 don't cross
50  *  1 cross
51  *  2 on a side
52  *  3 touch out (a segment boundary is on a polygon edge, 
53  *  and the second segment boundary is out of the polygon)
54  *  Fill the intersect_pt if not NULL.
55  */
56 uint8_t 
57 is_crossing_poly(point_t p1, point_t p2, point_t *intersect_pt,
58                  poly_t *pol);
59
60 /*
61  * set coords of bounding box.
62  */
63 void polygon_set_boundingbox(int32_t x1, int32_t y1, int32_t x2, int32_t y2);
64
65 /* 
66  * return 1 if a point is in the bounding box.
67  */
68 uint8_t is_in_boundingbox(const point_t *p);
69
70 /* Giving the list of poygons, compute the graph of "visibility rays".
71  * This rays array is composed of indexes representing 2 polygon
72  * vertices that can "see" each others:
73  *
74  *  i  : the first polygon number in the input polygon list
75  *  i+1: the vertex index of this polygon (vertex 1)
76  *  i+2: the second polygon number in the input polygon list
77  *  i+3: the vertex index of this polygon (vertex 2)
78  *
79  *  Here, vertex 1 can "see" vertex 2 in our visibility graph
80  *
81  *  As the first polygon is not a real polygon but the start/stop
82  *  point, the polygon is NOT an ocluding polygon (but its vertices
83  *  are used to compute visibility to start/stop points)
84  */
85
86 uint8_t 
87 calc_rays(poly_t *polys, uint8_t npolys, uint8_t *rays);
88
89 /* Compute the weight of every rays: the length of the rays is used
90  * here. 
91  *
92  * Note the +1 is a little hack to introduce a preference between to
93  * possiblity path: If we have 3 checpoint aligned in a path (say A,
94  * B, C) the algorithm will prefer (A, C) instead of (A, B, C) */
95 void 
96 calc_rays_weight(poly_t *polys, uint8_t npolys, uint8_t *rays, 
97                  uint8_t ray_n, uint16_t *weight);
98
99 #endif