/*
 * ----------------------------------------------------------------------------
 * "THE BEER-WARE LICENSE" (Revision 42):
 * <phk@FreeBSD.ORG> wrote this file.  As long as you retain this notice you
 * can do whatever you want with this stuff. If we meet some day, and you think
 * this stuff is worth it, you can buy me a beer in return.   Poul-Henning Kamp
 * ----------------------------------------------------------------------------
 * $Id: plt2g.h,v 1.4 2009/06/03 19:04:42 phk Exp $
 *
 */

/**********************************************************************/

struct job;

struct vector {
	int x0, y0, x1, y1;
	TAILQ_ENTRY(vector)	list;
};

TAILQ_HEAD(vhead, vector);

struct segment {
	struct vhead		vectors;
	int			x0, y0, x1, y1;
	int 			loop;
	int			flip;
	struct vector		*vb;
	TAILQ_ENTRY(segment)	list;
};

TAILQ_HEAD(shead, segment);

struct run {
	struct job		*job;
	int			pen;
	int			nvect;
	int			nseg;
	double			dist_0;
	double			dist_up;
	struct vhead		vectors;
	struct segment		**seglist;
	struct segment		**worklist;
	unsigned		listlen;
	TAILQ_ENTRY(run)	list;
};

struct job {
	char			*fn;
	int			down;
	int			pen;
	int			vx, vy;
	TAILQ_HEAD(, run)	runs;
	struct run		*last_run;
	int			x0, x1, y0, y1;

	/* Output state */
	FILE			*fo;
	int			bit_x, bit_y;
};

#define HOME_X	-400
#define HOME_Y	-600

extern int	bit_width;

/* emit_gcode.c */
void emit_gcode(struct job *j);
