BWAPI
|
00001 #pragma once 00002 00010 template<class Functor> 00011 void BresenhamCircle(Functor& functor, int radius, bool filled) 00012 { 00013 if(radius == 0) 00014 { 00015 functor(0, 0); // ? 00016 return; 00017 } 00018 00019 int x = 0; 00020 int y = radius; 00021 int prevy = radius; 00022 int h = 1 - radius; 00023 00024 if(filled) 00025 { 00026 for(int i=1; i<2*radius; ++i) 00027 { 00028 functor(-radius + i, 0); 00029 } 00030 } 00031 00032 functor(0, radius); 00033 functor(0, -radius); 00034 functor( radius, 0); 00035 functor(-radius, 0); 00036 00037 while(y > x+1) 00038 { 00039 prevy = y; 00040 00041 if(h < 0) 00042 { 00043 h += 2*x + 3; 00044 } 00045 else 00046 { 00047 h += 2*(x-y) + 5; 00048 --y; 00049 } 00050 00051 ++x; 00052 00053 if(filled) 00054 { 00055 if(prevy > y && x < y) 00056 { 00057 for(int i=1; i<2*x; ++i) 00058 { 00059 functor(-x + i, y); 00060 functor(-x + i, -y); 00061 } 00062 } 00063 00064 for(int i=1; i<2*y; ++i) 00065 { 00066 functor(-y + i, x); 00067 functor(-y + i, -x); 00068 } 00069 } 00070 00071 functor( x, y); 00072 functor(-x, y); 00073 functor( x, -y); 00074 functor(-x, -y); 00075 if(x != y) 00076 { 00077 functor( y, x); 00078 functor(-y, x); 00079 functor( y, -x); 00080 functor(-y, -x); 00081 } 00082 } 00083 }