/*
 *                     circle.c
 *
 */

#include "defn.h"

circle(type)
int	type;
{
    float	radius;
    float	start_angle = 0;
    float	end_angle = 360;
    float	chord_angle = 0;
    float	Xc, Yc;
    float	percent;
    float	distance;
    float	length;
    float	angle;
    int         CCW = 0;

    end_draw();

    switch (type)
    {
    case RDGLCIRCLE:
	Xc = absX;
	Yc = absY;
	if (test_token())
	    radius = getval() * XSCALE;
	if (test_token())
	    {
	      chord_angle = getval();
	      polygon(Xc, Yc, radius, chord_angle);
            }
         else exact_circle(Xc, Yc, radius);
        return;

    case CIRCLE:
	if (test_token())
	    absX = Xc = getval() * XSCALE;
	if (test_token())
	    absY = Yc = getval() * YSCALE;
	if (test_token())
	    radius = getval() * XSCALE;
	if (test_token())
	    start_angle = getval();
	if (test_token())
	    end_angle = getval();
	if (test_token())
	    chord_angle = getval();
	break;

    case RCIRCLE:
	if (test_token())
	    radius = getval() * XSCALE;
	if (test_token())
	    start_angle = getval();
	if (test_token())
	    end_angle = getval();
	if (test_token())
	    chord_angle = getval();
	angle = deg_rad * (90.0 - start_angle);
	Xc = absX - radius * cos(angle);
	angle = deg_rad * (90.0 - start_angle);
	Yc = absY + radius * sin(angle);
	break;

    case CCIRCLE:
	if (test_token())
	   absX = getval() * XSCALE;
	if (test_token())
	   absY = getval() * YSCALE;
	break;

    case ACIRCLE:
	Xc = absX;
	Yc = absY;
	if (test_token())
	    radius = getval() * XSCALE;
	if (test_token())
	    start_angle = getval();
	if (test_token())
	    end_angle = getval();
	if (test_token())
	    chord_angle = getval();
	break;

    case SCIRCLE:
	if (test_token())
	    percent = getval();
	if (test_token())
	    distance = getval();
	if (test_token())
	    length = getval();
	fprintf(stderr, "Warning: segment and indication lines not available yet\n");
	break;
    }

    fprintf(outfile, "%d %g %g %g %g %g %g Ellipse\n",
		CCW, Xc, Yc, radius, radius, start_angle, end_angle);
}
