/*
 *
 *                     polygon.c
 *
 *
 *      Procedures for drawing circles & polygons
 *
 *   Marek Krawus, PCC,  March '89
 */

#include "defn.h"

exact_circle(xc, yc, Radius)
float      xc;
float      yc;
float      Radius;
{
   float      xRad;
   float      yRad;
   float      start_angle = 0;
   float      end_angle = 360;
   int        CCW = 0;

   xRad = yRad = Radius;
   if (USER_UNITS)
	 yRad = (Radius * YSCALE) / XSCALE;

   fprintf(outfile, "%d %g %g %g %g %g %g Ellipse\n",
	     CCW, xc, yc, xRad, yRad, start_angle, end_angle);
}


polygon(xc, yc, Radius, Chord_angle)
float      xc;
float      yc;
float      Radius;
float      Chord_angle;
{
    float    xRad;
    float    yRad;
    int      alfa;
    int      start = 0;
    int      i;
    float    betarad;
    float    chord;
    float    gamma;
    float    epsilon;


    if (Radius < 0)
	{
	   Radius = - Radius;
	   start = 1;
        }
    alfa = rintx(Chord_angle);
    if (alfa < 0) alfa = - alfa;
    if (alfa >= 360) alfa = alfa % 360;
    if (alfa <= 5) 
	 {
	     exact_circle(xc, yc, Radius);
	     return;
         }
    if (alfa > 180) alfa = 360 - alfa;
    while ( (360 % alfa) != 0 ) alfa--;
    if (alfa <= 5) 
	 {
	     exact_circle(xc, yc, Radius);
	     return;
         }
    i = 360 / alfa;
    betarad = deg_rad * (alfa / 2.0);
    chord = 2 * Radius * sin(betarad);
    gamma = alfa / 2.0;
    epsilon = 90.0 + gamma;


    xRad = yRad = Radius;
    if (USER_UNITS)
	 yRad = (Radius * YSCALE) / XSCALE;
    fprintf(outfile, "%g %g %g %g %g %d %g %d %d Poly\n",
	       xc, yc, xRad, yRad, chord, start, epsilon, alfa, i);

}
