Merge pull request #3345 from afabri/Kernel-fix_Point_2_Line_2_projection-GF

Improve Projection of 2D point on line
This commit is contained in:
Laurent Rineau 2018-10-29 10:27:30 +01:00
commit 3601c6d69e
2 changed files with 24 additions and 17 deletions

View File

@ -313,34 +313,24 @@ line_project_pointC2(const FT &la, const FT &lb, const FT &lc,
const FT &px, const FT &py,
FT &x, FT &y)
{
#if 1 // FIXME
// Original old version
if (CGAL_NTS is_zero(la)) // horizontal line
if (certainly(is_zero(la))) // horizontal line
{
x = px;
y = -lc/lb;
}
else if (CGAL_NTS is_zero(lb)) // vertical line
else if (certainly(is_zero(lb))) // vertical line
{
x = -lc/la;
y = py;
}
else
{
FT ab = la/lb, ba = lb/la, ca = lc/la;
y = ( -px + ab*py - ca ) / ( ba + ab );
x = -ba * y - ca;
FT a2 = CGAL_NTS square(la);
FT b2 = CGAL_NTS square(lb);
FT d = a2 + b2;
x = (b2*px - la*lb*py - la*lc) / d;
y = (-la*lb*px + a2*py - lb*lc) / d;
}
#else
// New version, with more multiplications, but less divisions and tests.
// Let's compare the results of the 2, benchmark them, as well as check
// the precision with the intervals.
FT a2 = CGAL_NTS square(la);
FT b2 = CGAL_NTS square(lb);
FT d = a2 + b2;
x = (la * (lb * py - lc) - px * b2) / d;
y = (lb * (lc - la * px) + py * a2) / d;
#endif
}
template < class FT >

View File

@ -0,0 +1,17 @@
#include <CGAL/Simple_cartesian.h>
#include <iostream>
typedef CGAL::Simple_cartesian<double> K;
typedef K::Point_2 Point_2;
typedef K::Line_2 Line_2;
int main()
{
Line_2 line(-4.2885603045067812e-18, 1, 250.73609999999996);
Point_2 point(35.306000000000004, 250.69800000000001);
std::cout.precision(17);
std::cout << line.projection(point) << std::endl;
return 0;
}