many optimizations and bugfixes in the new intersector code
[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 _edge {
17     point_t a;
18     point_t b;
19     struct _edge *next;
20 } edge_t;
21
22 typedef struct _segment {
23     point_t a;
24     point_t b;
25     point_t delta;
26     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)
27     segment_dir_t dir;
28     int nr;
29     struct _segment*left;
30     struct _segment*right;
31     int tmp;
32     point_t pos;
33
34     dict_t scheduled_crossings;
35 } segment_t;
36
37 #define LINE_EQ(p,s) ((double)(s)->delta.y*(p).x - (double)(s)->delta.x*(p).y - (s)->k)
38
39 typedef edge_t gfxpoly_t;
40 gfxpoly_t* gfxpoly_new();
41 void gfxpoly_dump(gfxpoly_t*poly);
42 gfxpoly_t* gfxpoly_process(gfxpoly_t*poly);
43
44 typedef struct _event {
45     eventtype_t type;
46     point_t p;
47     segment_t*s1;
48     segment_t*s2;
49 } event_t;
50
51 void segment_init(segment_t*s, int32_t x1, int32_t y1, int32_t x2, int32_t y2);
52 segment_t*segment_new(int32_t x1, int32_t y1, int32_t x2, int32_t y2);
53 void segment_insert_before(segment_t**list, segment_t*add);
54
55 #endif