Hi I have a little doubt about what’s better, thinking about efficiency and maintainability of my code, what’s more important is the efficiency but I want to sacrifice the less in code maintainability.

I’m programming the distance transform using Euclidean distance, Cityblock distance, Chessboard distance.

I have the following code

```
for (idxI = 0; idxI < matrix->row; idxI++)
{
for (idxJ = 0; idxJ < matrix->col; idxJ++)
{
if ( distTransform->data[idxI*matrix->col+idxJ] == 0 )
{
for (idxK = 0; idxK < matrix->row; idxK++)
{
for (idxL = 0; idxL < matrix->col; idxL++)
{
switch (type) {
case CITYBLOCK:
distance = abs(idxK-idxI) + abs(idxL-idxJ);
break;
case CHESSBOARD:
distance = fmax(abs(idxK-idxI), abs(idxL-idxJ));
break;
case EUCLIDEAN:
distance = sqrt(pow(idxK-idxI, 2) + pow(idxL-idxJ,2));
break;
}
if ( distTransform->data[idxK*matrix->col+idxL] > distance )
distTransform->data[idxK*matrix->col+idxL] = distance;
}
}
}
}
}
```

My problem is with the switch structure will it be less efficient? because if I don’t want to use the switch structure I will me duplicating code like a beast ! This is my secuencial code but after this little dilemma I will be programming the parallel version so first I need to solve this …

Any ideas?

Thanks !