Skip to content

Commit

Permalink
Use if constexpr macro instead of condition macro.
Browse files Browse the repository at this point in the history
  • Loading branch information
awulkiew committed Feb 24, 2024
1 parent 16a7423 commit f25545b
Show file tree
Hide file tree
Showing 41 changed files with 909 additions and 810 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
#include <boost/geometry/strategies/convex_hull/spherical.hpp>
#include <boost/geometry/strategies/default_strategy.hpp>

#include <boost/geometry/util/condition.hpp>
#include <boost/geometry/util/constexpr.hpp>
#include <boost/geometry/util/range.hpp>
#include <boost/geometry/util/sequence.hpp>
#include <boost/geometry/util/type_traits.hpp>
Expand Down Expand Up @@ -240,7 +240,7 @@ struct convex_hull<Box, box_tag>
geometry::detail::assign_box_corners_oriented<Reverse>(box, arr);

std::move(arr.begin(), arr.end(), range::back_inserter(out));
if (BOOST_GEOMETRY_CONDITION(Close))
if BOOST_GEOMETRY_CONSTEXPR (Close)
{
range::push_back(out, range::front(out));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
// Boost.Geometry (aka GGL, Generic Geometry Library)

// Copyright (c) 2014-2021, Oracle and/or its affiliates.
// Copyright (c) 2023 Adam Wulkiewicz, Lodz, Poland.

// Copyright (c) 2014-2021, Oracle and/or its affiliates.
// Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle
// Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle

Expand Down Expand Up @@ -35,7 +36,7 @@
#include <boost/geometry/strategies/distance.hpp>
#include <boost/geometry/strategies/tags.hpp>

#include <boost/geometry/util/condition.hpp>
#include <boost/geometry/util/constexpr.hpp>


namespace boost { namespace geometry
Expand Down Expand Up @@ -247,26 +248,28 @@ class geometry_to_segment_or_box
}
}

if (BOOST_GEOMETRY_CONDITION(is_comparable<strategy_type>::value))
if BOOST_GEOMETRY_CONSTEXPR (is_comparable<strategy_type>::value)
{
return (std::min)(cd_min1, cd_min2);
}

if (cd_min1 < cd_min2)
{
return strategy.apply(*pit_min, *it_min1, *it_min2);
}
else
else // else prevents unreachable code warning
{
return dispatch::distance
<
segment_or_box_point,
typename std::iterator_traits
<
segment_iterator_type
>::value_type,
Strategies
>::apply(*it_min, *sit_min, strategies);
if (cd_min1 < cd_min2)
{
return strategy.apply(*pit_min, *it_min1, *it_min2);
}
else
{
return dispatch::distance
<
segment_or_box_point,
typename std::iterator_traits
<
segment_iterator_type
>::value_type,
Strategies
>::apply(*it_min, *sit_min, strategies);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// Boost.Geometry (aka GGL, Generic Geometry Library)

// Copyright (c) 2023-2024 Adam Wulkiewicz, Lodz, Poland.

// Copyright (c) 2014-2023 Oracle and/or its affiliates.

// Contributed and/or modified by Vissarion Fysikopoulos, on behalf of Oracle
Expand Down Expand Up @@ -41,7 +43,7 @@
#include <boost/geometry/policies/compare.hpp>

#include <boost/geometry/util/calculation_type.hpp>
#include <boost/geometry/util/condition.hpp>
#include <boost/geometry/util/constexpr.hpp>
#include <boost/geometry/util/has_nan_coordinate.hpp>
#include <boost/geometry/util/math.hpp>

Expand Down Expand Up @@ -154,21 +156,23 @@ class segment_to_box_2D_generic
}
}

if (BOOST_GEOMETRY_CONDITION(is_comparable<ps_strategy_type>::value))
if BOOST_GEOMETRY_CONSTEXPR (is_comparable<ps_strategy_type>::value)
{
return cd[imin];
}

if (imin < 4)
{
return strategy.apply(box_points[imin], p[0], p[1]);
}
else
else // else prevents unreachable code warning
{
unsigned int bimin = imin - 4;
return strategy.apply(p[bimin],
*bit_min[bimin].first,
*bit_min[bimin].second);
if (imin < 4)
{
return strategy.apply(box_points[imin], p[0], p[1]);
}
else
{
unsigned int bimin = imin - 4;
return strategy.apply(p[bimin],
*bit_min[bimin].first,
*bit_min[bimin].second);
}
}
}
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
// Boost.Geometry (aka GGL, Generic Geometry Library)

