I was told that despite the min and max functions being called in the declaration of the loop, they get called for each iteration of the loop and that therefore I should store them in variables and use those variables. Is this true?
Code:
vs.
Code:
Code:
if (vTmp1.x == vTmp2.x) {
for (int y = min(vTmp1.y, vTmp2.y); y <= max(vTmp1.y, vTmp2.y); ++y) {
putPixel(vTmp1.x, y, fillColor);
}
} else if (vTmp1.y == vTmp2.y) {
for (int x = min(vTmp1.x, vTmp2.x); x <= max(vTmp1.x, vTmp2.x); ++x) {
putPixel(x, vTmp1.y, fillColor);
}
}
vs.
Code:
if (vTmp1.x == vTmp2.x) {
int yMax = max(vTmp1.y, vTmp2.y);
int yMin = min(vTmp1.y, vTmp2.y);
for (int y = yMin; y <= yMax; ++y) {
putPixel(vTmp1.x, y, fillColor);
}
} else if (vTmp1.y == vTmp2.y) {
int xMin = min(vTmp1.x, vTmp2.x);
int xMax = max(vTmp1.x, vTmp2.x);
for (int x = xMin; x <= xMax; ++x) {
putPixel(x, vTmp1.y, fillColor);
}
}