/*<html><pre>*/
#ifndef V_PLANE_H
#define V_PLANE_H

/*	Equation of line on plane is 'n[0]*x + n[1]*y + dist = 0' */
typedef struct	line2_s
{
	vec2_t	normal;		/* for forward dir: normal is on right */
	vec_t	dist;		/* distance positive in direction of normal */
}	line2_t, *line2_p;

typedef struct ray2_s
{
	vec2_t	origin;
	line2_t	line;
}	ray2_t, *ray2_p;

typedef struct poly2_s		/* planar polygon */
{
	int			numpoints;	/* maximal number of points */
	int			count;		/* current number of points */
	int			size;		/* size of object in memory */
	ray2_t		rays[1];	/* edges */
} poly2_t, *poly2_p;

#ifdef	__cplusplus
extern "C" {
#endif	/* __cplusplus */
	/* compites rotation matrix */
	void	V_GLOBAL	mat2Rotation(matrix2_t mat,vec_t radians);
	/* computes cross between two lines */
	void	V_GLOBAL	line2Cross(vec2_t point,line2_p l1,line2_p l2);
	/* computes equation of line */
	void	V_GLOBAL	line2FromPoints(line2_p line,vec2_t p1,vec2_t p2);
	/* compites distance betwwen line and plane */
	vec_t	V_GLOBAL	line2DistFromPoint(line2_p line,vec2_t p);
	/* returns memAlloc()'ed and zeroed block */
	poly2_p	V_GLOBAL	poly2Alloc(int max_points);
	/* returns memAlloc()'ed block filled with contents of 'ref' */
	poly2_p	V_GLOBAL	poly2Duplicate(poly2_t *ref);
#ifdef	PLANE_NO_MACRO
	/*	Points must be added CLOCKWISE */
	void	V_GLOBAL	poly2AddPoint(poly2_p w,vec2_t pt);
#endif	/* PLANE_NO_MACRO */
	/* computes equations of edges */
	void	V_GLOBAL	poly2ComputeEdges(poly2_p w);
	/* returns true if 'p' is insize 'w' */
	vboolean	V_GLOBAL	poly2PointInside(poly2_p w,vec2_t p);
#ifdef	__cplusplus
}
#endif	/* __cplusplus */

#ifndef	PLANE_NO_MACRO
#define	poly2AddPoint(w,pt)\
		V_ASSERT((w)->count!=(w)->numpoints);\
		vec2Copy((w)->rays[w->count++].origin,(pt));
#endif	/* PLANE_NO_MACRO */

#endif	/* V_PLANE_H */
/*</pre></html>*/
/*EOF*/
