optimize filter failures

cmp_epeck_points.cpp runtime goes from 23s. to 5s.

based on mglisse suggestion
This commit is contained in:
Sébastien Loriot 2021-04-10 07:10:29 +02:00
parent 51490546c1
commit 68dc09b3d9
4 changed files with 26 additions and 21 deletions

View File

@ -55,10 +55,10 @@ equal_lineC2(const FT &l1a, const FT &l1b, const FT &l1c,
return false; // Not parallel.
typename Sgn<FT>::result_type s1a = CGAL_NTS sign(l1a);
if (s1a != ZERO)
return s1a == CGAL_NTS sign(l2a)
&& sign_of_determinant(l1a, l1c, l2a, l2c) == ZERO;
return CGAL_NTS sign(l1b) == CGAL_NTS sign(l2b)
&& sign_of_determinant(l1b, l1c, l2b, l2c) == ZERO;
return CGAL_AND(s1a == CGAL_NTS sign(l2a),
sign_of_determinant(l1a, l1c, l2a, l2c) == ZERO);
return CGAL_AND(CGAL_NTS sign(l1b) == CGAL_NTS sign(l2b),
sign_of_determinant(l1b, l1c, l2b, l2c) == ZERO);
}
template < class FT >
@ -230,7 +230,7 @@ compare_y_at_x_segment_C2(const FT &px,
CGAL_kernel_precondition(are_ordered(s1sx, px, s1tx));
CGAL_kernel_precondition(are_ordered(s2sx, px, s2tx));
if (s1sx != s1tx && s2sx != s2tx) {
if (CGAL_AND(s1sx != s1tx, s2sx != s2tx)) {
FT s1stx = s1sx-s1tx;
FT s2stx = s2sx-s2tx;
@ -265,9 +265,9 @@ typename Equal_to<FT>::result_type
equal_directionC2(const FT &dx1, const FT &dy1,
const FT &dx2, const FT &dy2)
{
return CGAL_NTS sign(dx1) == CGAL_NTS sign(dx2)
&& CGAL_NTS sign(dy1) == CGAL_NTS sign(dy2)
&& sign_of_determinant(dx1, dy1, dx2, dy2) == ZERO;
return CGAL_AND_3( CGAL_NTS sign(dx1) == CGAL_NTS sign(dx2),
CGAL_NTS sign(dy1) == CGAL_NTS sign(dy2),
sign_of_determinant(dx1, dy1, dx2, dy2) == ZERO );
}
template < class FT >
@ -391,7 +391,9 @@ typename Compare<FT>::result_type
compare_lexicographically_xyC2(const FT &px, const FT &py,
const FT &qx, const FT &qy)
{
typename Compare<FT>::result_type c = CGAL_NTS compare(px,qx);
typedef typename Compare<FT>::result_type Cmp;
Cmp c = CGAL_NTS compare(px,qx);
if (is_indeterminate(c)) return indeterminate<Cmp>();
return (c != EQUAL) ? c : CGAL_NTS compare(py,qy);
}

View File

@ -61,8 +61,10 @@ compare_lexicographically_xyzC3(const FT &px, const FT &py, const FT &pz,
{
typedef typename Compare<FT>::result_type Cmp;
Cmp c = CGAL_NTS compare(px, qx);
if (is_indeterminate(c)) return indeterminate<Cmp>();
if (c != EQUAL) return c;
c = CGAL_NTS compare(py, qy);
if (is_indeterminate(c)) return indeterminate<Cmp>();
if (c != EQUAL) return c;
return CGAL_NTS compare(pz, qz);
}
@ -288,12 +290,12 @@ typename Equal_to<FT>::result_type
equal_directionC3(const FT &dx1, const FT &dy1, const FT &dz1,
const FT &dx2, const FT &dy2, const FT &dz2)
{
return sign_of_determinant(dx1, dy1, dx2, dy2) == ZERO
&& sign_of_determinant(dx1, dz1, dx2, dz2) == ZERO
&& sign_of_determinant(dy1, dz1, dy2, dz2) == ZERO
&& CGAL_NTS sign(dx1) == CGAL_NTS sign(dx2)
&& CGAL_NTS sign(dy1) == CGAL_NTS sign(dy2)
&& CGAL_NTS sign(dz1) == CGAL_NTS sign(dz2);
return CGAL_AND_6(sign_of_determinant(dx1, dy1, dx2, dy2) == ZERO,
sign_of_determinant(dx1, dz1, dx2, dz2) == ZERO,
sign_of_determinant(dy1, dz1, dy2, dz2) == ZERO,
CGAL_NTS sign(dx1) == CGAL_NTS sign(dx2),
CGAL_NTS sign(dy1) == CGAL_NTS sign(dy2),
CGAL_NTS sign(dz1) == CGAL_NTS sign(dz2) );
}
template < class FT >
@ -313,10 +315,10 @@ equal_planeC3(const FT &ha, const FT &hb, const FT &hc, const FT &hd,
sign_of_determinant(pa, pd, ha, hd) == ZERO );
Sg s1b = CGAL_NTS sign(hb);
if (s1b != ZERO)
return s1b == CGAL_NTS sign(pb)
&& sign_of_determinant(pb, pd, hb, hd) == ZERO;
return CGAL_NTS sign(pc) == CGAL_NTS sign(hc)
&& sign_of_determinant(pc, pd, hc, hd) == ZERO;
return CGAL_AND(s1b == CGAL_NTS sign(pb),
sign_of_determinant(pb, pd, hb, hd) == ZERO );
return CGAL_AND( CGAL_NTS sign(pc) == CGAL_NTS sign(hc),
sign_of_determinant(pc, pd, hc, hd) == ZERO );
}
template <class FT >

View File

@ -3111,7 +3111,7 @@ namespace CommonKernelFunctors {
result_type
operator()(const Iso_rectangle_2& i1, const Iso_rectangle_2& i2) const
{
return ((i1.min)() == (i2.min)()) && ((i1.max)() == (i2.max)());
return CGAL_AND((i1.min)() == (i2.min)(), (i1.max)() == (i2.max)());
}
};
@ -3138,7 +3138,7 @@ namespace CommonKernelFunctors {
result_type
operator()(const Point_3 &p, const Point_3 &q) const
{
return p.x() == q.x() && p.y() == q.y() && p.z() == q.z();
return CGAL_AND_3(p.x() == q.x(), p.y() == q.y(), p.z() == q.z());
}
result_type

View File

@ -348,6 +348,7 @@ Uncertain<bool> operator&(Uncertain<bool> a, bool b)
#endif
#define CGAL_AND_3(X, Y, Z) CGAL_AND(X, CGAL_AND(Y, Z))
#define CGAL_AND_6(A, B, C, D, E, F) CGAL_AND(CGAL_AND_3(A, B, C), CGAL_AND_3(D, E,F))
#define CGAL_OR_3(X, Y, Z) CGAL_OR(X, CGAL_OR(Y, Z))