simple-draw/src/Shapes.cpp

58 lines
1.3 KiB
C++

//
// Created by shaohuatong on 06.12.19.
//
#include <iostream>
#include "Shapes.hpp"
void Shapes::addShape(std::vector<std::vector<bool>> shape, int startX, int startY, int endX, int endY) {
count++;
shapes.resize(count);
startXs.resize(count);
startYs.resize(count);
endXs.resize(count);
endYs.resize(count);
startXs[count-1] = startX;
startYs[count-1] = startY;
endXs[count-1] = endX;
endYs[count-1] = endY;
// shapes[count-1].resize(shape.size());
// for(int y = 0; y < shape.size(); y++) {
// shapes[count-1][y].resize(shape[y].size());
// for(int x = 0; x < shape[y].size(); x++) {
// shapes[count-1][y][x] = shape[y][x];
// }
// }
shapes[count-1] = shape;
}
bool Shapes::containsPixel(int x, int y) {
for(int i = 0; i < count; i++) {
if(x >= startXs[i] && x < endXs[i] && y >= startYs[i] && y < endYs[i]) {
if(shapes[i][y-startYs[i]][x-startXs[i]]) {
return true;
}
}
}
return false;
}
int Shapes::getCount() {
return count;
}
std::vector<std::vector<bool>> Shapes::getShape(int index) {
return shapes[index];
}
int Shapes::getStartX(int index) {
return startXs[index];
}
int Shapes::getStartY(int index) {
return startYs[index];
}