// Copyright (c) 2014-2021, Oracle and/or its affiliates.
// Copyright (c) 2023 Adam Wulkiewicz, Lodz, Poland.

// Copyright (c) 2014-2021, Oracle and/or its affiliates.
// Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle
// Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle

Expand All @@ -28,7 +29,7 @@
#include <boost/geometry/strategies/distance.hpp>
#include <boost/geometry/strategies/tags.hpp>

#include <boost/geometry/util/condition.hpp>
#include <boost/geometry/util/constexpr.hpp>


namespace boost { namespace geometry
Expand Down Expand Up @@ -82,21 +83,23 @@ class segment_to_segment
std::size_t imin = std::distance(boost::addressof(d[0]),
std::min_element(d, d + 4));

if (BOOST_GEOMETRY_CONDITION(is_comparable<strategy_type>::value))
if BOOST_GEOMETRY_CONSTEXPR (is_comparable<strategy_type>::value)
{
return d[imin];
}

switch (imin)
else // else prevents unreachable code warning
{
case 0:
return strategy.apply(q[0], p[0], p[1]);
case 1:
return strategy.apply(q[1], p[0], p[1]);
case 2:
return strategy.apply(p[0], q[0], q[1]);
default:
return strategy.apply(p[1], q[0], q[1]);
switch (imin)
{
case 0:
return strategy.apply(q[0], p[0], p[1]);
case 1:
return strategy.apply(q[1], p[0], p[1]);
case 2:
return strategy.apply(p[0], q[0], q[1]);
default:
return strategy.apply(p[1], q[0], q[1]);
}
}
}
};
Expand Down
31 changes: 16 additions & 15 deletions include/boost/geometry/algorithms/detail/is_valid/pointlike.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
// Boost.Geometry (aka GGL, Generic Geometry Library)

// Copyright (c) 2014-2020, Oracle and/or its affiliates.
// Copyright (c) 2023 Adam Wulkiewicz, Lodz, Poland.

// Copyright (c) 2014-2020, Oracle and/or its affiliates.
// Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle
// Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle

Expand All @@ -20,7 +21,7 @@
#include <boost/geometry/algorithms/detail/is_valid/has_invalid_coordinate.hpp>
#include <boost/geometry/algorithms/dispatch/is_valid.hpp>

#include <boost/geometry/util/condition.hpp>
#include <boost/geometry/util/constexpr.hpp>


namespace boost { namespace geometry
Expand Down Expand Up @@ -63,21 +64,21 @@ struct is_valid<MultiPoint, multi_point_tag, AllowEmptyMultiGeometries>
{
boost::ignore_unused(multipoint, visitor);

if (BOOST_GEOMETRY_CONDITION(
AllowEmptyMultiGeometries || !boost::empty(multipoint)))
{
// we allow empty multi-geometries, so an empty multipoint
// is considered valid
return ! detail::is_valid::has_invalid_coordinate
<
MultiPoint
>::apply(multipoint, visitor);
}
else
if BOOST_GEOMETRY_CONSTEXPR (! AllowEmptyMultiGeometries)
{
// we do not allow an empty multipoint
return visitor.template apply<failure_few_points>();
if (boost::empty(multipoint))
{
// we do not allow an empty multipoint
return visitor.template apply<failure_few_points>();
}
}

// if we allow empty multi-geometries, an empty multipoint
// is considered valid
return ! detail::is_valid::has_invalid_coordinate
<
MultiPoint
>::apply(multipoint, visitor);
}
};

