ini
[aversive.git] / modules / base / math / geometry / polygon.h
1 #ifndef _POLYGON_H_
2 #define _POLYGON_H_
3
4 typedef struct _poly {
5         point_t * pts;
6         uint8_t l;
7 } poly_t;
8
9 /* XXX add const, fix arg order */
10
11 /*
12  * return:
13  *  0 not inside
14  *  1 inside
15  *  2 on edge
16  */
17 uint8_t is_in_poly(const point_t *p, poly_t *pol);
18
19 /*
20  * public wrapper for is_in_poly()
21  *  0 not inside
22  *  1 inside
23  *  2 on edge
24  */
25 uint8_t is_point_in_poly(poly_t *pol, int16_t x, int16_t y);
26
27 /* Is segment crossing polygon? (including edges)
28  *  0 don't cross
29  *  1 cross
30  *  2 on a side
31  *  3 touch out (a segment boundary is on a polygon edge, 
32  *  and the second segment boundary is out of the polygon)
33  *  Fill the intersect_pt if not NULL.
34  */
35 uint8_t 
36 is_crossing_poly(point_t p1, point_t p2, point_t *intersect_pt,
37                  poly_t *pol);
38
39 /*
40  * set coords of bounding box.
41  */
42 void polygon_set_boundingbox(int32_t x1, int32_t y1, int32_t x2, int32_t y2);
43
44 /* 
45  * return 1 if a point is in the bounding box.
46  */
47 uint8_t is_in_boundingbox(const point_t *p);
48
49 /* Giving the list of poygons, compute the graph of "visibility rays".
50  * This rays array is composed of indexes representing 2 polygon
51  * vertices that can "see" each others:
52  *
53  *  i  : the first polygon number in the input polygon list
54  *  i+1: the vertex index of this polygon (vertex 1)
55  *  i+2: the second polygon number in the input polygon list
56  *  i+3: the vertex index of this polygon (vertex 2)
57  *
58  *  Here, vertex 1 can "see" vertex 2 in our visibility graph
59  *
60  *  As the first polygon is not a real polygon but the start/stop
61  *  point, the polygon is NOT an ocluding polygon (but its vertices
62  *  are used to compute visibility to start/stop points)
63  */
64
65 uint8_t 
66 calc_rays(poly_t *polys, uint8_t npolys, uint8_t *rays);
67
68 /* Compute the weight of every rays: the length of the rays is used
69  * here. 
70  *
71  * Note the +1 is a little hack to introduce a preference between to
72  * possiblity path: If we have 3 checpoint aligned in a path (say A,
73  * B, C) the algorithm will prefer (A, C) instead of (A, B, C) */
74 void 
75 calc_rays_weight(poly_t *polys, uint8_t npolys, uint8_t *rays, 
76                  uint8_t ray_n, uint16_t *weight);
77
78 #endif