In my program I got a vector matrix. This vector contains the x, y and z coodinates of points. To simplify the programm the z coordinates do not change. Now I got a variable called infill. The idea is that the coordinates of the points form a conture. The variable infill defines the gap between the contur and a smaller contur of the model. To illustrate this here picture:
As you can see I get the conture of the model and a smaller contur. For rectangles it's working fine. But it's just a special case. If I use it on a circle it's not working anymore.
So my idea was to check with if-statements. Because I have at least for conditions, I would have to check 16 if statements.
case 1 x<0 y<0 x<infill y<infill
case 2 x<0 y<0 x<infill y>infill
case 3 x<0 y<0 x>infill y<infill
case 4 x<0 y<0 x>infill y>infill
case 5 x<0 y>0 x<infill y<infill
case 6 x<0 y>0 x<infill y>infill
case 7 x<0 y>0 x>infill y<infill
case 8 x<0 y>0 x>infill y>infill
case 9 x>0 y<0 x<infill y<infill
case 10 x>0 y<0 x<infill y>infill
case 11 x>0 y<0 x>infill y<infill
case 12 x>0 y<0 x>infill y>infill
case 13 x>0 y>0 x<infill y<infill
case 14 x>0 y>0 x<infill y>infill
case 15 x>0 y>0 x>infill y<infill
case 16 x>0 y>0 x>infill y>infill
If I also check if x or y are equal to 0 or infill I would have about 87 cases. Now my problem is, that if I use if/else if/else statements my could would be a pain in the ase to read, even if I comment on everythin. Because I have to do this for every element in the vector I'm using a for-loop.
My Qustion to the community is: Is there an intelligent way to handle all this cases. Is the if-statement the best? Or is it better to use switch/case? Here my problem is I don't know how to use switch with a vector of doubles and an integer variable.
Edit: Regarding to the comments here's the code for one case
int size=matrix.size();
for(size_t i=0; i<size; i++) {
if(matrix[i][0] < 0) {
if(matrix[i][1] < 0){
if(matrix[i][0] < (infill*(-1))) {
if(matrix[i][1] < (infill*(-1))) {
matrix.push_back(std::vector<double>(3, 0));
r = matrix.size()-1;
matrix[r][0]=matrix[i][0]+infill;
matrix[r][1]=matrix[i][1]+infill;
matrix[r][2]=matrix[i][2];
}
else if(matrix[i][1] > (infill*(-1))) {
matrix.push_back(std::vector<double>(3, 0));
r = matrix.size()-1;
matrix[r][0]=matrix[i][0]+infill;
matrix[r][1]=(matrix[i][1]+infill)*(-1);
matrix[r][2]=matrix[i][2];
}
}
}
}
}
So I'm checking witch case belongs to the x and y value and then calculate the the coordinates for the inner conture. Furthermore, I can not be sure that all points always group around the origin.