Expand Down
60 changes: 31 additions & 29 deletions include/boost/geometry/algorithms/detail/is_valid/polygon.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -450,42 +450,44 @@ class is_valid_polygon
{
return true;
}
else // else prevents unreachable code warning
{
// compute turns and check if all are acceptable
typedef debug_validity_phase<Polygon> debug_phase;
debug_phase::apply(3);

// compute turns and check if all are acceptable
typedef debug_validity_phase<Polygon> debug_phase;
debug_phase::apply(3);

typedef has_valid_self_turns<Polygon, typename Strategy::cs_tag> has_valid_turns;
typedef has_valid_self_turns<Polygon, typename Strategy::cs_tag> has_valid_turns;

std::deque<typename has_valid_turns::turn_type> turns;
bool has_invalid_turns
= ! has_valid_turns::apply(polygon, turns, visitor, strategy);
debug_print_turns(turns.begin(), turns.end());
std::deque<typename has_valid_turns::turn_type> turns;
bool has_invalid_turns
= ! has_valid_turns::apply(polygon, turns, visitor, strategy);
debug_print_turns(turns.begin(), turns.end());

if (has_invalid_turns)
{
return false;
}
if (has_invalid_turns)
{
return false;
}

// check if all interior rings are inside the exterior ring
debug_phase::apply(4);
// check if all interior rings are inside the exterior ring
debug_phase::apply(4);

if (! has_holes_inside::apply(polygon,
turns.begin(), turns.end(),
visitor,
strategy))
{
return false;
}
if (! has_holes_inside::apply(polygon,
turns.begin(), turns.end(),
visitor,
strategy))
{
return false;
}

// check whether the interior of the polygon is a connected set
debug_phase::apply(5);
// check whether the interior of the polygon is a connected set
debug_phase::apply(5);

return has_connected_interior::apply(polygon,
turns.begin(),
turns.end(),
visitor,
strategy);
return has_connected_interior::apply(polygon,
turns.begin(),
turns.end(),
visitor,
strategy);
}
}
};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// Boost.Geometry (aka GGL, Generic Geometry Library)

// Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands.
// Copyright (c) 2023 Adam Wulkiewicz, Lodz, Poland.

// This file was modified by Oracle on 2014-2020.
// Modifications copyright (c) 2014-2020 Oracle and/or its affiliates.

// Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle

// Use, modification and distribution is subject to the Boost Software License,
Expand All @@ -29,7 +29,7 @@

#include <boost/geometry/core/closure.hpp>

#include <boost/geometry/util/condition.hpp>
#include <boost/geometry/util/constexpr.hpp>
#include <boost/geometry/util/range.hpp>


Expand All @@ -53,30 +53,32 @@ inline bool points_equal_or_close(Point1 const& point1,
return true;
}

if (BOOST_GEOMETRY_CONDITION(! RobustPolicy::enabled))
if BOOST_GEOMETRY_CONSTEXPR (! RobustPolicy::enabled)
{
return false;
}

// Try using specified robust policy
typedef typename geometry::robust_point_type
<
Point1,
RobustPolicy
>::type robust_point_type;

robust_point_type point1_rob, point2_rob;
geometry::recalculate(point1_rob, point1, robust_policy);
geometry::recalculate(point2_rob, point2, robust_policy);

// Only if this is the case the same strategy can be used.
BOOST_STATIC_ASSERT((std::is_same
<
typename geometry::cs_tag<Point1>::type,
typename geometry::cs_tag<robust_point_type>::type
>::value));

return detail::equals::equals_point_point(point1_rob, point2_rob, strategy);
else // else prevents unreachable code warning
{
// Try using specified robust policy
using robust_point_type = typename geometry::robust_point_type
<
Point1,
RobustPolicy
>::type;

robust_point_type point1_rob, point2_rob;
geometry::recalculate(point1_rob, point1, robust_policy);
geometry::recalculate(point2_rob, point2, robust_policy);

// Only if this is the case the same strategy can be used.
BOOST_STATIC_ASSERT((std::is_same
<
typename geometry::cs_tag<Point1>::type,
typename geometry::cs_tag<robust_point_type>::type
>::value));

return detail::equals::equals_point_point(point1_rob, point2_rob, strategy);
}
}


Expand Down Expand Up @@ -214,7 +216,7 @@ inline void remove_spikes_at_closure(Ring& ring, Strategy const& strategy,
template <typename Ring, typename Strategy>
inline void fix_closure(Ring& ring, Strategy const& strategy)
{
if (BOOST_GEOMETRY_CONDITION(geometry::closure<Ring>::value == geometry::open))
if BOOST_GEOMETRY_CONSTEXPR (geometry::closure<Ring>::value == geometry::open)
{
if (! boost::empty(ring)
&& detail::equals::equals_point_point(range::front(ring), range::back(ring), strategy))
Expand Down
Loading

0 comments on commit f25545b

Please sign in to comment.