simple-draw/src/Rectangle.cpp

57 lines
1.5 KiB
C++

//
// Created by shaohuatong on 06.12.19.
//
#include "Rectangle.hpp"
Rectangle::Rectangle() {
}
Rectangle::Rectangle(vkvm::Coordinates mouseLeftDownPostion, vkvm::Coordinates mousePostion, int penWidth) {
this -> mouseLeftDownPosition = mouseLeftDownPostion;
this -> mousePosition = mousePostion;
int x_draw = 0;
int y_draw = 0;
length = abs(mouseLeftDownPosition.x - mousePosition.x);
width = abs(mouseLeftDownPosition.y - mousePosition.y);
uperLeft.x = std::min(mouseLeftDownPosition.x, mousePosition.x);
uperLeft.y = std::min(mouseLeftDownPosition.y, mousePosition.y);
bottomRight.x = std::max(mouseLeftDownPosition.x, mousePosition.x);
bottomRight.y = std::max(mouseLeftDownPosition.y, mousePosition.y);
rectangle.resize(width);
for(y_draw = 0; y_draw < width; y_draw++) {
rectangle[y_draw].resize(length);
for(x_draw = 0; x_draw < length; x_draw++) {
if((x_draw >= 0 && x_draw <= penWidth) || (y_draw >= 0 && y_draw <= penWidth)
|| (x_draw <= length && x_draw >= length - penWidth)
|| (y_draw <= width && y_draw >= width - penWidth)) {
rectangle[y_draw][x_draw] = true;
}
}
}
}
std::vector<std::vector<bool>> Rectangle::getRectangle() {
return rectangle;
}
int Rectangle::getWidth() {
return width;
}
int Rectangle::getLength() {
return length;
}
vkvm::Coordinates Rectangle::getUperLeft() {
return uperLeft;
}
vkvm::Coordinates Rectangle::getBottomRight() {
return bottomRight;
}