diff --git a/Intersections_3/include/CGAL/Triangle_3_Tetrahedron_3_do_intersect.h b/Intersections_3/include/CGAL/Triangle_3_Tetrahedron_3_do_intersect.h index a0987b3529f..f5ee6802f7a 100644 --- a/Intersections_3/include/CGAL/Triangle_3_Tetrahedron_3_do_intersect.h +++ b/Intersections_3/include/CGAL/Triangle_3_Tetrahedron_3_do_intersect.h @@ -27,6 +27,7 @@ #define CGAL_TRIANGLE_3_TETRAHEDRON_3_DO_INTERSECT_H #include +#include namespace CGAL { @@ -36,11 +37,12 @@ namespace CGAL { namespace internal { // This code is not optimized: -template + template typename K::Boolean -do_intersect(const typename K::Triangle_3 &tr, - const typename K::Tetrahedron_3 &tet, - const K & k) +do_intersect_tetrahedron_bounded(const typename Bounded &tr, + const typename K::Tetrahedron_3 &tet, + const typename K::Point_3 p, + const K & k) { typedef typename K::Triangle_3 Triangle; @@ -52,12 +54,7 @@ do_intersect(const typename K::Triangle_3 &tr, if (do_intersect(tr, Triangle(tet[0], tet[2], tet[3]), k)) return true; if (do_intersect(tr, Triangle(tet[1], tet[2], tet[3]), k)) return true; - CGAL_kernel_assertion(k.bounded_side_3_object()(tet, tr[0]) == - k.bounded_side_3_object()(tet, tr[1])); - CGAL_kernel_assertion(k.bounded_side_3_object()(tet, tr[0]) == - k.bounded_side_3_object()(tet, tr[2])); - - return k.has_on_bounded_side_3_object()(tet, tr[0]); + return k.has_on_bounded_side_3_object()(tet, p); } @@ -68,12 +65,134 @@ do_intersect(const typename K::Tetrahedron_3 &tet, const typename K::Triangle_3 &tr, const K & k) { - return do_intersect(tr, tet, k); + return do_intersect_tetrahedron_bounded(tr, tet, tr[0], k); } +template +inline +typename K::Boolean +do_intersect(const typename K::Triangle_3 &tr, + const typename K::Tetrahedron_3 &tet, + const K & k) +{ + return do_intersect_tetrahedron_bounded(tr, tet, tr[0], k); +} + + +template +inline +typename K::Boolean +do_intersect(const typename K::Tetrahedron_3 &tet, + const typename K::Segment_3 &seg, + const K & k) +{ + return do_intersect_tetrahedron_bounded(seg, tet, seg.source(), k); +} + +template +inline +typename K::Boolean +do_intersect(const typename K::Segment_3 &seg, + const typename K::Tetrahedron_3 &tet, + const K & k) +{ + return do_intersect_tetrahedron_bounded(seg, tet, seg.source(), k); +} + + +template +inline +typename K::Boolean +do_intersect(const typename K::Tetrahedron_3 &tet, + const typename K::Iso_cuboid_3 &ic, + const K & k) +{ + return do_intersect_tetrahedron_bounded(ic, tet, ic[0], k); +} + +template +inline +typename K::Boolean +do_intersect(const typename K::Iso_cuboid_3 &ic, + const typename K::Tetrahedron_3 &tet, + const K & k) +{ + return do_intersect_tetrahedron_bounded(ic, tet, ic[0], k); +} + + +template +inline +typename K::Boolean +do_intersect(const typename K::Tetrahedron_3 &tet, + const typename K::Sphere_3 &sp, + const K & k) +{ + return do_intersect_tetrahedron_bounded(sp, tet, sp.center(), k); +} + +template +inline +typename K::Boolean +do_intersect(const typename K::Sphere_3 &sp, + const typename K::Tetrahedron_3 &tet, + const K & k) +{ + return do_intersect_tetrahedron_bounded(sp, tet, sp.center(), k); +} + + +template +inline +typename K::Boolean +do_intersect(const typename K::Tetrahedron_3 &tet, + const typename K::Tetrahedron_3 &sp, + const K & k) +{ + return do_intersect_tetrahedron_bounded(sp, tet, tet[0], k); +} + +template +inline +typename K::Boolean +do_intersect(const typename K::Tetrahedron_3 &tet, + const typename Bbox_3 &bb, + const K & k) +{ + return do_intersect_tetrahedron_bounded(bb, tet, typename K::Point_3(bb.xmin(), bb.ymin(), bb.zmin()), k); +} + + template +inline +typename K::Boolean +do_intersect(const typename Bbox_3 &bb, + const typename K::Tetrahedron_3 &tet, + const K & k) +{ + return do_intersect_tetrahedron_bounded(bb, tet, typename K::Point_3(bb.xmin(), bb.ymin(), bb.zmin()), k); +} + } // namespace internal CGAL_DO_INTERSECT_FUNCTION(Triangle_3, Tetrahedron_3, 3) +CGAL_DO_INTERSECT_FUNCTION(Segment_3, Tetrahedron_3, 3) +CGAL_DO_INTERSECT_FUNCTION(Iso_cuboid_3, Tetrahedron_3, 3) +CGAL_DO_INTERSECT_FUNCTION(Sphere_3, Tetrahedron_3, 3) +CGAL_DO_INTERSECT_FUNCTION_SELF(Tetrahedron_3, 3) + + +template +bool do_intersect(const CGAL::Tetrahedron_3& a, + const CGAL::Bbox_3& b) { + return K().do_intersect_3_object()(a, b); +} + + +template +bool do_intersect(const CGAL::Bbox_3& b, + const CGAL::Tetrahedron_3& a) { + return K().do_intersect_3_object()(a, b); +} } //namespace CGAL diff --git a/Intersections_3/include/CGAL/internal/Intersections_3/Tetrahedron_3_do_intersect.h b/Intersections_3/include/CGAL/internal/Intersections_3/Tetrahedron_3_do_intersect.h new file mode 100644 index 00000000000..b735b3d2346 --- /dev/null +++ b/Intersections_3/include/CGAL/internal/Intersections_3/Tetrahedron_3_do_intersect.h @@ -0,0 +1,116 @@ +// Copyright (c) 2018 GeometryFactory Sarl (France). +// All rights reserved. +// +// This file is part of CGAL (www.cgal.org); you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public License as +// published by the Free Software Foundation; either version 3 of the License, +// or (at your option) any later version. +// +// Licensees holding a valid commercial license may use this file in +// accordance with the commercial license agreement provided with the software. +// +// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +// +// $URL$ +// $Id$ +// SPDX-License-Identifier: LGPL-3.0+ +// +// +// Author(s) : Andreas Fabri + +#ifndef CGAL_INTERNAL_INTERSECTIONS_3_TETRAHEDRON_3_DO_INTERSECT_H +#define CGAL_INTERNAL_INTERSECTIONS_3_TETRAHEDRON_3_DO_INTERSECT_H + +#include +#include +#include +#include + +namespace CGAL { + +namespace internal { + +template +bool do_intersect_tetrahedron_unbounded(const typename K::Tetrahedron_3& tet, + const Unbounded& unb, + const K& k) { + if (do_intersect(unb, Triangle(tet[0], tet[1], tet[2]), k)) return true; + if (do_intersect(unb, Triangle(tet[0], tet[1], tet[3]), k)) return true; + if (do_intersect(unb, Triangle(tet[0], tet[2], tet[3]), k)) return true; + if (do_intersect(unb, Triangle(tet[1], tet[2], tet[3]), k)) return true; + return false; +} + + + +template +bool do_intersect(const typename K::Tetrahedron_3& tet, + const typename K::Plane_3& unb, + const K& k) { + return do_intersect_tetrahedron_unbounded(tet, unb, k); +} + + +template +bool do_intersect(const typename K::Tetrahedron_3& tet, + const typename K::Line_3& unb, + const K& k) { + return do_intersect_tetrahedron_unbounded(tet, unb, k); +} + + +template +bool do_intersect(const typename K::Tetrahedron_3& tet, + const typename K::Ray_3& unb, + const K& k) { + return do_intersect_tetrahedron_unbounded(tet, unb, k); +} + +} // namespace internal + + +template +bool do_intersect(const CGAL::Tetrahedron_3& a, + const CGAL::Plane_3& b) { + return K().do_intersect_3_object()(a, b); +} + + +template +bool do_intersect(const CGAL::Plane_3& b, + const CGAL::Tetrahedron_3& a) { + return K().do_intersect_3_object()(a, b); +} + + +template +bool do_intersect(const CGAL::Tetrahedron_3& a, + const CGAL::Line_3& b) { + return K().do_intersect_3_object()(a, b); +} + + +template +bool do_intersect(const CGAL::Line_3& b, + const CGAL::Tetrahedron_3& a) { + return K().do_intersect_3_object()(a, b); +} + + +template +bool do_intersect(const CGAL::Tetrahedron_3& a, + const CGAL::Ray_3& b) { + return K().do_intersect_3_object()(a, b); +} + + +template +bool do_intersect(const CGAL::Ray_3& b, + const CGAL::Tetrahedron_3& a) { + return K().do_intersect_3_object()(a, b); +} + +} // namespace CGAL + +#endif CGAL_INTERNAL_INTERSECTIONS_3_TETRAHEDRON_3_DO_INTERSECT_H diff --git a/Intersections_3/include/CGAL/internal/Intersections_3/Triangle_3_Sphere_3_do_intersect.h b/Intersections_3/include/CGAL/internal/Intersections_3/Triangle_3_Sphere_3_do_intersect.h new file mode 100644 index 00000000000..8c129fa07a4 --- /dev/null +++ b/Intersections_3/include/CGAL/internal/Intersections_3/Triangle_3_Sphere_3_do_intersect.h @@ -0,0 +1,125 @@ +// Copyright (c) 2018 GeometryFactory Sarl +// All rights reserved. +// +// This file is part of CGAL (www.cgal.org); you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public License as +// published by the Free Software Foundation; either version 3 of the License, +// or (at your option) any later version. +// +// Licensees holding a valid commercial license may use this file in +// accordance with the commercial license agreement provided with the software. +// +// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +// +// $URL$ +// $Id$ +// SPDX-License-Identifier: LGPL-3.0+ +// +// +// Author(s) : Andreas Fabri + +#ifndef CGAL_TRIANGLE_3_SPHERE_3_DO_INTERSECT_H +#define CGAL_TRIANGLE_3_SPHERE_3_DO_INTERSECT_H + +#include +#include + +namespace CGAL { + + template + class Triangle_3; + + template + class Sphere_3; + + template + class Line_3; + +namespace internal { + +template +inline +typename K::Boolean +do_intersect(const typename K::Sphere_3 &sp, + const typename K::Triangle_3 &tr, + const K & k) +{ + return squared_distance(sp.center(), tr) <= sp.squared_radius(); +} + +template +inline +typename K::Boolean +do_intersect(const typename K::Sphere_3 &sp, + const typename K::Line_3 &lin, + const K & k) +{ + return squared_distance(sp.center(), lin) <= sp.squared_radius(); +} + + +template +inline +typename K::Boolean +do_intersect(const typename K::Line_3 &lin, + const typename K::Sphere_3 &sp, + const K & k) +{ + return squared_distance(sp.center(), lin) <= sp.squared_radius(); +} + + + +template +inline +typename K::Boolean +do_intersect(const typename K::Sphere_3 &sp, + const typename K::Ray_3 &lin, + const K & k) +{ + return squared_distance(sp.center(), lin) <= sp.squared_radius(); +} + + +template +inline +typename K::Boolean +do_intersect(const typename K::Ray_3 &lin, + const typename K::Sphere_3 &sp, + const K & k) +{ + return squared_distance(sp.center(), lin) <= sp.squared_radius(); +} + +template +inline +typename K::Boolean +do_intersect(const typename K::Sphere_3 &sp, + const typename K::Segment_3 &lin, + const K & k) +{ + return squared_distance(sp.center(), lin) <= sp.squared_radius(); +} + + +template +inline +typename K::Boolean +do_intersect(const typename K::Segment_3 &lin, + const typename K::Sphere_3 &sp, + const K & k) +{ + return squared_distance(sp.center(), lin) <= sp.squared_radius(); +} +} // namespace internal + +CGAL_DO_INTERSECT_FUNCTION(Triangle_3, Sphere_3, 3) +CGAL_DO_INTERSECT_FUNCTION(Line_3, Sphere_3, 3) +CGAL_DO_INTERSECT_FUNCTION(Ray_3, Sphere_3, 3) +CGAL_DO_INTERSECT_FUNCTION(Segment_3, Sphere_3, 3) + +} // namespace CGAL + +#endif CGAL_TRIANGLE_3_SPHERE_3_DO_INTERSECT_H + diff --git a/Intersections_3/include/CGAL/intersection_3.h b/Intersections_3/include/CGAL/intersection_3.h index f2cefb8f31c..3d74dbf38d4 100644 --- a/Intersections_3/include/CGAL/intersection_3.h +++ b/Intersections_3/include/CGAL/intersection_3.h @@ -64,6 +64,8 @@ #include #include #include +#include +#include #include diff --git a/Intersections_3/test/Intersections_3/tetrahedron.cpp b/Intersections_3/test/Intersections_3/tetrahedron.cpp new file mode 100644 index 00000000000..6c05a321df6 --- /dev/null +++ b/Intersections_3/test/Intersections_3/tetrahedron.cpp @@ -0,0 +1,56 @@ +#include + +#include +#include + +typedef CGAL::Cartesian K; + +typedef K::Tetrahedron_3 Tetrahedron; + +typedef K::Segment_3 Segment; +typedef K::Triangle_3 Triangle; +typedef K::Iso_cuboid_3 Iso_cuboid; +typedef K::Sphere_3 Sphere; + +typedef K::Plane_3 Plane; +typedef K::Line_3 Line; +typedef K::Ray_3 Ray; + +typedef CGAL::Bbox_3 Bbox; + +int main() +{ + Tetrahedron tet; + Sphere sp; + + CGAL::do_intersect(tet,Triangle()); + CGAL::do_intersect(tet,Segment()); + CGAL::do_intersect(tet,Iso_cuboid()); + CGAL::do_intersect(tet,Sphere()); + CGAL::do_intersect(tet,Plane()); + CGAL::do_intersect(tet,Line()); + CGAL::do_intersect(tet,Ray()); + CGAL::do_intersect(tet,tet); + CGAL::do_intersect(tet,Bbox()); + CGAL::do_intersect(sp, Line()); + CGAL::do_intersect(sp, Ray()); + CGAL::do_intersect(sp, Segment()); + + + CGAL::do_intersect(Triangle(), tet); + CGAL::do_intersect(Segment(), tet); + CGAL::do_intersect(Iso_cuboid(), tet); + CGAL::do_intersect(Sphere(), tet); + CGAL::do_intersect(Plane(), tet); + CGAL::do_intersect(Line(), tet); + CGAL::do_intersect(Ray(), tet); + CGAL::do_intersect(Bbox(), tet); + + CGAL::do_intersect(Line(), sp); + CGAL::do_intersect(Ray(), sp); + CGAL::do_intersect(Segment(), sp); + + + return 0; + +} diff --git a/Intersections_3/test/Intersections_3/triangle_other.cpp b/Intersections_3/test/Intersections_3/triangle_other.cpp index fdfccc372fe..d96a444b24b 100644 --- a/Intersections_3/test/Intersections_3/triangle_other.cpp +++ b/Intersections_3/test/Intersections_3/triangle_other.cpp @@ -1,7 +1,5 @@ #include - -#include #include #include #include