Skip to content

Commit 641b06e

Browse files
DIlkhush00mvieth
andauthored
Simplify boolean expression by DeMorgan's theorem (#6129)
* Simplify boolean expression by DeMorgan's theorem * fix indentation * Fix boolean expressions Co-authored-by: Markus Vieth <[email protected]> * Correct boolean expressions Co-authored-by: Markus Vieth <[email protected]> * avoid "exact equality" comparison between floating point numbers --------- Co-authored-by: Markus Vieth <[email protected]>
1 parent c02905a commit 641b06e

File tree

12 files changed

+17
-18
lines changed

12 files changed

+17
-18
lines changed

common/include/pcl/range_image/impl/range_image.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,7 @@ RangeImage::isValid (int index) const
470470
bool
471471
RangeImage::isObserved (int x, int y) const
472472
{
473-
return !(!isInImage (x,y) || (std::isinf (getPoint (x,y).range) && getPoint (x,y).range < 0.0f));
473+
return (isInImage (x,y) && (!std::isinf (getPoint (x,y).range) || getPoint (x,y).range >= 0.0f));
474474
}
475475

476476
/////////////////////////////////////////////////////////////////////////

features/include/pcl/features/impl/range_image_border_extractor.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ bool RangeImageBorderExtractor::calculateMainPrincipalCurvature(int x, int y, in
334334
bool& beam_valid = beams_valid[beam_idx++];
335335
if (step==1)
336336
{
337-
beam_valid = !(x2==x && y2==y);
337+
beam_valid = (x2!=x || y2!=y);
338338
}
339339
else
340340
if (!beam_valid)

geometry/include/pcl/geometry/mesh_base.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1333,7 +1333,7 @@ class MeshBase {
13331333
HalfEdgeIndex& /*idx_free_half_edge*/,
13341334
std::true_type /*is_manifold*/) const
13351335
{
1336-
return !(is_new_ab && is_new_bc && !is_isolated_b);
1336+
return (!is_new_ab || !is_new_bc || is_isolated_b);
13371337
}
13381338

13391339
/** \brief Check if the half-edge bc is the next half-edge of ab.

keypoints/src/brisk_2d.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1192,7 +1192,7 @@ pcl::keypoints::brisk::ScaleSpace::subpixel2D (
11921192
return (static_cast<float>(coeff6) / 18.0f);
11931193
}
11941194

1195-
if (!(H_det > 0 && coeff1 < 0))
1195+
if (H_det <= 0 || coeff1 >= 0)
11961196
{
11971197
// The maximum must be at the one of the 4 patch corners.
11981198
int tmp_max = coeff3 + coeff4 + coeff5;

octree/include/pcl/octree/impl/octree_search.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -557,9 +557,9 @@ OctreePointCloudSearch<PointT, LeafContainerT, BranchContainerT>::boxSearchRecur
557557

558558
// test if search region overlap with voxel space
559559

560-
if (!((lower_voxel_corner(0) > max_pt(0)) || (min_pt(0) > upper_voxel_corner(0)) ||
561-
(lower_voxel_corner(1) > max_pt(1)) || (min_pt(1) > upper_voxel_corner(1)) ||
562-
(lower_voxel_corner(2) > max_pt(2)) || (min_pt(2) > upper_voxel_corner(2)))) {
560+
if ((lower_voxel_corner(0) <= max_pt(0)) && (min_pt(0) <= upper_voxel_corner(0)) &&
561+
(lower_voxel_corner(1) <= max_pt(1)) && (min_pt(1) <= upper_voxel_corner(1)) &&
562+
(lower_voxel_corner(2) <= max_pt(2)) && (min_pt(2) <= upper_voxel_corner(2))) {
563563

564564
if (child_node->getNodeType() == BRANCH_NODE) {
565565
// we have not reached maximum tree depth

recognition/include/pcl/recognition/ransac_based/bvh.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,8 +190,8 @@ namespace pcl
190190
inline bool
191191
intersect(const float box[6]) const
192192
{
193-
return !(box[1] < bounds_[0] || box[3] < bounds_[2] || box[5] < bounds_[4] ||
194-
box[0] > bounds_[1] || box[2] > bounds_[3] || box[4] > bounds_[5]);
193+
return (box[1] >= bounds_[0] && box[3] >= bounds_[2] && box[5] >= bounds_[4] &&
194+
box[0] <= bounds_[1] && box[2] <= bounds_[3] && box[4] <= bounds_[5]);
195195
}
196196

197197
/** \brief Computes and returns the volume of the bounding box of this node. */

registration/include/pcl/registration/impl/ndt.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -730,8 +730,8 @@ NormalDistributionsTransform<PointSource, PointTarget, Scalar>::computeStepLengt
730730
// the sufficient decrease, Equation 1.1, and curvature condition, Equation 1.2 [More,
731731
// Thuente 1994]
732732
while (!interval_converged && step_iterations < max_step_iterations &&
733-
!(psi_t <= 0 /*Sufficient Decrease*/ &&
734-
d_phi_t <= -nu * d_phi_0 /*Curvature Condition*/)) {
733+
(psi_t > 0 /*Sufficient Decrease*/ ||
734+
d_phi_t > -nu * d_phi_0 /*Curvature Condition*/)) {
735735
// Use auxiliary function if interval I is not closed
736736
if (open_interval) {
737737
a_t = trialValueSelectionMT(a_l, f_l, g_l, a_u, f_u, g_u, a_t, psi_t, d_psi_t);

segmentation/include/pcl/segmentation/plane_refinement_comparator.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ namespace pcl
177177
int current_label = (*labels_)[idx1].label;
178178
int next_label = (*labels_)[idx2].label;
179179

180-
if (!((*refine_labels_)[current_label] && !(*refine_labels_)[next_label]))
180+
if (!(*refine_labels_)[current_label] || (*refine_labels_)[next_label])
181181
return (false);
182182

183183
const pcl::ModelCoefficients& model_coeff = (*models_)[(*label_to_model_)[current_label]];

surface/include/pcl/surface/impl/convex_hull.hpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,13 +85,12 @@ pcl::ConvexHull<PointInT>::performReconstruction2D (PointCloud &hull, std::vecto
8585
PointInT p0 = (*input_)[(*indices_)[0]];
8686
PointInT p1 = (*input_)[(*indices_)[indices_->size () - 1]];
8787
PointInT p2 = (*input_)[(*indices_)[indices_->size () / 2]];
88-
Eigen::Array4f dy1dy2 = (p1.getArray4fMap () - p0.getArray4fMap ()) / (p2.getArray4fMap () - p0.getArray4fMap ());
89-
while (!( (dy1dy2[0] != dy1dy2[1]) || (dy1dy2[2] != dy1dy2[1]) ) )
88+
while (!pcl::isXYZFinite(p0) || !pcl::isXYZFinite(p1) || !pcl::isXYZFinite(p2) ||
89+
(p1.getVector3fMap() - p0.getVector3fMap()).cross(p2.getVector3fMap() - p0.getVector3fMap()).stableNorm() < Eigen::NumTraits<float>::dummy_precision ())
9090
{
9191
p0 = (*input_)[(*indices_)[rand () % indices_->size ()]];
9292
p1 = (*input_)[(*indices_)[rand () % indices_->size ()]];
9393
p2 = (*input_)[(*indices_)[rand () % indices_->size ()]];
94-
dy1dy2 = (p1.getArray4fMap () - p0.getArray4fMap ()) / (p2.getArray4fMap () - p0.getArray4fMap ());
9594
}
9695

9796
pcl::PointCloud<PointInT> normal_calc_cloud;

surface/include/pcl/surface/impl/gp3.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -667,7 +667,7 @@ pcl::GreedyProjectionTriangulation<PointInT>::reconstructPolygons (std::vector<p
667667
}
668668
if (inside_CB && !outside_CB)
669669
need_invert = true;
670-
else if (!(!inside_CB && outside_CB))
670+
else if (inside_CB || !outside_CB)
671671
{
672672
if ((angles_[end].angle - angles_[start].angle) < M_PI)
673673
need_invert = true;

0 commit comments

Comments
 (0)