mirror of https://github.com/CGAL/cgal
updated test suite in 2D
This commit is contained in:
parent
3d0500cb10
commit
a95003cc56
|
|
@ -17,6 +17,7 @@ typedef Kernel::FT FT;
|
||||||
typedef Kernel::Line_2 Line_2;
|
typedef Kernel::Line_2 Line_2;
|
||||||
typedef Kernel::Point_2 Point_2;
|
typedef Kernel::Point_2 Point_2;
|
||||||
typedef Kernel::Triangle_2 Triangle_2;
|
typedef Kernel::Triangle_2 Triangle_2;
|
||||||
|
typedef Kernel::Vector_2 Vector_2;
|
||||||
|
|
||||||
typedef Kernel::Line_3 Line_3;
|
typedef Kernel::Line_3 Line_3;
|
||||||
typedef Kernel::Point_3 Point_3;
|
typedef Kernel::Point_3 Point_3;
|
||||||
|
|
@ -24,10 +25,10 @@ typedef Kernel::Triangle_3 Triangle_3;
|
||||||
|
|
||||||
// case with only one point in container
|
// case with only one point in container
|
||||||
// the fitting line must be horizontal by default
|
// the fitting line must be horizontal by default
|
||||||
void test_2()
|
void test_2D()
|
||||||
{
|
{
|
||||||
std::vector<Point_2> points;
|
std::vector<Point_2> points;
|
||||||
points.push_back(Point(0.0,0.0));
|
points.push_back(Point_2(0.0,0.0));
|
||||||
|
|
||||||
// fit a line
|
// fit a line
|
||||||
// call all versions of the function
|
// call all versions of the function
|
||||||
|
|
@ -41,28 +42,35 @@ void test_2()
|
||||||
quality = linear_least_squares_fitting_2(points.begin(),points.end(),line,centroid,k);
|
quality = linear_least_squares_fitting_2(points.begin(),points.end(),line,centroid,k);
|
||||||
std::cout << "done (quality: " << quality << ")" << std::endl;
|
std::cout << "done (quality: " << quality << ")" << std::endl;
|
||||||
|
|
||||||
|
Vector_2 v = line.to_vector();
|
||||||
|
v = v / std::sqrt(v*v); // normalize
|
||||||
|
std::cout << "vector: " << v.x() << " "
|
||||||
|
<< v.y() << std::endl;
|
||||||
|
|
||||||
if(!line.is_horizontal())
|
if(!line.is_horizontal())
|
||||||
|
{
|
||||||
|
std::cout << "failure" << std::endl;
|
||||||
exit(1); // failure
|
exit(1); // failure
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// case with a point set on a horizontal segment
|
// case with a point set on a horizontal segment
|
||||||
// the fitting line must be horizontal
|
// the fitting line must be horizontal
|
||||||
void test_2_point_set(const unsigned int nb_points)
|
void test_2D_point_set(const unsigned int nb_points)
|
||||||
{
|
{
|
||||||
std::cout << "2D: fit a line to a point set" << std::endl;
|
|
||||||
|
|
||||||
// create random points on a horizontal segment
|
// create random points on a horizontal segment
|
||||||
std::vector<Point_2> points;
|
std::vector<Point_2> points;
|
||||||
Point_2 p = Point(0.0,0.0);
|
points.push_back(Point_2(0.0,0.0));
|
||||||
Point_2 q = Point(1.0,0.0);
|
points.push_back(Point_2(1.0,0.0));
|
||||||
std::cout << " generate " << nb_points <<
|
std::cout << "generate " << nb_points <<
|
||||||
" 2D random points on a unit horizontal segment...";
|
" 2D random collinear points on a horizontal line...";
|
||||||
points_on_segment_2(p,q,nb_points,std::back_inserter(points));
|
random_collinear_points_2(points.begin(),points.end(),nb_points,
|
||||||
std::cout << "done" << std::endl;
|
std::back_inserter(points));
|
||||||
|
std::cout << "done " << std::endl;
|
||||||
|
|
||||||
// fit a line
|
// fit a line
|
||||||
std::cout << " fit a 2D line...";
|
std::cout << "fit 2D line...";
|
||||||
Line_2 line;
|
Line_2 line;
|
||||||
Point_2 centroid;
|
Point_2 centroid;
|
||||||
|
|
||||||
|
|
@ -75,8 +83,16 @@ void test_2_point_set(const unsigned int nb_points)
|
||||||
|
|
||||||
std::cout << "done (quality: " << quality << ")" << std::endl;
|
std::cout << "done (quality: " << quality << ")" << std::endl;
|
||||||
|
|
||||||
|
FT y1 = line.y_at_x((FT)0);
|
||||||
|
FT y2 = line.y_at_x((FT)1);
|
||||||
|
|
||||||
|
std::cout << "y1" << y1 << " " << y2 << std::endl;
|
||||||
|
|
||||||
if(!line.is_horizontal())
|
if(!line.is_horizontal())
|
||||||
|
{
|
||||||
|
std::cout << "failure" << std::endl;
|
||||||
exit(1); // failure
|
exit(1); // failure
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue