mirror of https://github.com/CGAL/cgal
added explicit tests for deprecated api
This commit is contained in:
parent
c57619382c
commit
138f75e5e3
|
|
@ -40,6 +40,12 @@ if(CGAL_FOUND)
|
|||
create_single_source_cgal_program("test_dh_triangle.cpp")
|
||||
create_single_source_cgal_program("test_dh_weights.cpp")
|
||||
|
||||
create_single_source_cgal_program("test_sc_deprecated_api.cpp")
|
||||
create_single_source_cgal_program("test_tc_deprecated_api.cpp")
|
||||
create_single_source_cgal_program("test_wp_deprecated_api.cpp")
|
||||
create_single_source_cgal_program("test_mv_deprecated_api.cpp")
|
||||
create_single_source_cgal_program("test_dh_deprecated_api.cpp")
|
||||
|
||||
find_package(Eigen3 REQUIRED)
|
||||
include(CGAL_Eigen3_support)
|
||||
if(TARGET CGAL::Eigen3_support)
|
||||
|
|
|
|||
|
|
@ -0,0 +1,74 @@
|
|||
#include <cmath>
|
||||
#include <cassert>
|
||||
#include <CGAL/Exact_predicates_exact_constructions_kernel.h>
|
||||
#include <CGAL/Barycentric_coordinates_2/triangle_coordinates_2.h>
|
||||
#include <CGAL/Barycentric_coordinates_2/Discrete_harmonic_2.h>
|
||||
#include <CGAL/Barycentric_coordinates_2/Generalized_barycentric_coordinates_2.h>
|
||||
|
||||
typedef CGAL::Exact_predicates_exact_constructions_kernel Kernel;
|
||||
|
||||
typedef Kernel::FT Scalar;
|
||||
typedef Kernel::Point_2 Point;
|
||||
|
||||
typedef std::vector<Scalar> Coordinate_vector;
|
||||
typedef std::vector<Point> Point_vector;
|
||||
|
||||
typedef std::back_insert_iterator<Coordinate_vector> Vector_insert_iterator;
|
||||
|
||||
typedef CGAL::Barycentric_coordinates::Triangle_coordinates_2<Kernel> Triangle_coordinates;
|
||||
typedef CGAL::Barycentric_coordinates::Discrete_harmonic_2<Kernel> Discrete_harmonic;
|
||||
typedef CGAL::Barycentric_coordinates::Generalized_barycentric_coordinates_2<Discrete_harmonic, Kernel> Discrete_harmonic_coordinates;
|
||||
|
||||
typedef boost::optional<Vector_insert_iterator> Output_type;
|
||||
|
||||
using std::cout; using std::endl; using std::string;
|
||||
|
||||
int main()
|
||||
{
|
||||
const Point first_vertex = Point(0, 0);
|
||||
const Point second_vertex = Point(1, 0);
|
||||
const Point third_vertex = Point(0, 1);
|
||||
|
||||
Triangle_coordinates triangle_coordinates(first_vertex, second_vertex, third_vertex);
|
||||
|
||||
Point_vector vertices(3);
|
||||
vertices[0] = first_vertex; vertices[1] = second_vertex; vertices[2] = third_vertex;
|
||||
|
||||
Discrete_harmonic_coordinates discrete_harmonic_coordinates(vertices.begin(), vertices.end());
|
||||
|
||||
Coordinate_vector tri_coordinates;
|
||||
Coordinate_vector dh_coordinates;
|
||||
|
||||
const Scalar step = Scalar(1) / Scalar(100);
|
||||
const Scalar scale = Scalar(50);
|
||||
|
||||
int count = 0;
|
||||
const Scalar limit = scale * step;
|
||||
|
||||
for (Scalar x = step; x < limit; x += step) {
|
||||
for (Scalar y = step; y < limit; y += step) {
|
||||
const Point point(x, y);
|
||||
|
||||
const Output_type tri_result = triangle_coordinates(point, tri_coordinates);
|
||||
const Output_type dh_result = discrete_harmonic_coordinates(point, dh_coordinates);
|
||||
|
||||
assert(
|
||||
tri_coordinates[count + 0] - dh_coordinates[count + 0] == Scalar(0) &&
|
||||
tri_coordinates[count + 1] - dh_coordinates[count + 1] == Scalar(0) &&
|
||||
tri_coordinates[count + 2] - dh_coordinates[count + 2] == Scalar(0) );
|
||||
|
||||
if (
|
||||
tri_coordinates[count + 0] - dh_coordinates[count + 0] != Scalar(0) ||
|
||||
tri_coordinates[count + 1] - dh_coordinates[count + 1] != Scalar(0) ||
|
||||
tri_coordinates[count + 2] - dh_coordinates[count + 2] != Scalar(0) )
|
||||
{
|
||||
cout << endl << "DH_deprecated_api_test: FAILED." << endl << endl;
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
count += 3;
|
||||
}
|
||||
}
|
||||
|
||||
cout << endl << "DH_deprecated_api_test: PASSED." << endl << endl;
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
|
@ -0,0 +1,76 @@
|
|||
#include <cmath>
|
||||
#include <cassert>
|
||||
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
|
||||
#include <CGAL/Barycentric_coordinates_2/triangle_coordinates_2.h>
|
||||
#include <CGAL/Barycentric_coordinates_2/Mean_value_2.h>
|
||||
#include <CGAL/Barycentric_coordinates_2/Generalized_barycentric_coordinates_2.h>
|
||||
|
||||
typedef CGAL::Exact_predicates_inexact_constructions_kernel Kernel;
|
||||
|
||||
typedef Kernel::FT Scalar;
|
||||
typedef Kernel::Point_2 Point;
|
||||
|
||||
typedef std::vector<Scalar> Coordinate_vector;
|
||||
typedef std::vector<Point> Point_vector;
|
||||
|
||||
typedef std::back_insert_iterator<Coordinate_vector> Vector_insert_iterator;
|
||||
|
||||
typedef CGAL::Barycentric_coordinates::Triangle_coordinates_2<Kernel> Triangle_coordinates;
|
||||
typedef CGAL::Barycentric_coordinates::Mean_value_2<Kernel> Mean_value;
|
||||
typedef CGAL::Barycentric_coordinates::Generalized_barycentric_coordinates_2<Mean_value, Kernel> Mean_value_coordinates;
|
||||
|
||||
typedef boost::optional<Vector_insert_iterator> Output_type;
|
||||
|
||||
using std::cout; using std::endl; using std::string;
|
||||
|
||||
int main()
|
||||
{
|
||||
const Point first_vertex = Point(0, 0);
|
||||
const Point second_vertex = Point(1, 0);
|
||||
const Point third_vertex = Point(0, 1);
|
||||
|
||||
Triangle_coordinates triangle_coordinates(first_vertex, second_vertex, third_vertex);
|
||||
|
||||
Point_vector vertices(3);
|
||||
|
||||
vertices[0] = Point(0, 0); vertices[1] = Point(1, 0); vertices[2] = Point(0, 1);
|
||||
|
||||
Mean_value_coordinates mean_value_coordinates(vertices.begin(), vertices.end());
|
||||
|
||||
Coordinate_vector tri_coordinates;
|
||||
Coordinate_vector mv_coordinates;
|
||||
|
||||
const Scalar step = Scalar(1) / Scalar(100);
|
||||
const Scalar scale = Scalar(50);
|
||||
|
||||
int count = 0;
|
||||
const Scalar limit = scale * step;
|
||||
const Scalar epsilon = Scalar(1) / Scalar(std::pow(10.0, 14.0));
|
||||
|
||||
for (Scalar x = step; x < limit; x += step) {
|
||||
for (Scalar y = step; y < limit; y += step) {
|
||||
const Point point(x, y);
|
||||
|
||||
const Output_type tri_result = triangle_coordinates(point, tri_coordinates);
|
||||
const Output_type mv_result = mean_value_coordinates(point, mv_coordinates);
|
||||
|
||||
assert(
|
||||
(tri_coordinates[count + 0] - mv_coordinates[count + 0]) < epsilon &&
|
||||
(tri_coordinates[count + 1] - mv_coordinates[count + 1]) < epsilon &&
|
||||
(tri_coordinates[count + 2] - mv_coordinates[count + 2]) < epsilon );
|
||||
|
||||
if (
|
||||
(tri_coordinates[count + 0] - mv_coordinates[count + 0]) > epsilon ||
|
||||
(tri_coordinates[count + 1] - mv_coordinates[count + 1]) > epsilon ||
|
||||
(tri_coordinates[count + 2] - mv_coordinates[count + 2]) > epsilon )
|
||||
{
|
||||
cout << endl << "MV_deprecated_api_test: FAILED." << endl << endl;
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
count += 3;
|
||||
}
|
||||
}
|
||||
|
||||
cout << endl << "MV_deprecated_api_test: PASSED." << endl << endl;
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
|
@ -0,0 +1,85 @@
|
|||
#include <cmath>
|
||||
#include <cassert>
|
||||
#include <CGAL/Exact_predicates_exact_constructions_kernel.h>
|
||||
#include <CGAL/Barycentric_coordinates_2/segment_coordinates_2.h>
|
||||
|
||||
typedef CGAL::Exact_predicates_exact_constructions_kernel Kernel;
|
||||
|
||||
typedef Kernel::FT Scalar;
|
||||
typedef Kernel::Point_2 Point;
|
||||
|
||||
typedef std::vector<Scalar> Coordinate_vector;
|
||||
typedef std::back_insert_iterator<Coordinate_vector> Vector_insert_iterator;
|
||||
|
||||
typedef CGAL::Barycentric_coordinates::Segment_coordinates_2<Kernel> Segment_coordinates;
|
||||
|
||||
typedef boost::optional<Vector_insert_iterator> Output_type;
|
||||
|
||||
using std::cout; using std::endl; using std::string;
|
||||
|
||||
int main()
|
||||
{
|
||||
const Point first_vertex = Point(0, 0);
|
||||
const Point second_vertex = Point(1, 0);
|
||||
|
||||
Segment_coordinates segment_coordinates(first_vertex, second_vertex);
|
||||
|
||||
const Point query_points[6] = {
|
||||
Point(Scalar(2) /Scalar(5) , 0),
|
||||
Point(1 , 0),
|
||||
Point(Scalar(7) /Scalar(10), 0),
|
||||
Point(Scalar(-3)/Scalar(10), 0),
|
||||
Point(Scalar(6) /Scalar(5) , 0),
|
||||
Point(0 , 0) };
|
||||
|
||||
const Scalar expected_coordinates[12] = {
|
||||
Scalar(3) /Scalar(5) , Scalar(2) /Scalar(5) ,
|
||||
0 , 1 ,
|
||||
Scalar(3) /Scalar(10), Scalar(7) /Scalar(10),
|
||||
Scalar(13)/Scalar(10), Scalar(-3)/Scalar(10),
|
||||
Scalar(-1)/Scalar(5) , Scalar(6) /Scalar(5) ,
|
||||
1 , 0 };
|
||||
|
||||
Coordinate_vector coordinates;
|
||||
|
||||
int count = 0;
|
||||
for (int i = 0; i < 6; ++i) {
|
||||
const Output_type result = segment_coordinates(query_points[i], std::back_inserter(coordinates));
|
||||
|
||||
assert(
|
||||
coordinates[count + 0] - expected_coordinates[count + 0] == Scalar(0) &&
|
||||
coordinates[count + 1] - expected_coordinates[count + 1] == Scalar(0) );
|
||||
|
||||
if (
|
||||
coordinates[count + 0] - expected_coordinates[count + 0] != Scalar(0) ||
|
||||
coordinates[count + 1] - expected_coordinates[count + 1] != Scalar(0) )
|
||||
{
|
||||
cout << endl << "Segment_coordinates_deprecated_api_test: FAILED." << endl << endl;
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
count += 2;
|
||||
}
|
||||
coordinates.clear();
|
||||
|
||||
count = 0;
|
||||
for (int i = 0; i < 6; ++i) {
|
||||
const auto bc = CGAL::Barycentric_coordinates::
|
||||
compute_segment_coordinates_2(first_vertex, second_vertex, query_points[i], Kernel());
|
||||
|
||||
assert(
|
||||
bc[0] - expected_coordinates[count + 0] == Scalar(0) &&
|
||||
bc[1] - expected_coordinates[count + 1] == Scalar(0) );
|
||||
|
||||
if (
|
||||
bc[0] - expected_coordinates[count + 0] != Scalar(0) ||
|
||||
bc[1] - expected_coordinates[count + 1] != Scalar(0) )
|
||||
{
|
||||
cout << endl << "Segment_coordinates_deprecated_api_test: FAILED." << endl << endl;
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
count += 2;
|
||||
}
|
||||
|
||||
cout << endl << "Segment_coordinates_deprecated_api_test: PASSED." << endl << endl;
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
|
@ -0,0 +1,88 @@
|
|||
#include <cmath>
|
||||
#include <cassert>
|
||||
#include <CGAL/Exact_predicates_exact_constructions_kernel.h>
|
||||
#include <CGAL/Barycentric_coordinates_2/triangle_coordinates_2.h>
|
||||
|
||||
typedef CGAL::Exact_predicates_exact_constructions_kernel Kernel;
|
||||
|
||||
typedef Kernel::FT Scalar;
|
||||
typedef Kernel::Point_2 Point;
|
||||
|
||||
typedef std::vector<Scalar> Coordinate_vector;
|
||||
typedef std::back_insert_iterator<Coordinate_vector> Vector_insert_iterator;
|
||||
|
||||
typedef CGAL::Barycentric_coordinates::Triangle_coordinates_2<Kernel> Triangle_coordinates;
|
||||
|
||||
typedef boost::optional<Vector_insert_iterator> Output_type;
|
||||
|
||||
using std::cout; using std::endl; using std::string;
|
||||
|
||||
int main()
|
||||
{
|
||||
const Point first_vertex = Point(0, 0);
|
||||
const Point second_vertex = Point(1, 0);
|
||||
const Point third_vertex = Point(Scalar(1)/Scalar(2), 1);
|
||||
|
||||
Triangle_coordinates triangle_coordinates(first_vertex, second_vertex, third_vertex);
|
||||
|
||||
const Point query_points[5] = {
|
||||
Point(Scalar(1)/Scalar(2), Scalar(1)/Scalar(2)),
|
||||
Point(Scalar(1)/Scalar(2), 0 ),
|
||||
Point(Scalar(1)/Scalar(2), 1 ),
|
||||
Point(1 , Scalar(1)/Scalar(2)),
|
||||
Point(0 , Scalar(1)/Scalar(2)) };
|
||||
|
||||
const Scalar expected_coordinates[15] = {
|
||||
Scalar(1) /Scalar(4), Scalar(1) /Scalar(4), Scalar(1)/Scalar(2),
|
||||
Scalar(1) /Scalar(2), Scalar(1) /Scalar(2), 0 ,
|
||||
0 , 0 , 1 ,
|
||||
Scalar(-1)/Scalar(4), Scalar(3) /Scalar(4), Scalar(1)/Scalar(2),
|
||||
Scalar(3) /Scalar(4), Scalar(-1)/Scalar(4), Scalar(1)/Scalar(2) };
|
||||
|
||||
Coordinate_vector coordinates;
|
||||
|
||||
int count = 0;
|
||||
for (int i = 0; i < 5; ++i) {
|
||||
const Output_type result = triangle_coordinates(query_points[i], std::back_inserter(coordinates));
|
||||
|
||||
assert(
|
||||
coordinates[count + 0] - expected_coordinates[count + 0] == Scalar(0) &&
|
||||
coordinates[count + 1] - expected_coordinates[count + 1] == Scalar(0) &&
|
||||
coordinates[count + 2] - expected_coordinates[count + 2] == Scalar(0) );
|
||||
|
||||
if (
|
||||
coordinates[count + 0] - expected_coordinates[count + 0] != Scalar(0) ||
|
||||
coordinates[count + 1] - expected_coordinates[count + 1] != Scalar(0) ||
|
||||
coordinates[count + 2] - expected_coordinates[count + 2] != Scalar(0) )
|
||||
{
|
||||
cout << endl << "Triangle_coordinates_deprecated_api_test: FAILED." << endl << endl;
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
count += 3;
|
||||
}
|
||||
coordinates.clear();
|
||||
|
||||
count = 0;
|
||||
for (int i = 0; i < 5; ++i) {
|
||||
const auto bc = CGAL::Barycentric_coordinates::
|
||||
compute_triangle_coordinates_2(first_vertex, second_vertex, third_vertex, query_points[i], Kernel());
|
||||
|
||||
assert(
|
||||
bc[0] - expected_coordinates[count + 0] == Scalar(0) &&
|
||||
bc[1] - expected_coordinates[count + 1] == Scalar(0) &&
|
||||
bc[2] - expected_coordinates[count + 2] == Scalar(0) );
|
||||
|
||||
if (
|
||||
bc[0] - expected_coordinates[count + 0] != Scalar(0) ||
|
||||
bc[1] - expected_coordinates[count + 1] != Scalar(0) ||
|
||||
bc[2] - expected_coordinates[count + 2] != Scalar(0) )
|
||||
{
|
||||
cout << endl << "Triangle_coordinates_deprecated_api_test: FAILED." << endl << endl;
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
count += 3;
|
||||
}
|
||||
|
||||
cout << endl << "Triangle_coordinates_deprecated_api_test: PASSED." << endl << endl;
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
|
@ -0,0 +1,75 @@
|
|||
#include <cmath>
|
||||
#include <cassert>
|
||||
#include <CGAL/Exact_predicates_exact_constructions_kernel.h>
|
||||
#include <CGAL/Barycentric_coordinates_2/Wachspress_2.h>
|
||||
#include <CGAL/Barycentric_coordinates_2/triangle_coordinates_2.h>
|
||||
#include <CGAL/Barycentric_coordinates_2/Generalized_barycentric_coordinates_2.h>
|
||||
|
||||
typedef CGAL::Exact_predicates_exact_constructions_kernel Kernel;
|
||||
|
||||
typedef Kernel::FT Scalar;
|
||||
typedef Kernel::Point_2 Point;
|
||||
|
||||
typedef std::vector<Scalar> Coordinate_vector;
|
||||
typedef std::vector<Point> Point_vector;
|
||||
|
||||
typedef std::back_insert_iterator<Coordinate_vector> Vector_insert_iterator;
|
||||
|
||||
typedef CGAL::Barycentric_coordinates::Triangle_coordinates_2<Kernel> Triangle_coordinates;
|
||||
typedef CGAL::Barycentric_coordinates::Wachspress_2<Kernel> Wachspress;
|
||||
typedef CGAL::Barycentric_coordinates::Generalized_barycentric_coordinates_2<Wachspress, Kernel> Wachspress_coordinates;
|
||||
|
||||
typedef boost::optional<Vector_insert_iterator> Output_type;
|
||||
|
||||
using std::cout; using std::endl; using std::string;
|
||||
|
||||
int main()
|
||||
{
|
||||
const Point first_vertex = Point(0, 0);
|
||||
const Point second_vertex = Point(1, 0);
|
||||
const Point third_vertex = Point(0, 1);
|
||||
|
||||
Triangle_coordinates triangle_coordinates(first_vertex, second_vertex, third_vertex);
|
||||
|
||||
Point_vector vertices(3);
|
||||
|
||||
vertices[0] = Point(0, 0); vertices[1] = Point(1, 0); vertices[2] = Point(0, 1);
|
||||
|
||||
Wachspress_coordinates wachspress_coordinates(vertices.begin(), vertices.end());
|
||||
|
||||
Coordinate_vector tri_coordinates;
|
||||
Coordinate_vector wp_coordinates;
|
||||
|
||||
const Scalar step = Scalar(1) / Scalar(100);
|
||||
const Scalar scale = Scalar(50);
|
||||
|
||||
int count = 0;
|
||||
const Scalar limit = scale * step;
|
||||
|
||||
for (Scalar x = step; x < limit; x += step) {
|
||||
for (Scalar y = step; y < limit; y += step) {
|
||||
const Point point(x, y);
|
||||
|
||||
const Output_type tri_result = triangle_coordinates(point, tri_coordinates);
|
||||
const Output_type wp_result = wachspress_coordinates(point, wp_coordinates);
|
||||
|
||||
assert(
|
||||
tri_coordinates[count + 0] - wp_coordinates[count + 0] == Scalar(0) &&
|
||||
tri_coordinates[count + 1] - wp_coordinates[count + 1] == Scalar(0) &&
|
||||
tri_coordinates[count + 2] - wp_coordinates[count + 2] == Scalar(0) );
|
||||
|
||||
if (
|
||||
tri_coordinates[count + 0] - wp_coordinates[count + 0] != Scalar(0) ||
|
||||
tri_coordinates[count + 1] - wp_coordinates[count + 1] != Scalar(0) ||
|
||||
tri_coordinates[count + 2] - wp_coordinates[count + 2] != Scalar(0) )
|
||||
{
|
||||
cout << endl << "WP_deprecated_api_test: FAILED." << endl << endl;
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
count += 3;
|
||||
}
|
||||
}
|
||||
|
||||
cout << endl << "WP_deprecated_api_test: PASSED." << endl << endl;
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
|
@ -9,3 +9,5 @@
|
|||
* Merge this package with the natural neighbor coordinates package.
|
||||
* Improve the solver interface and make it a parameter for the harmonic coordinates class.
|
||||
* Add a demo with visualization of the coordinate functions.
|
||||
|
||||
* Do not forget to mention that segment and triangle headers are not capitalized now.
|
||||
Loading…
Reference in New Issue