I want to change a vector. I don't know whether it would be better to change the vector per reference or to return a copy. Is the additional copy operation (necessary for the version with the return) optimized out by avr gcc? What is the better practice?
inline void wrap180_Vec3f(Vector3f &vec) {
vec.x = vec.x < -180.f ? (vec.x + 360.f) : (vec.x > 180.f ? (vec.x - 360.f) : vec.x);
vec.y = vec.y < -180.f ? (vec.y + 360.f) : (vec.y > 180.f ? (vec.y - 360.f) : vec.y);
vec.z = vec.z < -180.f ? (vec.z + 360.f) : (vec.z > 180.f ? (vec.z - 360.f) : vec.z);
}
Or
inline Vector3f wrap180_Vec3f(Vector3f vec) {
vec.x = vec.x < -180.f ? (vec.x + 360.f) : (vec.x > 180.f ? (vec.x - 360.f) : vec.x);
vec.y = vec.y < -180.f ? (vec.y + 360.f) : (vec.y > 180.f ? (vec.y - 360.f) : vec.y);
vec.z = vec.z < -180.f ? (vec.z + 360.f) : (vec.z > 180.f ? (vec.z - 360.f) : vec.z);
return vec;
}