mirror of https://github.com/CGAL/cgal
progress with generic test function
This commit is contained in:
parent
a23aa45846
commit
71c3a87cdc
|
|
@ -31,7 +31,7 @@ namespace CGAL {
|
|||
|
||||
namespace Visibility_2 {
|
||||
|
||||
template<class Arrangement_2, class Regularization_tag>
|
||||
template<class Arrangement_2, class RegularizationTag>
|
||||
class Simple_visibility_2 {
|
||||
|
||||
public:
|
||||
|
|
@ -55,6 +55,10 @@ public:
|
|||
typedef typename Geometry_traits_2::FT Number_type;
|
||||
typedef typename Geometry_traits_2::Object_2 Object_2;
|
||||
|
||||
typedef RegularizationTag Regularization_tag;
|
||||
typedef CGAL::Tag_false Supports_general_polygon_tag;
|
||||
typedef CGAL::Tag_true Supports_simple_polygon_tag;
|
||||
|
||||
Simple_visibility_2() : p_arr(NULL), geom_traits(NULL) {};
|
||||
|
||||
/*! Constructor given an arrangement and the Regularization tag. */
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@
|
|||
#define CGAL_TEST_MODEL_METHODS_H
|
||||
|
||||
#include <CGAL/basic.h>
|
||||
#include <CGAL/test_utils.h>
|
||||
#include <cassert>
|
||||
|
||||
namespace CGAL {
|
||||
|
|
@ -32,5 +33,30 @@ bool test_is_attached(_Visibility_2 visibility) {
|
|||
return visibility.is_attached();
|
||||
}
|
||||
|
||||
template <class _Visibility_2>
|
||||
void test_model_methods(_Visibility_2 &visibility,
|
||||
const typename _Visibility_2::Input_arrangement_2 &arr) {
|
||||
|
||||
// Check concept obediance
|
||||
typedef _Visibility_2 Visibility_2;
|
||||
typedef typename Visibility_2::Input_arrangement_2 Input_arrangement_2;
|
||||
typedef typename Visibility_2::Output_arrangement_2 Output_arrangement_2;
|
||||
typedef typename Visibility_2::Regularization_tag Regularization_tag;
|
||||
typedef typename Visibility_2::Supports_general_polygon_tag
|
||||
Supports_general_polygon_tag;
|
||||
typedef typename Visibility_2::Supports_simple_polygon_tag
|
||||
Supports_simple_polygon_tag;
|
||||
|
||||
assert(false == visibility.is_attached());
|
||||
visibility.attach(arr);
|
||||
assert(true == visibility.is_attached());
|
||||
visibility.detach();
|
||||
assert(false == visibility.is_attached());
|
||||
visibility.attach(arr);
|
||||
assert(true == visibility.is_attached());
|
||||
assert(true == (CGAL::test_are_equal<Input_arrangement_2>(arr,
|
||||
visibility.arr())));
|
||||
}
|
||||
|
||||
} // end CGAL namespace
|
||||
#endif
|
||||
|
|
@ -177,6 +177,68 @@ std::string num2string(Number_type& n) {
|
|||
ss<<n;
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
template <class _Arrangement_2>
|
||||
void create_lazy_arrangement_from_file(std::ifstream &input,
|
||||
_Arrangement_2 &arr) {
|
||||
|
||||
typedef _Arrangement_2 Arrangement_2;
|
||||
typedef typename Arrangement_2::Geometry_traits_2 Geometry_traits_2;
|
||||
typedef typename Arrangement_2::Face_const_handle Face_const_handle;
|
||||
typedef typename Geometry_traits_2::Segment_2 Segment_2;
|
||||
typedef typename Geometry_traits_2::Point_2 Point_2;
|
||||
typedef typename Geometry_traits_2::FT Number_type;
|
||||
if (input) {
|
||||
std::string curr_line;
|
||||
std::vector<Point_2> isolated_vertices;
|
||||
std::stringstream convert(curr_line);
|
||||
int number_of_isolated_vertices;
|
||||
convert >> number_of_isolated_vertices;
|
||||
Face_const_handle uface = arr.unbounded_face();
|
||||
|
||||
for (int i = 0 ; i < number_of_isolated_vertices ; i++) {
|
||||
std::getline(input, curr_line);
|
||||
std::istringstream iss(curr_line);
|
||||
std::string x, y;
|
||||
iss >> x >> y;
|
||||
arr.insert_in_face_interior(Point_2(x, y));
|
||||
}
|
||||
|
||||
std::vector<Segment_2> edges;
|
||||
int number_of_edges;
|
||||
input >> number_of_edges;
|
||||
for (int i = 0 ; i < number_of_edges ; i++) {
|
||||
std::getline(input, curr_line);
|
||||
std::string x1, y1, x2, y2;
|
||||
std::istringstream iss(curr_line);
|
||||
iss >> x1 >> y1 >> x2 >> y2;
|
||||
edges.push_back(Segment_2(Point_2(x1, y1), Point_2(x2, y2)));
|
||||
}
|
||||
CGAL::insert(arr, edges.begin(), edges.end());
|
||||
}
|
||||
}
|
||||
|
||||
template <class _Visibility_2>
|
||||
void run_tests(_Visibility_2 visibility, int case_number) {
|
||||
typedef _Visibility_2 Visibility_2;
|
||||
typedef Visibility_2::Input_arrangement_2 Input_arrangement_2;
|
||||
typedef Visibility_2::Output_arrangement_2 Output_arrangement_2;
|
||||
|
||||
for (int i=1 ; i <= case_number ; i++) {
|
||||
|
||||
std::cout<<"Test "<<i<<" begins"<<std::endl;
|
||||
std::string input_arr_file("data/test");
|
||||
input_arr_file += number2string(i);
|
||||
std::ifstream input(input_arr_file.c_str());
|
||||
Input_arrangement_2 in_arr;
|
||||
Output_arrangement_2 out_arr;
|
||||
|
||||
while (std::getline(input, curr_line)) {
|
||||
if (curr_line[0] != '#' && curr_line[0] != '/')
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
template <class _Arrangement_2>
|
||||
void create_arrangement_from_file(_Arrangement_2 &arr, std::ifstream& input) {
|
||||
typedef _Arrangement_2 Arrangement_2;
|
||||
|
|
|
|||
|
|
@ -42,25 +42,15 @@ int main() {
|
|||
typedef Traits_2::Point_2 Point_2;
|
||||
typedef Traits_2::X_monotone_curve_2 Segment_2;
|
||||
typedef CGAL::Arrangement_2<Traits_2> Arrangement_2;
|
||||
typedef CGAL::Visibility_2::Simple_visibility_2<Arrangement_2, CGAL::Tag_false>
|
||||
Simple_visibility_2;
|
||||
|
||||
// First read arrangement
|
||||
Arrangement_2 arr;
|
||||
std::ifstream input("./data/simple_polygon_test_case_1.in");
|
||||
CGAL::create_arrangement_from_file<Arrangement_2>(arr, input);
|
||||
CGAL::Visibility_2::Simple_visibility_2<Arrangement_2, CGAL::Tag_false> visibility;
|
||||
assert(false == (CGAL::test_is_attached<CGAL::Visibility_2::Simple_visibility_2<Arrangement_2, CGAL::Tag_false> >(visibility)));
|
||||
visibility.attach(arr);
|
||||
assert(true == (CGAL::test_is_attached<CGAL::Visibility_2::Simple_visibility_2<Arrangement_2, CGAL::Tag_false> >(visibility)));
|
||||
visibility.detach();
|
||||
assert(false == (CGAL::test_is_attached<CGAL::Visibility_2::Simple_visibility_2<Arrangement_2, CGAL::Tag_false> >(visibility)));
|
||||
visibility.attach(arr);
|
||||
assert(true == (CGAL::test_are_equal<Arrangement_2>(arr, visibility.arr())));
|
||||
|
||||
// Run test cases from https://cgal.geometryfactory.com/CGAL/Members/wiki/Visibility/TestCases
|
||||
assert(true == (CGAL::simple_polygon_test_case_1<CGAL::Visibility_2::Simple_visibility_2<Arrangement_2, CGAL::Tag_false>, Arrangement_2> ()));
|
||||
assert(true == (CGAL::simple_polygon_test_case_2<CGAL::Visibility_2::Simple_visibility_2<Arrangement_2, CGAL::Tag_false>, Arrangement_2> ()));
|
||||
assert(true == (CGAL::simple_polygon_test_case_3<CGAL::Visibility_2::Simple_visibility_2<Arrangement_2, CGAL::Tag_false>, Arrangement_2> ()));
|
||||
assert(true == (CGAL::simple_polygon_test_case_4<CGAL::Visibility_2::Simple_visibility_2<Arrangement_2, CGAL::Tag_false>, Arrangement_2> ()));
|
||||
Simple_visibility_2 visibility;
|
||||
CGAL::test_model_methods<Simple_visibility_2>(visibility, arr);
|
||||
}
|
||||
{
|
||||
typedef CGAL::Exact_predicates_exact_constructions_kernel Kernel;
|
||||
|
|
|
|||
Loading…
Reference in New Issue