simple-draw/src/Circle.cpp

55 lines
1.3 KiB
C++

#include "Circle.hpp"
Circle::Circle() {
}
Circle::Circle(vkvm::Coordinates center, int radius, int penWidth, bool brush) {
this -> center = center;
this -> radius = radius;
int x_draw = 0;
int y_draw = 0;
int distance = 0;
uperLeft.x = center.x - radius;
uperLeft.y = center.y - radius;
bottomRight.x = center.x + radius;
bottomRight.y = center.y + radius;
vkvm::Coordinates temp;
circle.resize(2 * radius);
for(y_draw = 0; y_draw < 2 * radius; y_draw++) {
circle[y_draw].resize(2 * radius);
for(x_draw = 0; x_draw < 2 * radius; x_draw++) {
temp.x = uperLeft.x + x_draw;
temp.y = uperLeft.y + y_draw;
distance = utils::squareOfDistance(temp, center);
if(!brush) {
if( distance <= (radius * radius) && distance >= ((radius - penWidth) * (radius - penWidth)))
circle[y_draw][x_draw] = true;
}
else {
if( distance <= (radius * radius))
circle[y_draw][x_draw] = true;
}
}
}
}
std::vector<std::vector<bool>> Circle::getCircle() {
return circle;
}
int Circle::getRadius() {
return radius;
}
vkvm::Coordinates Circle::getUperLeft() {
return uperLeft;
}
vkvm::Coordinates Circle::getBottomRight() {
return bottomRight;
}