1 /************************************************************************/
2 /*									*/
3 /*  Various definitions relating to document geometry.			*/
4 /*									*/
5 /************************************************************************/
6 
7 #   ifndef		GEO_2D_INTEGER_H
8 #   define		GEO_2D_INTEGER_H
9 
10 typedef struct DocumentRectangle
11     {
12     int		drX0;
13     int		drY0;
14     int		drX1;
15     int		drY1;
16     } DocumentRectangle;
17 
18 #   define RECTDEB(dr) appDebug(					\
19 			    "%s(%3d) %s= [%d..%d x %d..%d]\n",		\
20 			    __FILE__, __LINE__, #dr,			\
21 			    (dr)->drX0, (dr)->drX1,			\
22 			    (dr)->drY0, (dr)->drY1 )
23 
24 typedef struct Point2DI
25     {
26     int		x;
27     int		y;
28     } Point2DI;
29 
30 /**
31   * A two dimensional arc
32   */
33 typedef struct Arc2DI
34     {
35 			/**
36 			  * The rectangle that holds the full ellipse
37 			  */
38     DocumentRectangle	a2diRect;
39 			/**
40 			 * The start angle relative to the 3-o-clock angle
41 			 * in 64th of a degree counter clock wise.
42 			 */
43     int			a2diAngleFrom;
44 			/**
45 			 * The change of angle relative to a2diAngleFrom
46 			 * Also counter clock wise and also in 64th of a degree.
47 			 */
48     int			a2diAngleStep;
49     } Arc2DI;
50 
51 typedef struct LineSegment2DI
52     {
53     int		ls2diX0;
54     int		ls2diY0;
55     int		ls2diX1;
56     int		ls2diY1;
57     } LineSegment2DI;
58 
59 # define geo2DIXYInBox( x, y, b ) \
60 		    ( (x) >= (b)->drX0 && \
61 		      (x) <= (b)->drX1 && \
62 		      (y) >= (b)->drY0 && \
63 		      (y) <= (b)->drY1 )
64 
65 # define geo2DIPointInBox( p, b ) geo2DIXYInBox( (p)->x, (p)->y, (b) )
66 
67 # define geo2DIBoxAroundXY( x, y, b ) \
68     { \
69     if  ( (b)->drX0 > (x) ) { (b)->drX0=  (x);	} \
70     if  ( (b)->drY0 > (y) ) { (b)->drY0=  (y);	} \
71     if  ( (b)->drX1 < (x) ) { (b)->drX1=  (x);	} \
72     if  ( (b)->drY1 < (y) ) { (b)->drY1=  (y);	} \
73     }
74 
75 # define geoShiftRectangle( dr, ox, oy ) \
76     { \
77     (dr)->drX0 += (ox); \
78     (dr)->drX1 += (ox); \
79     (dr)->drY0 += (oy); \
80     (dr)->drY1 += (oy); \
81     }
82 
83 /************************************************************************/
84 /*									*/
85 /*  Routine declarations.						*/
86 /*									*/
87 /************************************************************************/
88 
89 extern void geoInitRectangle(		DocumentRectangle *		dr );
90 extern void geoInvalidateRectangle(	DocumentRectangle *		dr );
91 
92 extern void geoUnionRectangle(	DocumentRectangle *		dr,
93 				const DocumentRectangle *	dr1,
94 				const DocumentRectangle *	dr2	);
95 
96 extern void geoNormalizeRectangle(
97 				DocumentRectangle *		drTo,
98 				const DocumentRectangle *	drFrom );
99 
100 extern int geoIntersectRectangle(	DocumentRectangle *		dr,
101 					const DocumentRectangle *	dr1,
102 					const DocumentRectangle *	dr2 );
103 
104 extern int geo2DIIntersectSegments(	Point2DI *		p1,
105 					Point2DI *		p2,
106 					double *		pXab1,
107 					double *		pXab2,
108 					double *		pXcd1,
109 					double *		pXcd2,
110 					const Point2DI *	ab,
111 					const Point2DI *	cd );
112 
113 extern double geo2DIDistanceToLine(	const Point2DI *	ab,
114 					const Point2DI *	c );
115 
116 extern double geo2DIProjectionOnLine(	const Point2DI *	ab,
117 					const Point2DI *	c );
118 
119 extern int geo2DIPointInPolygon(	const Point2DI *	p,
120 					const Point2DI *	points,
121 					int			pointCount );
122 
123 extern int geo2DIClipSegmentToRectangle(
124 				Point2DI			vpChanged[2],
125 				double *			pXp0,
126 				double *			pXp1,
127 				const Point2DI			vp[2],
128 				const DocumentRectangle *	dr );
129 
130 extern int geo2DISurface(	Point2DI *			points,
131 				int				n );
132 
133 #   endif	/*	GEO_2D_INTEGER_H */
134