From c1389c006df5a84381565bc893787b0f79a52de9 Mon Sep 17 00:00:00 2001 From: Sylvain Pion Date: Tue, 12 Aug 2008 12:43:20 +0000 Subject: [PATCH] Add a couple of handy functions: bool are_sorted(const T & a, const T & b, const T & c) bool are_strictly_sorted(const T & a, const T & b, const T & c) bool are_ordered(const T & a, const T & b, const T & c) bool are_strictly_ordered(const T & a, const T & b, const T & c) --- .../include/CGAL/predicates/kernel_ftC2.h | 7 ++-- STL_Extension/include/CGAL/algorithm.h | 40 ++++++++++++++++++- 2 files changed, 43 insertions(+), 4 deletions(-) diff --git a/Cartesian_kernel/include/CGAL/predicates/kernel_ftC2.h b/Cartesian_kernel/include/CGAL/predicates/kernel_ftC2.h index f17c69f3af0..a9f79fd092c 100644 --- a/Cartesian_kernel/include/CGAL/predicates/kernel_ftC2.h +++ b/Cartesian_kernel/include/CGAL/predicates/kernel_ftC2.h @@ -25,6 +25,7 @@ #ifndef CGAL_PREDICATES_KERNEL_FTC2_H #define CGAL_PREDICATES_KERNEL_FTC2_H +#include #include #include #include @@ -195,7 +196,7 @@ compare_y_at_xC2(const FT &px, const FT &py, // compares the y-coordinates of p and the vertical projection of p on s. // Precondition : p is in the x-range of s. - CGAL_kernel_precondition(px >= (CGAL::min)(ssx, stx) && px <= (CGAL::max)(ssx, stx)); + CGAL_kernel_precondition(are_ordered(ssx, px, stx)); if (ssx < stx) return orientationC2(px, py, ssx, ssy, stx, sty); @@ -225,8 +226,8 @@ compare_y_at_x_segment_C2(const FT &px, // - if the segments intersect, return EQUAL // - if not, return the obvious SMALLER/LARGER. - CGAL_kernel_precondition(px >= (CGAL::min)(s1sx, s1tx) && px <= (CGAL::max)(s1sx, s1tx)); - CGAL_kernel_precondition(px >= (CGAL::min)(s2sx, s2tx) && px <= (CGAL::max)(s2sx, s2tx)); + CGAL_kernel_precondition(are_ordered(s1sx, px, s1tx)); + CGAL_kernel_precondition(are_ordered(s2sx, px, s2tx)); if (s1sx != s1tx && s2sx != s2tx) { FT s1stx = s1sx-s1tx; diff --git a/STL_Extension/include/CGAL/algorithm.h b/STL_Extension/include/CGAL/algorithm.h index 135d2e9fd80..1ed3d2568f1 100644 --- a/STL_Extension/include/CGAL/algorithm.h +++ b/STL_Extension/include/CGAL/algorithm.h @@ -29,11 +29,49 @@ #include #include #include - #include CGAL_BEGIN_NAMESPACE +// Not documented +template inline +bool +are_sorted(const T & a, const T & b, const T & c) +{ + return a <= b && b <= c; +} + +// Not documented +template inline +bool +are_strictly_sorted(const T & a, const T & b, const T & c) +{ + return a < b && b < c; +} + +// Not documented +// Checks that b is in the interval [min(a, c) , max(a, c)]. +template inline +bool +are_ordered(const T & a, const T & b, const T & c) +{ + const T& min = (CGAL::min)(a, c); + const T& max = (CGAL::max)(a, c); + return min <= b && b <= max; +} + +// Not documented +// Checks that b is in the interval ]min(a, c) , max(a, c)[. +template inline +bool +are_strictly_ordered(const T & a, const T & b, const T & c) +{ + const T& min = (CGAL::min)(a, c); + const T& max = (CGAL::max)(a, c); + return min < b && b < max; +} + + template inline ForwardIterator