diff --git a/.gitattributes b/.gitattributes index 6ee895d9af3..0acb2ab74c1 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1541,6 +1541,7 @@ Envelope_3/test/Envelope_3/spheres_test.cmd eol=lf Envelope_3/test/Envelope_3/triangles_test.cmd eol=lf Filtered_kernel/developer_scripts/profile_cleanup -text Filtered_kernel/include/CGAL/internal/Static_filters/Compare_squared_radius_3.h -text +Filtered_kernel/test/Filtered_kernel/test_lazy_vector_objects.cpp -text Generator/demo/Generator/qt3/help/index.html svneol=native#text/html Generator/doc_tex/Generator/Segment_generator_prog1.png -text svneol=unset#image/png Generator/doc_tex/Generator/Segment_generator_prog2.png -text svneol=unset#image/png diff --git a/Cartesian_kernel/include/CGAL/Cartesian_converter.h b/Cartesian_kernel/include/CGAL/Cartesian_converter.h index 8275270d454..22a6dd87318 100644 --- a/Cartesian_kernel/include/CGAL/Cartesian_converter.h +++ b/Cartesian_kernel/include/CGAL/Cartesian_converter.h @@ -103,14 +103,20 @@ public: #include - if (const std::vector * ptr = object_cast >(&obj)) { - std::vector res; - res.reserve((*ptr).size()); - for(unsigned int i=0; i < (*ptr).size(); i++){ - res.push_back(operator()((*ptr)[i])); - } - return make_object(res); +#define CGAL_Kernel_obj(X) \ + if (const std::vector * ptr = object_cast >(&obj)) { \ + std::vector res; \ + res.reserve((*ptr).size()); \ + for(unsigned int i=0; i < (*ptr).size(); i++){ \ + res.push_back(operator()((*ptr)[i])); \ + } \ + return make_object(res); \ } + + CGAL_Kernel_obj(Point_2) + CGAL_Kernel_obj(Point_3) +#undef CGAL_Kernel_obj + CGAL_error_msg("Cartesian_converter is unable to determine what is wrapped in the Object"); return Object(); diff --git a/Filtered_kernel/include/CGAL/Lazy.h b/Filtered_kernel/include/CGAL/Lazy.h index 11f2e960a00..06b53aac52c 100644 --- a/Filtered_kernel/include/CGAL/Lazy.h +++ b/Filtered_kernel/include/CGAL/Lazy.h @@ -1371,6 +1371,24 @@ struct Ith { } }; +// This functor selects the i'th element in a vector of T2's +template +struct Ith_for_intersection { + typedef T2 result_type; + int i; + + Ith_for_intersection(int i_) + : i(i_) + {} + + const T2& + operator()(const Object& o) const + { + const std::vector* ptr = object_cast >(&o); + return (*ptr)[i]; + } +}; + template struct Lazy_cartesian_const_iterator_2 @@ -1690,6 +1708,29 @@ public: #include + // We now check vector + + #define CGAL_Kernel_obj(X) \ + { \ + const std::vector* v_ptr;\ + if ( (v_ptr = object_cast >(& (lo.approx()))) ) { \ + \ + std::vector V;\ + V.resize(v_ptr->size()); \ + for (unsigned int i = 0; i < v_ptr->size(); i++) { \ + V[i] = typename LK::X(new Lazy_rep_1, \ + Ith_for_intersection, E2A, Lazy_object> \ + (Ith_for_intersection(i), Ith_for_intersection(i), lo)); \ + \ + } \ + return make_object(V); \ + }\ + } + + CGAL_Kernel_obj(Point_2) + CGAL_Kernel_obj(Point_3) + #undef CGAL_Kernel_obj + std::cerr << "object_cast inside Lazy_construction_rep::operator() failed. It needs more else if's (#1)" << std::endl; std::cerr << "dynamic type of the Object : " << lo.approx().type().name() << std::endl; diff --git a/Filtered_kernel/test/Filtered_kernel/test_lazy_vector_objects.cpp b/Filtered_kernel/test/Filtered_kernel/test_lazy_vector_objects.cpp new file mode 100644 index 00000000000..6094615114f --- /dev/null +++ b/Filtered_kernel/test/Filtered_kernel/test_lazy_vector_objects.cpp @@ -0,0 +1,58 @@ +#include +#include +#include + + +typedef CGAL::Exact_predicates_exact_constructions_kernel K; +typedef K::Segment_2 Segment_2; +typedef K::Triangle_2 Triangle_2; +typedef K::Triangle_3 Triangle_3; +typedef K::Point_2 Point_2; +typedef K::Point_3 Point_3; + + +int main() +{ + { + Point_2 p1(0,0), p2(2,0), p3(1,3), q1(0,2), q2(2,2), q3(1,-1); + Triangle_2 t1(p1,p2,p3); + Triangle_2 t2(q1,q2,q3); + + Segment_2 s1(p1,p3), s2(p2, q1); + CGAL::Object obj = CGAL::intersection(t1,t2); + const std::vector *V; + if( !(V = CGAL::object_cast > (&obj)) ){ + std::cerr << "ERROR" << std::endl; + return EXIT_FAILURE; + } + else{ + std::cerr << "OK" << std::endl; + for(std::size_t i = 0; i < V->size(); i++){ + std::cerr << (*V)[i] << std::endl; + std::cerr << CGAL::exact((*V)[i]) << std::endl; + } + } + obj = CGAL::intersection(s1,s2); + } + + { + Point_3 p1(0,0,1), p2(2,0,1), p3(1,3,1), q1(0,2,1), q2(2,2,1), q3(1,-1,1); + Triangle_3 t1(p1,p2,p3); + Triangle_3 t2(q1,q2,q3); + + CGAL::Object obj = CGAL::intersection(t1,t2); + const std::vector *V; + if( !(V = CGAL::object_cast > (&obj)) ){ + std::cerr << "ERROR" << std::endl; + return EXIT_FAILURE; + } + else{ + std::cerr << "OK" << std::endl; + for(std::size_t i = 0; i < V->size(); i++){ + std::cerr << (*V)[i] << std::endl; + std::cerr << CGAL::exact((*V)[i]) << std::endl; + } + } + } + +}