-
Notifications
You must be signed in to change notification settings - Fork 0
/
wu_circle+antialiasing.cpp
82 lines (73 loc) · 2.08 KB
/
wu_circle+antialiasing.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/***********************************************************************
This code is generated by the AlgoPascal translator
This code is distributed under the ALGLIB license
(see http://www.alglib.net/copyrules.php for details)
***********************************************************************/
#include "ap.h"
/*-----------------------------------------------
This routines must be defined by the programmer:
void setpixel(int x, int y, double alpha);
-----------------------------------------------*/
void drawwucircle(int cx, int cy, int r);
/*************************************************************************
<<<<<<< HEAD
РиÑование круга Ñ Ð¸Ñпользованием метода Ву длÑ
антиалиаÑинга.
=======
Ðèñîâàíèå êðóãà ñ èñïîëüçîâàíèåì ìåòîäà Âó äëÿ
àíòèàëèàñèíãà.
>>>>>>> 58e3d87... Added Wu's antialiasing algorithms for circle, ellipsis, line
*************************************************************************/
void drawwucircle(int cx, int cy, int r)
{
int x;
int y;
double t;
double d;
int j;
int kx;
int ky;
int lastx;
x = r;
lastx = r;
y = 0;
t = 0;
for(j = 0; j <= 3; j++)
{
kx = j%2*2-1;
ky = j/2%2*2-1;
setpixel(kx*x+cx, ky*y+cy, double(1));
setpixel(kx*y+cx, ky*x+cy, double(1));
}
while(x>y)
{
y = y+1;
d = ap::iceil(sqrt(double(r*r-y*y)))-sqrt(double(r*r-y*y));
if( d<t )
{
x = x-1;
}
if( x<y )
{
break;
}
if( x==y&&lastx==x )
{
break;
}
for(j = 0; j <= 3; j++)
{
kx = j%2*2-1;
ky = j/2%2*2-1;
setpixel(kx*x+cx, ky*y+cy, 1-d);
setpixel(kx*y+cx, ky*x+cy, 1-d);
if( x-1>=y )
{
setpixel(kx*(x-1)+cx, ky*y+cy, d);
setpixel(kx*y+cx, ky*(x-1)+cy, d);
}
}
t = d;
lastx = x;
}
}