forked from edrosten/libcvd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdraw.cc
41 lines (32 loc) · 885 Bytes
/
draw.cc
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
#include <cvd/draw.h>
namespace CVD {
std::vector<ImageRef> getCircle(int radius) {
std::vector<ImageRef> points;
int y = 0;
for (int x=-radius; x<=0; x++) {
int nexty2 = radius*radius - ((x+1)*(x+1));
while (true) {
points.push_back(ImageRef(x,y));
if (y*y >= nexty2)
break;
++y;
}
}
size_t i;
for (i=points.size()-1;i>0;i--)
points.push_back(ImageRef(-points[i-1].x, points[i-1].y));
for (i=points.size()-1;i>1;i--)
points.push_back(ImageRef(points[i-1].x, -points[i-1].y));
return points;
}
std::vector<ImageRef> getDisc(float radius)
{
std::vector<ImageRef> points;
int r = (int)ceil(radius + 1);
for(ImageRef p(0,-r); p.y <= r; p.y++)
for(p.x = -r; p.x <= r; p.x++)
if(p.mag_squared() <= radius*radius)
points.push_back(p);
return points;
}
};