Merge pull request #4099 from sloriot/CGAL-epeck_pts_cmp

Speed up comparison of points
This commit is contained in:
Sebastien Loriot 2021-04-21 15:24:11 +02:00 committed by GitHub
commit 5b253ad2fc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 88 additions and 22 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

@ -480,6 +480,16 @@ public:
};
struct Less_xyz_3 : public BaseClass::Less_xyz_3
{
typedef typename Kernel_::Point_3 Point_3;
bool operator()(const Point_3& p, const Point_3& q) const
{
if (p.rep().identical(q.rep())) { return false; }
return BaseClass::Less_xyz_3::operator()(p,q);
}
};
Construct_point_2 construct_point_2_object() const
{
@ -502,7 +512,6 @@ public:
return Compute_weight_3();
}
Assign_2
assign_2_object() const
{ return Assign_2(); }
@ -534,6 +543,10 @@ public:
Compute_approximate_area_3
compute_approximate_area_3_object() const
{ return Compute_approximate_area_3(); }
Less_xyz_3
less_xyz_3_object() const
{ return Less_xyz_3(); }
}; // end class Lazy_kernel_base<EK_, AK_, E2A_, Kernel_2>

View File

@ -0,0 +1,12 @@
# Created by the script cgal_create_cmake_script
# This is the CMake script for compiling a CGAL application.
cmake_minimum_required(VERSION 3.1...3.14)
project( benchmark )
find_package(CGAL REQUIRED QUIET OPTIONAL_COMPONENTS Core )
include_directories (BEFORE "../include")
create_single_source_cgal_program( "cmp_epeck_points.cpp" )

View File

@ -0,0 +1,36 @@
#define TEST_IDENTICAL
#include <CGAL/Exact_predicates_exact_constructions_kernel.h>
#include <CGAL/Timer.h>
#include <vector>
#include <algorithm>
typedef CGAL::Exact_predicates_exact_constructions_kernel K;
typedef K::Point_3 Point_3;
typedef K::Vector_3 Vector_3;
int main(){
int N = 10000000;
std::vector<Point_3> points(N);
int count = 0;
for(int i = 0; i < N; i+=10){
points[i] = Point_3((N-i) * CGAL_PI , 0, 0) + Vector_3(i * (CGAL_PI/2.0), 0, 0);
if(points[i].approx().x().inf() != points[i].approx().x().sup()){
++count;
}
for(int j = 1; j < 10; j++){
points[i+j] = points[i];
}
}
std::cout << count << " points approx().x().inf() != approx().x().sup()" << std::endl;
CGAL::Timer t;
t.start();
std::sort(points.begin(), points.end());
std::cout << t.time() << " sec." << std::endl;
return 0;
}

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))