From a95003cc564cce2d720e471de7cf4a83efa8b7e3 Mon Sep 17 00:00:00 2001 From: Pierre Alliez Date: Thu, 2 Mar 2006 09:42:27 +0000 Subject: [PATCH] updated test suite in 2D --- .../Principal_component_analysis/fitting.C | 40 +++++++++++++------ 1 file changed, 28 insertions(+), 12 deletions(-) diff --git a/Principal_component_analysis/test/Principal_component_analysis/fitting.C b/Principal_component_analysis/test/Principal_component_analysis/fitting.C index cbbd74bb824..077ee3f2596 100644 --- a/Principal_component_analysis/test/Principal_component_analysis/fitting.C +++ b/Principal_component_analysis/test/Principal_component_analysis/fitting.C @@ -17,6 +17,7 @@ typedef Kernel::FT FT; typedef Kernel::Line_2 Line_2; typedef Kernel::Point_2 Point_2; typedef Kernel::Triangle_2 Triangle_2; +typedef Kernel::Vector_2 Vector_2; typedef Kernel::Line_3 Line_3; typedef Kernel::Point_3 Point_3; @@ -24,10 +25,10 @@ typedef Kernel::Triangle_3 Triangle_3; // case with only one point in container // the fitting line must be horizontal by default -void test_2() +void test_2D() { std::vector points; - points.push_back(Point(0.0,0.0)); + points.push_back(Point_2(0.0,0.0)); // fit a line // 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); 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()) + { + std::cout << "failure" << std::endl; exit(1); // failure + } } // case with a point set on a horizontal segment // 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 std::vector points; - Point_2 p = Point(0.0,0.0); - Point_2 q = Point(1.0,0.0); - std::cout << " generate " << nb_points << - " 2D random points on a unit horizontal segment..."; - points_on_segment_2(p,q,nb_points,std::back_inserter(points)); - std::cout << "done" << std::endl; + points.push_back(Point_2(0.0,0.0)); + points.push_back(Point_2(1.0,0.0)); + std::cout << "generate " << nb_points << + " 2D random collinear points on a horizontal line..."; + random_collinear_points_2(points.begin(),points.end(),nb_points, + std::back_inserter(points)); + std::cout << "done " << std::endl; // fit a line - std::cout << " fit a 2D line..."; + std::cout << "fit 2D line..."; Line_2 line; Point_2 centroid; @@ -75,8 +83,16 @@ void test_2_point_set(const unsigned int nb_points) 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()) + { + std::cout << "failure" << std::endl; exit(1); // failure + } }