diff --git a/Nef_3/include/CGAL/Nef_3/Bounding_box_3.h b/Nef_3/include/CGAL/Nef_3/Bounding_box_3.h index 50fe5ed0a48..cf295b5b8e2 100644 --- a/Nef_3/include/CGAL/Nef_3/Bounding_box_3.h +++ b/Nef_3/include/CGAL/Nef_3/Bounding_box_3.h @@ -73,17 +73,13 @@ public: } void extend(const Point_3& p) { - FT q[3]; - q[0] = p.x(); - q[1] = p.y(); - q[2] = p.z(); + FT q[3] = { p.x(), p.y(), p.z() }; if(initialized) Base::extend(q); else { initialized = true; - std::copy( q, q + 3, Base::lo ); - std::copy( q, q + 3, Base::hi ); + *this = Bounding_box_3(q); } } }; diff --git a/Nef_3/include/CGAL/Nef_3/SNC_constructor.h b/Nef_3/include/CGAL/Nef_3/SNC_constructor.h index 9f33a0991df..f93e584549d 100644 --- a/Nef_3/include/CGAL/Nef_3/SNC_constructor.h +++ b/Nef_3/include/CGAL/Nef_3/SNC_constructor.h @@ -229,9 +229,10 @@ public: Vertex_handle v = this->sncp()->new_vertex(p , boundary); CGAL_NEF_TRACEN( v->point()); SM_decorator SD(&*v); - Sphere_point sp[] = { Sphere_point(NT(-x), 0, 0), - Sphere_point(0, NT(-y), 0), - Sphere_point(0, 0, NT(-z)) }; + const NT zero(0); + Sphere_point sp[] = { Sphere_point(NT(-x), zero, zero), + Sphere_point(zero, NT(-y), zero), + Sphere_point(zero, zero, NT(-z)) }; /* create box vertices */ SVertex_handle sv[3]; diff --git a/Nef_3/include/CGAL/Nef_3/SNC_io_parser.h b/Nef_3/include/CGAL/Nef_3/SNC_io_parser.h index 835afa81e99..5eee7528ee7 100644 --- a/Nef_3/include/CGAL/Nef_3/SNC_io_parser.h +++ b/Nef_3/include/CGAL/Nef_3/SNC_io_parser.h @@ -56,7 +56,8 @@ namespace Nef_3_internal{ BOOST_MPL_HAS_XXX_TRAIT_NAMED_DEF(Has_nested_Exact_kernel,Exact_kernel,false) -template ::value, class FT = typename R::RT, class Kernel_tag=typename R::Kernel_tag> +template ::value && + !std::is_floating_point::value, class FT = typename R::RT, class Kernel_tag=typename R::Kernel_tag> struct Type_converter{ typedef const CGAL::Point_3& Point_3; typedef const CGAL::Vector_3& Vector_3; @@ -670,8 +671,9 @@ template class Geometry_io; template class Geometry_io { public: - template static - typename EK::Point_3 read_point(std::istream& in) { + + template static + typename EK::Point_3 read_point_impl(std::istream& in, Compose_) { typedef Fraction_traits FracTraits; typename FracTraits::Type hx, hy, hz, hw; typename FracTraits::Numerator_type num; @@ -688,8 +690,8 @@ class Geometry_io { return typename EK::Point_3(hx,hy,hz,hw); } - template static - typename EK::Plane_3 read_plane(std::istream& in) { + template static + typename EK::Plane_3 read_plane_impl(std::istream& in, Compose_) { typedef Fraction_traits FracTraits; typename FracTraits::Type a, b, c, d; typename FracTraits::Numerator_type num; @@ -706,8 +708,32 @@ class Geometry_io { return typename EK::Plane_3(a,b,c,d); } - template static - void print_point_impl(std::ostream& out, const CGAL::Point_3 p) { + template static + typename EK::Point_3 read_point_impl(std::istream& in, Null_functor) { + typename K::FT hx, hy, hz, hw; + in >> hx >> hy >> hz >> hw; + return typename EK::Point_3(hx,hy,hz,hw); + } + + template static + typename EK::Plane_3 read_plane_impl(std::istream& in, Null_functor) { + typename K::FT a, b, c, d; + in >> a >> b >> c >> d; + return typename EK::Plane_3(a,b,c,d); + } + + template static + typename EK::Point_3 read_point(std::istream& in) { + return read_point_impl(in, typename Fraction_traits::Compose()); + } + + template static + typename EK::Plane_3 read_plane(std::istream& in) { + return read_plane_impl(in, typename Fraction_traits::Compose()); + } + + template static + void print_point_impl(std::ostream& out, const CGAL::Point_3 p, Decompose_) { typedef Fraction_traits FracTraits; typedef std::vector NV; @@ -737,8 +763,8 @@ class Geometry_io { << vec[2] << " " << vec[3]; } - template static - void print_vector_impl(std::ostream& out, const CGAL::Vector_3 p) { + template static + void print_vector_impl(std::ostream& out, const CGAL::Vector_3 p, Decompose_) { typedef Fraction_traits FracTraits; typedef typename FracTraits::Numerator_type NumType; typedef std::vector NV; @@ -766,8 +792,8 @@ class Geometry_io { << vec[2] << " " << NumType(1); } - template static - void print_plane_impl(std::ostream& out, const CGAL::Plane_3 p) { + template static + void print_plane_impl(std::ostream& out, const CGAL::Plane_3 p, Decompose_) { typedef Fraction_traits FracTraits; typedef std::vector NV; @@ -803,19 +829,37 @@ class Geometry_io { << vec[2] << " " << vec[3]; } + template static + void print_point_impl(std::ostream& out, const CGAL::Point_3 p, Null_functor) + { + out << p.x() << " " << p.y() << " " << p.z() << " " << 1; + } + + template static + void print_vector_impl(std::ostream& out, const CGAL::Vector_3 v, Null_functor) + { + out << v.x() << " " << v.y() << " " << v.z() << " " << 1; + } + + template static + void print_plane_impl(std::ostream& out, const CGAL::Plane_3 p, Null_functor) + { + out << p.a() << " " << p.b() << " " << p.c() << " " << p.d(); + } + template static void print_point(std::ostream& out, const CGAL::Point_3& p) { - print_point_impl(out, Nef_3_internal::get_point(p) ); + print_point_impl(out, Nef_3_internal::get_point(p), typename Fraction_traits::Decompose() ); } template static void print_vector(std::ostream& out, const CGAL::Vector_3& v) { - print_vector_impl(out, Nef_3_internal::get_vector(v) ); + print_vector_impl(out, Nef_3_internal::get_vector(v), typename Fraction_traits::Decompose() ); } template static void print_plane(std::ostream& out, const CGAL::Plane_3& p) { - print_plane_impl(out, Nef_3_internal::get_plane(p) ); + print_plane_impl(out, Nef_3_internal::get_plane(p), typename Fraction_traits::Decompose() ); } }; diff --git a/Nef_3/include/CGAL/Nef_3/SNC_point_locator.h b/Nef_3/include/CGAL/Nef_3/SNC_point_locator.h index 966ac064b88..3b81b1119c0 100644 --- a/Nef_3/include/CGAL/Nef_3/SNC_point_locator.h +++ b/Nef_3/include/CGAL/Nef_3/SNC_point_locator.h @@ -563,7 +563,7 @@ public: Partial_facet pf; #endif bool hit = false; - Point_3 eor; // 'end of ray', the latest ray's hit point + Point_3 eor = CGAL::ORIGIN; // 'end of ray', the latest ray's hit point Objects_along_ray objects = candidate_provider->objects_along_ray(ray); Objects_along_ray_iterator objects_iterator = objects.begin(); while( !hit && objects_iterator != objects.end()) { diff --git a/Nef_3/test/Nef_3/CMakeLists.txt b/Nef_3/test/Nef_3/CMakeLists.txt index 2b8b1921f41..3bfee8a90ce 100644 --- a/Nef_3/test/Nef_3/CMakeLists.txt +++ b/Nef_3/test/Nef_3/CMakeLists.txt @@ -24,6 +24,7 @@ if ( CGAL_FOUND ) execution___of__test_nef_3_io_Cartesian execution___of__test_nef_3_io_Cartesian_Lazy execution___of__test_nef_3_io_EPEC + execution___of__test_nef_3_io_EPIC execution___of__test_nef_3_io_Homogeneous execution___of__test_nef_3_io_Homogenoeus_Lazy execution___of__test_with_extended_homogeneous diff --git a/Nef_3/test/Nef_3/test_nef_3_io_EPIC.cpp b/Nef_3/test/Nef_3/test_nef_3_io_EPIC.cpp new file mode 100644 index 00000000000..a5b68f14d17 --- /dev/null +++ b/Nef_3/test/Nef_3/test_nef_3_io_EPIC.cpp @@ -0,0 +1,57 @@ +#include + +#include +#include +#include + +#include + +typedef CGAL::Exact_predicates_inexact_constructions_kernel EPEC; + +template +void test_write_read() +{ + typedef CGAL::Nef_polyhedron_3< Kernel > Nef_polyhedron; + typedef CGAL::Polyhedron_3< Kernel > Polyhedron; + typedef typename Kernel::Point_3 Point; + + typename Kernel::RT n, d; + std::istringstream str_n("5"); + str_n >> n; + std::istringstream str_d("1"); + str_d >> d; + + Point p(n, 0, 0, d); + Point q(0, n, 0, d); + Point r(0, 0, n, d); + Point s(0, 0, 0, 1); + + std::cout << " build...\n"; + Polyhedron P; + P.make_tetrahedron( p, q, r, s); + Nef_polyhedron nef_1( P ); + + std::cout << " write...\n"; + std::ofstream out ("temp.nef"); + out << std::setprecision(17) << nef_1; + out.close(); + + std::cout << " read...\n"; + std::ifstream in ("temp.nef"); + Nef_polyhedron nef_2; + in >> nef_2; + in.close(); + + std::cout << " check...\n"; + assert( nef_1 == nef_2); +} + +int main() +{ + std::cout << "Testing Exact_predicates_inexact_constructions_kernel\n"; + test_write_read(); + std::cout << "Testing Simple_cartesian\n"; + test_write_read>(); + + return 0; +}