lib/mgCircle.c File Reference

#include "common.h"
#include "memgfx.h"

Include dependency graph for mgCircle.c:

Go to the source code of this file.

Functions

void mgCircle (struct memGfx *mg, int xCen, int yCen, int rad, Color color, boolean filled)


Function Documentation

void mgCircle ( struct memGfx mg,
int  xCen,
int  yCen,
int  rad,
Color  color,
boolean  filled 
)

Definition at line 7 of file mgCircle.c.

References mgLineH(), and mgPutDot.

00011 {
00012 int err;
00013 int derr, yerr, xerr;
00014 int aderr, ayerr, axerr;
00015 register int x,y;
00016 int lasty;
00017 
00018 if (rad <= 0)
00019     {
00020     mgPutDot(mg, xCen, yCen, color);
00021     return;
00022     }
00023 err = 0;
00024 x = rad;
00025 lasty = y = 0;
00026 for (;;)
00027     {
00028     if (filled)
00029         {
00030         if (y == 0)
00031             mgLineH(mg, yCen, xCen-x, xCen+x, color);
00032         else
00033             {
00034             if (lasty != y)
00035                 {
00036                 mgLineH(mg, yCen-y, xCen-x, xCen+x, color);
00037                 mgLineH(mg, yCen+y, xCen-x, xCen+x, color);
00038                 lasty = y;
00039                 }
00040             }
00041         }
00042     else
00043         {
00044         /* draw 4 quadrandts of a circle */
00045         mgPutDot(mg, xCen+x, yCen+y, color);
00046         mgPutDot(mg, xCen+x, yCen-y, color);
00047         mgPutDot(mg, xCen-x, yCen+y, color);
00048         mgPutDot(mg, xCen-x, yCen-y, color);
00049         }
00050     axerr = xerr = err -x-x+1;
00051     ayerr = yerr = err +y+y+1;
00052     aderr = derr = yerr+xerr-err;
00053     if (aderr < 0)
00054         aderr = -aderr;
00055     if (ayerr < 0)
00056         ayerr = -ayerr;
00057     if (axerr < 0)
00058         axerr = -axerr;
00059     if (aderr <= ayerr && aderr <= axerr)
00060         {
00061         err = derr;
00062         x -= 1;
00063         y += 1;
00064         }
00065     else if (ayerr <= axerr)
00066         {
00067         err = yerr;
00068         y += 1;
00069         }
00070     else
00071         {
00072         err = xerr;
00073         x -= 1;
00074         }
00075     if (x < 0)
00076         break;
00077     }
00078 }

Here is the call graph for this function:


Generated on Tue Dec 25 20:02:37 2007 for blat by  doxygen 1.5.2