Skip to content

Commit

Permalink
refactor: simplify if condition
Browse files Browse the repository at this point in the history
  • Loading branch information
mebasoglu committed Apr 16, 2024
1 parent 96ecbb3 commit a47d4a7
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -237,14 +237,20 @@ void Vlp16Decoder::unpack(const velodyne_msgs::msg::VelodynePacket & velodyne_pa

// Condition added to avoid calculating points which are not in the interesting
// defined area (min_angle < area < max_angle).
if (
((azimuth_corrected >= sensor_configuration_->cloud_min_angle * 100 &&
const bool is_within_min_max_angle =
(azimuth_corrected >= sensor_configuration_->cloud_min_angle * 100 &&
azimuth_corrected <= sensor_configuration_->cloud_max_angle * 100 &&
sensor_configuration_->cloud_min_angle < sensor_configuration_->cloud_max_angle) ||
sensor_configuration_->cloud_min_angle < sensor_configuration_->cloud_max_angle);

const bool is_outside_max_min_angle =
(sensor_configuration_->cloud_min_angle > sensor_configuration_->cloud_max_angle &&
(azimuth_corrected <= sensor_configuration_->cloud_max_angle * 100 ||
azimuth_corrected >= sensor_configuration_->cloud_min_angle * 100))) &&
!check_excluded_point(corrections.laser_ring, azimuth_corrected)) {
azimuth_corrected >= sensor_configuration_->cloud_min_angle * 100));

const bool is_not_excluded_point =
!check_excluded_point(corrections.laser_ring, azimuth_corrected);

if ((is_within_min_max_angle || is_outside_max_min_angle) && is_not_excluded_point) {
// Convert polar coordinates to Euclidean XYZ.
const float cos_vert_angle = corrections.cos_vert_correction;
const float sin_vert_angle = corrections.sin_vert_correction;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,14 +194,20 @@ void Vlp32Decoder::unpack(const velodyne_msgs::msg::VelodynePacket & velodyne_pa
distance < sensor_configuration_->max_range) {
/*condition added to avoid calculating points which are not
in the interesting defined area (min_angle < area < max_angle)*/
if (
((block.rotation >= sensor_configuration_->cloud_min_angle * 100 &&
const bool is_within_min_max_angle =
(block.rotation >= sensor_configuration_->cloud_min_angle * 100 &&
block.rotation <= sensor_configuration_->cloud_max_angle * 100 &&
sensor_configuration_->cloud_min_angle < sensor_configuration_->cloud_max_angle) ||
sensor_configuration_->cloud_min_angle < sensor_configuration_->cloud_max_angle);

const bool is_outside_max_min_angle =
(sensor_configuration_->cloud_min_angle > sensor_configuration_->cloud_max_angle &&
(raw->blocks[i].rotation <= sensor_configuration_->cloud_max_angle * 100 ||
raw->blocks[i].rotation >= sensor_configuration_->cloud_min_angle * 100))) &&
!check_excluded_point(corrections.laser_ring, block.rotation)) {
raw->blocks[i].rotation >= sensor_configuration_->cloud_min_angle * 100));

const bool is_not_excluded_point =
!check_excluded_point(corrections.laser_ring, block.rotation);

if ((is_within_min_max_angle || is_outside_max_min_angle) && is_not_excluded_point) {
const float cos_vert_angle = corrections.cos_vert_correction;
const float sin_vert_angle = corrections.sin_vert_correction;
const float cos_rot_correction = corrections.cos_rot_correction;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,14 +258,20 @@ void Vls128Decoder::unpack(const velodyne_msgs::msg::VelodynePacket & velodyne_p
distance < sensor_configuration_->max_range) {
// Condition added to avoid calculating points which are not in the interesting defined
// area (cloud_min_angle < area < cloud_max_angle).
if (
((azimuth_corrected >= sensor_configuration_->cloud_min_angle * 100 &&
const bool is_within_min_max_angle =
(azimuth_corrected >= sensor_configuration_->cloud_min_angle * 100 &&
azimuth_corrected <= sensor_configuration_->cloud_max_angle * 100 &&
sensor_configuration_->cloud_min_angle < sensor_configuration_->cloud_max_angle) ||
sensor_configuration_->cloud_min_angle < sensor_configuration_->cloud_max_angle);

const bool is_outside_max_min_angle =
(sensor_configuration_->cloud_min_angle > sensor_configuration_->cloud_max_angle &&
(azimuth_corrected <= sensor_configuration_->cloud_max_angle * 100 ||
azimuth_corrected >= sensor_configuration_->cloud_min_angle * 100))) &&
!check_excluded_point(corrections.laser_ring, azimuth_corrected)) {
azimuth_corrected >= sensor_configuration_->cloud_min_angle * 100));

const bool is_not_excluded_point =
!check_excluded_point(corrections.laser_ring, azimuth_corrected);

if ((is_within_min_max_angle || is_outside_max_min_angle) && is_not_excluded_point) {
// convert polar coordinates to Euclidean XYZ.
const float cos_vert_angle = corrections.cos_vert_correction;
const float sin_vert_angle = corrections.sin_vert_correction;
Expand Down

0 comments on commit a47d4a7

Please sign in to comment.