Skip to content

Commit

Permalink
Fixed Are_mergable_2 functor; add code that tests whether the equal o…
Browse files Browse the repository at this point in the history
…perator (operator==) is applicable to the data that extends the curve
  • Loading branch information
efifogel committed Nov 9, 2023
1 parent 7458d6a commit a850c34
Showing 1 changed file with 20 additions and 16 deletions.
36 changes: 20 additions & 16 deletions Arrangement_on_surface_2/include/CGAL/Arr_curve_data_traits_2.h
Original file line number Diff line number Diff line change
Expand Up @@ -247,38 +247,42 @@ class Arr_curve_data_traits_2 : public Traits_ {
private:
const Base_traits_2& m_base;

/*! Generate a helper class template to find out whether the base geometry
* traits has a nested type named Are_mergeable_2.
*/
BOOST_MPL_HAS_XXX_TRAIT_NAMED_DEF(has_are_mergeable_2,
Are_mergeable_2, false)
template <typename T>
bool are_mergeable_data(const T& cv1, const T& cv2, long) const {
CGAL_error_msg("Equality operator is not supported.");
return false;
}

template <typename T>
auto are_mergeable_data(const T& cv1, const T& cv2, int) const ->
decltype(cv1.data() == cv2.data())
{ return cv1.data() == cv2.data(); }

/*! Implementation of the predicate in case the base geometry traits class
* has a nested type named Are_mergeable_2.
*/
template <typename GeomeTraits_2>
std::enable_if_t<has_are_mergeable_2<GeomeTraits_2>::value,bool>
are_mergeable(const X_monotone_curve_2& cv1,
const X_monotone_curve_2& cv2) const
{
auto are_mergeable(const X_monotone_curve_2& cv1,
const X_monotone_curve_2& cv2,
const GeomeTraits_2& traits, int) const ->
decltype(traits.are_mergeable_2_object(), bool()) {
// In case the two base curves are not mergeable, the extended curves
// are not mergeable as well.
if (! (m_base.are_mergeable_2_object()(cv1, cv2))) return false;
if (! (traits.are_mergeable_2_object()(cv1, cv2))) return false;

// In case the two base curves are mergeable, check that they have the
// same data fields.
return (cv1.data() == cv2.data());
return are_mergeable_data(cv1, cv2, 0);
}

/*! Implementation of the predicate in case the base geometry traits class
* does not have a nested type named Are_mergeable_2.
* This function should never be called!
*/
template <typename GeomeTraits_2>
std::enable_if_t<!has_are_mergeable_2<GeomeTraits_2>::value,bool>
are_mergeable(const X_monotone_curve_2& /* cv1 */,
const X_monotone_curve_2& /* cv2 */) const
{
bool are_mergeable(const X_monotone_curve_2& /* cv1 */,
const X_monotone_curve_2& /* cv2 */,
const GeomeTraits_2& /* traits */, long) const {
CGAL_error_msg("Are mergeable is not supported.");
return false;
}
Expand All @@ -294,7 +298,7 @@ class Arr_curve_data_traits_2 : public Traits_ {
*/
bool operator()(const X_monotone_curve_2& cv1,
const X_monotone_curve_2& cv2) const
{ return are_mergeable<Base_traits_2>(cv1, cv2); }
{ return are_mergeable<Base_traits_2>(cv1, cv2, m_base, 0); }
};

/*! Obtain an Are_mergeable_2 functor object. */
Expand Down

0 comments on commit a850c34

Please sign in to comment.