/*
 *  Simple C program to generate input for xfig 
 *  to draw a thrackle embedding of the hexagon.
 *  (Symmetries forced)
 *  Stephan Wehner, Dec 9, 2000.
 */

#include <stdio.h>

void giveSpline(int *x, int *y, int numPoints, int mirrorX, int mirrorY);

int main(int argc, char **argv) 
{
	/* 
 	 * Drawing is obtained from two lines named "a" and "b"
 	 * and their mirror images. Suffix x,y for x,y coordinate.
	 */
	#define a_length  7
	#define b_length  5


	/* 
	 * coordinates obtained with xfig
	 */
	int axy[2*a_length]={75,-2850,-375,-3225,-2775,-2925,-3450,300,-1350,1725,-75,1800,0,1800};
	int bxy[2*b_length]={75,-2850,450,-2550,1050,-1725,1050,-825,0,0};
  
  	int ax[a_length]; 
  	int ay[a_length];
  	int bx[b_length];
  	int by[b_length];

	/*
	 * generic loop variable
	 */
  	int i;

	/*
	 * set up arrays
	 */
  	for (i = 0; i<a_length; i++) {
	  	ax[i]=axy[2*i]; 
		ay[i]=axy[2*i+1];
  	}
  	for (i = 0; i<b_length; i++) {
	  	bx[i]=bxy[2*i];
		by[i]=bxy[2*i+1];
  	}

	/*
	 * Generic xfig header
	 */
  	printf (
"#FIG 3.2
Landscape
Center
Inches
Letter  
100.00
Single
-2
1200 2\n");

	/* 
	 * paste a and b lines together
	 */
	 giveSpline(ax,ay, a_length,  1,  1);
	 giveSpline(ax,ay, a_length, -1,  1);

	 giveSpline(bx,by, b_length,  1,  1);
	 giveSpline(bx,by, b_length, -1, -1);

	 giveSpline(ax,ay, a_length,  1, -1);
	 giveSpline(ax,ay, a_length, -1, -1);

	 giveSpline(bx,by, b_length,  1, -1);
	 giveSpline(bx,by, b_length, -1,  1);

	 /*
	  * place "spots"
	  * Coordinates obtained by hand placement
	  */
	printf(
"
1 3 0 1 0 0 50 0 20 0.000 1 0.0000 1994 -1200 150 150 1963 -1200 2175 -1200
1 3 0 1 0 0 50 0 20 0.000 1 0.0000 -1015 -1200 150 150 -950 -1121 -738 -1121
1 3 0 1 0 0 50 0 20 0.000 1 0.0000 -3015 -1200 150 150 -3051 -967 -2839 -967
"
"
1 3 0 1 0 0 50 0 20 0.000 1 0.0000 1994 1200 150 150 1963 -1200 2175 -1200
1 3 0 1 0 0 50 0 20 0.000 1 0.0000 -1015 1200 150 150 -950 -1121 -738 -1121
1 3 0 1 0 0 50 0 20 0.000 1 0.0000 -3015 1200 150 150 -3051 -967 -2839 -967
\n");

		return 0;
} /* end main */


/* 
 * prints to stdout definition of an open approximated spline for xfig.
 * specify whether want mirror image with respect to x and y axis
*/
void giveSpline(int *x, int *y, int numPoints, int mirrorX, int mirrorY) 
{
	int i;
	/*
	 * xfig header
	 */
        printf("3 "); /* object_code 3: SPLINE */
        printf("0 "); /* open approximated SPLINE */
        printf("0 "); /* line_style solid */
        printf("2 "); /* thickness (1/80 inch) */
        printf("0 "); /* pencolor */
        printf("7 "); /* fillcolor */
        printf("50 "); /* depth */
        printf("0  "); /* penstyle */
        printf("-1 "); /* area_fill (-1 = nofill) */
        printf("0.000 "); /* style_val (1/80 inch) */
        printf("0 "); /* enumeration type (only used for open splines) */
        printf("0 "); /* forward arrow (0=off 1=on) */
        printf("0 "); /* backward arrow, same */
        printf("%d \n", numPoints);

        for(i=0; i<numPoints; i++)  {
		if (mirrorX > 0)
        	 	printf("%d ",x[i]);
        	else
        	 	printf("%d ",-x[i]);
		if (mirrorY > 0)
        	 	printf("%d ",y[i]);
        	else
        	 	printf("%d ",-y[i]);
		printf("\n");
        }

	/*
	 * shape factors: first and last point : 0 = discontinuity
	 * all others: 1 = approximate point
	 */
	printf("0.0 ");
  	for (i=1; i<numPoints-1; i++) 
		printf("1.0 ");
	printf("0.0 ");
	printf("\n");
} /* end giveSpline */
