implicit conversion bool -> 'const float'
141 const bool ZED_POSETRACK_FLOOR_IS_ORIGIN = true; // Sets the floor plane as origin for tracking. This turns on floor plane detection temporarily.
142 const bool ZED_POSETRACK_ENABLE_IMU_FUSION = true; // Allows ZED to use both optical odometry and IMU data for pose tracking.
143 const float ZED_POSETRACK_USABLE_DEPTH_MIN = 0.75; // Minimum depth used for pose tracking, useful if a static object is partial in view of the camera.
144 const float ZED_POSETRACK_USE_GRAVITY_ORIGIN = true; // Override 2 of the 3 rotations from initial_world_transform using the IMU.145 // ZedCam Spatial Mapping Config.
146 const sl::SpatialMappingParameters::SPATIAL_MAP_TYPE ZED_MAPPING_TYPE = sl::SpatialMappingParameters::SPATIAL_MAP_TYPE::MESH; // Mesh or point cloud output.
147 const float ZED_MAPPING_RANGE_METER = 20.0; // The max range in meters that the ZED cameras should use for mapping. 0 = auto.
Description
Found an implicit conversion between built-in types and booleans. Such a conversion can lead to readability issues and potential bugs in the code.
For example, if a variable of type int
is used in a boolean context, it can lead to confusion as to whether it represents true or false. Additionally, implicit conversions can hide potential bugs, as the code may behave differently than expected.
To fix this issue, it is recommended to explicitly compare the value to expected value or refactor code to use a boolean variable. This makes the code more readable and reduces the chances of unintended behavior.
Bad practice
void iTakeFloat(float param);
int x = 5;
if (x) { // issue: implicit conversion from int to bool
// code logic
}
bool value{false};
iTakeFloat(value); // issue: implicit conversion from bool to float
Recommended
int x = 5;
if (x != 0) {
// code logic
}
// OR
if (static_cast<bool>(x)) {
// code logic
}
bool value{false};
iTakeFloat(static_cast<bool>(value));