e9da73c16425b983a13c6e2dc5dec14c5557c9fe
[swftools.git] / lib / gfxpoly / poly.h
1 #ifndef __poly_h__
2 #define __poly_h__
3
4 #include <stdint.h>
5 #include "../q.h"
6
7 typedef enum {DIR_UP, DIR_DOWN} segment_dir_t;
8 typedef enum {EVENT_CROSS, EVENT_END, EVENT_START} eventtype_t;
9 typedef enum {SLOPE_POSITIVE, SLOPE_NEGATIVE} slope_t;
10
11 typedef struct _point {
12     int32_t x;
13     int32_t y;
14 } point_t;
15
16 typedef struct _segment {
17     point_t a;
18     point_t b;
19     point_t delta;
20     double k; //k = a.x*b.y-a.y*b.x = delta.y*a.x - delta.x*a.y (=0 for points on the segment)
21     segment_dir_t dir;
22     int nr;
23     struct _segment*left;
24     struct _segment*right;
25     int tmp;
26     point_t pos;
27
28     dict_t scheduled_crossings;
29 } segment_t;
30
31 #define LINE_EQ(p,s) ((double)(s)->delta.y*(p).x - (double)(s)->delta.x*(p).y - (s)->k)
32
33 typedef segment_t gfxpoly_t;
34 gfxpoly_t* gfxpoly_new();
35 void gfxpoly_dump(gfxpoly_t*poly);
36
37 typedef struct _event {
38     eventtype_t type;
39     point_t p;
40     segment_t*s1;
41     segment_t*s2;
42 } event_t;
43
44 void segment_init(segment_t*s, int32_t x1, int32_t y1, int32_t x2, int32_t y2);
45 segment_t*segment_new(int32_t x1, int32_t y1, int32_t x2, int32_t y2);
46 void segment_insert_before(segment_t**list, segment_t*add);
47
48 #endif