Repository: FreeCAD/FreeCAD
File: src/Gui/View3DInventorViewer.cpp (C++)

Code before:
        if (cameraZ.dot(directionZ) < 0) {
            directionZ.negate();
        }

        // Rotate the camera to align with directionZ by the smallest angle to align the z-axis
        const SbRotation intermediateOrientation = cameraOrientation * SbRotation(cameraZ, directionZ);

        SbVec3f intermediateX;
        intermediateOrientation.multVec(SbVec3f(1, 0, 0), intermediateX);

        // Find angle between directionX and intermediateX
        const SbRotation rotation(directionX, intermediateX);
        SbVec3f axis;
        float angle;
        rotation.getValue(axis, angle);

        // Flip the sign of the angle if axis and directionZ are in opposite direction
        if (axis.dot(directionZ) < 0 && angle != 0) {
            angle *= -1;
        }
        
        static const float pi = boost::math::constants::pi<float>();
        static const float pi2 = boost::math::constants::two_pi<float>();
        static const float pi1_2 = boost::math::constants::half_pi<float>();
        static const float pi1_4 = boost::math::constants::quarter_pi<float>();
        static const float pi3_4 = boost::math::constants::three_quarters_pi<float>();
        
        // Make angle positive
        if (angle < 0) {
            angle += pi2;
        }
        
        // Find the angle to rotate to the nearest horizontal or vertical alignment with directionX.
        // f is a small value used to get more deterministic behavior when the camera is at directionX +- 45 degrees.
        const float f = 0.00001F;
        
        if (angle <= pi1_4 + f) {
            angle = 0;
        }
        else if (angle <= pi3_4 + f) {
            angle = pi1_2;
        }
        else if (angle < pi + pi1_4 - f) {
            angle = pi;
        }
        else if (angle < pi + pi3_4 - f) {
            angle = pi + pi1_2;
        }
        else {
            angle = 0;
        }

Review comment (suggestion):
Please use `constexpr`, and please use `M_PI` from `<cmath>` or `pi_v` from `<numbers>`; then we'll not depend on an external library.

Code after:
        }

        // Rotate the camera to align with directionZ by the smallest angle to align the z-axis
        const SbRotation intermediateOrientation = cameraOrientation * SbRotation(cameraZ, directionZ);

        SbVec3f intermediateX;
        intermediateOrientation.multVec(SbVec3f(1, 0, 0), intermediateX);

        // Find angle between directionX and intermediateX
        const SbRotation rotation(directionX, intermediateX);
        SbVec3f axis;
        float angle;
        rotation.getValue(axis, angle);

        // Flip the sign of the angle if axis and directionZ are in opposite direction
        if (axis.dot(directionZ) < 0 && angle != 0) {
            angle *= -1;
        }
        
        // Make angle positive
        if (angle < 0) {
            angle += 2 * M_PI;
        }
        
        // Find the angle to rotate to the nearest horizontal or vertical alignment with directionX.
        // f is a small value used to get more deterministic behavior when the camera is at directionX +- 45 degrees.
        const float f = 0.00001F;
        
        if (angle <= M_PI_4 + f) {
            angle = 0;
        }
        else if (angle <= 3 * M_PI_4 + f) {
            angle = M_PI_2;
        }
        else if (angle < M_PI + M_PI_4 - f) {
            angle = M_PI;
        }
        else if (angle < M_PI + 3 * M_PI_4 - f) {
            angle = M_PI + M_PI_2;
        }
        else {
            angle = 0;
        }

        SbRotation(directionZ, angle).multVec(directionX, directionX);

        const SbVec3f directionY = directionZ.cross(directionX);

        const auto orientation = SbRotation(SbMatrix(
            directionX[0],  directionX[1],  directionX[2],  0,
            directionY[0],  directionY[1],  directionY[2],  0,