From 5880dc719592d8cfc32109beb053d77990d56360 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mael=20Rouxel-Labb=C3=A9?= Date: Mon, 14 Jun 2021 11:28:18 +0200 Subject: [PATCH 01/31] Replace global function CGAL::do_intersect() call --- AABB_tree/include/CGAL/AABB_traits.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/AABB_tree/include/CGAL/AABB_traits.h b/AABB_tree/include/CGAL/AABB_traits.h index e3ffcacf50c..e5da86350ad 100644 --- a/AABB_tree/include/CGAL/AABB_traits.h +++ b/AABB_tree/include/CGAL/AABB_traits.h @@ -332,7 +332,7 @@ public: template bool operator()(const Query& q, const Bounding_box& bbox) const { - return CGAL::do_intersect(q, bbox); + return GeomTraits().do_intersect_3_object()(q, bbox); } template From c2d1adfb69b1856ec191acc7f1b81013bcc6f0f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mael=20Rouxel-Labb=C3=A9?= Date: Wed, 23 Jun 2021 17:34:48 +0200 Subject: [PATCH 02/31] Fix missing, extra do_intersect()/intersection() overloads and reorganize everything... --- .../include/CGAL/Intersection_traits_3.h | 12 +- .../CGAL/Intersections_3/Bbox_3_Bbox_3.h | 42 +- .../Intersections_3/Bbox_3_Iso_cuboid_3.h | 44 +- .../CGAL/Intersections_3/Bbox_3_Line_3.h | 38 +- .../CGAL/Intersections_3/Bbox_3_Plane_3.h | 46 +- .../CGAL/Intersections_3/Bbox_3_Point_3.h | 54 +- .../CGAL/Intersections_3/Bbox_3_Ray_3.h | 46 +- .../CGAL/Intersections_3/Bbox_3_Segment_3.h | 42 +- .../CGAL/Intersections_3/Bbox_3_Sphere_3.h | 28 +- .../Intersections_3/Bbox_3_Tetrahedron_3.h | 26 +- .../CGAL/Intersections_3/Bbox_3_Triangle_3.h | 35 +- .../Iso_cuboid_3_Iso_cuboid_3.h | 20 +- .../Intersections_3/Iso_cuboid_3_Line_3.h | 21 +- .../Intersections_3/Iso_cuboid_3_Plane_3.h | 23 +- .../Intersections_3/Iso_cuboid_3_Point_3.h | 66 +- .../CGAL/Intersections_3/Iso_cuboid_3_Ray_3.h | 23 +- .../Intersections_3/Iso_cuboid_3_Segment_3.h | 25 +- .../Intersections_3/Iso_cuboid_3_Sphere_3.h | 19 +- .../Iso_cuboid_3_Tetrahedron_3.h | 19 +- .../Intersections_3/Iso_cuboid_3_Triangle_3.h | 23 +- .../CGAL/Intersections_3/Line_3_Line_3.h | 20 +- .../CGAL/Intersections_3/Line_3_Plane_3.h | 32 +- .../CGAL/Intersections_3/Line_3_Point_3.h | 66 +- .../CGAL/Intersections_3/Line_3_Ray_3.h | 22 +- .../CGAL/Intersections_3/Line_3_Segment_3.h | 22 +- .../CGAL/Intersections_3/Line_3_Sphere_3.h | 17 +- .../Intersections_3/Line_3_Tetrahedron_3.h | 31 +- .../CGAL/Intersections_3/Line_3_Triangle_3.h | 23 +- .../CGAL/Intersections_3/Plane_3_Plane_3.h | 28 +- .../Intersections_3/Plane_3_Plane_3_Plane_3.h | 64 + .../CGAL/Intersections_3/Plane_3_Point_3.h | 71 +- .../CGAL/Intersections_3/Plane_3_Ray_3.h | 22 +- .../CGAL/Intersections_3/Plane_3_Segment_3.h | 22 +- .../CGAL/Intersections_3/Plane_3_Sphere_3.h | 22 +- .../Intersections_3/Plane_3_Tetrahedron_3.h | 23 +- .../CGAL/Intersections_3/Plane_3_Triangle_3.h | 23 +- .../CGAL/Intersections_3/Point_3_Point_3.h | 46 +- .../CGAL/Intersections_3/Point_3_Ray_3.h | 71 +- .../CGAL/Intersections_3/Point_3_Segment_3.h | 71 +- .../CGAL/Intersections_3/Point_3_Sphere_3.h | 71 +- .../Intersections_3/Point_3_Tetrahedron_3.h | 68 +- .../CGAL/Intersections_3/Point_3_Triangle_3.h | 119 +- .../CGAL/Intersections_3/Ray_3_Ray_3.h | 20 +- .../CGAL/Intersections_3/Ray_3_Segment_3.h | 20 +- .../CGAL/Intersections_3/Ray_3_Sphere_3.h | 19 +- .../Intersections_3/Ray_3_Tetrahedron_3.h | 23 +- .../CGAL/Intersections_3/Ray_3_Triangle_3.h | 25 +- .../Intersections_3/Segment_3_Segment_3.h | 18 +- .../CGAL/Intersections_3/Segment_3_Sphere_3.h | 19 +- .../Intersections_3/Segment_3_Tetrahedron_3.h | 23 +- .../Intersections_3/Segment_3_Triangle_3.h | 25 +- .../CGAL/Intersections_3/Sphere_3_Sphere_3.h | 18 +- .../Intersections_3/Sphere_3_Tetrahedron_3.h | 19 +- .../Intersections_3/Sphere_3_Triangle_3.h | 19 +- .../Tetrahedron_3_Tetrahedron_3.h | 19 +- .../Tetrahedron_3_Triangle_3.h | 25 +- .../Intersections_3/Triangle_3_Triangle_3.h | 16 +- .../internal/Bbox_3_Bbox_3_do_intersect.h | 36 - .../Bbox_3_Iso_cuboid_3_do_intersect.h | 15 +- .../Bbox_3_Iso_cuboid_3_intersection.h | 54 + .../internal/Bbox_3_Line_3_do_intersect.h | 240 ++- .../internal/Bbox_3_Line_3_intersection.h | 67 + .../internal/Bbox_3_Plane_3_do_intersect.h | 141 +- .../internal/Bbox_3_Ray_3_do_intersect.h | 64 +- .../internal/Bbox_3_Ray_3_intersection.h | 67 + .../internal/Bbox_3_Segment_3_do_intersect.h | 774 +++---- .../internal/Bbox_3_Segment_3_intersection.h | 209 ++ .../internal/Bbox_3_Sphere_3_do_intersect.h | 141 +- .../Bbox_3_Tetrahedron_3_do_intersect.h | 71 + .../internal/Bbox_3_Triangle_3_do_intersect.h | 556 ++--- .../Iso_cuboid_3_Iso_cuboid_3_do_intersect.h | 54 + .../Iso_cuboid_3_Iso_cuboid_3_intersection.h | 92 + .../Iso_cuboid_3_Line_3_do_intersect.h | 95 + .../Iso_cuboid_3_Line_3_intersection.h | 102 + .../Iso_cuboid_3_Plane_3_do_intersect.h | 136 ++ .../Iso_cuboid_3_Plane_3_intersection.h | 44 +- .../Iso_cuboid_3_Point_3_do_intersect.h | 44 + .../Iso_cuboid_3_Point_3_intersection.h | 51 + .../Iso_cuboid_3_Ray_3_do_intersect.h | 32 +- .../Iso_cuboid_3_Ray_3_intersection.h | 94 + .../Iso_cuboid_3_Segment_3_do_intersect.h | 16 +- .../Iso_cuboid_3_Segment_3_intersection.h | 96 + .../Iso_cuboid_3_Sphere_3_do_intersect.h | 119 +- .../Iso_cuboid_3_Tetrahedron_3_do_intersect.h | 46 + .../Iso_cuboid_3_Triangle_3_do_intersect.h | 14 +- .../Iso_cuboid_3_Triangle_3_intersection.h | 4 +- .../internal/Line_3_Line_3_do_intersect.h | 47 + .../internal/Line_3_Line_3_intersection.h | 74 + .../internal/Line_3_Plane_3_do_intersect.h | 63 + .../internal/Line_3_Plane_3_intersection.h | 100 + .../internal/Line_3_Point_3_do_intersect.h | 42 + .../internal/Line_3_Point_3_intersection.h | 48 + .../internal/Line_3_Ray_3_do_intersect.h | 62 + .../internal/Line_3_Ray_3_intersection.h | 64 + .../internal/Line_3_Segment_3_do_intersect.h | 67 + .../internal/Line_3_Segment_3_intersection.h | 62 + .../internal/Line_3_Sphere_3_do_intersect.h | 53 + .../Line_3_Tetrahedron_3_do_intersect.h | 45 + ....h => Line_3_Tetrahedron_3_intersection.h} | 55 +- .../internal/Line_3_Triangle_3_do_intersect.h | 87 + ...ion.h => Line_3_Triangle_3_intersection.h} | 52 +- .../Plane_3_Plane_3_Plane_3_do_intersect.h | 69 + .../Plane_3_Plane_3_Plane_3_intersection.h | 133 ++ .../internal/Plane_3_Plane_3_do_intersect.h | 68 + .../internal/Plane_3_Plane_3_intersection.h | 99 + .../internal/Plane_3_Point_3_do_intersect.h | 42 + .../internal/Plane_3_Point_3_intersection.h | 48 + .../internal/Plane_3_Ray_3_do_intersect.h | 55 + .../internal/Plane_3_Ray_3_intersection.h | 70 + .../internal/Plane_3_Segment_3_do_intersect.h | 56 + .../internal/Plane_3_Segment_3_intersection.h | 120 ++ .../internal/Plane_3_Sphere_3_do_intersect.h | 52 + .../internal/Plane_3_Sphere_3_intersection.h | 71 + .../Plane_3_Tetrahedron_3_do_intersect.h | 44 + ...h => Plane_3_Tetrahedron_3_intersection.h} | 47 +- .../Plane_3_Triangle_3_do_intersect.h | 63 + .../Plane_3_Triangle_3_intersection.h | 161 ++ .../internal/Point_3_Point_3_do_intersect.h | 33 + .../internal/Point_3_Point_3_intersection.h | 39 + .../internal/Point_3_Ray_3_do_intersect.h | 57 + .../internal/Point_3_Ray_3_intersection.h | 47 + .../internal/Point_3_Segment_3_do_intersect.h | 44 + .../internal/Point_3_Segment_3_intersection.h | 50 + .../internal/Point_3_Sphere_3_do_intersect.h | 44 + .../internal/Point_3_Sphere_3_intersection.h | 48 + .../Point_3_Tetrahedron_3_do_intersect.h | 44 + .../Point_3_Tetrahedron_3_intersection.h | 48 + .../Point_3_Triangle_3_do_intersect.h | 82 + .../Point_3_Triangle_3_intersection.h | 50 + .../internal/Ray_3_Ray_3_do_intersect.h | 61 + .../internal/Ray_3_Ray_3_intersection.h | 81 + .../internal/Ray_3_Segment_3_do_intersect.h | 71 + .../internal/Ray_3_Segment_3_intersection.h | 91 + .../internal/Ray_3_Sphere_3_do_intersect.h | 53 + .../Ray_3_Tetrahedron_3_do_intersect.h | 45 + ...n.h => Ray_3_Tetrahedron_3_intersection.h} | 47 +- ...sect.h => Ray_3_Triangle_3_do_intersect.h} | 396 ++-- ...tion.h => Ray_3_Triangle_3_intersection.h} | 139 +- .../Segment_3_Segment_3_do_intersect.h | 64 + .../Segment_3_Segment_3_intersection.h | 129 ++ .../Segment_3_Sphere_3_do_intersect.h | 53 + .../Segment_3_Tetrahedron_3_do_intersect.h | 46 + ...=> Segment_3_Tetrahedron_3_intersection.h} | 47 +- ....h => Segment_3_Triangle_3_do_intersect.h} | 249 +-- ....h => Segment_3_Triangle_3_intersection.h} | 346 ++-- .../internal/Sphere_3_Sphere_3_do_intersect.h | 47 + .../internal/Sphere_3_Sphere_3_intersection.h | 71 + .../Sphere_3_Tetrahedron_3_do_intersect.h | 46 + .../Sphere_3_Triangle_3_do_intersect.h | 53 + .../Tetrahedron_3_Bounded_3_do_intersect.h | 206 +- ...Tetrahedron_3_Tetrahedron_3_do_intersect.h | 40 + .../Tetrahedron_3_Triangle_3_do_intersect.h | 53 + .../Tetrahedron_3_Triangle_3_intersection.h | 453 ++--- .../Tetrahedron_3_Unbounded_3_do_intersect.h | 82 +- .../internal/Triangle_3_Line_3_do_intersect.h | 117 -- .../Triangle_3_Plane_3_do_intersect.h | 80 - .../Triangle_3_Sphere_3_do_intersect.h | 148 -- .../Triangle_3_Triangle_3_do_intersect.h | 547 ++--- .../Triangle_3_Triangle_3_intersection.h | 166 +- .../internal/bbox_intersection_3.h | 172 -- .../internal/intersection_3_1_impl.h | 1811 ----------------- .../tetrahedron_intersection_helpers.h | 57 +- .../tetrahedron_lines_intersections_3.h | 38 +- Intersections_3/include/CGAL/intersection_3.h | 14 +- .../include/CGAL/intersection_3_1.h | 25 - Intersections_3/include/CGAL/intersections.h | 8 +- 166 files changed, 8220 insertions(+), 6025 deletions(-) create mode 100644 Intersections_3/include/CGAL/Intersections_3/Plane_3_Plane_3_Plane_3.h delete mode 100644 Intersections_3/include/CGAL/Intersections_3/internal/Bbox_3_Bbox_3_do_intersect.h create mode 100644 Intersections_3/include/CGAL/Intersections_3/internal/Bbox_3_Iso_cuboid_3_intersection.h create mode 100644 Intersections_3/include/CGAL/Intersections_3/internal/Bbox_3_Line_3_intersection.h create mode 100644 Intersections_3/include/CGAL/Intersections_3/internal/Bbox_3_Ray_3_intersection.h create mode 100644 Intersections_3/include/CGAL/Intersections_3/internal/Bbox_3_Segment_3_intersection.h create mode 100644 Intersections_3/include/CGAL/Intersections_3/internal/Bbox_3_Tetrahedron_3_do_intersect.h create mode 100644 Intersections_3/include/CGAL/Intersections_3/internal/Iso_cuboid_3_Iso_cuboid_3_do_intersect.h create mode 100644 Intersections_3/include/CGAL/Intersections_3/internal/Iso_cuboid_3_Iso_cuboid_3_intersection.h create mode 100644 Intersections_3/include/CGAL/Intersections_3/internal/Iso_cuboid_3_Line_3_do_intersect.h create mode 100644 Intersections_3/include/CGAL/Intersections_3/internal/Iso_cuboid_3_Line_3_intersection.h create mode 100644 Intersections_3/include/CGAL/Intersections_3/internal/Iso_cuboid_3_Plane_3_do_intersect.h create mode 100644 Intersections_3/include/CGAL/Intersections_3/internal/Iso_cuboid_3_Point_3_do_intersect.h create mode 100644 Intersections_3/include/CGAL/Intersections_3/internal/Iso_cuboid_3_Point_3_intersection.h create mode 100644 Intersections_3/include/CGAL/Intersections_3/internal/Iso_cuboid_3_Ray_3_intersection.h create mode 100644 Intersections_3/include/CGAL/Intersections_3/internal/Iso_cuboid_3_Segment_3_intersection.h create mode 100644 Intersections_3/include/CGAL/Intersections_3/internal/Iso_cuboid_3_Tetrahedron_3_do_intersect.h create mode 100644 Intersections_3/include/CGAL/Intersections_3/internal/Line_3_Line_3_do_intersect.h create mode 100644 Intersections_3/include/CGAL/Intersections_3/internal/Line_3_Line_3_intersection.h create mode 100644 Intersections_3/include/CGAL/Intersections_3/internal/Line_3_Plane_3_do_intersect.h create mode 100644 Intersections_3/include/CGAL/Intersections_3/internal/Line_3_Plane_3_intersection.h create mode 100644 Intersections_3/include/CGAL/Intersections_3/internal/Line_3_Point_3_do_intersect.h create mode 100644 Intersections_3/include/CGAL/Intersections_3/internal/Line_3_Point_3_intersection.h create mode 100644 Intersections_3/include/CGAL/Intersections_3/internal/Line_3_Ray_3_do_intersect.h create mode 100644 Intersections_3/include/CGAL/Intersections_3/internal/Line_3_Ray_3_intersection.h create mode 100644 Intersections_3/include/CGAL/Intersections_3/internal/Line_3_Segment_3_do_intersect.h create mode 100644 Intersections_3/include/CGAL/Intersections_3/internal/Line_3_Segment_3_intersection.h create mode 100644 Intersections_3/include/CGAL/Intersections_3/internal/Line_3_Sphere_3_do_intersect.h create mode 100644 Intersections_3/include/CGAL/Intersections_3/internal/Line_3_Tetrahedron_3_do_intersect.h rename Intersections_3/include/CGAL/Intersections_3/internal/{Tetrahedron_3_Line_3_intersection.h => Line_3_Tetrahedron_3_intersection.h} (50%) create mode 100644 Intersections_3/include/CGAL/Intersections_3/internal/Line_3_Triangle_3_do_intersect.h rename Intersections_3/include/CGAL/Intersections_3/internal/{Triangle_3_Line_3_intersection.h => Line_3_Triangle_3_intersection.h} (92%) create mode 100644 Intersections_3/include/CGAL/Intersections_3/internal/Plane_3_Plane_3_Plane_3_do_intersect.h create mode 100644 Intersections_3/include/CGAL/Intersections_3/internal/Plane_3_Plane_3_Plane_3_intersection.h create mode 100644 Intersections_3/include/CGAL/Intersections_3/internal/Plane_3_Plane_3_do_intersect.h create mode 100644 Intersections_3/include/CGAL/Intersections_3/internal/Plane_3_Plane_3_intersection.h create mode 100644 Intersections_3/include/CGAL/Intersections_3/internal/Plane_3_Point_3_do_intersect.h create mode 100644 Intersections_3/include/CGAL/Intersections_3/internal/Plane_3_Point_3_intersection.h create mode 100644 Intersections_3/include/CGAL/Intersections_3/internal/Plane_3_Ray_3_do_intersect.h create mode 100644 Intersections_3/include/CGAL/Intersections_3/internal/Plane_3_Ray_3_intersection.h create mode 100644 Intersections_3/include/CGAL/Intersections_3/internal/Plane_3_Segment_3_do_intersect.h create mode 100644 Intersections_3/include/CGAL/Intersections_3/internal/Plane_3_Segment_3_intersection.h create mode 100644 Intersections_3/include/CGAL/Intersections_3/internal/Plane_3_Sphere_3_do_intersect.h create mode 100644 Intersections_3/include/CGAL/Intersections_3/internal/Plane_3_Sphere_3_intersection.h create mode 100644 Intersections_3/include/CGAL/Intersections_3/internal/Plane_3_Tetrahedron_3_do_intersect.h rename Intersections_3/include/CGAL/Intersections_3/internal/{Tetrahedron_3_Plane_3_intersection.h => Plane_3_Tetrahedron_3_intersection.h} (86%) create mode 100644 Intersections_3/include/CGAL/Intersections_3/internal/Plane_3_Triangle_3_do_intersect.h create mode 100644 Intersections_3/include/CGAL/Intersections_3/internal/Plane_3_Triangle_3_intersection.h create mode 100644 Intersections_3/include/CGAL/Intersections_3/internal/Point_3_Point_3_do_intersect.h create mode 100644 Intersections_3/include/CGAL/Intersections_3/internal/Point_3_Point_3_intersection.h create mode 100644 Intersections_3/include/CGAL/Intersections_3/internal/Point_3_Ray_3_do_intersect.h create mode 100644 Intersections_3/include/CGAL/Intersections_3/internal/Point_3_Ray_3_intersection.h create mode 100644 Intersections_3/include/CGAL/Intersections_3/internal/Point_3_Segment_3_do_intersect.h create mode 100644 Intersections_3/include/CGAL/Intersections_3/internal/Point_3_Segment_3_intersection.h create mode 100644 Intersections_3/include/CGAL/Intersections_3/internal/Point_3_Sphere_3_do_intersect.h create mode 100644 Intersections_3/include/CGAL/Intersections_3/internal/Point_3_Sphere_3_intersection.h create mode 100644 Intersections_3/include/CGAL/Intersections_3/internal/Point_3_Tetrahedron_3_do_intersect.h create mode 100644 Intersections_3/include/CGAL/Intersections_3/internal/Point_3_Tetrahedron_3_intersection.h create mode 100644 Intersections_3/include/CGAL/Intersections_3/internal/Point_3_Triangle_3_do_intersect.h create mode 100644 Intersections_3/include/CGAL/Intersections_3/internal/Point_3_Triangle_3_intersection.h create mode 100644 Intersections_3/include/CGAL/Intersections_3/internal/Ray_3_Ray_3_do_intersect.h create mode 100644 Intersections_3/include/CGAL/Intersections_3/internal/Ray_3_Ray_3_intersection.h create mode 100644 Intersections_3/include/CGAL/Intersections_3/internal/Ray_3_Segment_3_do_intersect.h create mode 100644 Intersections_3/include/CGAL/Intersections_3/internal/Ray_3_Segment_3_intersection.h create mode 100644 Intersections_3/include/CGAL/Intersections_3/internal/Ray_3_Sphere_3_do_intersect.h create mode 100644 Intersections_3/include/CGAL/Intersections_3/internal/Ray_3_Tetrahedron_3_do_intersect.h rename Intersections_3/include/CGAL/Intersections_3/internal/{Tetrahedron_3_Ray_3_intersection.h => Ray_3_Tetrahedron_3_intersection.h} (63%) rename Intersections_3/include/CGAL/Intersections_3/internal/{Triangle_3_Ray_3_do_intersect.h => Ray_3_Triangle_3_do_intersect.h} (60%) rename Intersections_3/include/CGAL/Intersections_3/internal/{Triangle_3_Ray_3_intersection.h => Ray_3_Triangle_3_intersection.h} (87%) create mode 100644 Intersections_3/include/CGAL/Intersections_3/internal/Segment_3_Segment_3_do_intersect.h create mode 100644 Intersections_3/include/CGAL/Intersections_3/internal/Segment_3_Segment_3_intersection.h create mode 100644 Intersections_3/include/CGAL/Intersections_3/internal/Segment_3_Sphere_3_do_intersect.h create mode 100644 Intersections_3/include/CGAL/Intersections_3/internal/Segment_3_Tetrahedron_3_do_intersect.h rename Intersections_3/include/CGAL/Intersections_3/internal/{Tetrahedron_3_Segment_3_intersection.h => Segment_3_Tetrahedron_3_intersection.h} (73%) rename Intersections_3/include/CGAL/Intersections_3/internal/{Triangle_3_Segment_3_do_intersect.h => Segment_3_Triangle_3_do_intersect.h} (51%) rename Intersections_3/include/CGAL/Intersections_3/internal/{Triangle_3_Segment_3_intersection.h => Segment_3_Triangle_3_intersection.h} (70%) create mode 100644 Intersections_3/include/CGAL/Intersections_3/internal/Sphere_3_Sphere_3_do_intersect.h create mode 100644 Intersections_3/include/CGAL/Intersections_3/internal/Sphere_3_Sphere_3_intersection.h create mode 100644 Intersections_3/include/CGAL/Intersections_3/internal/Sphere_3_Tetrahedron_3_do_intersect.h create mode 100644 Intersections_3/include/CGAL/Intersections_3/internal/Sphere_3_Triangle_3_do_intersect.h create mode 100644 Intersections_3/include/CGAL/Intersections_3/internal/Tetrahedron_3_Tetrahedron_3_do_intersect.h create mode 100644 Intersections_3/include/CGAL/Intersections_3/internal/Tetrahedron_3_Triangle_3_do_intersect.h delete mode 100644 Intersections_3/include/CGAL/Intersections_3/internal/Triangle_3_Line_3_do_intersect.h delete mode 100644 Intersections_3/include/CGAL/Intersections_3/internal/Triangle_3_Plane_3_do_intersect.h delete mode 100644 Intersections_3/include/CGAL/Intersections_3/internal/Triangle_3_Sphere_3_do_intersect.h delete mode 100644 Intersections_3/include/CGAL/Intersections_3/internal/bbox_intersection_3.h delete mode 100644 Intersections_3/include/CGAL/Intersections_3/internal/intersection_3_1_impl.h delete mode 100644 Intersections_3/include/CGAL/intersection_3_1.h diff --git a/Intersections_3/include/CGAL/Intersection_traits_3.h b/Intersections_3/include/CGAL/Intersection_traits_3.h index dee4d2e3e8b..84cac64e4bd 100644 --- a/Intersections_3/include/CGAL/Intersection_traits_3.h +++ b/Intersections_3/include/CGAL/Intersection_traits_3.h @@ -1,4 +1,10 @@ -// Copyright (c) 2011 GeometryFactory (France). All rights reserved. +// Copyright (c) 1997-2021 +// Utrecht University (The Netherlands), +// ETH Zurich (Switzerland), +// INRIA Sophia-Antipolis (France), +// Max-Planck-Institute Saarbruecken (Germany), +// and Tel-Aviv University (Israel). +// GeometryFactory (France) // All rights reserved. // // This file is part of CGAL (www.cgal.org) @@ -14,6 +20,10 @@ #define CGAL_INTERSECTION_TRAITS_3_H #include + +#include +#include + #include namespace CGAL { diff --git a/Intersections_3/include/CGAL/Intersections_3/Bbox_3_Bbox_3.h b/Intersections_3/include/CGAL/Intersections_3/Bbox_3_Bbox_3.h index b0220d8ad8f..f497eb4527f 100644 --- a/Intersections_3/include/CGAL/Intersections_3/Bbox_3_Bbox_3.h +++ b/Intersections_3/include/CGAL/Intersections_3/Bbox_3_Bbox_3.h @@ -1,4 +1,10 @@ -// Copyright (c) 2010 GeometryFactory (France). +// Copyright (c) 1997-2021 +// Utrecht University (The Netherlands), +// ETH Zurich (Switzerland), +// INRIA Sophia-Antipolis (France), +// Max-Planck-Institute Saarbruecken (Germany), +// and Tel-Aviv University (Israel). +// GeometryFactory (France) // All rights reserved. // // This file is part of CGAL (www.cgal.org) @@ -14,9 +20,15 @@ #ifndef CGAL_INTERSECTIONS_3_BBOX_3_BBOX_3_H #define CGAL_INTERSECTIONS_3_BBOX_3_BBOX_3_H -#include #include +#include + +#include +#include + +#include + namespace CGAL { bool @@ -48,7 +60,31 @@ intersection(const CGAL::Bbox_3& a, return result_type(std::forward(Bbox_3(xmin, ymin, zmin, xmax, ymax, zmax))); } -} //namespace CGAL +namespace Intersections { +namespace internal { +template +bool +inline +do_intersect(const CGAL::Bbox_3& c, + const CGAL::Bbox_3& bbox, + const K&) +{ + return CGAL::do_intersect(c, bbox); +} + +template +inline +typename Intersection_traits::result_type +intersection(const Bbox_3& a, + const Bbox_3& b, + const K&) +{ + return CGAL::intersection(a, b); +} + +} // namespace internal +} // namespace Intersections +} // namespace CGAL #endif // CGAL_INTERSECTIONS_3_BBOX_3_BBOX_3_H diff --git a/Intersections_3/include/CGAL/Intersections_3/Bbox_3_Iso_cuboid_3.h b/Intersections_3/include/CGAL/Intersections_3/Bbox_3_Iso_cuboid_3.h index 5457d7eab46..fae76f0d787 100644 --- a/Intersections_3/include/CGAL/Intersections_3/Bbox_3_Iso_cuboid_3.h +++ b/Intersections_3/include/CGAL/Intersections_3/Bbox_3_Iso_cuboid_3.h @@ -1,4 +1,10 @@ -// Copyright (c) 2010 GeometryFactory (France). +// Copyright (c) 1997-2021 +// Utrecht University (The Netherlands), +// ETH Zurich (Switzerland), +// INRIA Sophia-Antipolis (France), +// Max-Planck-Institute Saarbruecken (Germany), +// and Tel-Aviv University (Israel). +// GeometryFactory (France) // All rights reserved. // // This file is part of CGAL (www.cgal.org) @@ -14,39 +20,45 @@ #ifndef CGAL_INTERSECTIONS_3_BBOX_3_ISO_CUBOID_3_H #define CGAL_INTERSECTIONS_3_BBOX_3_ISO_CUBOID_3_H +#include +#include +#include + #include #include -#include -#include - namespace CGAL { template -bool do_intersect(const CGAL::Bbox_3& a, - const Iso_cuboid_3& b) { - return K().do_intersect_3_object()(a, b); +bool do_intersect(const CGAL::Bbox_3& box, + const Iso_cuboid_3& ic) +{ + return K().do_intersect_3_object()(box, ic); } template -bool do_intersect(const Iso_cuboid_3& a, - const CGAL::Bbox_3& b) { - return K().do_intersect_3_object()(b, a); +bool do_intersect(const Iso_cuboid_3& ic, + const CGAL::Bbox_3& box) +{ + return K().do_intersect_3_object()(ic, box); } template typename Intersection_traits::result_type -intersection(const CGAL::Bbox_3& a, - const Iso_cuboid_3& b) { - return K().intersect_3_object()(a, b); +intersection(const CGAL::Bbox_3& box, + const Iso_cuboid_3& ic) +{ + return K().intersect_3_object()(box, ic); } template typename Intersection_traits::result_type -intersection(const Iso_cuboid_3& a, - const CGAL::Bbox_3& b) { - return K().intersect_3_object()(a, b); +intersection(const Iso_cuboid_3& ic, + const CGAL::Bbox_3& box) +{ + return K().intersect_3_object()(ic, box); } + } // namespace CGAL #endif // CGAL_INTERSECTIONS_3_BBOX_3_ISO_CUBOID_3_H diff --git a/Intersections_3/include/CGAL/Intersections_3/Bbox_3_Line_3.h b/Intersections_3/include/CGAL/Intersections_3/Bbox_3_Line_3.h index 1468403373d..20a9e5e3d2a 100644 --- a/Intersections_3/include/CGAL/Intersections_3/Bbox_3_Line_3.h +++ b/Intersections_3/include/CGAL/Intersections_3/Bbox_3_Line_3.h @@ -14,39 +14,45 @@ #ifndef CGAL_INTERSECTIONS_3_BBOX_3_LINE_3_H #define CGAL_INTERSECTIONS_3_BBOX_3_LINE_3_H +#include +#include +#include + #include #include -#include -#include - namespace CGAL { template -bool do_intersect(const CGAL::Bbox_3& a, - const Line_3& b) { - return K().do_intersect_3_object()(a, b); +bool do_intersect(const CGAL::Bbox_3& box, + const Line_3& l) +{ + return K().do_intersect_3_object()(box, l); } template -bool do_intersect(const Line_3& a, - const CGAL::Bbox_3& b) { - return K().do_intersect_3_object()(a, b); +bool do_intersect(const Line_3& l, + const CGAL::Bbox_3& box) +{ + return K().do_intersect_3_object()(l, box); } template typename Intersection_traits::result_type -intersection(const CGAL::Bbox_3& a, - const Line_3& b) { - return K().intersect_3_object()(a, b); +intersection(const CGAL::Bbox_3& box, + const Line_3& l) +{ + return K().intersect_3_object()(box, l); } template typename Intersection_traits::result_type -intersection(const Line_3& a, - const CGAL::Bbox_3& b) { - return K().intersect_3_object()(a, b); -} +intersection(const Line_3& l, + const CGAL::Bbox_3& box) +{ + return K().intersect_3_object()(l, box); } +} // namespace CGAL + #endif // CGAL_INTERSECTIONS_3_BBOX_3_LINE_3_H diff --git a/Intersections_3/include/CGAL/Intersections_3/Bbox_3_Plane_3.h b/Intersections_3/include/CGAL/Intersections_3/Bbox_3_Plane_3.h index 616d11b38f7..ce7888e7539 100644 --- a/Intersections_3/include/CGAL/Intersections_3/Bbox_3_Plane_3.h +++ b/Intersections_3/include/CGAL/Intersections_3/Bbox_3_Plane_3.h @@ -1,4 +1,10 @@ -// Copyright (c) 2010 GeometryFactory (France). +// Copyright (c) 1997-2021 +// Utrecht University (The Netherlands), +// ETH Zurich (Switzerland), +// INRIA Sophia-Antipolis (France), +// Max-Planck-Institute Saarbruecken (Germany), +// and Tel-Aviv University (Israel). +// GeometryFactory (France) // All rights reserved. // // This file is part of CGAL (www.cgal.org) @@ -14,44 +20,48 @@ #ifndef CGAL_INTERSECTIONS_3_BBOX_3_PLANE_3_H #define CGAL_INTERSECTIONS_3_BBOX_3_PLANE_3_H -#include -#include - +#include #include #include +#include +#include namespace CGAL { template -bool do_intersect(const CGAL::Bbox_3& a, - const Plane_3& b) { - return K().do_intersect_3_object()(a, b); +bool do_intersect(const CGAL::Bbox_3& box, + const Plane_3& pl) +{ + return K().do_intersect_3_object()(box, pl); } template -bool do_intersect(const Plane_3& a, - const CGAL::Bbox_3& b) { - return K().do_intersect_3_object()(a, b); +bool do_intersect(const Plane_3& pl, + const CGAL::Bbox_3& box) +{ + return K().do_intersect_3_object()(pl, box); } template typename Intersection_traits::result_type intersection(const CGAL::Bbox_3& box, - const Plane_3& pl) { + const Plane_3& pl) +{ + // @fixme illegal for non-CGAL kernels typename K::Iso_cuboid_3 cub(box.xmin(), box.ymin(), box.zmin(), - box.xmax(), box.ymax(), box.zmax()); - return typename K::Intersect_3()(cub, pl); + box.xmax(), box.ymax(), box.zmax()); + return K().intersect_3_object()(cub, pl); } template typename Intersection_traits::result_type -intersection(const Plane_3& a, - const CGAL::Bbox_3& b) { - return intersection(b,a); +intersection(const Plane_3& pl, + const CGAL::Bbox_3& box) +{ + return intersection(box, pl); } - -} +} // namespace CGAL #endif // CGAL_INTERSECTIONS_3_BBOX_3_PLANE_3_H diff --git a/Intersections_3/include/CGAL/Intersections_3/Bbox_3_Point_3.h b/Intersections_3/include/CGAL/Intersections_3/Bbox_3_Point_3.h index 5e7285429d7..5737a04dba5 100644 --- a/Intersections_3/include/CGAL/Intersections_3/Bbox_3_Point_3.h +++ b/Intersections_3/include/CGAL/Intersections_3/Bbox_3_Point_3.h @@ -1,4 +1,10 @@ -// Copyright (c) 2010 GeometryFactory (France). +// Copyright (c) 1997-2021 +// Utrecht University (The Netherlands), +// ETH Zurich (Switzerland), +// INRIA Sophia-Antipolis (France), +// Max-Planck-Institute Saarbruecken (Germany), +// and Tel-Aviv University (Israel). +// GeometryFactory (France) // All rights reserved. // // This file is part of CGAL (www.cgal.org) @@ -14,49 +20,51 @@ #ifndef CGAL_INTERSECTIONS_3_BBOX_3_POINT_3_H #define CGAL_INTERSECTIONS_3_BBOX_3_POINT_3_H -#include -#include - -#include +#include #include +#include +#include +#include + namespace CGAL { template -bool do_intersect(const CGAL::Bbox_3& a, - const Point_3& b) { - Point_3 bl(a.xmin(), a.ymin(),a.zmin()), tr(a.xmax(), a.ymax(),a.zmax()); - - Iso_cuboid_3 ic(bl,tr); - return K().do_intersect_3_object()(ic, b); +bool do_intersect(const CGAL::Bbox_3& box, + const Point_3& p) +{ + Point_3 bl(box.xmin(), box.ymin(), box.zmin()), + tr(box.xmax(), box.ymax(), box.zmax()); + Iso_cuboid_3 ic(bl, tr); + return K().do_intersect_3_object()(ic, p); } - template bool do_intersect(const Point_3& a, - const CGAL::Bbox_3& b) { + const CGAL::Bbox_3& b) +{ return do_intersect(b,a); } - template typename Intersection_traits::result_type -intersection(const Point_3& a, - const CGAL::Bbox_3& b) +intersection(const Point_3& p, + const CGAL::Bbox_3& box) { - if (do_intersect(a,b)) - return Intersections::internal::intersection_return(a); + if(do_intersect(p, box)) + return Intersections::internal::intersection_return(p); + return Intersections::internal::intersection_return(); } - template typename Intersection_traits::result_type -intersection(const CGAL::Bbox_3& b, - const Point_3& a) +intersection(const CGAL::Bbox_3& box, + const Point_3& p) { - if (do_intersect(a,b)) - return Intersections::internal::intersection_return(a); + if(do_intersect(box, p)) + return Intersections::internal::intersection_return(p); + return Intersections::internal::intersection_return(); } diff --git a/Intersections_3/include/CGAL/Intersections_3/Bbox_3_Ray_3.h b/Intersections_3/include/CGAL/Intersections_3/Bbox_3_Ray_3.h index 691851b6bfa..3d557b0ecdd 100644 --- a/Intersections_3/include/CGAL/Intersections_3/Bbox_3_Ray_3.h +++ b/Intersections_3/include/CGAL/Intersections_3/Bbox_3_Ray_3.h @@ -1,4 +1,10 @@ -// Copyright (c) 2010 GeometryFactory (France). +// Copyright (c) 1997-2021 +// Utrecht University (The Netherlands), +// ETH Zurich (Switzerland), +// INRIA Sophia-Antipolis (France), +// Max-Planck-Institute Saarbruecken (Germany), +// and Tel-Aviv University (Israel). +// GeometryFactory (France) // All rights reserved. // // This file is part of CGAL (www.cgal.org) @@ -14,39 +20,45 @@ #ifndef CGAL_INTERSECTIONS_3_BBOX_3_RAY_3_H #define CGAL_INTERSECTIONS_3_BBOX_3_RAY_3_H +#include +#include +#include + #include #include -#include -#include - namespace CGAL { template -bool do_intersect(const CGAL::Bbox_3& a, - const Ray_3& b) { - return K().do_intersect_3_object()(a, b); +bool do_intersect(const CGAL::Bbox_3& box, + const Ray_3& r) +{ + return K().do_intersect_3_object()(box, r); } template -bool do_intersect(const Ray_3& a, - const CGAL::Bbox_3& b) { - return K().do_intersect_3_object()(a, b); +bool do_intersect(const Ray_3& r, + const CGAL::Bbox_3& box) +{ + return K().do_intersect_3_object()(r, box); } template typename Intersection_traits::result_type -intersection(const CGAL::Bbox_3& a, - const Ray_3& b) { - return K().intersect_3_object()(a, b); +intersection(const CGAL::Bbox_3& box, + const Ray_3& r) +{ + return K().intersect_3_object()(box, r); } template typename Intersection_traits::result_type -intersection(const Ray_3& a, - const CGAL::Bbox_3& b) { - return K().intersect_3_object()(a, b); +intersection(const Ray_3& r, + const CGAL::Bbox_3& box) +{ + return K().intersect_3_object()(r, box); } -} +} // namespace CGAL + #endif // CGAL_INTERSECTIONS_3_BBOX_3_RAY_3_H diff --git a/Intersections_3/include/CGAL/Intersections_3/Bbox_3_Segment_3.h b/Intersections_3/include/CGAL/Intersections_3/Bbox_3_Segment_3.h index 08d99c0c665..35b20b8091d 100644 --- a/Intersections_3/include/CGAL/Intersections_3/Bbox_3_Segment_3.h +++ b/Intersections_3/include/CGAL/Intersections_3/Bbox_3_Segment_3.h @@ -1,4 +1,10 @@ -// Copyright (c) 2010 GeometryFactory (France). +// Copyright (c) 1997-2021 +// Utrecht University (The Netherlands), +// ETH Zurich (Switzerland), +// INRIA Sophia-Antipolis (France), +// Max-Planck-Institute Saarbruecken (Germany), +// and Tel-Aviv University (Israel). +// GeometryFactory (France) // All rights reserved. // // This file is part of CGAL (www.cgal.org) @@ -14,37 +20,43 @@ #ifndef CGAL_INTERSECTIONS_3_BBOX_3_SEGMENT_3_H #define CGAL_INTERSECTIONS_3_BBOX_3_SEGMENT_3_H +#include +#include +#include + #include #include -#include -#include namespace CGAL { template -bool do_intersect(const CGAL::Bbox_3& a, - const Segment_3& b) { - return K().do_intersect_3_object()(a, b); +bool do_intersect(const CGAL::Bbox_3& box, + const Segment_3& s) +{ + return K().do_intersect_3_object()(box, s); } template -bool do_intersect(const Segment_3& a, - const CGAL::Bbox_3& b) { - return K().do_intersect_3_object()(a, b); +bool do_intersect(const Segment_3& s, + const CGAL::Bbox_3& box) +{ + return K().do_intersect_3_object()(s, box); } template typename Intersection_traits::result_type -intersection(const CGAL::Bbox_3& a, - const Segment_3& b) { - return K().intersect_3_object()(a, b); +intersection(const CGAL::Bbox_3& box, + const Segment_3& s) +{ + return K().intersect_3_object()(box, s); } template typename Intersection_traits::result_type -intersection(const Segment_3& a, - const CGAL::Bbox_3& b) { - return K().intersect_3_object()(a, b); +intersection(const Segment_3& s, + const CGAL::Bbox_3& box) +{ + return K().intersect_3_object()(s, box); } } // namespace CGAL diff --git a/Intersections_3/include/CGAL/Intersections_3/Bbox_3_Sphere_3.h b/Intersections_3/include/CGAL/Intersections_3/Bbox_3_Sphere_3.h index 49f3da173fd..913020d62cd 100644 --- a/Intersections_3/include/CGAL/Intersections_3/Bbox_3_Sphere_3.h +++ b/Intersections_3/include/CGAL/Intersections_3/Bbox_3_Sphere_3.h @@ -1,4 +1,10 @@ -// Copyright (c) 2010 GeometryFactory (France). +// Copyright (c) 1997-2021 +// Utrecht University (The Netherlands), +// ETH Zurich (Switzerland), +// INRIA Sophia-Antipolis (France), +// Max-Planck-Institute Saarbruecken (Germany), +// and Tel-Aviv University (Israel). +// GeometryFactory (France) // All rights reserved. // // This file is part of CGAL (www.cgal.org) @@ -14,25 +20,27 @@ #ifndef CGAL_INTERSECTIONS_3_BBOX_3_SPHERE_3_H #define CGAL_INTERSECTIONS_3_BBOX_3_SPHERE_3_H +#include + #include #include -#include - namespace CGAL { template -bool do_intersect(const CGAL::Bbox_3& a, - const Sphere_3& b) { - return K().do_intersect_3_object()(a, b); +bool do_intersect(const CGAL::Bbox_3& box, + const Sphere_3& s) +{ + return K().do_intersect_3_object()(box, s); } template -bool do_intersect(const Sphere_3& a, - const CGAL::Bbox_3& b) { - return K().do_intersect_3_object()(a, b); +bool do_intersect(const Sphere_3& s, + const CGAL::Bbox_3& box) +{ + return K().do_intersect_3_object()(s, box); } -} +} // namespace CGAL #endif // CGAL_INTERSECTIONS_3_BBOX_3_SPHERE_3_H diff --git a/Intersections_3/include/CGAL/Intersections_3/Bbox_3_Tetrahedron_3.h b/Intersections_3/include/CGAL/Intersections_3/Bbox_3_Tetrahedron_3.h index de5dffa00f5..456973dbc6a 100644 --- a/Intersections_3/include/CGAL/Intersections_3/Bbox_3_Tetrahedron_3.h +++ b/Intersections_3/include/CGAL/Intersections_3/Bbox_3_Tetrahedron_3.h @@ -1,4 +1,10 @@ -// Copyright (c) 2010 GeometryFactory (France). +// Copyright (c) 1997-2021 +// Utrecht University (The Netherlands), +// ETH Zurich (Switzerland), +// INRIA Sophia-Antipolis (France), +// Max-Planck-Institute Saarbruecken (Germany), +// and Tel-Aviv University (Israel). +// GeometryFactory (France) // All rights reserved. // // This file is part of CGAL (www.cgal.org) @@ -14,23 +20,25 @@ #ifndef CGAL_INTERSECTIONS_3_BBOX_3_TETRAHEDRON_3_H #define CGAL_INTERSECTIONS_3_BBOX_3_TETRAHEDRON_3_H +#include + #include #include -#include - namespace CGAL { template -bool do_intersect(const CGAL::Bbox_3& a, - const Tetrahedron_3& b) { - return K().do_intersect_3_object()(a, b); +bool do_intersect(const CGAL::Bbox_3& box, + const Tetrahedron_3& t) +{ + return K().do_intersect_3_object()(box, t); } template -bool do_intersect(const Tetrahedron_3& a, - const CGAL::Bbox_3& b) { - return K().do_intersect_3_object()(a, b); +bool do_intersect(const Tetrahedron_3& t, + const CGAL::Bbox_3& box) +{ + return K().do_intersect_3_object()(t, box); } } // namespace CGAL diff --git a/Intersections_3/include/CGAL/Intersections_3/Bbox_3_Triangle_3.h b/Intersections_3/include/CGAL/Intersections_3/Bbox_3_Triangle_3.h index d11de75760c..202765284c7 100644 --- a/Intersections_3/include/CGAL/Intersections_3/Bbox_3_Triangle_3.h +++ b/Intersections_3/include/CGAL/Intersections_3/Bbox_3_Triangle_3.h @@ -1,4 +1,10 @@ -// Copyright (c) 2010 GeometryFactory (France). +// Copyright (c) 1997-2021 +// Utrecht University (The Netherlands), +// ETH Zurich (Switzerland), +// INRIA Sophia-Antipolis (France), +// Max-Planck-Institute Saarbruecken (Germany), +// and Tel-Aviv University (Israel). +// GeometryFactory (France) // All rights reserved. // // This file is part of CGAL (www.cgal.org) @@ -23,31 +29,36 @@ namespace CGAL { template -bool do_intersect(const CGAL::Bbox_3& a, - const Triangle_3& b) { - return K().do_intersect_3_object()(a, b); +bool do_intersect(const CGAL::Bbox_3& box, + const Triangle_3& tr) +{ + return K().do_intersect_3_object()(box, tr); } template -bool do_intersect(const Triangle_3& a, - const CGAL::Bbox_3& b) { - return K().do_intersect_3_object()(a, b); +bool do_intersect(const Triangle_3& tr, + const CGAL::Bbox_3& box) +{ + return K().do_intersect_3_object()(tr, box); } template typename Intersection_traits::result_type intersection(const CGAL::Bbox_3& box, - const Triangle_3& tr) { + const Triangle_3& tr) +{ + // @fixme illegal for non-CGAL kernels typename K::Iso_cuboid_3 cub(box.xmin(), box.ymin(), box.zmin(), - box.xmax(), box.ymax(), box.zmax()); + box.xmax(), box.ymax(), box.zmax()); return typename K::Intersect_3()(cub, tr); } template typename Intersection_traits::result_type -intersection(const Triangle_3& a, - const CGAL::Bbox_3& b) { - return intersection(b,a); +intersection(const Triangle_3& tr, + const CGAL::Bbox_3& box) +{ + return intersection(box, tr); } } // namespace CGAL diff --git a/Intersections_3/include/CGAL/Intersections_3/Iso_cuboid_3_Iso_cuboid_3.h b/Intersections_3/include/CGAL/Intersections_3/Iso_cuboid_3_Iso_cuboid_3.h index 03bf7032646..7fb4a74ee8f 100644 --- a/Intersections_3/include/CGAL/Intersections_3/Iso_cuboid_3_Iso_cuboid_3.h +++ b/Intersections_3/include/CGAL/Intersections_3/Iso_cuboid_3_Iso_cuboid_3.h @@ -1,4 +1,10 @@ -// Copyright (c) 2010 GeometryFactory (France). +// Copyright (c) 1997-2021 +// Utrecht University (The Netherlands), +// ETH Zurich (Switzerland), +// INRIA Sophia-Antipolis (France), +// Max-Planck-Institute Saarbruecken (Germany), +// and Tel-Aviv University (Israel). +// GeometryFactory (France) // All rights reserved. // // This file is part of CGAL (www.cgal.org) @@ -14,13 +20,17 @@ #ifndef CGAL_INTERSECTIONS_3_ISO_CUBOID_3_ISO_CUBOID_3_H #define CGAL_INTERSECTIONS_3_ISO_CUBOID_3_ISO_CUBOID_3_H +#include +#include +#include + #include -#include - namespace CGAL { -CGAL_INTERSECTION_FUNCTION_SELF(Iso_cuboid_3, 3) + CGAL_DO_INTERSECT_FUNCTION_SELF(Iso_cuboid_3, 3) -} +CGAL_INTERSECTION_FUNCTION_SELF(Iso_cuboid_3, 3) + +} // namespace CGAL #endif // CGAL_INTERSECTIONS_3_ISO_CUBOID_3_ISO_CUBOID_3_H diff --git a/Intersections_3/include/CGAL/Intersections_3/Iso_cuboid_3_Line_3.h b/Intersections_3/include/CGAL/Intersections_3/Iso_cuboid_3_Line_3.h index 0c88cdca7af..41f7a1489fb 100644 --- a/Intersections_3/include/CGAL/Intersections_3/Iso_cuboid_3_Line_3.h +++ b/Intersections_3/include/CGAL/Intersections_3/Iso_cuboid_3_Line_3.h @@ -1,4 +1,10 @@ -// Copyright (c) 2010 GeometryFactory (France). +// Copyright (c) 1997-2021 +// Utrecht University (The Netherlands), +// ETH Zurich (Switzerland), +// INRIA Sophia-Antipolis (France), +// Max-Planck-Institute Saarbruecken (Germany), +// and Tel-Aviv University (Israel). +// GeometryFactory (France) // All rights reserved. // // This file is part of CGAL (www.cgal.org) @@ -14,13 +20,18 @@ #ifndef CGAL_INTERSECTIONS_3_ISO_CUBOID_3_LINE_3_H #define CGAL_INTERSECTIONS_3_ISO_CUBOID_3_LINE_3_H -#include +#include +#include +#include + #include #include namespace CGAL { - CGAL_DO_INTERSECT_FUNCTION(Iso_cuboid_3,Line_3, 3) - CGAL_INTERSECTION_FUNCTION(Line_3, Iso_cuboid_3, 3) -} + +CGAL_DO_INTERSECT_FUNCTION(Iso_cuboid_3, Line_3, 3) +CGAL_INTERSECTION_FUNCTION(Iso_cuboid_3, Line_3, 3) + +} // namespace CGAL #endif // CGAL_INTERSECTIONS_3_BBOX_3_LINE_3_H diff --git a/Intersections_3/include/CGAL/Intersections_3/Iso_cuboid_3_Plane_3.h b/Intersections_3/include/CGAL/Intersections_3/Iso_cuboid_3_Plane_3.h index ceff9a4d83c..f29e40aaffe 100644 --- a/Intersections_3/include/CGAL/Intersections_3/Iso_cuboid_3_Plane_3.h +++ b/Intersections_3/include/CGAL/Intersections_3/Iso_cuboid_3_Plane_3.h @@ -1,4 +1,10 @@ -// Copyright (c) 2010 GeometryFactory (France). +// Copyright (c) 1997-2021 +// Utrecht University (The Netherlands), +// ETH Zurich (Switzerland), +// INRIA Sophia-Antipolis (France), +// Max-Planck-Institute Saarbruecken (Germany), +// and Tel-Aviv University (Israel). +// GeometryFactory (France) // All rights reserved. // // This file is part of CGAL (www.cgal.org) @@ -14,15 +20,18 @@ #ifndef CGAL_INTERSECTIONS_3_ISO_CUBOID_3_PLANE_3_H #define CGAL_INTERSECTIONS_3_ISO_CUBOID_3_PLANE_3_H -#include -#include -#include +#include +#include #include +#include +#include namespace CGAL { - CGAL_DO_INTERSECT_FUNCTION(Iso_cuboid_3, Plane_3, 3) - CGAL_INTERSECTION_FUNCTION(Iso_cuboid_3, Plane_3, 3) -} + +CGAL_DO_INTERSECT_FUNCTION(Iso_cuboid_3, Plane_3, 3) +CGAL_INTERSECTION_FUNCTION(Iso_cuboid_3, Plane_3, 3) + +} // namespace CGAL #endif // CGAL_INTERSECTIONS_3_ISO_CUBOID_3_PLANE_3_H diff --git a/Intersections_3/include/CGAL/Intersections_3/Iso_cuboid_3_Point_3.h b/Intersections_3/include/CGAL/Intersections_3/Iso_cuboid_3_Point_3.h index 39ad5de441b..02623d7d9d2 100644 --- a/Intersections_3/include/CGAL/Intersections_3/Iso_cuboid_3_Point_3.h +++ b/Intersections_3/include/CGAL/Intersections_3/Iso_cuboid_3_Point_3.h @@ -1,4 +1,10 @@ -// Copyright (c) 2018 INRIA Sophia-Antipolis (France). +// Copyright (c) 1997-2021 +// Utrecht University (The Netherlands), +// ETH Zurich (Switzerland), +// INRIA Sophia-Antipolis (France), +// Max-Planck-Institute Saarbruecken (Germany), +// and Tel-Aviv University (Israel). +// GeometryFactory (France) // All rights reserved. // // This file is part of CGAL (www.cgal.org) @@ -13,62 +19,18 @@ #ifndef CGAL_INTERSECTIONS_3_ISO_CUBOID_3_POINT_3_H #define CGAL_INTERSECTIONS_3_ISO_CUBOID_3_POINT_3_H +#include +#include +#include + #include #include -#include namespace CGAL { -namespace Intersections { -namespace internal { -template -inline -bool -do_intersect(const typename K::Point_3 &pt, - const typename K::Iso_cuboid_3 &iso, - const K&) -{ - return !iso.has_on_unbounded_side(pt); -} +CGAL_DO_INTERSECT_FUNCTION(Iso_cuboid_3, Point_3, 3) +CGAL_INTERSECTION_FUNCTION(Iso_cuboid_3, Point_3, 3) -template -inline -bool -do_intersect(const typename K::Iso_cuboid_3 &iso, - const typename K::Point_3 &pt, - const K&) -{ - return !iso.has_on_unbounded_side(pt); -} - -template -typename CGAL::Intersection_traits -::result_type -intersection(const typename K::Point_3 &pt, - const typename K::Iso_cuboid_3 &iso, - const K& k) -{ - if (internal::do_intersect(pt,iso,k)) - return intersection_return(pt); - return intersection_return(); -} - -template -typename CGAL::Intersection_traits -::result_type -intersection(const typename K::Iso_cuboid_3 &iso, - const typename K::Point_3 &pt, - const K& k) -{ - return internal::intersection(pt, iso, k); -} - -} // namespace internal -} // namespace Intersections - -CGAL_INTERSECTION_FUNCTION(Point_3, Iso_cuboid_3, 3) -CGAL_DO_INTERSECT_FUNCTION(Point_3, Iso_cuboid_3, 3) - -} //namespace CGAL +} // namespace CGAL #endif // CGAL_INTERSECTIONS_3_ISO_CUBOID_3_POINT_3_H diff --git a/Intersections_3/include/CGAL/Intersections_3/Iso_cuboid_3_Ray_3.h b/Intersections_3/include/CGAL/Intersections_3/Iso_cuboid_3_Ray_3.h index edbe27c21fa..8b49b575110 100644 --- a/Intersections_3/include/CGAL/Intersections_3/Iso_cuboid_3_Ray_3.h +++ b/Intersections_3/include/CGAL/Intersections_3/Iso_cuboid_3_Ray_3.h @@ -1,4 +1,10 @@ -// Copyright (c) 2010 GeometryFactory (France). +// Copyright (c) 1997-2021 +// Utrecht University (The Netherlands), +// ETH Zurich (Switzerland), +// INRIA Sophia-Antipolis (France), +// Max-Planck-Institute Saarbruecken (Germany), +// and Tel-Aviv University (Israel). +// GeometryFactory (France) // All rights reserved. // // This file is part of CGAL (www.cgal.org) @@ -14,15 +20,18 @@ #ifndef CGAL_INTERSECTIONS_3_ISO_CUBOID_3_RAY_3_H #define CGAL_INTERSECTIONS_3_ISO_CUBOID_3_RAY_3_H +#include +#include +#include + #include #include -#include -#include - namespace CGAL { - CGAL_DO_INTERSECT_FUNCTION(Iso_cuboid_3,Ray_3, 3) - CGAL_INTERSECTION_FUNCTION(Ray_3, Iso_cuboid_3, 3) -} + +CGAL_DO_INTERSECT_FUNCTION(Iso_cuboid_3, Ray_3, 3) +CGAL_INTERSECTION_FUNCTION(Iso_cuboid_3, Ray_3, 3) + +} // namespace CGAL #endif // CGAL_INTERSECTIONS_3_ISSO_CUBOID_3_RAY_3_H diff --git a/Intersections_3/include/CGAL/Intersections_3/Iso_cuboid_3_Segment_3.h b/Intersections_3/include/CGAL/Intersections_3/Iso_cuboid_3_Segment_3.h index 77f81e769b3..c81b7f50f3d 100644 --- a/Intersections_3/include/CGAL/Intersections_3/Iso_cuboid_3_Segment_3.h +++ b/Intersections_3/include/CGAL/Intersections_3/Iso_cuboid_3_Segment_3.h @@ -1,4 +1,10 @@ -// Copyright (c) 2010 GeometryFactory (France). +// Copyright (c) 1997-2021 +// Utrecht University (The Netherlands), +// ETH Zurich (Switzerland), +// INRIA Sophia-Antipolis (France), +// Max-Planck-Institute Saarbruecken (Germany), +// and Tel-Aviv University (Israel). +// GeometryFactory (France) // All rights reserved. // // This file is part of CGAL (www.cgal.org) @@ -14,15 +20,18 @@ #ifndef CGAL_INTERSECTIONS_3_ISO_CUBOID_3_SEGMENT_3_H #define CGAL_INTERSECTIONS_3_ISO_CUBOID_3_SEGMENT_3_H +#include +#include +#include + #include #include -#include -#include - namespace CGAL { - CGAL_DO_INTERSECT_FUNCTION(Iso_cuboid_3,Segment_3, 3) - CGAL_INTERSECTION_FUNCTION(Segment_3, Iso_cuboid_3, 3) -} -#endif // CGAL_INTERSECTIONS_3_BBOX_3_SEGMENT_3_H +CGAL_DO_INTERSECT_FUNCTION(Iso_cuboid_3, Segment_3, 3) +CGAL_INTERSECTION_FUNCTION(Iso_cuboid_3, Segment_3, 3) + +} // namespace CGAL + +#endif // CGAL_INTERSECTIONS_3_ISO_CUBOID_3_SEGMENT_3_H diff --git a/Intersections_3/include/CGAL/Intersections_3/Iso_cuboid_3_Sphere_3.h b/Intersections_3/include/CGAL/Intersections_3/Iso_cuboid_3_Sphere_3.h index 62cddeb9657..0c212a596a6 100644 --- a/Intersections_3/include/CGAL/Intersections_3/Iso_cuboid_3_Sphere_3.h +++ b/Intersections_3/include/CGAL/Intersections_3/Iso_cuboid_3_Sphere_3.h @@ -1,4 +1,10 @@ -// Copyright (c) 2010 GeometryFactory (France). +// Copyright (c) 1997-2021 +// Utrecht University (The Netherlands), +// ETH Zurich (Switzerland), +// INRIA Sophia-Antipolis (France), +// Max-Planck-Institute Saarbruecken (Germany), +// and Tel-Aviv University (Israel). +// GeometryFactory (France) // All rights reserved. // // This file is part of CGAL (www.cgal.org) @@ -14,13 +20,16 @@ #ifndef CGAL_INTERSECTIONS_3_ISO_CUBOID_3_SPHERE_3_H #define CGAL_INTERSECTIONS_3_ISO_CUBOID_3_SPHERE_3_H +#include +#include + #include #include -#include - namespace CGAL { - CGAL_DO_INTERSECT_FUNCTION(Iso_cuboid_3, Sphere_3, 3) -} + +CGAL_DO_INTERSECT_FUNCTION(Iso_cuboid_3, Sphere_3, 3) + +} // namespace CGAL #endif // CGAL_INTERSECTIONS_3_ISO_CUBOID_3_SPHERE_3_H diff --git a/Intersections_3/include/CGAL/Intersections_3/Iso_cuboid_3_Tetrahedron_3.h b/Intersections_3/include/CGAL/Intersections_3/Iso_cuboid_3_Tetrahedron_3.h index 0775542fffe..61b3d416e1a 100644 --- a/Intersections_3/include/CGAL/Intersections_3/Iso_cuboid_3_Tetrahedron_3.h +++ b/Intersections_3/include/CGAL/Intersections_3/Iso_cuboid_3_Tetrahedron_3.h @@ -1,4 +1,10 @@ -// Copyright (c) 2010 GeometryFactory (France). +// Copyright (c) 1997-2021 +// Utrecht University (The Netherlands), +// ETH Zurich (Switzerland), +// INRIA Sophia-Antipolis (France), +// Max-Planck-Institute Saarbruecken (Germany), +// and Tel-Aviv University (Israel). +// GeometryFactory (France) // All rights reserved. // // This file is part of CGAL (www.cgal.org) @@ -14,13 +20,16 @@ #ifndef CGAL_INTERSECTIONS_3_ISO_CUBOID_3_TETRAHEDRON_3_H #define CGAL_INTERSECTIONS_3_ISO_CUBOID_3_TETRAHEDRON_3_H +#include +#include + #include #include -#include - namespace CGAL { - CGAL_DO_INTERSECT_FUNCTION(Iso_cuboid_3, Tetrahedron_3, 3) -} + +CGAL_DO_INTERSECT_FUNCTION(Iso_cuboid_3, Tetrahedron_3, 3) + +} // namespace CGAL #endif // CGAL_INTERSECTIONS_3_ISO_CUBOID_3_TETRAHEDRON_3_H diff --git a/Intersections_3/include/CGAL/Intersections_3/Iso_cuboid_3_Triangle_3.h b/Intersections_3/include/CGAL/Intersections_3/Iso_cuboid_3_Triangle_3.h index af6ae4e0dbb..b6d7c174b9f 100644 --- a/Intersections_3/include/CGAL/Intersections_3/Iso_cuboid_3_Triangle_3.h +++ b/Intersections_3/include/CGAL/Intersections_3/Iso_cuboid_3_Triangle_3.h @@ -1,4 +1,10 @@ -// Copyright (c) 2010 GeometryFactory (France). +// Copyright (c) 1997-2021 +// Utrecht University (The Netherlands), +// ETH Zurich (Switzerland), +// INRIA Sophia-Antipolis (France), +// Max-Planck-Institute Saarbruecken (Germany), +// and Tel-Aviv University (Israel). +// GeometryFactory (France) // All rights reserved. // // This file is part of CGAL (www.cgal.org) @@ -14,15 +20,18 @@ #ifndef CGAL_INTERSECTIONS_3_ISO_CUBOID_3_TRIANGLE_3_H #define CGAL_INTERSECTIONS_3_ISO_CUBOID_3_TRIANGLE_3_H -#include -#include - +#include #include #include +#include +#include + namespace CGAL { - CGAL_DO_INTERSECT_FUNCTION(Iso_cuboid_3, Triangle_3, 3) - CGAL_INTERSECTION_FUNCTION(Iso_cuboid_3, Triangle_3, 3) -} + +CGAL_DO_INTERSECT_FUNCTION(Iso_cuboid_3, Triangle_3, 3) +CGAL_INTERSECTION_FUNCTION(Iso_cuboid_3, Triangle_3, 3) + +} // namespace CGAL #endif // CGAL_INTERSECTIONS_3_BBOX_3_TRIANGLE_3_H diff --git a/Intersections_3/include/CGAL/Intersections_3/Line_3_Line_3.h b/Intersections_3/include/CGAL/Intersections_3/Line_3_Line_3.h index 350ac31118d..34607c3cac4 100644 --- a/Intersections_3/include/CGAL/Intersections_3/Line_3_Line_3.h +++ b/Intersections_3/include/CGAL/Intersections_3/Line_3_Line_3.h @@ -1,4 +1,10 @@ -// Copyright (c) 2010 GeometryFactory (France). +// Copyright (c) 1997-2021 +// Utrecht University (The Netherlands), +// ETH Zurich (Switzerland), +// INRIA Sophia-Antipolis (France), +// Max-Planck-Institute Saarbruecken (Germany), +// and Tel-Aviv University (Israel). +// GeometryFactory (France) // All rights reserved. // // This file is part of CGAL (www.cgal.org) @@ -8,19 +14,23 @@ // SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-Commercial // // -// Author(s) : Sebastien Loriot +// Author(s) : Pedro Machado Manhaes de Castro // #ifndef CGAL_INTERSECTIONS_3_LINE_3_LINE_3_H #define CGAL_INTERSECTIONS_3_LINE_3_LINE_3_H +#include +#include +#include + #include -#include - namespace CGAL { + CGAL_INTERSECTION_FUNCTION_SELF(Line_3, 3) CGAL_DO_INTERSECT_FUNCTION_SELF(Line_3, 3) -} + +} // namespace CGAL #endif // CGAL_INTERSECTIONS_3_LINE_3_LINE_3_H diff --git a/Intersections_3/include/CGAL/Intersections_3/Line_3_Plane_3.h b/Intersections_3/include/CGAL/Intersections_3/Line_3_Plane_3.h index 49f64fa5fca..ec3806b41f7 100644 --- a/Intersections_3/include/CGAL/Intersections_3/Line_3_Plane_3.h +++ b/Intersections_3/include/CGAL/Intersections_3/Line_3_Plane_3.h @@ -1,4 +1,10 @@ -// Copyright (c) 2010 GeometryFactory (France). +// Copyright (c) 1997-2021 +// Utrecht University (The Netherlands), +// ETH Zurich (Switzerland), +// INRIA Sophia-Antipolis (France), +// Max-Planck-Institute Saarbruecken (Germany), +// and Tel-Aviv University (Israel). +// GeometryFactory (France) // All rights reserved. // // This file is part of CGAL (www.cgal.org) @@ -14,30 +20,38 @@ #ifndef CGAL_INTERSECTIONS_3_LINE_PLANE_3_H #define CGAL_INTERSECTIONS_3_LINE_PLANE_3_H +#include +#include +#include + #include #include -#include +#include namespace CGAL { -CGAL_INTERSECTION_FUNCTION(Plane_3, Line_3, 3) -CGAL_DO_INTERSECT_FUNCTION(Plane_3, Line_3, 3) -template < class K > +CGAL_DO_INTERSECT_FUNCTION(Line_3, Plane_3, 3) +CGAL_INTERSECTION_FUNCTION(Line_3, Plane_3, 3) + +template inline boost::optional -intersection_point_for_polyhedral_envelope(const Plane_3& plane, const Line_3& line) +intersection_point_for_polyhedral_envelope(const Plane_3& plane, + const Line_3& line) { return K().intersect_point_3_for_polyhedral_envelope_object()(plane, line); } - template < class K > +template inline boost::optional - intersection_point_for_polyhedral_envelope(const Line_3& line, const Plane_3& plane) +intersection_point_for_polyhedral_envelope(const Line_3& line, + const Plane_3& plane) { return K().intersect_point_3_for_polyhedral_envelope_object()(plane, line); } -} + +} // namespace CGAL #endif // CGAL_INTERSECTIONS_3_LINE_PLANE_3_H diff --git a/Intersections_3/include/CGAL/Intersections_3/Line_3_Point_3.h b/Intersections_3/include/CGAL/Intersections_3/Line_3_Point_3.h index abbfd75146f..e1f3e81b3af 100644 --- a/Intersections_3/include/CGAL/Intersections_3/Line_3_Point_3.h +++ b/Intersections_3/include/CGAL/Intersections_3/Line_3_Point_3.h @@ -1,4 +1,10 @@ -// Copyright (c) 2018 INRIA Sophia-Antipolis (France). +// Copyright (c) 1997-2021 +// Utrecht University (The Netherlands), +// ETH Zurich (Switzerland), +// INRIA Sophia-Antipolis (France), +// Max-Planck-Institute Saarbruecken (Germany), +// and Tel-Aviv University (Israel). +// GeometryFactory (France) // All rights reserved. // // This file is part of CGAL (www.cgal.org) @@ -13,62 +19,18 @@ #ifndef CGAL_INTERSECTIONS_3_LINE_3_POINT_3_H #define CGAL_INTERSECTIONS_3_LINE_3_POINT_3_H +#include +#include +#include + #include #include -#include namespace CGAL { -namespace Intersections { +CGAL_DO_INTERSECT_FUNCTION(Line_3, Point_3, 3) +CGAL_INTERSECTION_FUNCTION(Line_3, Point_3, 3) -namespace internal { - -template -inline bool -do_intersect(const typename K::Point_3 &pt, - const typename K::Line_3 &line, - const K& k) -{ - return k.has_on_3_object()(line,pt); -} - -template -inline bool -do_intersect(const typename K::Line_3 &line, - const typename K::Point_3 &pt, - const K& k) -{ - return k.has_on_3_object()(line, pt); -} - -template -typename CGAL::Intersection_traits -::result_type -intersection(const typename K::Point_3 &pt, - const typename K::Line_3 &line, - const K& k) -{ - if (do_intersect(pt,line,k)) - return intersection_return(pt); - return intersection_return(); -} - -template -typename CGAL::Intersection_traits -::result_type -intersection(const typename K::Line_3 &line, - const typename K::Point_3 &pt, - const K& k) -{ - return internal::intersection(pt, line, k); -} - -} // namespace internal -} // namespace Intersections - -CGAL_INTERSECTION_FUNCTION(Point_3, Line_3, 3) -CGAL_DO_INTERSECT_FUNCTION(Point_3, Line_3, 3) - -} //namespace CGAL +} // namespace CGAL #endif // CGAL_INTERSECTIONS_3_LINE_3_POINT_3_H diff --git a/Intersections_3/include/CGAL/Intersections_3/Line_3_Ray_3.h b/Intersections_3/include/CGAL/Intersections_3/Line_3_Ray_3.h index 2606784edf7..c639825a718 100644 --- a/Intersections_3/include/CGAL/Intersections_3/Line_3_Ray_3.h +++ b/Intersections_3/include/CGAL/Intersections_3/Line_3_Ray_3.h @@ -1,4 +1,10 @@ -// Copyright (c) 2010 GeometryFactory (France). +// Copyright (c) 1997-2021 +// Utrecht University (The Netherlands), +// ETH Zurich (Switzerland), +// INRIA Sophia-Antipolis (France), +// Max-Planck-Institute Saarbruecken (Germany), +// and Tel-Aviv University (Israel). +// GeometryFactory (France) // All rights reserved. // // This file is part of CGAL (www.cgal.org) @@ -14,14 +20,18 @@ #ifndef CGAL_INTERSECTIONS_3_LINE_3_RAY_3_H #define CGAL_INTERSECTIONS_3_LINE_3_RAY_3_H +#include +#include +#include + #include #include -#include - namespace CGAL { -CGAL_INTERSECTION_FUNCTION(Ray_3, Line_3, 3) -CGAL_DO_INTERSECT_FUNCTION(Ray_3, Line_3, 3) -} + +CGAL_DO_INTERSECT_FUNCTION(Line_3, Ray_3, 3) +CGAL_INTERSECTION_FUNCTION(Line_3, Ray_3, 3) + +} // namespace CGAL #endif // CGAL_INTERSECTIONS_3_LINE_3_RAY_3_H diff --git a/Intersections_3/include/CGAL/Intersections_3/Line_3_Segment_3.h b/Intersections_3/include/CGAL/Intersections_3/Line_3_Segment_3.h index 184dbca348a..f4954f361e6 100644 --- a/Intersections_3/include/CGAL/Intersections_3/Line_3_Segment_3.h +++ b/Intersections_3/include/CGAL/Intersections_3/Line_3_Segment_3.h @@ -1,4 +1,10 @@ -// Copyright (c) 2010 GeometryFactory (France). +// Copyright (c) 1997-2021 +// Utrecht University (The Netherlands), +// ETH Zurich (Switzerland), +// INRIA Sophia-Antipolis (France), +// Max-Planck-Institute Saarbruecken (Germany), +// and Tel-Aviv University (Israel). +// GeometryFactory (France) // All rights reserved. // // This file is part of CGAL (www.cgal.org) @@ -14,14 +20,18 @@ #ifndef CGAL_INTERSECTIONS_3_LINE_3_SEGMENT_3_H #define CGAL_INTERSECTIONS_3_LINE_3_SEGMENT_3_H +#include +#include +#include + #include #include -#include - namespace CGAL { - CGAL_INTERSECTION_FUNCTION(Line_3, Segment_3, 3) - CGAL_DO_INTERSECT_FUNCTION(Line_3, Segment_3, 3) -} + +CGAL_DO_INTERSECT_FUNCTION(Line_3, Segment_3, 3) +CGAL_INTERSECTION_FUNCTION(Line_3, Segment_3, 3) + +} // namespace CGAL #endif // CGAL_INTERSECTIONS_3_LINE_3_SEGMENT_3_H diff --git a/Intersections_3/include/CGAL/Intersections_3/Line_3_Sphere_3.h b/Intersections_3/include/CGAL/Intersections_3/Line_3_Sphere_3.h index b77fc673356..f9dc05f52f1 100644 --- a/Intersections_3/include/CGAL/Intersections_3/Line_3_Sphere_3.h +++ b/Intersections_3/include/CGAL/Intersections_3/Line_3_Sphere_3.h @@ -1,4 +1,10 @@ -// Copyright (c) 2010 GeometryFactory (France). +// Copyright (c) 1997-2021 +// Utrecht University (The Netherlands), +// ETH Zurich (Switzerland), +// INRIA Sophia-Antipolis (France), +// Max-Planck-Institute Saarbruecken (Germany), +// and Tel-Aviv University (Israel). +// GeometryFactory (France) // All rights reserved. // // This file is part of CGAL (www.cgal.org) @@ -14,13 +20,16 @@ #ifndef CGAL_INTERSECTIONS_3_LINE_3_SPHERE_3_H #define CGAL_INTERSECTIONS_3_LINE_3_SPHERE_3_H +#include +#include + #include #include -#include - namespace CGAL { - CGAL_DO_INTERSECT_FUNCTION(Line_3, Sphere_3, 3) + +CGAL_DO_INTERSECT_FUNCTION(Line_3, Sphere_3, 3) + } #endif // CGAL_INTERSECTIONS_3_LINE_3_SPHERE_3_H diff --git a/Intersections_3/include/CGAL/Intersections_3/Line_3_Tetrahedron_3.h b/Intersections_3/include/CGAL/Intersections_3/Line_3_Tetrahedron_3.h index 6f3af29ab63..53bfd16ce09 100644 --- a/Intersections_3/include/CGAL/Intersections_3/Line_3_Tetrahedron_3.h +++ b/Intersections_3/include/CGAL/Intersections_3/Line_3_Tetrahedron_3.h @@ -1,4 +1,10 @@ -// Copyright (c) 2010 GeometryFactory (France). +// Copyright (c) 1997-2021 +// Utrecht University (The Netherlands), +// ETH Zurich (Switzerland), +// INRIA Sophia-Antipolis (France), +// Max-Planck-Institute Saarbruecken (Germany), +// and Tel-Aviv University (Israel). +// GeometryFactory (France) // All rights reserved. // // This file is part of CGAL (www.cgal.org) @@ -14,27 +20,18 @@ #ifndef CGAL_INTERSECTIONS_3_LINE_3_TETRAHEDRON_3_H #define CGAL_INTERSECTIONS_3_LINE_3_TETRAHEDRON_3_H +#include +#include +#include + #include #include -#include - namespace CGAL { - CGAL_DO_INTERSECT_FUNCTION(Line_3, Tetrahedron_3, 3) - template - typename Intersection_traits::result_type - intersection(const Line_3& line, - const Tetrahedron_3& tet) { - return K().intersect_3_object()(line, tet); - } +CGAL_DO_INTERSECT_FUNCTION(Line_3, Tetrahedron_3, 3) +CGAL_INTERSECTION_FUNCTION(Line_3, Tetrahedron_3, 3) - template - typename Intersection_traits::result_type - intersection(const Tetrahedron_3& tet, - const Line_3& line) { - return K().intersect_3_object()(tet, line); - } -} +} // namespace CGAL #endif // CGAL_INTERSECTIONS_3_LINE_3_TETRAHEDRON_3_H diff --git a/Intersections_3/include/CGAL/Intersections_3/Line_3_Triangle_3.h b/Intersections_3/include/CGAL/Intersections_3/Line_3_Triangle_3.h index faa64c03758..e2b42c35129 100644 --- a/Intersections_3/include/CGAL/Intersections_3/Line_3_Triangle_3.h +++ b/Intersections_3/include/CGAL/Intersections_3/Line_3_Triangle_3.h @@ -1,4 +1,10 @@ -// Copyright (c) 2010 GeometryFactory (France). +// Copyright (c) 1997-2021 +// Utrecht University (The Netherlands), +// ETH Zurich (Switzerland), +// INRIA Sophia-Antipolis (France), +// Max-Planck-Institute Saarbruecken (Germany), +// and Tel-Aviv University (Israel). +// GeometryFactory (France) // All rights reserved. // // This file is part of CGAL (www.cgal.org) @@ -14,15 +20,18 @@ #ifndef CGAL_INTERSECTIONS_3_LINE_3_TRIANGLE_3_H #define CGAL_INTERSECTIONS_3_LINE_3_TRIANGLE_3_H +#include +#include +#include + #include #include -#include -#include - namespace CGAL { -CGAL_INTERSECTION_FUNCTION(Triangle_3, Line_3, 3) -CGAL_DO_INTERSECT_FUNCTION(Triangle_3, Line_3, 3) -} + +CGAL_DO_INTERSECT_FUNCTION(Line_3, Triangle_3, 3) +CGAL_INTERSECTION_FUNCTION(Line_3, Triangle_3, 3) + +} // namespace CGAL #endif // CGAL_INTERSECTIONS_3_LINE_3_TRIANGLE_3_H diff --git a/Intersections_3/include/CGAL/Intersections_3/Plane_3_Plane_3.h b/Intersections_3/include/CGAL/Intersections_3/Plane_3_Plane_3.h index 7f82f23b740..bbe2ba4b876 100644 --- a/Intersections_3/include/CGAL/Intersections_3/Plane_3_Plane_3.h +++ b/Intersections_3/include/CGAL/Intersections_3/Plane_3_Plane_3.h @@ -1,4 +1,10 @@ -// Copyright (c) 2010 GeometryFactory (France). +// Copyright (c) 1997-2021 +// Utrecht University (The Netherlands), +// ETH Zurich (Switzerland), +// INRIA Sophia-Antipolis (France), +// Max-Planck-Institute Saarbruecken (Germany), +// and Tel-Aviv University (Israel). +// GeometryFactory (France) // All rights reserved. // // This file is part of CGAL (www.cgal.org) @@ -14,23 +20,17 @@ #ifndef CGAL_INTERSECTIONS_3_PLANE_3_PLANE_3_H #define CGAL_INTERSECTIONS_3_PLANE_3_PLANE_3_H +#include +#include +#include + #include -#include - namespace CGAL { -CGAL_INTERSECTION_FUNCTION_SELF(Plane_3, 3) + CGAL_DO_INTERSECT_FUNCTION_SELF(Plane_3, 3) +CGAL_INTERSECTION_FUNCTION_SELF(Plane_3, 3) - -template < class K > -inline -boost::optional -intersection_point_for_polyhedral_envelope(const Plane_3& p0, const Plane_3& p1, const Plane_3& p2) -{ - return K().intersect_point_3_for_polyhedral_envelope_object()(p0, p1, p2); -} - -} +} // namespace CGAL #endif // CGAL_INTERSECTIONS_3_PLANE_3_PLANE_3_H diff --git a/Intersections_3/include/CGAL/Intersections_3/Plane_3_Plane_3_Plane_3.h b/Intersections_3/include/CGAL/Intersections_3/Plane_3_Plane_3_Plane_3.h new file mode 100644 index 00000000000..236fd2a9f50 --- /dev/null +++ b/Intersections_3/include/CGAL/Intersections_3/Plane_3_Plane_3_Plane_3.h @@ -0,0 +1,64 @@ +// Copyright (c) 1997-2021 +// Utrecht University (The Netherlands), +// ETH Zurich (Switzerland), +// INRIA Sophia-Antipolis (France), +// Max-Planck-Institute Saarbruecken (Germany), +// and Tel-Aviv University (Israel). +// GeometryFactory (France) +// All rights reserved. +// +// This file is part of CGAL (www.cgal.org) +// +// $URL$ +// $Id$ +// SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-Commercial +// +// +// Author(s) : Geert-Jan Giezeman, +// Andreas Fabri +// + +#ifndef CGAL_INTERSECTIONS_3_PLANE_3_PLANE_3_PLANE_3_H +#define CGAL_INTERSECTIONS_3_PLANE_3_PLANE_3_PLANE_3_H + +#include +#include +#include + +#include + +namespace CGAL { + +template +inline bool +do_intersect(const Plane_3& plane1, + const Plane_3& plane2, + const Plane_3& plane3) +{ + return K().do_intersect_3_object()(plane1, plane2, plane3); +} + +// the special plane_3 function +template +inline +decltype(auto) +intersection(const Plane_3& plane1, + const Plane_3& plane2, + const Plane_3& plane3) +{ + return K().intersect_3_object()(plane1, plane2, plane3); +} + +template +inline +boost::optional +intersection_point_for_polyhedral_envelope(const Plane_3& p0, + const Plane_3& p1, + const Plane_3& p2) +{ + return K().intersect_point_3_for_polyhedral_envelope_object()(p0, p1, p2); +} + +} // namespace CGAL + +#endif // CGAL_INTERSECTIONS_3_PLANE_3_PLANE_3_PLANE_3_H diff --git a/Intersections_3/include/CGAL/Intersections_3/Plane_3_Point_3.h b/Intersections_3/include/CGAL/Intersections_3/Plane_3_Point_3.h index 3f862cba645..1b915cf88e4 100644 --- a/Intersections_3/include/CGAL/Intersections_3/Plane_3_Point_3.h +++ b/Intersections_3/include/CGAL/Intersections_3/Plane_3_Point_3.h @@ -1,4 +1,10 @@ -// Copyright (c) 2018 INRIA Sophia-Antipolis (France). +// Copyright (c) 1997-2021 +// Utrecht University (The Netherlands), +// ETH Zurich (Switzerland), +// INRIA Sophia-Antipolis (France), +// Max-Planck-Institute Saarbruecken (Germany), +// and Tel-Aviv University (Israel). +// GeometryFactory (France) // All rights reserved. // // This file is part of CGAL (www.cgal.org) @@ -10,64 +16,21 @@ // // Author(s) : Maxime Gimeno -#ifndef CGAL_INTERSECTIONS_3_PLANE_3_POINT_3_PLANE_3_H -#define CGAL_INTERSECTIONS_3_PLANE_3_POINT_3_PLANE_3_H +#ifndef CGAL_INTERSECTIONS_3_PLANE_3_POINT_3_H +#define CGAL_INTERSECTIONS_3_PLANE_3_POINT_3_H + +#include +#include +#include #include #include -#include namespace CGAL { -namespace Intersections { +CGAL_DO_INTERSECT_FUNCTION(Plane_3, Point_3, 3) +CGAL_INTERSECTION_FUNCTION(Plane_3, Point_3, 3) -namespace internal { +} // namespace CGAL -template -inline bool -do_intersect(const typename K::Point_3 &pt, - const typename K::Plane_3 &plane, - const K& k) -{ - return k.has_on_3_object()(plane,pt); -} - -template -inline bool -do_intersect(const typename K::Plane_3 &plane, - const typename K::Point_3 &pt, - const K& k) -{ - return k.has_on_3_object()(plane,pt); -} - -template -typename CGAL::Intersection_traits -::result_type -intersection(const typename K::Point_3 &pt, - const typename K::Plane_3 &plane, - const K& k) -{ - if (do_intersect(pt,plane,k)) - return intersection_return(pt); - return intersection_return(); -} - -template -typename CGAL::Intersection_traits -::result_type -intersection(const typename K::Plane_3 &plane, - const typename K::Point_3 &pt, - const K& k) -{ - return internal::intersection(pt, plane,k); -} - -} // namespace internal -} // namespace Intersections - -CGAL_INTERSECTION_FUNCTION(Point_3, Plane_3, 3) -CGAL_DO_INTERSECT_FUNCTION(Point_3, Plane_3, 3) - -} //namespace CGAL -#endif // CGAL_INTERSECTIONS_3_PLANE_3_POINT_3_PLANE_3_H +#endif // CGAL_INTERSECTIONS_3_PLANE_3_POINT_3_H diff --git a/Intersections_3/include/CGAL/Intersections_3/Plane_3_Ray_3.h b/Intersections_3/include/CGAL/Intersections_3/Plane_3_Ray_3.h index 0490c2984cb..3d643a1d2b9 100644 --- a/Intersections_3/include/CGAL/Intersections_3/Plane_3_Ray_3.h +++ b/Intersections_3/include/CGAL/Intersections_3/Plane_3_Ray_3.h @@ -1,4 +1,10 @@ -// Copyright (c) 2010 GeometryFactory (France). +// Copyright (c) 1997-2021 +// Utrecht University (The Netherlands), +// ETH Zurich (Switzerland), +// INRIA Sophia-Antipolis (France), +// Max-Planck-Institute Saarbruecken (Germany), +// and Tel-Aviv University (Israel). +// GeometryFactory (France) // All rights reserved. // // This file is part of CGAL (www.cgal.org) @@ -14,14 +20,18 @@ #ifndef CGAL_INTERSECTIONS_3_PLANE_3_RAY_3_H #define CGAL_INTERSECTIONS_3_PLANE_3_RAY_3_H +#include +#include +#include + #include #include -#include - namespace CGAL { -CGAL_INTERSECTION_FUNCTION(Ray_3, Plane_3, 3) -CGAL_DO_INTERSECT_FUNCTION(Ray_3, Plane_3, 3) -} + +CGAL_DO_INTERSECT_FUNCTION(Plane_3, Ray_3, 3) +CGAL_INTERSECTION_FUNCTION(Plane_3, Ray_3, 3) + +} // namespace CGAL #endif // CGAL_INTERSECTIONS_3_PLANE_3_RAY_3_H diff --git a/Intersections_3/include/CGAL/Intersections_3/Plane_3_Segment_3.h b/Intersections_3/include/CGAL/Intersections_3/Plane_3_Segment_3.h index f33fa57adad..a52fb59a8e5 100644 --- a/Intersections_3/include/CGAL/Intersections_3/Plane_3_Segment_3.h +++ b/Intersections_3/include/CGAL/Intersections_3/Plane_3_Segment_3.h @@ -1,4 +1,10 @@ -// Copyright (c) 2010 GeometryFactory (France). +// Copyright (c) 1997-2021 +// Utrecht University (The Netherlands), +// ETH Zurich (Switzerland), +// INRIA Sophia-Antipolis (France), +// Max-Planck-Institute Saarbruecken (Germany), +// and Tel-Aviv University (Israel). +// GeometryFactory (France) // All rights reserved. // // This file is part of CGAL (www.cgal.org) @@ -14,14 +20,18 @@ #ifndef CGAL_INTERSECTIONS_3_PLANE_3_SEGMENT_3_H #define CGAL_INTERSECTIONS_3_PLANE_3_SEGMENT_3_H +#include +#include +#include + #include #include -#include - namespace CGAL { -CGAL_INTERSECTION_FUNCTION(Segment_3, Plane_3, 3) -CGAL_DO_INTERSECT_FUNCTION(Segment_3, Plane_3, 3) -} + +CGAL_DO_INTERSECT_FUNCTION(Plane_3, Segment_3, 3) +CGAL_INTERSECTION_FUNCTION(Plane_3, Segment_3, 3) + +} // namespace CGAL #endif // CGAL_INTERSECTIONS_3_PLANE_3_SEGMENT_3_H diff --git a/Intersections_3/include/CGAL/Intersections_3/Plane_3_Sphere_3.h b/Intersections_3/include/CGAL/Intersections_3/Plane_3_Sphere_3.h index 910a637aa47..61ce06c27b5 100644 --- a/Intersections_3/include/CGAL/Intersections_3/Plane_3_Sphere_3.h +++ b/Intersections_3/include/CGAL/Intersections_3/Plane_3_Sphere_3.h @@ -1,4 +1,10 @@ -// Copyright (c) 2010 GeometryFactory (France). +// Copyright (c) 1997-2021 +// Utrecht University (The Netherlands), +// ETH Zurich (Switzerland), +// INRIA Sophia-Antipolis (France), +// Max-Planck-Institute Saarbruecken (Germany), +// and Tel-Aviv University (Israel). +// GeometryFactory (France) // All rights reserved. // // This file is part of CGAL (www.cgal.org) @@ -14,14 +20,18 @@ #ifndef CGAL_INTERSECTIONS_3_PLANE_3_SPHERE_3_H #define CGAL_INTERSECTIONS_3_PLANE_3_SPHERE_3_H +#include +#include +#include + #include #include -#include - namespace CGAL { -CGAL_INTERSECTION_FUNCTION(Sphere_3, Plane_3, 3) -CGAL_DO_INTERSECT_FUNCTION(Sphere_3, Plane_3, 3) -} + +CGAL_DO_INTERSECT_FUNCTION(Plane_3, Sphere_3, 3) +CGAL_INTERSECTION_FUNCTION(Plane_3, Sphere_3, 3) + +} // namespace CGAL #endif // CGAL_INTERSECTIONS_3_PLANE_3_SPHERE_3_H diff --git a/Intersections_3/include/CGAL/Intersections_3/Plane_3_Tetrahedron_3.h b/Intersections_3/include/CGAL/Intersections_3/Plane_3_Tetrahedron_3.h index 8b19bf63b8d..f10e826021e 100644 --- a/Intersections_3/include/CGAL/Intersections_3/Plane_3_Tetrahedron_3.h +++ b/Intersections_3/include/CGAL/Intersections_3/Plane_3_Tetrahedron_3.h @@ -1,4 +1,10 @@ -// Copyright (c) 2010 GeometryFactory (France). +// Copyright (c) 1997-2021 +// Utrecht University (The Netherlands), +// ETH Zurich (Switzerland), +// INRIA Sophia-Antipolis (France), +// Max-Planck-Institute Saarbruecken (Germany), +// and Tel-Aviv University (Israel). +// GeometryFactory (France) // All rights reserved. // // This file is part of CGAL (www.cgal.org) @@ -14,15 +20,18 @@ #ifndef CGAL_INTERSECTIONS_3_PLANE_3_TETRAHEDRON_3_H #define CGAL_INTERSECTIONS_3_PLANE_3_TETRAHEDRON_3_H +#include +#include +#include + #include #include -#include -#include - namespace CGAL { - CGAL_DO_INTERSECT_FUNCTION(Tetrahedron_3, Plane_3, 3) - CGAL_INTERSECTION_FUNCTION(Tetrahedron_3, Plane_3, 3) -} + +CGAL_DO_INTERSECT_FUNCTION(Plane_3, Tetrahedron_3, 3) +CGAL_INTERSECTION_FUNCTION(Plane_3, Tetrahedron_3, 3) + +} // namespace CGAL #endif // CGAL_INTERSECTIONS_3_PLANE_3_TETRAHEDRON_3_H diff --git a/Intersections_3/include/CGAL/Intersections_3/Plane_3_Triangle_3.h b/Intersections_3/include/CGAL/Intersections_3/Plane_3_Triangle_3.h index bf347be917f..02d5c9d2876 100644 --- a/Intersections_3/include/CGAL/Intersections_3/Plane_3_Triangle_3.h +++ b/Intersections_3/include/CGAL/Intersections_3/Plane_3_Triangle_3.h @@ -1,4 +1,10 @@ -// Copyright (c) 2010 GeometryFactory (France). +// Copyright (c) 1997-2021 +// Utrecht University (The Netherlands), +// ETH Zurich (Switzerland), +// INRIA Sophia-Antipolis (France), +// Max-Planck-Institute Saarbruecken (Germany), +// and Tel-Aviv University (Israel). +// GeometryFactory (France) // All rights reserved. // // This file is part of CGAL (www.cgal.org) @@ -14,15 +20,18 @@ #ifndef CGAL_INTERSECTIONS_3_PLANE_3_TRIANGLE_3_H #define CGAL_INTERSECTIONS_3_PLANE_3_TRIANGLE_3_H +#include +#include +#include + #include #include -#include -#include - namespace CGAL { -CGAL_INTERSECTION_FUNCTION(Triangle_3, Plane_3, 3) -CGAL_DO_INTERSECT_FUNCTION(Triangle_3, Plane_3, 3) -} + +CGAL_DO_INTERSECT_FUNCTION(Plane_3, Triangle_3, 3) +CGAL_INTERSECTION_FUNCTION(Plane_3, Triangle_3, 3) + +} // namespace CGAL #endif // CGAL_INTERSECTIONS_3_PLANE_3_TRIANGLE_3_H diff --git a/Intersections_3/include/CGAL/Intersections_3/Point_3_Point_3.h b/Intersections_3/include/CGAL/Intersections_3/Point_3_Point_3.h index 172688c1a34..79fd09fd9b8 100644 --- a/Intersections_3/include/CGAL/Intersections_3/Point_3_Point_3.h +++ b/Intersections_3/include/CGAL/Intersections_3/Point_3_Point_3.h @@ -1,4 +1,10 @@ -// Copyright (c) 2018 INRIA Sophia-Antipolis (France). +// Copyright (c) 1997-2021 +// Utrecht University (The Netherlands), +// ETH Zurich (Switzerland), +// INRIA Sophia-Antipolis (France), +// Max-Planck-Institute Saarbruecken (Germany), +// and Tel-Aviv University (Israel). +// GeometryFactory (France) // All rights reserved. // // This file is part of CGAL (www.cgal.org) @@ -13,41 +19,17 @@ #ifndef CGAL_INTERSECTIONS_3_POINT_3_POINT_3_H #define CGAL_INTERSECTIONS_3_POINT_3_POINT_3_H -#include #include +#include +#include + +#include namespace CGAL { -namespace Intersections { - -namespace internal { - -template -inline bool -do_intersect(const typename K::Point_3 &pt1, - const typename K::Point_3 &pt2, - const K&) -{ - return pt1 == pt2; -} - -template -typename CGAL::Intersection_traits -::result_type -intersection(const typename K::Point_3 &pt1, - const typename K::Point_3 &pt2, - const K&) -{ - if (pt1 == pt2) - return intersection_return(pt1); - return intersection_return(); -} - -} // namespace internal -} // namespace Intersections - -CGAL_INTERSECTION_FUNCTION_SELF(Point_3, 3) CGAL_DO_INTERSECT_FUNCTION_SELF(Point_3, 3) -}//nmaespace cgal +CGAL_INTERSECTION_FUNCTION_SELF(Point_3, 3) + +} // namespace CGAL #endif // CGAL_INTERSECTIONS_3_POINT_3_POINT_3_H diff --git a/Intersections_3/include/CGAL/Intersections_3/Point_3_Ray_3.h b/Intersections_3/include/CGAL/Intersections_3/Point_3_Ray_3.h index 7d41e283a89..7915faeea0c 100644 --- a/Intersections_3/include/CGAL/Intersections_3/Point_3_Ray_3.h +++ b/Intersections_3/include/CGAL/Intersections_3/Point_3_Ray_3.h @@ -1,4 +1,10 @@ -// Copyright (c) 2018 INRIA Sophia-Antipolis (France). +// Copyright (c) 1997-2021 +// Utrecht University (The Netherlands), +// ETH Zurich (Switzerland), +// INRIA Sophia-Antipolis (France), +// Max-Planck-Institute Saarbruecken (Germany), +// and Tel-Aviv University (Israel). +// GeometryFactory (France) // All rights reserved. // // This file is part of CGAL (www.cgal.org) @@ -13,67 +19,18 @@ #ifndef CGAL_INTERSECTIONS_3_POINT_3_RAY_3_H #define CGAL_INTERSECTIONS_3_POINT_3_RAY_3_H -#include -#include #include +#include +#include + +#include +#include namespace CGAL { -namespace Intersections { - -namespace internal { - -template -inline -bool -do_intersect(const typename K::Point_3 &pt, - const typename K::Ray_3 &ray, - const K& k) -{ - return k.has_on_3_object()(ray,pt); -} - - -template -inline -bool -do_intersect(const typename K::Ray_3 &ray, - const typename K::Point_3 &pt, - const K& k) -{ - return k.has_on_3_object()(ray,pt); -} - - -template -typename CGAL::Intersection_traits -::result_type -intersection(const typename K::Point_3 &pt, - const typename K::Ray_3 &ray, - const K& k) -{ - if (do_intersect(pt,ray, k)) { - return intersection_return(pt); - } - return intersection_return(); -} - -template -typename CGAL::Intersection_traits -::result_type -intersection(const typename K::Ray_3 &ray, - const typename K::Point_3 &pt, - const K& k) -{ - return internal::intersection(pt, ray, k); -} - -} // namespace internal -} // namespace Intersections - -CGAL_INTERSECTION_FUNCTION(Point_3, Ray_3, 3) CGAL_DO_INTERSECT_FUNCTION(Point_3, Ray_3, 3) +CGAL_INTERSECTION_FUNCTION(Point_3, Ray_3, 3) +} // namespace CGAL -} //namespace CGAL #endif // CGAL_INTERSECTIONS_3_POINT_3_RAY_3_H diff --git a/Intersections_3/include/CGAL/Intersections_3/Point_3_Segment_3.h b/Intersections_3/include/CGAL/Intersections_3/Point_3_Segment_3.h index b1860dbbb95..a071848f458 100644 --- a/Intersections_3/include/CGAL/Intersections_3/Point_3_Segment_3.h +++ b/Intersections_3/include/CGAL/Intersections_3/Point_3_Segment_3.h @@ -1,4 +1,10 @@ -// Copyright (c) 2018 INRIA Sophia-Antipolis (France). +// Copyright (c) 1997-2021 +// Utrecht University (The Netherlands), +// ETH Zurich (Switzerland), +// INRIA Sophia-Antipolis (France), +// Max-Planck-Institute Saarbruecken (Germany), +// and Tel-Aviv University (Israel). +// GeometryFactory (France) // All rights reserved. // // This file is part of CGAL (www.cgal.org) @@ -13,67 +19,18 @@ #ifndef CGAL_INTERSECTIONS_3_POINT_3_SEGMENT_3_H #define CGAL_INTERSECTIONS_3_POINT_3_SEGMENT_3_H -#include -#include #include +#include +#include + +#include +#include namespace CGAL { -namespace Intersections { - -namespace internal { - -template -inline -bool -do_intersect(const typename K::Point_3 &pt, - const typename K::Segment_3 &seg, - const K& k) -{ - return k.has_on_3_object()(seg, pt); -} - -template -inline -bool -do_intersect(const typename K::Segment_3 &seg, - const typename K::Point_3 &pt, - const K& k) -{ - return k.has_on_3_object()(seg, pt); -} - - -template -inline -typename CGAL::Intersection_traits -::result_type -intersection(const typename K::Point_3 &pt, - const typename K::Segment_3 &seg, - const K& k) -{ - if (do_intersect(pt,seg, k)) - return intersection_return(pt); - return intersection_return(); -} - -template -inline -typename CGAL::Intersection_traits -::result_type -intersection( const typename K::Segment_3 &seg, - const typename K::Point_3 &pt, - const K& k) -{ - return internal::intersection(pt, seg, k); -} - -} // namespace internal -} // namespace Intersections - -CGAL_INTERSECTION_FUNCTION(Point_3, Segment_3, 3) CGAL_DO_INTERSECT_FUNCTION(Point_3, Segment_3, 3) +CGAL_INTERSECTION_FUNCTION(Point_3, Segment_3, 3) -} //namespace CGAL +} // namespace CGAL #endif // CGAL_INTERSECTIONS_3_POINT_3_SEGMENT_3_H diff --git a/Intersections_3/include/CGAL/Intersections_3/Point_3_Sphere_3.h b/Intersections_3/include/CGAL/Intersections_3/Point_3_Sphere_3.h index dfb034fb6d0..a5aa4d6fa68 100644 --- a/Intersections_3/include/CGAL/Intersections_3/Point_3_Sphere_3.h +++ b/Intersections_3/include/CGAL/Intersections_3/Point_3_Sphere_3.h @@ -1,4 +1,10 @@ -// Copyright (c) 2018 INRIA Sophia-Antipolis (France). +// Copyright (c) 1997-2021 +// Utrecht University (The Netherlands), +// ETH Zurich (Switzerland), +// INRIA Sophia-Antipolis (France), +// Max-Planck-Institute Saarbruecken (Germany), +// and Tel-Aviv University (Israel). +// GeometryFactory (France) // All rights reserved. // // This file is part of CGAL (www.cgal.org) @@ -13,65 +19,18 @@ #ifndef CGAL_INTERSECTIONS_3_POINT_3_SPHERE_3_H #define CGAL_INTERSECTIONS_3_POINT_3_SPHERE_3_H -#include -#include #include +#include +#include + +#include +#include namespace CGAL { -namespace Intersections { - -namespace internal { - -template -inline -bool -do_intersect(const typename K::Point_3 &pt, - const typename K::Sphere_3 &sphere, - const K&) -{ - return sphere.has_on_boundary(pt); -} - - -template -inline -bool -do_intersect(const typename K::Sphere_3 &sphere, - const typename K::Point_3 &pt, - const K&) -{ - return sphere.has_on_boundary(pt); -} - - -template -typename CGAL::Intersection_traits -::result_type -intersection(const typename K::Point_3 &pt, - const typename K::Sphere_3 &sphere, - const K& k) -{ - if (do_intersect(pt,sphere, k)) - return intersection_return(pt); - return intersection_return(); -} - -template -typename CGAL::Intersection_traits -::result_type -intersection(const typename K::Sphere_3 &sphere, - const typename K::Point_3 &pt, - const K& k) -{ - return internal::intersection(pt, sphere, k); -} - -} // namespace internal -} // namespace Intersections - -CGAL_INTERSECTION_FUNCTION(Point_3, Sphere_3, 3) CGAL_DO_INTERSECT_FUNCTION(Point_3, Sphere_3, 3) +CGAL_INTERSECTION_FUNCTION(Point_3, Sphere_3, 3) + +} // namespace CGAL -} //namespace CGAL #endif // CGAL_INTERSECTIONS_3_POINT_3_SPHERE_3_H diff --git a/Intersections_3/include/CGAL/Intersections_3/Point_3_Tetrahedron_3.h b/Intersections_3/include/CGAL/Intersections_3/Point_3_Tetrahedron_3.h index df2cd04d09c..36b750ef4e2 100644 --- a/Intersections_3/include/CGAL/Intersections_3/Point_3_Tetrahedron_3.h +++ b/Intersections_3/include/CGAL/Intersections_3/Point_3_Tetrahedron_3.h @@ -1,4 +1,10 @@ -// Copyright (c) 2018 INRIA Sophia-Antipolis (France). +// Copyright (c) 1997-2021 +// Utrecht University (The Netherlands), +// ETH Zurich (Switzerland), +// INRIA Sophia-Antipolis (France), +// Max-Planck-Institute Saarbruecken (Germany), +// and Tel-Aviv University (Israel). +// GeometryFactory (France) // All rights reserved. // // This file is part of CGAL (www.cgal.org) @@ -13,66 +19,18 @@ #ifndef CGAL_INTERSECTIONS_3_POINT_3_TETRAHEDRON_3_H #define CGAL_INTERSECTIONS_3_POINT_3_TETRAHEDRON_3_H +#include +#include +#include + #include #include -#include namespace CGAL { -namespace Intersections { - -namespace internal { - -template -inline -bool -do_intersect(const typename K::Point_3 &pt, - const typename K::Tetrahedron_3 &tetrahedron, - const K&) -{ - return ! tetrahedron.has_on_unbounded_side(pt); -} - - -template -inline -bool -do_intersect(const typename K::Tetrahedron_3 &tetrahedron, - const typename K::Point_3 &pt, - const K&) -{ - return ! tetrahedron.has_on_unbounded_side(pt); -} - - -template -typename CGAL::Intersection_traits -::result_type -intersection(const typename K::Point_3 &pt, - const typename K::Tetrahedron_3 &tetrahedron, - const K& k) -{ - if (do_intersect(pt,tetrahedron, k)) - return intersection_return(pt); - return intersection_return(); -} - -template -typename CGAL::Intersection_traits -::result_type -intersection(const typename K::Tetrahedron_3 &tetrahedron, - const typename K::Point_3 &pt, - const K& k) -{ - return internal::intersection(pt, tetrahedron, k); -} - -} // namespace internal -} // namespace Intersections - -CGAL_INTERSECTION_FUNCTION(Point_3, Tetrahedron_3, 3) CGAL_DO_INTERSECT_FUNCTION(Point_3, Tetrahedron_3, 3) +CGAL_INTERSECTION_FUNCTION(Point_3, Tetrahedron_3, 3) +} // namespace CGAL -} //namespace CGAL #endif // CGAL_INTERSECTIONS_3_POINT_3_TETRAHEDRON_3_H diff --git a/Intersections_3/include/CGAL/Intersections_3/Point_3_Triangle_3.h b/Intersections_3/include/CGAL/Intersections_3/Point_3_Triangle_3.h index 0b803e1e249..e90618bc164 100644 --- a/Intersections_3/include/CGAL/Intersections_3/Point_3_Triangle_3.h +++ b/Intersections_3/include/CGAL/Intersections_3/Point_3_Triangle_3.h @@ -1,4 +1,10 @@ -// Copyright (c) 2003 INRIA Sophia-Antipolis (France). +// Copyright (c) 1997-2021 +// Utrecht University (The Netherlands), +// ETH Zurich (Switzerland), +// INRIA Sophia-Antipolis (France), +// Max-Planck-Institute Saarbruecken (Germany), +// and Tel-Aviv University (Israel). +// GeometryFactory (France) // All rights reserved. // // This file is part of CGAL (www.cgal.org) @@ -13,113 +19,18 @@ #ifndef CGAL_INTERSECTIONS_3_POINT_3_TRIANGLE_3_H #define CGAL_INTERSECTIONS_3_POINT_3_TRIANGLE_3_H -#include -#include - -#include -#include #include +#include +#include + +#include +#include namespace CGAL { -namespace Intersections { +CGAL_DO_INTERSECT_FUNCTION(Point_3, Triangle_3, 3) +CGAL_INTERSECTION_FUNCTION(Point_3, Triangle_3, 3) -namespace internal { - -template -bool do_intersect(const typename K::Triangle_3 &t, - const typename K::Point_3 &p, - const K & k ) -{ - - CGAL_kernel_precondition( ! k.is_degenerate_3_object()(t)); - - typedef typename K::Point_3 Point_3; - - typename K::Construct_vertex_3 vertex_on = - k.construct_vertex_3_object(); - - typename K::Orientation_3 orientation = - k.orientation_3_object(); - - typename K::Coplanar_orientation_3 coplanar_orientation = - k.coplanar_orientation_3_object(); - - - - const Point_3 & a = vertex_on(t,0); - const Point_3 & b = vertex_on(t,1); - const Point_3 & c = vertex_on(t,2); - - - if (orientation(a,b,c,p) != COPLANAR) - return false; - - - const Orientation abp = coplanar_orientation(a,b,p); - const Orientation bcp = coplanar_orientation(b,c,p); - - - switch ( abp ) { - case POSITIVE: return bcp != NEGATIVE - && coplanar_orientation(c,a,p) != NEGATIVE ; - case NEGATIVE: return bcp != POSITIVE - && coplanar_orientation(c,a,p) != POSITIVE ; - case COLLINEAR: - switch ( bcp ) { - case POSITIVE: return coplanar_orientation(c,a,p) != NEGATIVE ; - case NEGATIVE: return coplanar_orientation(c,a,p) != POSITIVE ; - case COLLINEAR: return true; - default: // should not happen. - CGAL_kernel_assertion(false); - return false; - } - default: // should not happen. - CGAL_kernel_assertion(false); - return false; - } - -} - - -template -bool do_intersect(const typename K::Point_3 &p, - const typename K::Triangle_3 &t, - const K & k ) -{ - return do_intersect(t, p, k); -} - -template -inline -typename CGAL::Intersection_traits -::result_type -intersection(const typename K::Point_3 &pt, - const typename K::Triangle_3 &tr, - const K& k) -{ - if (do_intersect(pt,tr, k)) { - return intersection_return(pt); - } - return intersection_return(); -} - -template -inline -typename CGAL::Intersection_traits -::result_type -intersection( const typename K::Triangle_3 &tr, - const typename K::Point_3 &pt, - const K& k) -{ - return internal::intersection(pt, tr, k); -} -} // namespace internal -} // namespace Intersections - -CGAL_DO_INTERSECT_FUNCTION(Triangle_3, Point_3, 3) -CGAL_INTERSECTION_FUNCTION(Triangle_3, Point_3, 3) - -} //namespace CGAL +} // namespace CGAL #endif // CGAL_INTERSECTIONS_3_POINT_3_TRIANGLE_3_H diff --git a/Intersections_3/include/CGAL/Intersections_3/Ray_3_Ray_3.h b/Intersections_3/include/CGAL/Intersections_3/Ray_3_Ray_3.h index 937669ff9aa..30c12f99ebb 100644 --- a/Intersections_3/include/CGAL/Intersections_3/Ray_3_Ray_3.h +++ b/Intersections_3/include/CGAL/Intersections_3/Ray_3_Ray_3.h @@ -1,4 +1,10 @@ -// Copyright (c) 2010 GeometryFactory (France). +// Copyright (c) 1997-2021 +// Utrecht University (The Netherlands), +// ETH Zurich (Switzerland), +// INRIA Sophia-Antipolis (France), +// Max-Planck-Institute Saarbruecken (Germany), +// and Tel-Aviv University (Israel). +// GeometryFactory (France) // All rights reserved. // // This file is part of CGAL (www.cgal.org) @@ -14,13 +20,17 @@ #ifndef CGAL_INTERSECTIONS_3_RAY_3_RAY_3_H #define CGAL_INTERSECTIONS_3_RAY_3_RAY_3_H +#include +#include +#include + #include -#include - namespace CGAL { -CGAL_INTERSECTION_FUNCTION_SELF(Ray_3, 3) + CGAL_DO_INTERSECT_FUNCTION_SELF(Ray_3, 3) -} +CGAL_INTERSECTION_FUNCTION_SELF(Ray_3, 3) + +} // namespace CGAL #endif // CGAL_INTERSECTIONS_3_RAY_3_RAY_3_H diff --git a/Intersections_3/include/CGAL/Intersections_3/Ray_3_Segment_3.h b/Intersections_3/include/CGAL/Intersections_3/Ray_3_Segment_3.h index 7242ea399ec..c03f2e6a376 100644 --- a/Intersections_3/include/CGAL/Intersections_3/Ray_3_Segment_3.h +++ b/Intersections_3/include/CGAL/Intersections_3/Ray_3_Segment_3.h @@ -1,4 +1,10 @@ -// Copyright (c) 2010 GeometryFactory (France). +// Copyright (c) 1997-2021 +// Utrecht University (The Netherlands), +// ETH Zurich (Switzerland), +// INRIA Sophia-Antipolis (France), +// Max-Planck-Institute Saarbruecken (Germany), +// and Tel-Aviv University (Israel). +// GeometryFactory (France) // All rights reserved. // // This file is part of CGAL (www.cgal.org) @@ -14,14 +20,18 @@ #ifndef CGAL_INTERSECTIONS_3_RAY_3_SEGMENT_3_H #define CGAL_INTERSECTIONS_3_RAY_3_SEGMENT_3_H +#include +#include +#include + #include #include -#include - namespace CGAL { -CGAL_INTERSECTION_FUNCTION(Ray_3, Segment_3, 3) + CGAL_DO_INTERSECT_FUNCTION(Ray_3, Segment_3, 3) -} +CGAL_INTERSECTION_FUNCTION(Ray_3, Segment_3, 3) + +} // namespace CGAL #endif // CGAL_INTERSECTIONS_3_RAY_3_SEGMENT_3_H diff --git a/Intersections_3/include/CGAL/Intersections_3/Ray_3_Sphere_3.h b/Intersections_3/include/CGAL/Intersections_3/Ray_3_Sphere_3.h index a932fb71490..dc7d5ab7839 100644 --- a/Intersections_3/include/CGAL/Intersections_3/Ray_3_Sphere_3.h +++ b/Intersections_3/include/CGAL/Intersections_3/Ray_3_Sphere_3.h @@ -1,4 +1,10 @@ -// Copyright (c) 2010 GeometryFactory (France). +// Copyright (c) 1997-2021 +// Utrecht University (The Netherlands), +// ETH Zurich (Switzerland), +// INRIA Sophia-Antipolis (France), +// Max-Planck-Institute Saarbruecken (Germany), +// and Tel-Aviv University (Israel). +// GeometryFactory (France) // All rights reserved. // // This file is part of CGAL (www.cgal.org) @@ -14,13 +20,16 @@ #ifndef CGAL_INTERSECTIONS_3_RAY_3_SPHERE_3_H #define CGAL_INTERSECTIONS_3_RAY_3_SPHERE_3_H +#include +#include + #include #include -#include - namespace CGAL { - CGAL_DO_INTERSECT_FUNCTION(Ray_3, Sphere_3, 3) -} + +CGAL_DO_INTERSECT_FUNCTION(Ray_3, Sphere_3, 3) + +} // namespace CGAL #endif // CGAL_INTERSECTIONS_3_RAY_3_SPHERE_3_H diff --git a/Intersections_3/include/CGAL/Intersections_3/Ray_3_Tetrahedron_3.h b/Intersections_3/include/CGAL/Intersections_3/Ray_3_Tetrahedron_3.h index b2b00e4e716..a5e7312cb6b 100644 --- a/Intersections_3/include/CGAL/Intersections_3/Ray_3_Tetrahedron_3.h +++ b/Intersections_3/include/CGAL/Intersections_3/Ray_3_Tetrahedron_3.h @@ -1,4 +1,10 @@ -// Copyright (c) 2010 GeometryFactory (France). +// Copyright (c) 1997-2021 +// Utrecht University (The Netherlands), +// ETH Zurich (Switzerland), +// INRIA Sophia-Antipolis (France), +// Max-Planck-Institute Saarbruecken (Germany), +// and Tel-Aviv University (Israel). +// GeometryFactory (France) // All rights reserved. // // This file is part of CGAL (www.cgal.org) @@ -14,15 +20,18 @@ #ifndef CGAL_INTERSECTIONS_3_RAY_3_TETRAHEDRON_3_H #define CGAL_INTERSECTIONS_3_RAY_3_TETRAHEDRON_3_H +#include +#include +#include + #include #include -#include -#include - namespace CGAL { - CGAL_DO_INTERSECT_FUNCTION(Ray_3, Tetrahedron_3, 3) - CGAL_INTERSECTION_FUNCTION(Ray_3, Tetrahedron_3, 3) -} + +CGAL_DO_INTERSECT_FUNCTION(Ray_3, Tetrahedron_3, 3) +CGAL_INTERSECTION_FUNCTION(Ray_3, Tetrahedron_3, 3) + +} // namespace CGAL #endif // CGAL_INTERSECTIONS_3_RAY_3_TETRAHEDRON_3_H diff --git a/Intersections_3/include/CGAL/Intersections_3/Ray_3_Triangle_3.h b/Intersections_3/include/CGAL/Intersections_3/Ray_3_Triangle_3.h index 9860466bae2..7ca0ad33e54 100644 --- a/Intersections_3/include/CGAL/Intersections_3/Ray_3_Triangle_3.h +++ b/Intersections_3/include/CGAL/Intersections_3/Ray_3_Triangle_3.h @@ -1,4 +1,10 @@ -// Copyright (c) 2010 GeometryFactory (France). +// Copyright (c) 1997-2021 +// Utrecht University (The Netherlands), +// ETH Zurich (Switzerland), +// INRIA Sophia-Antipolis (France), +// Max-Planck-Institute Saarbruecken (Germany), +// and Tel-Aviv University (Israel). +// GeometryFactory (France) // All rights reserved. // // This file is part of CGAL (www.cgal.org) @@ -14,15 +20,18 @@ #ifndef CGAL_INTERSECTIONS_3_RAY_3_TRIANGLE_3_H #define CGAL_INTERSECTIONS_3_RAY_3_TRIANGLE_3_H +#include +#include +#include + #include #include -#include -#include - namespace CGAL { - CGAL_INTERSECTION_FUNCTION(Triangle_3, Ray_3, 3) - CGAL_DO_INTERSECT_FUNCTION(Triangle_3, Ray_3, 3) -} -#endif // CGAL_INTERSECTIONS_3_TRIANGLE_3_TRIANGLE_3_H +CGAL_INTERSECTION_FUNCTION(Ray_3, Triangle_3, 3) +CGAL_DO_INTERSECT_FUNCTION(Ray_3, Triangle_3, 3) + +} // namespace CGAL + +#endif // CGAL_INTERSECTIONS_3_RAY_3_TRIANGLE_3_H diff --git a/Intersections_3/include/CGAL/Intersections_3/Segment_3_Segment_3.h b/Intersections_3/include/CGAL/Intersections_3/Segment_3_Segment_3.h index 5252aeff492..3d60beb9f0a 100644 --- a/Intersections_3/include/CGAL/Intersections_3/Segment_3_Segment_3.h +++ b/Intersections_3/include/CGAL/Intersections_3/Segment_3_Segment_3.h @@ -1,4 +1,10 @@ -// Copyright (c) 2010 GeometryFactory (France). +// Copyright (c) 1997-2021 +// Utrecht University (The Netherlands), +// ETH Zurich (Switzerland), +// INRIA Sophia-Antipolis (France), +// Max-Planck-Institute Saarbruecken (Germany), +// and Tel-Aviv University (Israel). +// GeometryFactory (France) // All rights reserved. // // This file is part of CGAL (www.cgal.org) @@ -14,13 +20,17 @@ #ifndef CGAL_INTERSECTIONS_3_SEGMENT_3_SEGMENT_3_H #define CGAL_INTERSECTIONS_3_SEGMENT_3_SEGMENT_3_H +#include +#include +#include + #include -#include - namespace CGAL { + CGAL_INTERSECTION_FUNCTION_SELF(Segment_3, 3) CGAL_DO_INTERSECT_FUNCTION_SELF(Segment_3, 3) -} + +} // namespace CGAL #endif // CGAL_INTERSECTIONS_3_SEGMENT_3_SEGMENT_3_H diff --git a/Intersections_3/include/CGAL/Intersections_3/Segment_3_Sphere_3.h b/Intersections_3/include/CGAL/Intersections_3/Segment_3_Sphere_3.h index f0aa45ef000..b32c75456fb 100644 --- a/Intersections_3/include/CGAL/Intersections_3/Segment_3_Sphere_3.h +++ b/Intersections_3/include/CGAL/Intersections_3/Segment_3_Sphere_3.h @@ -1,4 +1,10 @@ -// Copyright (c) 2010 GeometryFactory (France). +// Copyright (c) 1997-2021 +// Utrecht University (The Netherlands), +// ETH Zurich (Switzerland), +// INRIA Sophia-Antipolis (France), +// Max-Planck-Institute Saarbruecken (Germany), +// and Tel-Aviv University (Israel). +// GeometryFactory (France) // All rights reserved. // // This file is part of CGAL (www.cgal.org) @@ -14,13 +20,16 @@ #ifndef CGAL_INTERSECTIONS_3_SEGMENT_3_SPHERE_3_H #define CGAL_INTERSECTIONS_3_SEGMENT_3_SPHERE_3_H +#include +#include + #include #include -#include - namespace CGAL { - CGAL_DO_INTERSECT_FUNCTION(Segment_3, Sphere_3, 3) -} + +CGAL_DO_INTERSECT_FUNCTION(Segment_3, Sphere_3, 3) + +} // namespace CGAL #endif // CGAL_INTERSECTIONS_3_SEGMENT_3_SPHERE_3_H diff --git a/Intersections_3/include/CGAL/Intersections_3/Segment_3_Tetrahedron_3.h b/Intersections_3/include/CGAL/Intersections_3/Segment_3_Tetrahedron_3.h index 4bc0e32e635..ea719ff89b0 100644 --- a/Intersections_3/include/CGAL/Intersections_3/Segment_3_Tetrahedron_3.h +++ b/Intersections_3/include/CGAL/Intersections_3/Segment_3_Tetrahedron_3.h @@ -1,4 +1,10 @@ -// Copyright (c) 2010 GeometryFactory (France). +// Copyright (c) 1997-2021 +// Utrecht University (The Netherlands), +// ETH Zurich (Switzerland), +// INRIA Sophia-Antipolis (France), +// Max-Planck-Institute Saarbruecken (Germany), +// and Tel-Aviv University (Israel). +// GeometryFactory (France) // All rights reserved. // // This file is part of CGAL (www.cgal.org) @@ -14,15 +20,18 @@ #ifndef CGAL_INTERSECTIONS_3_SEGMENT_3_TETRAHEDRON_3_H #define CGAL_INTERSECTIONS_3_SEGMENT_3_TETRAHEDRON_3_H +#include +#include +#include + #include #include -#include -#include - namespace CGAL { - CGAL_DO_INTERSECT_FUNCTION(Segment_3, Tetrahedron_3, 3) - CGAL_INTERSECTION_FUNCTION(Segment_3, Tetrahedron_3, 3) -} + +CGAL_DO_INTERSECT_FUNCTION(Segment_3, Tetrahedron_3, 3) +CGAL_INTERSECTION_FUNCTION(Segment_3, Tetrahedron_3, 3) + +} // namespace CGAL #endif // CGAL_INTERSECTIONS_3_SEGMENT_3_TETRAHEDRON_3_H diff --git a/Intersections_3/include/CGAL/Intersections_3/Segment_3_Triangle_3.h b/Intersections_3/include/CGAL/Intersections_3/Segment_3_Triangle_3.h index 44c961be241..4c27ad00d99 100644 --- a/Intersections_3/include/CGAL/Intersections_3/Segment_3_Triangle_3.h +++ b/Intersections_3/include/CGAL/Intersections_3/Segment_3_Triangle_3.h @@ -1,4 +1,10 @@ -// Copyright (c) 2010 GeometryFactory (France). +// Copyright (c) 1997-2021 +// Utrecht University (The Netherlands), +// ETH Zurich (Switzerland), +// INRIA Sophia-Antipolis (France), +// Max-Planck-Institute Saarbruecken (Germany), +// and Tel-Aviv University (Israel). +// GeometryFactory (France) // All rights reserved. // // This file is part of CGAL (www.cgal.org) @@ -14,15 +20,18 @@ #ifndef CGAL_INTERSECTIONS_3_TRIANGLE_3_SEGMENT_3_H #define CGAL_INTERSECTIONS_3_TRIANGLE_3_SEGMENT_3_H +#include +#include +#include + #include #include -#include -#include - namespace CGAL { -CGAL_INTERSECTION_FUNCTION(Triangle_3, Segment_3, 3) -CGAL_DO_INTERSECT_FUNCTION(Triangle_3, Segment_3, 3) -} -#endif // CGAL_INTERSECTIONS_3_TRIANGLE_3_SEGMENT_3_H +CGAL_INTERSECTION_FUNCTION(Segment_3, Triangle_3, 3) +CGAL_DO_INTERSECT_FUNCTION(Segment_3, Triangle_3, 3) + +} // namespace CGAL + +#endif // CGAL_INTERSECTIONS_3_SEGMENT_3_TRIANGLE_3_H diff --git a/Intersections_3/include/CGAL/Intersections_3/Sphere_3_Sphere_3.h b/Intersections_3/include/CGAL/Intersections_3/Sphere_3_Sphere_3.h index 3da8750f2b3..0732501b38a 100644 --- a/Intersections_3/include/CGAL/Intersections_3/Sphere_3_Sphere_3.h +++ b/Intersections_3/include/CGAL/Intersections_3/Sphere_3_Sphere_3.h @@ -1,4 +1,10 @@ -// Copyright (c) 2010 GeometryFactory (France). +// Copyright (c) 1997-2021 +// Utrecht University (The Netherlands), +// ETH Zurich (Switzerland), +// INRIA Sophia-Antipolis (France), +// Max-Planck-Institute Saarbruecken (Germany), +// and Tel-Aviv University (Israel). +// GeometryFactory (France) // All rights reserved. // // This file is part of CGAL (www.cgal.org) @@ -14,13 +20,17 @@ #ifndef CGAL_INTERSECTIONS_3_SPHERE_3_SPHERE_3_H #define CGAL_INTERSECTIONS_3_SPHERE_3_SPHERE_3_H +#include +#include +#include + #include -#include - namespace CGAL { + CGAL_DO_INTERSECT_FUNCTION_SELF(Sphere_3, 3) CGAL_INTERSECTION_FUNCTION_SELF(Sphere_3, 3) -} + +} // namespace CGAL #endif // CGAL_INTERSECTIONS_3_SPHERE_3_SPHERE_3_H diff --git a/Intersections_3/include/CGAL/Intersections_3/Sphere_3_Tetrahedron_3.h b/Intersections_3/include/CGAL/Intersections_3/Sphere_3_Tetrahedron_3.h index ecb64786a18..13d4515170e 100644 --- a/Intersections_3/include/CGAL/Intersections_3/Sphere_3_Tetrahedron_3.h +++ b/Intersections_3/include/CGAL/Intersections_3/Sphere_3_Tetrahedron_3.h @@ -1,4 +1,10 @@ -// Copyright (c) 2010 GeometryFactory (France). +// Copyright (c) 1997-2021 +// Utrecht University (The Netherlands), +// ETH Zurich (Switzerland), +// INRIA Sophia-Antipolis (France), +// Max-Planck-Institute Saarbruecken (Germany), +// and Tel-Aviv University (Israel). +// GeometryFactory (France) // All rights reserved. // // This file is part of CGAL (www.cgal.org) @@ -14,13 +20,16 @@ #ifndef CGAL_INTERSECTIONS_3_SPHERE_3_TETRAHEDRON_3_H #define CGAL_INTERSECTIONS_3_SPHERE_3_TETRAHEDRON_3_H +#include +#include + #include #include -#include - namespace CGAL { - CGAL_DO_INTERSECT_FUNCTION(Sphere_3, Tetrahedron_3, 3) -} + +CGAL_DO_INTERSECT_FUNCTION(Sphere_3, Tetrahedron_3, 3) + +} // namespace CGAL #endif // CGAL_INTERSECTIONS_3_SPHERE_3_TETRAHEDRON_3_H diff --git a/Intersections_3/include/CGAL/Intersections_3/Sphere_3_Triangle_3.h b/Intersections_3/include/CGAL/Intersections_3/Sphere_3_Triangle_3.h index d402b75bc6e..6457d6595fa 100644 --- a/Intersections_3/include/CGAL/Intersections_3/Sphere_3_Triangle_3.h +++ b/Intersections_3/include/CGAL/Intersections_3/Sphere_3_Triangle_3.h @@ -1,4 +1,10 @@ -// Copyright (c) 2010 GeometryFactory (France). +// Copyright (c) 1997-2021 +// Utrecht University (The Netherlands), +// ETH Zurich (Switzerland), +// INRIA Sophia-Antipolis (France), +// Max-Planck-Institute Saarbruecken (Germany), +// and Tel-Aviv University (Israel). +// GeometryFactory (France) // All rights reserved. // // This file is part of CGAL (www.cgal.org) @@ -14,13 +20,16 @@ #ifndef CGAL_INTERSECTIONS_3_SPHERE_3_TRIANGLE_3_H #define CGAL_INTERSECTIONS_3_SPHERE_3_TRIANGLE_3_H +#include +#include + #include #include -#include - namespace CGAL { - CGAL_DO_INTERSECT_FUNCTION(Sphere_3, Triangle_3, 3) -} + +CGAL_DO_INTERSECT_FUNCTION(Sphere_3, Triangle_3, 3) + +} // namespace CGAL #endif // CGAL_INTERSECTIONS_3_SPHERE_3_TRIANGLE_3_H diff --git a/Intersections_3/include/CGAL/Intersections_3/Tetrahedron_3_Tetrahedron_3.h b/Intersections_3/include/CGAL/Intersections_3/Tetrahedron_3_Tetrahedron_3.h index fc2fe52f06d..dd6a55aedef 100644 --- a/Intersections_3/include/CGAL/Intersections_3/Tetrahedron_3_Tetrahedron_3.h +++ b/Intersections_3/include/CGAL/Intersections_3/Tetrahedron_3_Tetrahedron_3.h @@ -1,4 +1,10 @@ -// Copyright (c) 2010 GeometryFactory (France). +// Copyright (c) 1997-2021 +// Utrecht University (The Netherlands), +// ETH Zurich (Switzerland), +// INRIA Sophia-Antipolis (France), +// Max-Planck-Institute Saarbruecken (Germany), +// and Tel-Aviv University (Israel). +// GeometryFactory (France) // All rights reserved. // // This file is part of CGAL (www.cgal.org) @@ -14,12 +20,15 @@ #ifndef CGAL_INTERSECTIONS_3_TETRAHEDRON_3_TETRAHEDRON_3_H #define CGAL_INTERSECTIONS_3_TETRAHEDRON_3_TETRAHEDRON_3_H +#include +#include + #include -#include - namespace CGAL { - CGAL_DO_INTERSECT_FUNCTION_SELF(Tetrahedron_3, 3) -} + +CGAL_DO_INTERSECT_FUNCTION_SELF(Tetrahedron_3, 3) + +} // namespace CGAL #endif // CGAL_INTERSECTIONS_3_TETRAHEDRON_3_TETRAHEDRON_3_H diff --git a/Intersections_3/include/CGAL/Intersections_3/Tetrahedron_3_Triangle_3.h b/Intersections_3/include/CGAL/Intersections_3/Tetrahedron_3_Triangle_3.h index 593c6481c7f..f8a296f21c0 100644 --- a/Intersections_3/include/CGAL/Intersections_3/Tetrahedron_3_Triangle_3.h +++ b/Intersections_3/include/CGAL/Intersections_3/Tetrahedron_3_Triangle_3.h @@ -1,4 +1,10 @@ -// Copyright (c) 2010 GeometryFactory (France). +// Copyright (c) 1997-2021 +// Utrecht University (The Netherlands), +// ETH Zurich (Switzerland), +// INRIA Sophia-Antipolis (France), +// Max-Planck-Institute Saarbruecken (Germany), +// and Tel-Aviv University (Israel). +// GeometryFactory (France) // All rights reserved. // // This file is part of CGAL (www.cgal.org) @@ -14,15 +20,18 @@ #ifndef CGAL_INTERSECTIONS_3_TETRAHEDRON_3_TRIANGLE_3_H #define CGAL_INTERSECTIONS_3_TETRAHEDRON_3_TRIANGLE_3_H -#include -#include - -#include +#include +#include #include +#include +#include + namespace CGAL { - CGAL_DO_INTERSECT_FUNCTION(Tetrahedron_3, Triangle_3, 3) - CGAL_INTERSECTION_FUNCTION(Tetrahedron_3, Triangle_3, 3) -} + +CGAL_DO_INTERSECT_FUNCTION(Tetrahedron_3, Triangle_3, 3) +CGAL_INTERSECTION_FUNCTION(Tetrahedron_3, Triangle_3, 3) + +} // namespace CGAL #endif // CGAL_INTERSECTIONS_3_TETRAHEDRON_3_TRIANGLE_3_H diff --git a/Intersections_3/include/CGAL/Intersections_3/Triangle_3_Triangle_3.h b/Intersections_3/include/CGAL/Intersections_3/Triangle_3_Triangle_3.h index 9ebe2c7565b..83599c08992 100644 --- a/Intersections_3/include/CGAL/Intersections_3/Triangle_3_Triangle_3.h +++ b/Intersections_3/include/CGAL/Intersections_3/Triangle_3_Triangle_3.h @@ -1,4 +1,10 @@ -// Copyright (c) 2010 GeometryFactory (France). +// Copyright (c) 1997-2021 +// Utrecht University (The Netherlands), +// ETH Zurich (Switzerland), +// INRIA Sophia-Antipolis (France), +// Max-Planck-Institute Saarbruecken (Germany), +// and Tel-Aviv University (Israel). +// GeometryFactory (France) // All rights reserved. // // This file is part of CGAL (www.cgal.org) @@ -16,12 +22,14 @@ #include -#include #include +#include namespace CGAL { -CGAL_INTERSECTION_FUNCTION_SELF(Triangle_3, 3) + CGAL_DO_INTERSECT_FUNCTION_SELF(Triangle_3, 3) -} +CGAL_INTERSECTION_FUNCTION_SELF(Triangle_3, 3) + +} // namespace CGAL #endif // CGAL_INTERSECTIONS_3_TRIANGLE_3_TRIANGLE_3_H diff --git a/Intersections_3/include/CGAL/Intersections_3/internal/Bbox_3_Bbox_3_do_intersect.h b/Intersections_3/include/CGAL/Intersections_3/internal/Bbox_3_Bbox_3_do_intersect.h deleted file mode 100644 index 4fa6604efd2..00000000000 --- a/Intersections_3/include/CGAL/Intersections_3/internal/Bbox_3_Bbox_3_do_intersect.h +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright (c) 2008 ETH Zurich (Switzerland) -// Copyright (c) 2008-2009 INRIA Sophia-Antipolis (France) -// Copyright (c) 2009 GeometryFactory (France) -// All rights reserved. -// -// This file is part of CGAL (www.cgal.org) -// -// $URL$ -// $Id$ -// SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-Commercial -// -// -// Author(s) : Laurent Rineau, Camille Wormser, Jane Tournois, Pierre Alliez - -#ifndef CGAL_INTERNAL_INTERSECTIONS_3_BBOX_3_BBOX_3_DO_INTERSECT_H -#define CGAL_INTERNAL_INTERSECTIONS_3_BBOX_3_BBOX_3_DO_INTERSECT_H - -// Turn off Visual C++ warning -#ifdef _MSC_VER -#pragma warning ( disable : 4003 ) -#endif - -#include - -namespace CGAL { - bool - inline - do_intersect(const CGAL::Bbox_3& c, - const CGAL::Bbox_3& bbox) - { - return CGAL::do_overlap(c, bbox); - } - -} //namespace CGAL - -#endif // CGAL_INTERNAL_INTERSECTIONS_3_BBOX_3_BBOX_3_DO_INTERSECT_H diff --git a/Intersections_3/include/CGAL/Intersections_3/internal/Bbox_3_Iso_cuboid_3_do_intersect.h b/Intersections_3/include/CGAL/Intersections_3/internal/Bbox_3_Iso_cuboid_3_do_intersect.h index a1a4f9bf0b0..853e253fecf 100644 --- a/Intersections_3/include/CGAL/Intersections_3/internal/Bbox_3_Iso_cuboid_3_do_intersect.h +++ b/Intersections_3/include/CGAL/Intersections_3/internal/Bbox_3_Iso_cuboid_3_do_intersect.h @@ -14,13 +14,10 @@ #ifndef CGAL_INTERNAL_INTERSECTIONS_3_BBOX_3_ISO_CUBOID_3_DO_INTERSECT_H #define CGAL_INTERNAL_INTERSECTIONS_3_BBOX_3_ISO_CUBOID_3_DO_INTERSECT_H -#include #include namespace CGAL { - namespace Intersections { - namespace internal { template @@ -37,8 +34,16 @@ bool do_intersect(const CGAL::Bbox_3& bb, return true; } +template +bool do_intersect(const typename K::Iso_cuboid_3& ic, + const CGAL::Bbox_3& bb, + const K& k) +{ + return do_intersect(bb, ic, k); +} + } // namespace internal } // namespace Intersections -} //namespace CGAL +} // namespace CGAL -#endif // CGAL_INTERNAL_INTERSECTIONS_3_BBOX_3_ISO_CUBOID_3_DO_INTERSECT_H +#endif // CGAL_INTERNAL_INTERSECTIONS_3_BBOX_3_ISO_CUBOID_3_DO_INTERSECT_H diff --git a/Intersections_3/include/CGAL/Intersections_3/internal/Bbox_3_Iso_cuboid_3_intersection.h b/Intersections_3/include/CGAL/Intersections_3/internal/Bbox_3_Iso_cuboid_3_intersection.h new file mode 100644 index 00000000000..34effddfde7 --- /dev/null +++ b/Intersections_3/include/CGAL/Intersections_3/internal/Bbox_3_Iso_cuboid_3_intersection.h @@ -0,0 +1,54 @@ +// Copyright (c) 1997-2010 +// Utrecht University (The Netherlands), +// ETH Zurich (Switzerland), +// INRIA Sophia-Antipolis (France), +// Max-Planck-Institute Saarbruecken (Germany), +// and Tel-Aviv University (Israel). All rights reserved. +// +// This file is part of CGAL (www.cgal.org) +// +// $URL$ +// $Id$ +// SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-Commercial +// +// +// Author(s) : Geert-Jan Giezeman +// Sebastien Loriot + +#ifndef CGAL_INTERNAL_INTERSECTIONS_3_BBOX_3_ISO_CUBOID_3_INTERSECTION_H +#define CGAL_INTERNAL_INTERSECTIONS_3_BBOX_3_ISO_CUBOID_3_INTERSECTION_H + +#include +#include + +#include + +namespace CGAL { +namespace Intersections { +namespace internal { + +template +typename Intersection_traits::result_type +intersection(const CGAL::Bbox_3& box, + const typename K::Iso_cuboid_3& cub, + const K&) +{ + typename K::Iso_cuboid_3 iso_cub(box); + return intersection(iso_cub, cub); +} + +template +inline +typename Intersection_traits::result_type +intersection(const typename K::Iso_cuboid_3& cub, + const CGAL::Bbox_3& box, + const K& k) +{ + return intersection(box, cub, k); +} + +} // namespace internal +} // namespace Intersections +} // namespace CGAL + +#endif // CGAL_INTERNAL_INTERSECTIONS_3_BBOX_3_ISO_CUBOID_3_INTERSECTION_H diff --git a/Intersections_3/include/CGAL/Intersections_3/internal/Bbox_3_Line_3_do_intersect.h b/Intersections_3/include/CGAL/Intersections_3/internal/Bbox_3_Line_3_do_intersect.h index 37ed296c783..f0054560f00 100644 --- a/Intersections_3/include/CGAL/Intersections_3/internal/Bbox_3_Line_3_do_intersect.h +++ b/Intersections_3/include/CGAL/Intersections_3/internal/Bbox_3_Line_3_do_intersect.h @@ -11,144 +11,142 @@ // // Author(s) : Camille Wormser, Jane Tournois, Pierre Alliez, Stephane Tayeb - #ifndef CGAL_INTERNAL_INTERSECTIONS_3_BBOX_3_LINE_3_DO_INTERSECT_H #define CGAL_INTERNAL_INTERSECTIONS_3_BBOX_3_LINE_3_DO_INTERSECT_H -#include -#include - // inspired from http://cag.csail.mit.edu/~amy/papers/box-jgt.pdf +#include + namespace CGAL { - namespace Intersections { - namespace internal { - template - inline - bool - bbox_line_do_intersect_aux(const FT& px, const FT& py, const FT& pz, - const FT& vx, const FT& vy, const FT& vz, - const FT& bxmin, const FT& bymin, const FT& bzmin, - const FT& bxmax, const FT& bymax, const FT& bzmax) +template +inline +bool +bbox_line_do_intersect_aux(const FT& px, const FT& py, const FT& pz, + const FT& vx, const FT& vy, const FT& vz, + const FT& bxmin, const FT& bymin, const FT& bzmin, + const FT& bxmax, const FT& bymax, const FT& bzmax) +{ + // ----------------------------------- + // treat x coord + // ----------------------------------- + FT dmin, tmin, tmax; + if(vx >= 0) { - // ----------------------------------- - // treat x coord - // ----------------------------------- - FT dmin, tmin, tmax; - if ( vx >= 0 ) - { - tmin = bxmin - px; - tmax = bxmax - px; - dmin = vx; - } - else - { - tmin = px - bxmax; - tmax = px - bxmin; - dmin = -vx; - } - - //if px is not in the x-slab - if ( dmin == FT(0) && (tmin > FT(0) || tmax < FT(0)) ) return false; - - FT dmax = dmin; - - // ----------------------------------- - // treat y coord - // ----------------------------------- - FT d_, tmin_, tmax_; - if ( vy >= 0 ) - { - tmin_ = bymin - py; - tmax_ = bymax - py; - d_ = vy; - } - else - { - tmin_ = py - bymax; - tmax_ = py - bymin; - d_ = -vy; - } - - - - - if ( d_ == FT(0) ){ - //if py is not in the y-slab - if( (tmin_ > FT(0) || tmax_ < FT(0)) ) return false; - } - else - if ( (dmin*tmax_) < (d_*tmin) || (dmax*tmin_) > (d_*tmax) ) - return false; - - if( (dmin*tmin_) > (d_*tmin) ) - { - tmin = tmin_; - dmin = d_; - } - - if( (dmax*tmax_) < (d_*tmax) ) - { - tmax = tmax_; - dmax = d_; - } - - // ----------------------------------- - // treat z coord - // ----------------------------------- - if ( vz >= 0 ) - { - tmin_ = bzmin - pz; - tmax_ = bzmax - pz; - d_ = vz; - } - else - { - tmin_ = pz - bzmax; - tmax_ = pz - bzmin; - d_ = -vz; - } - - //if pz is not in the z-slab - //if ( d_ == FT(0) && (tmin_ > FT(0) || tmax_ < FT(0)) ) return false; - //The previous line is not needed as either dmin or d_ are not 0 - //(otherwise the direction of the line would be null). - // The following is equivalent to the in z-slab test if d_=0. - - return ( (dmin*tmax_) >= (d_*tmin) && (dmax*tmin_) <= (d_*tmax) ); + tmin = bxmin - px; + tmax = bxmax - px; + dmin = vx; + } + else + { + tmin = px - bxmax; + tmax = px - bxmin; + dmin = -vx; } - template - bool do_intersect(const typename K::Line_3& line, - const CGAL::Bbox_3& bbox, - const K&) + //if px is not in the x-slab + if(dmin == FT(0) && (tmin > FT(0) || tmax < FT(0))) + return false; + + FT dmax = dmin; + + // ----------------------------------- + // treat y coord + // ----------------------------------- + FT d_, tmin_, tmax_; + if(vy >= 0) { - typedef typename K::FT FT; - typedef typename K::Point_3 Point_3; - typedef typename K::Vector_3 Vector_3; - - const Point_3& point = line.point(); - const Vector_3& v = line.to_vector(); - - return bbox_line_do_intersect_aux( - point.x(), point.y(), point.z(), - v.x(), v.y(), v.z(), - FT(bbox.xmin()), FT(bbox.ymin()), FT(bbox.zmin()), - FT(bbox.xmax()), FT(bbox.ymax()), FT(bbox.zmax()) ); + tmin_ = bymin - py; + tmax_ = bymax - py; + d_ = vy; + } + else + { + tmin_ = py - bymax; + tmax_ = py - bymin; + d_ = -vy; } - template - bool do_intersect(const CGAL::Bbox_3& bbox, - const typename K::Line_3& line, - const K&) - { return do_intersect(line, bbox, K()); } + if(d_ == FT(0)) + { + //if py is not in the y-slab + if((tmin_ > FT(0) || tmax_ < FT(0))) + return false; + } + else + { + if((dmin*tmax_) < (d_*tmin) || (dmax*tmin_) > (d_*tmax)) + return false; + } + if((dmin*tmin_) > (d_*tmin)) + { + tmin = tmin_; + dmin = d_; + } + + if((dmax*tmax_) < (d_*tmax)) + { + tmax = tmax_; + dmax = d_; + } + + // ----------------------------------- + // treat z coord + // ----------------------------------- + if(vz >= 0) + { + tmin_ = bzmin - pz; + tmax_ = bzmax - pz; + d_ = vz; + } + else + { + tmin_ = pz - bzmax; + tmax_ = pz - bzmin; + d_ = -vz; + } + + // if pz is not in the z-slab + // if(d_ == FT(0) && (tmin_ > FT(0) || tmax_ < FT(0))) return false; + // The previous line is not needed as either dmin or d_ are not 0 + // (otherwise the direction of the line would be null). + // The following is equivalent to the in z-slab test if d_=0. + + return ((dmin*tmax_) >= (d_*tmin) && (dmax*tmin_) <= (d_*tmax)); +} + +template +bool do_intersect(const typename K::Line_3& line, + const CGAL::Bbox_3& bbox, + const K&) +{ + typedef typename K::FT FT; + typedef typename K::Point_3 Point_3; + typedef typename K::Vector_3 Vector_3; + + const Point_3& point = line.point(); + const Vector_3& v = line.to_vector(); + + return bbox_line_do_intersect_aux(point.x(), point.y(), point.z(), + v.x(), v.y(), v.z(), + FT(bbox.xmin()), FT(bbox.ymin()), FT(bbox.zmin()), + FT(bbox.xmax()), FT(bbox.ymax()), FT(bbox.zmax())); +} + +template +bool do_intersect(const CGAL::Bbox_3& bbox, + const typename K::Line_3& line, + const K& k) +{ + return do_intersect(line, bbox, k); +} } // namespace internal } // namespace Intersections -} //namespace CGAL +} // namespace CGAL -#endif // CGAL_INTERNAL_INTERSECTIONS_3_BBOX_3_LINE_3_DO_INTERSECT_H +#endif // CGAL_INTERNAL_INTERSECTIONS_3_BBOX_3_LINE_3_DO_INTERSECT_H diff --git a/Intersections_3/include/CGAL/Intersections_3/internal/Bbox_3_Line_3_intersection.h b/Intersections_3/include/CGAL/Intersections_3/internal/Bbox_3_Line_3_intersection.h new file mode 100644 index 00000000000..2195a9cd3d4 --- /dev/null +++ b/Intersections_3/include/CGAL/Intersections_3/internal/Bbox_3_Line_3_intersection.h @@ -0,0 +1,67 @@ +// Copyright (c) 1997-2010 +// Utrecht University (The Netherlands), +// ETH Zurich (Switzerland), +// INRIA Sophia-Antipolis (France), +// Max-Planck-Institute Saarbruecken (Germany), +// and Tel-Aviv University (Israel). All rights reserved. +// +// This file is part of CGAL (www.cgal.org) +// +// $URL$ +// $Id$ +// SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-Commercial +// +// +// Author(s) : Geert-Jan Giezeman +// Sebastien Loriot + +#ifndef CGAL_INTERNAL_INTERSECTIONS_3_BBOX_3_LINE_3_INTERSECTION_H +#define CGAL_INTERNAL_INTERSECTIONS_3_BBOX_3_LINE_3_INTERSECTION_H + +#include +#include + +#include +#include + +namespace CGAL { +namespace Intersections { +namespace internal { + +template +typename Intersection_traits::result_type +intersection(const typename K::Line_3& line, + const Bbox_3& box, + const K&) +{ + typedef typename K::Point_3 Point_3; + typedef typename K::Direction_3 Direction_3; + + const Point_3& linepoint = line.point(); + const Direction_3& linedir = line.direction(); + + return intersection_bl(box, + CGAL::to_double(linepoint.x()), + CGAL::to_double(linepoint.y()), + CGAL::to_double(linepoint.z()), + CGAL::to_double(linedir.dx()), + CGAL::to_double(linedir.dy()), + CGAL::to_double(linedir.dz()), + true, true); +} + +template +inline +typename Intersection_traits::result_type +intersection(const Bbox_3& box, + const typename K::Line_3& line, + const K& k) +{ + return intersection(line, box, k); +} + +} // namespace internal +} // namespace Intersections +} // namespace CGAL + +#endif // CGAL_INTERNAL_INTERSECTIONS_3_BBOX_3_LINE_3_INTERSECTION_H diff --git a/Intersections_3/include/CGAL/Intersections_3/internal/Bbox_3_Plane_3_do_intersect.h b/Intersections_3/include/CGAL/Intersections_3/internal/Bbox_3_Plane_3_do_intersect.h index 368fc01b4c0..803d8594e64 100644 --- a/Intersections_3/include/CGAL/Intersections_3/internal/Bbox_3_Plane_3_do_intersect.h +++ b/Intersections_3/include/CGAL/Intersections_3/internal/Bbox_3_Plane_3_do_intersect.h @@ -10,140 +10,35 @@ // // Author(s) : Camille Wormser, Jane Tournois, Pierre Alliez - #ifndef CGAL_INTERNAL_INTERSECTIONS_3_BBOX_3_PLANE_3_DO_INTERSECT_H #define CGAL_INTERNAL_INTERSECTIONS_3_BBOX_3_PLANE_3_DO_INTERSECT_H -#include -#include +#include + #include -// Opcode like - namespace CGAL { - namespace Intersections { - namespace internal { - template - Uncertain get_min_max(const typename K::Vector_3& p, - Box3& bbox, - typename K::Point_3& p_min, - typename K::Point_3& p_max) - { - if(certainly(p.x() > 0)) { - if(certainly(p.y() > 0)) { - if(certainly(p.z() > 0)) { - p_min = typename K::Point_3(bbox.xmin(), bbox.ymin(),bbox.zmin()); - p_max = typename K::Point_3(bbox.xmax(), bbox.ymax(),bbox.zmax()); - return true; - } else if(certainly(p.z() <= 0)) { - p_min = typename K::Point_3(bbox.xmin(), bbox.ymin(),bbox.zmax()); - p_max = typename K::Point_3(bbox.xmax(), bbox.ymax(),bbox.zmin()); - return true; - } - } else if(certainly(p.y() <= 0)) { - if(certainly(p.z() > 0)) { - p_min = typename K::Point_3(bbox.xmin(), bbox.ymax(),bbox.zmin()); - p_max = typename K::Point_3(bbox.xmax(), bbox.ymin(),bbox.zmax()); - return true; - } else if(certainly(p.z() <= 0)) { - p_min = typename K::Point_3(bbox.xmin(), bbox.ymax(),bbox.zmax()); - p_max = typename K::Point_3(bbox.xmax(), bbox.ymin(),bbox.zmin()); - return true; - } - } - } - else if(certainly(p.x() <= 0)) { - if(certainly(p.y() > 0)) { - if(certainly(p.z() > 0)) { - p_min = typename K::Point_3(bbox.xmax(), bbox.ymin(),bbox.zmin()); - p_max = typename K::Point_3(bbox.xmin(), bbox.ymax(),bbox.zmax()); - return true;} - else if(certainly(p.z() <= 0)) { - p_min = typename K::Point_3(bbox.xmax(), bbox.ymin(),bbox.zmax()); - p_max = typename K::Point_3(bbox.xmin(), bbox.ymax(),bbox.zmin()); - return true; - } - } - else if(certainly(p.y() <= 0)) { - if(certainly(p.z() > 0)) { - p_min = typename K::Point_3(bbox.xmax(), bbox.ymax(),bbox.zmin()); - p_max = typename K::Point_3(bbox.xmin(), bbox.ymin(),bbox.zmax()); - return true; - } - else if(certainly(p.z() <= 0)) { - p_min = typename K::Point_3(bbox.xmax(), bbox.ymax(),bbox.zmax()); - p_max = typename K::Point_3(bbox.xmin(), bbox.ymin(),bbox.zmin()); - return true; - } - } - } - return Uncertain::indeterminate(); - } +template +bool do_intersect(const typename K::Plane_3& plane, + const Bbox_3& bbox, + const K& k) +{ + return do_intersect_plane_box(plane, bbox, k); +} - template - bool do_intersect_plane_box(const typename K::Plane_3& plane, - const Box3& bbox, - const K&) - { - typedef typename K::Point_3 Point_3; - Point_3 p_max, p_min; - Uncertain b = get_min_max(plane.orthogonal_vector(), bbox, p_min, p_max); - if(is_certain(b)){ - return ! (plane.oriented_side(p_max) == ON_NEGATIVE_SIDE || - plane.oriented_side(p_min) == ON_POSITIVE_SIDE); - } - CGAL::Oriented_side side = plane.oriented_side(Point_3(bbox.xmin(), bbox.ymin(),bbox.zmin())); - if(side == ON_ORIENTED_BOUNDARY) return true; - CGAL::Oriented_side s = plane.oriented_side(Point_3(bbox.xmax(), bbox.ymax(),bbox.zmax())); - if(s != side) return true; - s = plane.oriented_side(Point_3(bbox.xmin(), bbox.ymin(),bbox.zmax())); - if(s != side) return true; - s = plane.oriented_side(Point_3(bbox.xmax(), bbox.ymax(),bbox.zmin())); - if(s != side) return true; - s = plane.oriented_side(Point_3(bbox.xmin(), bbox.ymax(),bbox.zmin())); - if(s != side) return true; - s = plane.oriented_side(Point_3(bbox.xmax(), bbox.ymin(),bbox.zmax())); - if(s != side) return true; - s = plane.oriented_side(Point_3(bbox.xmin(), bbox.ymax(),bbox.zmax())); - if(s != side) return true; - s = plane.oriented_side(Point_3(bbox.xmax(), bbox.ymin(),bbox.zmin())); - if(s != side) return true; - return false; - } - - template - bool do_intersect(const typename K::Plane_3& plane, - const Bbox_3& bbox, - const K&) { - return do_intersect_plane_box(plane, bbox, K()); - } - - template - bool do_intersect(const typename K::Plane_3& plane, - const typename K::Iso_cuboid_3& bbox, - const K&) { - return do_intersect_plane_box(plane, bbox, K()); - } - - template - bool do_intersect(const Bbox_3& bbox, - const typename K::Plane_3& plane, - const K&) { - return do_intersect_plane_box(plane, bbox, K()); - } - - template - bool do_intersect(const typename K::Iso_cuboid_3& bbox, - const typename K::Plane_3& plane, - const K&) { - return do_intersect_plane_box(plane, bbox, K()); - } +template +bool do_intersect(const Bbox_3& bbox, + const typename K::Plane_3& plane, + const K& k) +{ + return do_intersect_plane_box(plane, bbox, k); +} } // namespace internal } // namespace Intersections -} //namespace CGAL +} // namespace CGAL -#endif // CGAL_INTERNAL_INTERSECTIONS_3_BBOX_3_PLANE_3_DO_INTERSECT_H +#endif // CGAL_INTERNAL_INTERSECTIONS_3_BBOX_3_PLANE_3_DO_INTERSECT_H diff --git a/Intersections_3/include/CGAL/Intersections_3/internal/Bbox_3_Ray_3_do_intersect.h b/Intersections_3/include/CGAL/Intersections_3/internal/Bbox_3_Ray_3_do_intersect.h index 4caa0f1c5cb..36ca263a827 100644 --- a/Intersections_3/include/CGAL/Intersections_3/internal/Bbox_3_Ray_3_do_intersect.h +++ b/Intersections_3/include/CGAL/Intersections_3/internal/Bbox_3_Ray_3_do_intersect.h @@ -14,52 +14,50 @@ #ifndef CGAL_INTERNAL_INTERSECTIONS_3_BBOX_3_RAY_3_DO_INTERSECT_H #define CGAL_INTERNAL_INTERSECTIONS_3_BBOX_3_RAY_3_DO_INTERSECT_H -#include -#include +// inspired from http://cag.csail.mit.edu/~amy/papers/box-jgt.pdf #include // for CGAL::internal::do_intersect_bbox_segment_aux -// inspired from http://cag.csail.mit.edu/~amy/papers/box-jgt.pdf +#include namespace CGAL { - namespace Intersections { - namespace internal { - template - bool do_intersect(const typename K::Ray_3& ray, - const CGAL::Bbox_3& bbox, - const K&) - { - typedef typename K::FT FT; - typedef typename K::Point_3 Point_3; +template +bool do_intersect(const typename K::Ray_3& ray, + const CGAL::Bbox_3& bbox, + const K&) +{ + typedef typename K::FT FT; + typedef typename K::Point_3 Point_3; - const Point_3& source = ray.source(); - const Point_3& point_on_ray = ray.second_point(); + const Point_3& source = ray.source(); + const Point_3& point_on_ray = ray.second_point(); - return do_intersect_bbox_segment_aux - // do not use static filters - ( - source.x(), source.y(), source.z(), - point_on_ray.x(), point_on_ray.y(), point_on_ray.z(), - bbox - ); - } + return do_intersect_bbox_segment_aux + // do not use static filters + ( + source.x(), source.y(), source.z(), + point_on_ray.x(), point_on_ray.y(), point_on_ray.z(), + bbox + ); +} - template - bool do_intersect(const CGAL::Bbox_3& bbox, - const typename K::Ray_3& ray, - const K&) { - return do_intersect(ray, bbox, K()); - } +template +bool do_intersect(const CGAL::Bbox_3& bbox, + const typename K::Ray_3& ray, + const K& k) +{ + return do_intersect(ray, bbox, k); +} } // namespace internal } // namespace Intersections -} //namespace CGAL +} // namespace CGAL -#endif // CGAL_INTERNAL_INTERSECTIONS_3_BBOX_3_RAY_3_DO_INTERSECT_H +#endif // CGAL_INTERNAL_INTERSECTIONS_3_BBOX_3_RAY_3_DO_INTERSECT_H diff --git a/Intersections_3/include/CGAL/Intersections_3/internal/Bbox_3_Ray_3_intersection.h b/Intersections_3/include/CGAL/Intersections_3/internal/Bbox_3_Ray_3_intersection.h new file mode 100644 index 00000000000..89756a9a2f1 --- /dev/null +++ b/Intersections_3/include/CGAL/Intersections_3/internal/Bbox_3_Ray_3_intersection.h @@ -0,0 +1,67 @@ +// Copyright (c) 1997-2010 +// Utrecht University (The Netherlands), +// ETH Zurich (Switzerland), +// INRIA Sophia-Antipolis (France), +// Max-Planck-Institute Saarbruecken (Germany), +// and Tel-Aviv University (Israel). All rights reserved. +// +// This file is part of CGAL (www.cgal.org) +// +// $URL$ +// $Id$ +// SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-Commercial +// +// +// Author(s) : Geert-Jan Giezeman +// Sebastien Loriot + +#ifndef CGAL_INTERNAL_INTERSECTIONS_3_BBOX_3_RAY_3_INTERSECTION_H +#define CGAL_INTERNAL_INTERSECTIONS_3_BBOX_3_RAY_3_INTERSECTION_H + +#include +#include + +#include +#include + +namespace CGAL { +namespace Intersections { +namespace internal { + +template +typename Intersection_traits::result_type +intersection(const typename K::Ray_3& ray, + const Bbox_3& box, + const K&) +{ + typedef typename K::Point_3 Point_3; + typedef typename K::Direction_3 Direction_3; + + const Point_3& linepoint = ray.source(); + const Direction_3& linedir = ray.direction(); + + return intersection_bl(box, + CGAL::to_double(linepoint.x()), + CGAL::to_double(linepoint.y()), + CGAL::to_double(linepoint.z()), + CGAL::to_double(linedir.dx()), + CGAL::to_double(linedir.dy()), + CGAL::to_double(linedir.dz()), + false, true); +} + +template +inline +typename Intersection_traits::result_type +intersection(const Bbox_3& box, + const typename K::Ray_3& ray, + const K& k) +{ + return intersection(ray, box, k); +} + +} // namespace internal +} // namespace Intersections +} // namespace CGAL + +#endif // CGAL_INTERNAL_INTERSECTIONS_3_BBOX_3_RAY_3_INTERSECTION_H diff --git a/Intersections_3/include/CGAL/Intersections_3/internal/Bbox_3_Segment_3_do_intersect.h b/Intersections_3/include/CGAL/Intersections_3/internal/Bbox_3_Segment_3_do_intersect.h index 7e0bd372bae..4b6d802250c 100644 --- a/Intersections_3/include/CGAL/Intersections_3/internal/Bbox_3_Segment_3_do_intersect.h +++ b/Intersections_3/include/CGAL/Intersections_3/internal/Bbox_3_Segment_3_do_intersect.h @@ -10,19 +10,16 @@ // // Author(s) : Laurent Rineau - #ifndef CGAL_INTERNAL_INTERSECTIONS_3_BBOX_3_SEGMENT_3_DO_INTERSECT_H #define CGAL_INTERNAL_INTERSECTIONS_3_BBOX_3_SEGMENT_3_DO_INTERSECT_H -#include - +#include #include #include -#include #include #include -#include -#include +#include + #include // inspired from http://cag.csail.mit.edu/~amy/papers/box-jgt.pdf @@ -37,425 +34,464 @@ // [t1, t2] intersects [0, 1]. namespace CGAL { - namespace Intersections { - namespace internal { - template - struct Do_intersect_bbox_segment_aux_is_greater +template +struct Do_intersect_bbox_segment_aux_is_greater +{ + typedef typename Same_uncertainty::type result_type; + + void register_new_input_values(const FT&, const FT&) {} + void compute_new_error_bound() { } + bool bound_overflow() { return false; } + bool value_might_underflow() { return false; } + + static result_type uncertain() { - typedef typename Same_uncertainty::type result_type; + return true; + } - void register_new_input_values(const FT&, const FT&) {} - void compute_new_error_bound() {} - bool bound_overflow() { return false; } - bool value_might_underflow() { return false; } + result_type operator()(const FT& a, const FT& b) const + { + return a > b; + } +}; - static result_type uncertain() { +template +class Do_intersect_bbox_segment_aux_is_greater +{ + double error; + double tmax; + double dmax; + +public: + CGAL_static_assertion((boost::is_same::value)); + + Do_intersect_bbox_segment_aux_is_greater() : error(0.), tmax(0.), dmax(0.) {} + + void register_new_input_values(const double t, const double d) + { + if(bounded_0) + { + if(t > tmax) + tmax = t; + if(d > dmax) + dmax = d; + } + else + { + const double at = CGAL::abs(t); + const double ad = CGAL::abs(d); + if(at > tmax) + tmax = at; + if(ad > dmax) + dmax = ad; + } + } + + void compute_new_error_bound() + { + const double EPS = 8.8872057372592798e-16; + error = tmax * dmax * EPS; + } + + bool bound_overflow() + { + const double OVERF = 1e153; + return dmax > OVERF || tmax > OVERF; + } + + bool value_might_underflow() + { + const double UNDERF = 1e-146; + return dmax < UNDERF || tmax < UNDERF; + } + + typedef Uncertain result_type; + + static result_type uncertain() + { + return result_type::indeterminate(); + } + + result_type operator()(const FT& a, const FT& b) const + { + const FT x = a - b; + if(x > error) return true; - } + else if(x < -error) + return false; + else + return uncertain(); + } +}; // end specialization Do_intersect_bbox_segment_aux_is_greater - result_type operator()(const FT& a, const FT& b) const { - return a > b; - } - }; // end struct template Do_intersect_bbox_segment_aux_is_greater - - template - class Do_intersect_bbox_segment_aux_is_greater +template +inline +typename Do_intersect_bbox_segment_aux_is_greater::result_type +do_intersect_bbox_segment_aux(const FT& px, const FT& py, const FT& pz, + const FT& qx, const FT& qy, const FT& qz, + const BFT& bxmin, const BFT& bymin, const BFT& bzmin, + const BFT& bxmax, const BFT& bymax, const BFT& bzmax) +{ + if(((px >= bxmin) && (px <= bxmax) && + (py >= bymin) && (py <= bymax) && + (pz >= bzmin) && (pz <= bzmax)) || + ((qx >= bxmin) && (qx <= bxmax) && + (qy >= bymin) && (qy <= bymax) && + (qz >= bzmin) && (qz <= bzmax))) { - double error; - double tmax; - double dmax; + return true; + } - public: - CGAL_static_assertion((boost::is_same::value)); + // The following code encode t1 and t2 by: + // t1 = tmin/dmin + // t2 = tmax/dmax + // For the first lines, dmax==dmin and is not explicitly defined. - Do_intersect_bbox_segment_aux_is_greater() : error(0.), tmax(0.), dmax(0.) {} - - void register_new_input_values(const double& t, const double& d) { - if(bounded_0) { - if(t > tmax) tmax = t; - if(d > dmax) dmax = d; - } else { - const double at = CGAL::abs(t); - const double ad = CGAL::abs(d); - if(at > tmax) tmax = at; - if(ad > dmax) dmax = ad; - } - } - - void compute_new_error_bound() { - const double EPS = 8.8872057372592798e-16; - error = tmax * dmax * EPS; - } - - bool bound_overflow() { - const double OVERF = 1e153; - return dmax > OVERF || tmax > OVERF; - } - - bool value_might_underflow() { - const double UNDERF = 1e-146; - return dmax < UNDERF || tmax < UNDERF; - } - - typedef Uncertain result_type; - - static result_type uncertain() { - return result_type::indeterminate(); - } - - result_type operator()(const FT& a, const FT& b) const { - const FT x = a - b; - if(x > error) return true; - else if(x < -error) return false; - else return uncertain(); - } - - }; // end specialization Do_intersect_bbox_segment_aux_is_greater - - - - template - inline - typename Do_intersect_bbox_segment_aux_is_greater - < - FT, - bounded_0, - use_static_filters - >::result_type - do_intersect_bbox_segment_aux( - const FT& px, const FT& py, const FT& pz, - const FT& qx, const FT& qy, const FT& qz, - const BFT& bxmin, const BFT& bymin, const BFT& bzmin, - const BFT& bxmax, const BFT& bymax, const BFT& bzmax) + // ----------------------------------- + // treat x coord + // ----------------------------------- + typedef typename Coercion_traits::Type CFT; + CFT dmin, tmin, tmax, dmax; + if(qx >= px) { - if( ( (px >= bxmin) && (px <= bxmax) && - (py >= bymin) && (py <= bymax) && - (pz >= bzmin) && (pz <= bzmax) ) || - ( (qx >= bxmin) && (qx <= bxmax) && - (qy >= bymin) && (qy <= bymax) && - (qz >= bzmin) && (qz <= bzmax) ) ) { - return true; - } + if(bounded_0 && px > bxmax) + return false; // segment on the right of bbox + if(bounded_1 && qx < bxmin) + return false; // segment on the left of bbox - // The following code encode t1 and t2 by: - // t1 = tmin/dmin - // t2 = tmax/dmax - // For the first lines, dmax==dmin and is not explicitly defined. - - // ----------------------------------- - // treat x coord - // ----------------------------------- - typedef typename Coercion_traits::Type CFT; - CFT dmin, tmin, tmax, dmax; - if ( qx >= px ) + if(bounded_1 && bxmax > qx) { - if(bounded_0 && px > bxmax) return false; // segment on the right of bbox - if(bounded_1 && qx < bxmin) return false; // segment on the left of bbox - - if(bounded_1 && bxmax > qx) { - tmax = 1; - dmax = 1; - } else { - tmax = bxmax - px; - dmax = qx - px; - } - - tmin = bxmin - px; - dmin = qx - px; + tmax = 1; + dmax = 1; } else { - if(bounded_1 && qx > bxmax) return false; // segment on the right of bbox - if(bounded_0 && px < bxmin) return false; // segment on the left of bbox - - if(bounded_1 && bxmin < qx) { - tmax = 1; - dmax = 1; - } else { - tmax = px - bxmin; - dmax = px - qx; - } - - tmin = px - bxmax; - dmin = px - qx; + tmax = bxmax - px; + dmax = qx - px; } - if(bounded_0) tmin = (CGAL::max)(CFT(0), tmin); + tmin = bxmin - px; + dmin = qx - px; + } + else + { + if(bounded_1 && qx > bxmax) + return false; // segment on the right of bbox + if(bounded_0 && px < bxmin) + return false; // segment on the left of bbox - // If the query is vertical for x, then check its x-coordinate is in - // the x-slab. - if( (px == qx) && // <=> (dmin == 0) - (! (bounded_0 && bounded_1) ) ) // do not check for a segment + if(bounded_1 && bxmin < qx) { - if(px > bxmax || px < bxmin) return false; - // Note: for a segment the condition has already been tested by the two - // previous tests tmax<0 || tmin>dmin (with dmin==0). - } - - // If dmin == 0, at this point, [t1, t2] == ]-inf, +inf[, or t1 or t2 - // is a NaN. But the case with NaNs is treated as if the interval - // [t1, t2] was ]-inf, +inf[. - - CGAL_assertion(dmin >= 0); - CGAL_assertion(dmax >= 0); - if(bounded_0) { - CGAL_assertion(tmin >= 0); - CGAL_assertion(tmax >= 0); - } - - - // ----------------------------------- - // treat y coord - // ----------------------------------- - CFT dymin, tymin, tymax, dymax; - if ( qy >= py ) - { - if(bounded_0 && py > bymax) return false; // segment on the right of bbox - if(bounded_1 && qy < bymin) return false; // segment on the left of bbox - - if(bounded_1 && bymax > qy) { - tymax = 1; - dymax = 1; - } else { - tymax = bymax - py; - dymax = qy - py; - } - - tymin = bymin - py; - dymin = qy - py; + tmax = 1; + dmax = 1; } else { - if(bounded_1 && qy > bymax) return false; // segment on the right of bbox - if(bounded_0 && py < bymin) return false; // segment on the left of bbox - - if(bounded_1 && bymin < qy) { - tymax = 1; - dymax = 1; - } else { - tymax = py - bymin; - dymax = py - qy; - } - - tymin = py - bymax; - dymin = py - qy; + tmax = px - bxmin; + dmax = px - qx; } - if(bounded_0) tymin = (CGAL::max)(CFT(0), tymin); + tmin = px - bxmax; + dmin = px - qx; + } - // If the query is vertical for y, then check its y-coordinate is in - // the y-slab. - if( (py == qy) && // <=> (dmin == 0) - (! (bounded_0 && bounded_1) ) ) // do not check for a segment + if(bounded_0) + tmin = (CGAL::max)(CFT(0), tmin); + + // If the query is vertical for x, then check its x-coordinate is in + // the x-slab. + if((px == qx) && // <=> (dmin == 0) + (! (bounded_0 && bounded_1))) // do not check for a segment + { + if(px > bxmax || px < bxmin) + return false; + + // Note: for a segment the condition has already been tested by the two + // previous tests tmax<0 || tmin>dmin (with dmin==0). + } + + // If dmin == 0, at this point, [t1, t2] == ]-inf, +inf[, or t1 or t2 + // is a NaN. But the case with NaNs is treated as if the interval + // [t1, t2] was ]-inf, +inf[. + + CGAL_assertion(dmin >= 0); + CGAL_assertion(dmax >= 0); + if(bounded_0) { + CGAL_assertion(tmin >= 0); + CGAL_assertion(tmax >= 0); + } + + // ----------------------------------- + // treat y coord + // ----------------------------------- + CFT dymin, tymin, tymax, dymax; + if(qy >= py) + { + if(bounded_0 && py > bymax) + return false; // segment on the right of bbox + if(bounded_1 && qy < bymin) + return false; // segment on the left of bbox + + if(bounded_1 && bymax > qy) { - if(py > bymax || py < bymin) return false; - } - - // If dmin == 0, at this point, [t1, t2] == ]-inf, +inf[, or t1 or t2 - // is a NaN. But the case with NaNs is treated as if the interval - // [t1, t2] was ]-inf, +inf[. - - CGAL_assertion(dymin >= 0); - CGAL_assertion(dymax >= 0); - if(bounded_0) { - CGAL_assertion(tymin >= 0); - CGAL_assertion(tymax >= 0); - } - - - // ----------------------------------- - // treat z coord - // ----------------------------------- - CFT dzmin, tzmin, tzmax, dzmax; - if ( qz >= pz ) - { - if(bounded_0 && pz > bzmax) return false; // segment on the right of bbox - if(bounded_1 && qz < bzmin) return false; // segment on the left of bbox - - if(bounded_1 && bzmax > qz) { - tzmax = 1; - dzmax = 1; - } else { - tzmax = bzmax - pz; - dzmax = qz - pz; - } - - tzmin = bzmin - pz; - dzmin = qz - pz; + tymax = 1; + dymax = 1; } else { - if(bounded_1 && qz > bzmax) return false; // segment on the right of bbox - if(bounded_0 && pz < bzmin) return false; // segment on the left of bbox - - if(bounded_1 && bzmin < qz) { - tzmax = 1; - dzmax = 1; - } else { - tzmax = pz - bzmin; - dzmax = pz - qz; - } - - tzmin = pz - bzmax; - dzmin = pz - qz; + tymax = bymax - py; + dymax = qy - py; } - if(bounded_0) tzmin = (CGAL::max)(CFT(0), tzmin); + tymin = bymin - py; + dymin = qy - py; + } + else + { + if(bounded_1 && qy > bymax) + return false; // segment on the right of bbox + if(bounded_0 && py < bymin) + return false; // segment on the left of bbox - // If the query is vertical for z, then check its z-coordinate is in - // the z-slab. - if( (pz == qz) && // <=> (dmin == 0) - (! (bounded_0 && bounded_1) ) ) // do not check for a segment + if(bounded_1 && bymin < qy) { - if(pz > bzmax || pz < bzmin) return false; + tymax = 1; + dymax = 1; + } + else + { + tymax = py - bymin; + dymax = py - qy; } - // If dmin == 0, at this point, [t1, t2] == ]-inf, +inf[, or t1 or t2 - // is a NaN. But the case with NaNs is treated as if the interval - // [t1, t2] was ]-inf, +inf[. + tymin = py - bymax; + dymin = py - qy; + } - CGAL_assertion(dzmin >= 0); - CGAL_assertion(dzmax >= 0); - if(bounded_0) { - CGAL_assertion(tzmin >= 0); - CGAL_assertion(tzmax >= 0); + if(bounded_0) + tymin = (CGAL::max)(CFT(0), tymin); + + // If the query is vertical for y, then check its y-coordinate is in + // the y-slab. + if((py == qy) && // <=> (dmin == 0) + (! (bounded_0 && bounded_1))) // do not check for a segment + { + if(py > bymax || py < bymin) + return false; + } + + // If dmin == 0, at this point, [t1, t2] == ]-inf, +inf[, or t1 or t2 + // is a NaN. But the case with NaNs is treated as if the interval + // [t1, t2] was ]-inf, +inf[. + + CGAL_assertion(dymin >= 0); + CGAL_assertion(dymax >= 0); + if(bounded_0) + { + CGAL_assertion(tymin >= 0); + CGAL_assertion(tymax >= 0); + } + + // ----------------------------------- + // treat z coord + // ----------------------------------- + CFT dzmin, tzmin, tzmax, dzmax; + if(qz >= pz) + { + if(bounded_0 && pz > bzmax) + return false; // segment on the right of bbox + if(bounded_1 && qz < bzmin) + return false; // segment on the left of bbox + + if(bounded_1 && bzmax > qz) + { + tzmax = 1; + dzmax = 1; + } + else + { + tzmax = bzmax - pz; + dzmax = qz - pz; } + tzmin = bzmin - pz; + dzmin = qz - pz; + } + else + { + if(bounded_1 && qz > bzmax) + return false; // segment on the right of bbox + if(bounded_0 && pz < bzmin) + return false; // segment on the left of bbox - typedef Do_intersect_bbox_segment_aux_is_greater - Is_greater; - typedef typename Is_greater::result_type Is_greater_value; - Is_greater is_greater; + if(bounded_1 && bzmin < qz) + { + tzmax = 1; + dzmax = 1; + } + else + { + tzmax = pz - bzmin; + dzmax = pz - qz; + } - is_greater.register_new_input_values(tmin, dmin); - is_greater.register_new_input_values(tymin, dymin); - is_greater.register_new_input_values(tmax, dmax); - is_greater.register_new_input_values(tymax, dymax); + tzmin = pz - bzmax; + dzmin = pz - qz; + } + + if(bounded_0) + tzmin = (CGAL::max)(CFT(0), tzmin); + + // If the query is vertical for z, then check its z-coordinate is in + // the z-slab. + if((pz == qz) && // <=> (dmin == 0) + (! (bounded_0 && bounded_1))) // do not check for a segment + { + if(pz > bzmax || pz < bzmin) + return false; + } + + // If dmin == 0, at this point, [t1, t2] == ]-inf, +inf[, or t1 or t2 + // is a NaN. But the case with NaNs is treated as if the interval + // [t1, t2] was ]-inf, +inf[. + + CGAL_assertion(dzmin >= 0); + CGAL_assertion(dzmax >= 0); + if(bounded_0) + { + CGAL_assertion(tzmin >= 0); + CGAL_assertion(tzmax >= 0); + } + + typedef Do_intersect_bbox_segment_aux_is_greater Is_greater; + typedef typename Is_greater::result_type Is_greater_value; + Is_greater is_greater; + + is_greater.register_new_input_values(tmin, dmin); + is_greater.register_new_input_values(tymin, dymin); + is_greater.register_new_input_values(tmax, dmax); + is_greater.register_new_input_values(tymax, dymax); + + is_greater.compute_new_error_bound(); + if(is_greater.bound_overflow() || is_greater.value_might_underflow()) + return Is_greater::uncertain(); + + // If t1 > tymax/dymax || tymin/dymin > t2, return false. + if( py != qy && px != qx) // dmin > 0, dymax >0, dmax > 0, dymin > 0 + { + const Is_greater_value b1 = is_greater(dymax* tmin, dmin*tymax); + if(possibly(b1)) + return !b1; // if(is_greater) return false; // or uncertain + + const Is_greater_value b2 = is_greater( dmax*tymin, dymin* tmax); + if(possibly(b2)) + return !b2; + } + + Is_greater_value b = Is_greater_value(); + // If tymin/dymin > t1, set t1 = tymin/dymin. + if((px == qx) || // <=> (dmin == 0) + ((py != qy) && // <=> (dymin > 0) + certainly(b = is_greater( dmin*tymin, dymin* tmin)))) + { + tmin = tymin; + dmin = dymin; + } + + if(is_indeterminate(b)) + return b; // Note that the default-constructed + + // Is_greater_value cannot be + // indeterminate. + + // If tymax/dymax < t2, set t2 = tymax/dymax. + if((px == qx) || // <=> (dmax > 0) + ((py != qy) && // <=> dymax > 0 + certainly(b = is_greater(dymax* tmax, dmax*tymax)))) + { + tmax = tymax; + dmax = dymax; + } + + if(is_indeterminate(b)) + return b; + + CGAL_assertion(dmin >= 0); + CGAL_assertion(dmax >= 0); + + // If t1 > tzmax || tzmin > t2, return false. + if((px != qx || py != qy) && + (pz != qz)) // dmin > 0, dmax > 0, dzmax > 0, dzmin > 0 + { + is_greater.register_new_input_values(tzmin, dzmin); + is_greater.register_new_input_values(tzmax, dzmax); is_greater.compute_new_error_bound(); if(is_greater.bound_overflow() || is_greater.value_might_underflow()) return Is_greater::uncertain(); - // If t1 > tymax/dymax || tymin/dymin > t2, return false. - if( py != qy && px != qx ) { // dmin > 0, dymax >0, dmax > 0, dymin > 0 - const Is_greater_value b1 = is_greater(dymax* tmin, dmin*tymax); - if(possibly(b1)) return !b1; // if(is_greater) return false; // or uncertain - const Is_greater_value b2 = is_greater( dmax*tymin, dymin* tmax); - if(possibly(b2)) return !b2; - } + const Is_greater_value b1 = is_greater(dzmax* tmin, dmin*tzmax); + if(possibly(b1)) + return !b1; // if(is_greater) return false; // or uncertain - Is_greater_value b = Is_greater_value(); - // If tymin/dymin > t1, set t1 = tymin/dymin. - if( (px == qx) || // <=> (dmin == 0) - ( (py != qy) && // <=> (dymin > 0) - certainly(b = is_greater( dmin*tymin, dymin* tmin)) ) ) - { - tmin = tymin; - dmin = dymin; - } - if(is_indeterminate(b)) return b; // Note that the default-constructed - // Is_greater_value cannot be - // indeterminate. - - // If tymax/dymax < t2, set t2 = tymax/dymax. - if( (px == qx) || // <=> (dmax > 0) - ( (py != qy) && // <=> dymax > 0 - certainly(b = is_greater(dymax* tmax, dmax*tymax)) ) ) - { - tmax = tymax; - dmax = dymax; - } - if(is_indeterminate(b)) return b; - - CGAL_assertion(dmin >= 0); - CGAL_assertion(dmax >= 0); - - // If t1 > tzmax || tzmin > t2, return false. - if( (px != qx || - py != qy ) && - (pz != qz) ) // dmin > 0, dmax > 0, dzmax > 0, dzmin > 0 - { - is_greater.register_new_input_values(tzmin, dzmin); - is_greater.register_new_input_values(tzmax, dzmax); - - is_greater.compute_new_error_bound(); - if(is_greater.bound_overflow() || is_greater.value_might_underflow()) - return Is_greater::uncertain(); - - const Is_greater_value b1 = is_greater(dzmax* tmin, dmin*tzmax); - if(possibly(b1)) return !b1; // if(is_greater) return false; // or uncertain - const Is_greater_value b2 = is_greater( dmax*tzmin, dzmin* tmax); - if(possibly(b2)) return !b2; // if(is_greater) return false; // or uncertain - } - return true; + const Is_greater_value b2 = is_greater( dmax*tzmin, dzmin* tmax); + if(possibly(b2)) + return !b2; // if(is_greater) return false; // or uncertain } + return true; +} +template +inline +typename Do_intersect_bbox_segment_aux_is_greater::result_type +do_intersect_bbox_segment_aux( + const FT& px, const FT& py, const FT& pz, + const FT& qx, const FT& qy, const FT& qz, + const Bbox_3& bb) - template - inline - typename Do_intersect_bbox_segment_aux_is_greater - < - FT, - bounded_0, - use_static_filters - >::result_type - do_intersect_bbox_segment_aux( - const FT& px, const FT& py, const FT& pz, - const FT& qx, const FT& qy, const FT& qz, - const Bbox_3& bb) +{ + return do_intersect_bbox_segment_aux(px, py, pz, + qx, qy, qz, + bb.xmin(), bb.ymin(), bb.zmin(), + bb.xmax(), bb.ymax(), bb.zmax()); +} - { - return do_intersect_bbox_segment_aux(px, py, pz, - qx, qy, qz, - bb.xmin(), bb.ymin(), bb.zmin(), - bb.xmax(), bb.ymax(), bb.zmax()); - } +template +bool do_intersect(const typename K::Segment_3& segment, + const CGAL::Bbox_3& bbox, + const K&) +{ + typedef typename K::FT FT; + typedef typename K::Point_3 Point_3; + const Point_3& source = segment.source(); + const Point_3& target = segment.target(); + return do_intersect_bbox_segment_aux(source.x(), source.y(), source.z(), + target.x(), target.y(), target.z(), + bbox); +} - - template - bool do_intersect(const typename K::Segment_3& segment, - const CGAL::Bbox_3& bbox, - const K&) - { - typedef typename K::FT FT; - typedef typename K::Point_3 Point_3; - - const Point_3& source = segment.source(); - const Point_3& target = segment.target(); - - return do_intersect_bbox_segment_aux( - source.x(), source.y(), source.z(), - target.x(), target.y(), target.z(), - bbox); - } - - template - bool do_intersect(const CGAL::Bbox_3& bbox, - const typename K::Segment_3& segment, - const K& k) - { - return do_intersect(segment, bbox, k); - } +template +bool do_intersect(const CGAL::Bbox_3& bbox, + const typename K::Segment_3& segment, + const K& k) +{ + return do_intersect(segment, bbox, k); +} } // namespace internal } // namespace Intersections -} //namespace CGAL +} // namespace CGAL -#include - -#endif // CGAL_INTERNAL_INTERSECTIONS_3_BBOX_3_SEGMENT_3_DO_INTERSECT_H +#endif // CGAL_INTERNAL_INTERSECTIONS_3_BBOX_3_SEGMENT_3_DO_INTERSECT_H diff --git a/Intersections_3/include/CGAL/Intersections_3/internal/Bbox_3_Segment_3_intersection.h b/Intersections_3/include/CGAL/Intersections_3/internal/Bbox_3_Segment_3_intersection.h new file mode 100644 index 00000000000..a82d17dd759 --- /dev/null +++ b/Intersections_3/include/CGAL/Intersections_3/internal/Bbox_3_Segment_3_intersection.h @@ -0,0 +1,209 @@ +// Copyright (c) 1997-2010 +// Utrecht University (The Netherlands), +// ETH Zurich (Switzerland), +// INRIA Sophia-Antipolis (France), +// Max-Planck-Institute Saarbruecken (Germany), +// and Tel-Aviv University (Israel). All rights reserved. +// +// This file is part of CGAL (www.cgal.org) +// +// $URL$ +// $Id$ +// SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-Commercial +// +// +// Author(s) : Michael.Hemmer@sophia.inria.fr + +#ifndef CGAL_INTERNAL_INTERSECTIONS_3_BBOX_3_SEGMENT_3_INTERSECTION_H +#define CGAL_INTERNAL_INTERSECTIONS_3_BBOX_3_SEGMENT_3_INTERSECTION_H + +#include + +#include +#include + +#include +#include + +namespace CGAL { +namespace Intersections { +namespace internal { + +// This function intersects a bbox with a ray, line or segment +// Its essentially a copy of the function that was in Bbox_3_intersections.cpp +// But it must be a template function since the original kernel must be +// taken into account. +template +typename boost::optional< boost::variant > +intersection_bl(const Bbox_3& box, + double lpx, double lpy, double lpz, + double ldx, double ldy, double ldz, + bool min_infinite, bool max_infinite) +{ + typedef typename K::FT FT; + typedef typename K::Point_3 Point_3; + typedef typename K::Vector_3 Vector_3; + typedef typename K::Segment_3 Segment_3; + + typedef typename boost::optional > result_type; + + double seg_min = 0.0, seg_max = 1.0; + // first on x value + if(ldx == 0.0) { + if(lpx < box.xmin()) + return result_type(); + if(lpx > box.xmax()) + return result_type(); + } else { + double newmin, newmax; + if(ldx > 0.0) { + newmin = (box.xmin()-lpx)/ldx; + newmax = (box.xmax()-lpx)/ldx; + } else { + newmin = (box.xmax()-lpx)/ldx; + newmax = (box.xmin()-lpx)/ldx; + } + + if(min_infinite) { + min_infinite = false; + seg_min = newmin; + } else { + if(newmin > seg_min) + seg_min = newmin; + } + + if(max_infinite) { + max_infinite = false; + seg_max = newmax; + } else { + if(newmax < seg_max) + seg_max = newmax; + } + + if(seg_max < seg_min) + return result_type(); + } + + // now on y value + if(ldy == 0.0) { + if(lpy < box.ymin()) + return result_type(); + if(lpy > box.ymax()) + return result_type(); + } else { + double newmin, newmax; + if(ldy > 0.0) { + newmin = (box.ymin()-lpy)/ldy; + newmax = (box.ymax()-lpy)/ldy; + } else { + newmin = (box.ymax()-lpy)/ldy; + newmax = (box.ymin()-lpy)/ldy; + } + + if(min_infinite) { + min_infinite = false; + seg_min = newmin; + } else { + if(newmin > seg_min) + seg_min = newmin; + } + + if(max_infinite) { + max_infinite = false; + seg_max = newmax; + } else { + if(newmax < seg_max) + seg_max = newmax; + } + + if(seg_max < seg_min) + return result_type(); + } + + // now on z value + if(ldz == 0.0) { + if(lpz < box.zmin()) + return result_type(); + if(lpz > box.zmax()) + return result_type(); + } else { + double newmin, newmax; + if(ldz > 0.0) { + newmin = (box.zmin()-lpz)/ldz; + newmax = (box.zmax()-lpz)/ldz; + } else { + newmin = (box.zmax()-lpz)/ldz; + newmax = (box.zmin()-lpz)/ldz; + } + + if(min_infinite) { + min_infinite = false; + seg_min = newmin; + } else { + if(newmin > seg_min) + seg_min = newmin; + } + + if(max_infinite) { + max_infinite = false; + seg_max = newmax; + } else { + if(newmax < seg_max) + seg_max = newmax; + } + + if(seg_max < seg_min) + return result_type(); + } + + if(min_infinite || max_infinite) { + seg_max = 0.0; + CGAL_kernel_assertion_msg(true, "Zero direction vector of line detected."); + } + + Point_3 ref_point{FT(lpx), FT(lpy), FT(lpz)}; + Vector_3 dir{FT(ldx), FT(ldy), FT(ldz)}; + + if(seg_max == seg_min) + return result_type(ref_point + dir * FT(seg_max)); + + return result_type(Segment_3{ref_point + dir*FT(seg_min), ref_point + dir*FT(seg_max)}); +} + +template +typename Intersection_traits::result_type +intersection(const typename K::Segment_3& seg, + const Bbox_3& box, + const K&) +{ + typedef typename K::Point_3 Point_3; + typedef typename K::Vector_3 Vector_3; + + const Point_3& linepoint = seg.source(); + const Vector_3& diffvec = seg.target() - linepoint; + + return intersection_bl(box, + CGAL::to_double(linepoint.x()), + CGAL::to_double(linepoint.y()), + CGAL::to_double(linepoint.z()), + CGAL::to_double(diffvec.x()), + CGAL::to_double(diffvec.y()), + CGAL::to_double(diffvec.z()), + false, false); +} + +template +inline +typename Intersection_traits::result_type +intersection(const Bbox_3& box, + const typename K::Segment_3& seg, + const K& k) +{ + return intersection(seg, box, k); +} + +} // namespace internal +} // namespace Intersections +} // namespace CGAL + +#endif // CGAL_INTERNAL_INTERSECTIONS_3_BBOX_3_SEGMENT_3_INTERSECTION_H diff --git a/Intersections_3/include/CGAL/Intersections_3/internal/Bbox_3_Sphere_3_do_intersect.h b/Intersections_3/include/CGAL/Intersections_3/internal/Bbox_3_Sphere_3_do_intersect.h index 7f74ddf1c8e..c4f9b9cb783 100644 --- a/Intersections_3/include/CGAL/Intersections_3/internal/Bbox_3_Sphere_3_do_intersect.h +++ b/Intersections_3/include/CGAL/Intersections_3/internal/Bbox_3_Sphere_3_do_intersect.h @@ -14,138 +14,33 @@ #ifndef CGAL_INTERNAL_INTERSECTIONS_3_BBOX_3_SPHERE_3_DO_INTERSECT_H #define CGAL_INTERNAL_INTERSECTIONS_3_BBOX_3_SPHERE_3_DO_INTERSECT_H -#include +#include + #include -#include - - namespace CGAL { - namespace Intersections { - namespace internal { - template - bool do_intersect_sphere_box_3(const typename K::Sphere_3& sphere, - const Box3& bbox, - const K&) - { - typedef typename K::FT FT; - typedef typename K::Point_3 Point; - FT d = FT(0); - FT distance = FT(0); - FT sr = sphere.squared_radius(); - - Point center = sphere.center(); - - if(center.x() < (FT)bbox.xmin()) - { - d = (FT)bbox.xmin() - center.x(); - d = square(d); - if(certainly(d > sr)){ - return false; - } - distance = d; - } - else if(center.x() > (FT)bbox.xmax()) - { - d = center.x() - (FT)bbox.xmax(); - d = square(d); - if(certainly(d > sr)){ - return false; - } - distance = d; - } - - if(center.y() < (FT)bbox.ymin()) - { - d = (FT)bbox.ymin() - center.y(); - d = square(d); - if(certainly(d > sr)){ - return false; - } - distance += d ; - } - else if(center.y() > (FT)bbox.ymax()) - { - d = center.y() - (FT)bbox.ymax(); - d = square(d); - if(certainly(d > sr)){ - return false; - } - distance += d; - } - - if(center.z() < (FT)bbox.zmin()) - { - d = (FT)bbox.zmin() - center.z(); - d = square(d); - distance += d; - } - else if(center.z() > (FT)bbox.zmax()) - { - d = center.z() - (FT)bbox.zmax(); - d = square(d); - distance += d; - } - - // For unknown reason this causes a syntax error on VC2005 - // but compiles fine on Linux and MAC - //int i; - //for(i = 0; i < 3; ++i) - //{ - // if(center[i] < (FT)bbox.min(i)) - // { - // d = (FT)bbox.min(i) - center[i]; - // distance += d * d; - // } - // else if(center[i] > (FT)bbox.max(i)) - // { - // d = center[i] - (FT)bbox.max(i); - // distance += d * d; - // } - //} - - return distance <= sr; - } - - template - bool do_intersect(const CGAL::Bbox_3& bbox, - const typename K::Sphere_3& sphere, - const K&) - { - return do_intersect_sphere_box_3(sphere, bbox, K()); - } +template +bool do_intersect(const CGAL::Bbox_3& bbox, + const typename K::Sphere_3& sphere, + const K& k) +{ + return do_intersect_sphere_box_3(sphere, bbox, k); +} - template - bool do_intersect(const typename K::Sphere_3& sphere, - const CGAL::Bbox_3& bbox, - const K&) - { - return do_intersect_sphere_box_3(sphere, bbox, K()); - } - - template - bool do_intersect(const typename K::Iso_cuboid_3& bbox, - const typename K::Sphere_3& sphere, - const K&) - { - return do_intersect_sphere_box_3(sphere, bbox, K()); - } - - - template - bool do_intersect(const typename K::Sphere_3& sphere, - const typename K::Iso_cuboid_3& bbox, - const K&) - { - return do_intersect_sphere_box_3(sphere, bbox, K()); - } +template +bool do_intersect(const typename K::Sphere_3& sphere, + const CGAL::Bbox_3& bbox, + const K& k) +{ + return do_intersect_sphere_box_3(sphere, bbox, k); +} } // namespace internal } // namespace Intersections -} //namespace CGAL +} // namespace CGAL -#endif // CGAL_INTERNAL_INTERSECTIONS_3_BBOX_3_SPHERE_3_DO_INTERSECT_H +#endif // CGAL_INTERNAL_INTERSECTIONS_3_BBOX_3_SPHERE_3_DO_INTERSECT_H diff --git a/Intersections_3/include/CGAL/Intersections_3/internal/Bbox_3_Tetrahedron_3_do_intersect.h b/Intersections_3/include/CGAL/Intersections_3/internal/Bbox_3_Tetrahedron_3_do_intersect.h new file mode 100644 index 00000000000..9be2c0ccef6 --- /dev/null +++ b/Intersections_3/include/CGAL/Intersections_3/internal/Bbox_3_Tetrahedron_3_do_intersect.h @@ -0,0 +1,71 @@ +// Copyright (c) 2008 INRIA Sophia-Antipolis (France), ETH Zurich (Switzerland). +// Copyright (c) 2010, 2014 GeometryFactory Sarl (France). +// All rights reserved. +// +// This file is part of CGAL (www.cgal.org) +// +// $URL$ +// $Id$ +// SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-Commercial +// +// +// Author(s) : Michael Hemmer + +#ifndef CGAL_INTERNAL_INTERSECTIONS_3_BBOX_3_TETRAHEDRON_3_DO_INTERSECT_H +#define CGAL_INTERNAL_INTERSECTIONS_3_BBOX_3_TETRAHEDRON_3_DO_INTERSECT_H + +#include + +#include +#include + +namespace CGAL { +namespace Intersections { +namespace internal { + +template +inline typename K::Boolean do_intersect(const CGAL::Bbox_3& aabb, + const typename K::Tetrahedron_3& tet, + const K& k) +{ + typename K::Construct_triangle_3 tr = k.construct_triangle_3_object(); + typename K::Boolean result = false; + typename K::Boolean b = false; + + b = do_intersect(aabb, tr(tet[0], tet[1], tet[2]), k); + if(certainly(b)) return b; + if(is_indeterminate(b)) result = b; + + b = do_intersect(aabb, tr(tet[1], tet[2], tet[3]), k); + if(certainly(b)) return b; + if(is_indeterminate(b)) result = b; + + b = do_intersect(aabb, tr(tet[2], tet[3], tet[0]), k); + if(certainly(b)) return b; + if(is_indeterminate(b)) result = b; + + b = do_intersect(aabb, tr(tet[3], tet[0], tet[1]), k); + if(certainly(b)) return b; + if(is_indeterminate(b)) result = b; + + b = k.has_on_bounded_side_3_object()( + tet, k.construct_point_3_object()(aabb.xmin(), aabb.ymin(), aabb.zmin())); + if(certainly(b)) return b; + if(is_indeterminate(b)) result = b; + + return result; +} + +template +inline typename K::Boolean do_intersect(const typename K::Tetrahedron_3& tet, + const CGAL::Bbox_3& bb, + const K &k) +{ + return do_intersect(bb, tet, k); +} + +} // namespace internal +} // namespace Intersections +} // namespace CGAL + +#endif // CGAL_INTERNAL_INTERSECTIONS_3_BBOX_3_TETRAHEDRON_3_DO_INTERSECT_H diff --git a/Intersections_3/include/CGAL/Intersections_3/internal/Bbox_3_Triangle_3_do_intersect.h b/Intersections_3/include/CGAL/Intersections_3/internal/Bbox_3_Triangle_3_do_intersect.h index a46ee15c7eb..ea709e2c9c3 100644 --- a/Intersections_3/include/CGAL/Intersections_3/internal/Bbox_3_Triangle_3_do_intersect.h +++ b/Intersections_3/include/CGAL/Intersections_3/internal/Bbox_3_Triangle_3_do_intersect.h @@ -14,188 +14,190 @@ #ifndef CGAL_INTERNAL_INTERSECTIONS_3_BBOX_3_TRIANGLE_3_DO_INTERSECT_H #define CGAL_INTERNAL_INTERSECTIONS_3_BBOX_3_TRIANGLE_3_DO_INTERSECT_H -#include -#include - -#include - // Fast Triangle-Cuboid intersection test, following Tomas Akenine-Moeller description. // The code looks slightly different from his code because we avoid the translation at -// a minimal cost (and we use C++ ;). +// a minimal cost (and we use C++;). -#include #include +#include +#include + namespace CGAL { - namespace Intersections { - namespace internal { - template - inline - bool do_bbox_intersect(const typename K::Triangle_3& triangle, - const Box3& bbox) - { - const typename K::Point_3& p = triangle.vertex(0); - const typename K::Point_3& q = triangle.vertex(1); - const typename K::Point_3& r = triangle.vertex(2); +template +inline +bool do_bbox_intersect(const typename K::Triangle_3& triangle, + const Box3& bbox) +{ + const typename K::Point_3& p = triangle.vertex(0); + const typename K::Point_3& q = triangle.vertex(1); + const typename K::Point_3& r = triangle.vertex(2); - for(int i = 0; i < 3; ++i) { - if(p[i] <= q[i]) { - if(q[i] <= r[i]) { // pqr - if((bbox.max_coord(i) < p[i]) || (bbox.min_coord(i) > r[i])) - return false; - } - else { - if(p[i] <= r[i]) { // prq - if(bbox.max_coord(i) < p[i] || bbox.min_coord(i) > q[i]) - return false; - } - else { // rpq - if(bbox.max_coord(i) < r[i] || bbox.min_coord(i) > q[i]) - return false; - } - } + for(int i = 0; i < 3; ++i) { + if(p[i] <= q[i]) { + if(q[i] <= r[i]) { // pqr + if((bbox.max_coord(i) < p[i]) || (bbox.min_coord(i) > r[i])) + return false; } else { - if(p[i] <= r[i]) { // qpr - if(bbox.max_coord(i) < q[i] || bbox.min_coord(i) > r[i]) + if(p[i] <= r[i]) { // prq + if(bbox.max_coord(i) < p[i] || bbox.min_coord(i) > q[i]) return false; } - else { - if(q[i] <= r[i]) { // qrp - if(bbox.max_coord(i) < q[i] || bbox.min_coord(i) > p[i]) - return false; - } - else { // rqp - if(bbox.max_coord(i) < r[i] || bbox.min_coord(i) > p[i]) - return false; - } - } - } - } - return true; - } - - // AXE is the axe such that p is orthogonal to it. - // if you do not know it, or if it does not exist, - // use get_min_max without the AXE template parameter - // available in _plane_is_cuboid_do_intersect.h - template - inline - void get_min_max(const typename K::FT& px, - const typename K::FT& py, - const typename K::FT& pz, - const Box3& c, - typename K::Point_3& p_min, - typename K::Point_3& p_max) - { - CGAL_USE(px); - CGAL_USE(py); - CGAL_USE(pz); - if(AXE == 0 || px > 0) { - if(AXE == 1 || py > 0) { - if(AXE == 2 || pz > 0) { - p_min = typename K::Point_3(c.xmin(), c.ymin(),c.zmin()); - p_max = typename K::Point_3(c.xmax(), c.ymax(),c.zmax()); - } - else { - p_min = typename K::Point_3(c.xmin(), c.ymin(),c.zmax()); - p_max = typename K::Point_3(c.xmax(), c.ymax(),c.zmin()); - } - } - else { - if(AXE == 2 || pz > 0) { - p_min = typename K::Point_3(c.xmin(), c.ymax(),c.zmin()); - p_max = typename K::Point_3(c.xmax(), c.ymin(),c.zmax()); - } - else { - p_min = typename K::Point_3(c.xmin(), c.ymax(),c.zmax()); - p_max = typename K::Point_3(c.xmax(), c.ymin(),c.zmin()); + else { // rpq + if(bbox.max_coord(i) < r[i] || bbox.min_coord(i) > q[i]) + return false; } } } else { - if(AXE == 1 || py > 0) { - if(AXE == 2 || pz > 0) { - p_min = typename K::Point_3(c.xmax(), c.ymin(),c.zmin()); - p_max = typename K::Point_3(c.xmin(), c.ymax(),c.zmax()); - } - else { - p_min = typename K::Point_3(c.xmax(), c.ymin(),c.zmax()); - p_max = typename K::Point_3(c.xmin(), c.ymax(),c.zmin()); - } + if(p[i] <= r[i]) { // qpr + if(bbox.max_coord(i) < q[i] || bbox.min_coord(i) > r[i]) + return false; } else { - if(AXE == 2 || pz > 0) { - p_min = typename K::Point_3(c.xmax(), c.ymax(),c.zmin()); - p_max = typename K::Point_3(c.xmin(), c.ymin(),c.zmax()); + if(q[i] <= r[i]) { // qrp + if(bbox.max_coord(i) < q[i] || bbox.min_coord(i) > p[i]) + return false; } - else { - p_min = typename K::Point_3(c.xmax(), c.ymax(),c.zmax()); - p_max = typename K::Point_3(c.xmin(), c.ymin(),c.zmin()); + else { // rqp + if(bbox.max_coord(i) < r[i] || bbox.min_coord(i) > p[i]) + return false; } } } } + return true; +} +// AXE is the axe such that p is orthogonal to it. +// if you do not know it, or if it does not exist, +// use get_min_max without the AXE template parameter +// available in _plane_is_cuboid_do_intersect.h +template +inline +void get_min_max(const typename K::FT& px, + const typename K::FT& py, + const typename K::FT& pz, + const Box3& c, + typename K::Point_3& p_min, + typename K::Point_3& p_max) +{ + CGAL_USE(px); + CGAL_USE(py); + CGAL_USE(pz); - template - inline - typename K::FT - do_axis_intersect_aux(const typename K::FT& alpha, - const typename K::FT& beta, - const typename K::Vector_3* sides) - { - switch ( AXE ) - { - case 0: - return -sides[SIDE].z()*alpha + sides[SIDE].y()*beta; - case 1: - return sides[SIDE].z()*alpha - sides[SIDE].x()*beta; - case 2: - return -sides[SIDE].y()*alpha + sides[SIDE].x()*beta; - default: - CGAL_error(); - return typename K::FT(0); + if(AXE == 0 || px > 0) { + if(AXE == 1 || py > 0) { + if(AXE == 2 || pz > 0) { + p_min = typename K::Point_3(c.xmin(), c.ymin(),c.zmin()); + p_max = typename K::Point_3(c.xmax(), c.ymax(),c.zmax()); + } + else { + p_min = typename K::Point_3(c.xmin(), c.ymin(),c.zmax()); + p_max = typename K::Point_3(c.xmax(), c.ymax(),c.zmin()); + } + } + else { + if(AXE == 2 || pz > 0) { + p_min = typename K::Point_3(c.xmin(), c.ymax(),c.zmin()); + p_max = typename K::Point_3(c.xmax(), c.ymin(),c.zmax()); + } + else { + p_min = typename K::Point_3(c.xmin(), c.ymax(),c.zmax()); + p_max = typename K::Point_3(c.xmax(), c.ymin(),c.zmin()); + } } } + else { + if(AXE == 1 || py > 0) { + if(AXE == 2 || pz > 0) { + p_min = typename K::Point_3(c.xmax(), c.ymin(),c.zmin()); + p_max = typename K::Point_3(c.xmin(), c.ymax(),c.zmax()); + } + else { + p_min = typename K::Point_3(c.xmax(), c.ymin(),c.zmax()); + p_max = typename K::Point_3(c.xmin(), c.ymax(),c.zmin()); + } + } + else { + if(AXE == 2 || pz > 0) { + p_min = typename K::Point_3(c.xmax(), c.ymax(),c.zmin()); + p_max = typename K::Point_3(c.xmin(), c.ymin(),c.zmax()); + } + else { + p_min = typename K::Point_3(c.xmax(), c.ymax(),c.zmax()); + p_max = typename K::Point_3(c.xmin(), c.ymin(),c.zmin()); + } + } + } +} - //given a vector checks whether it is collinear to a base vector - //of the orthonormal frame. return -1 otherwise - template - inline - int - collinear_axis(typename K::Vector_3 side){ - if ( certainly(side[0]==0) ){ - if ( certainly(side[1]==0) ) return 2; - if ( certainly(side[2]==0) ) return 1; - } - else{ - if ( certainly(side[1]==0) && - certainly(side[2]==0) ) return 0; - } - return -1; + +template +inline +typename K::FT +do_axis_intersect_aux(const typename K::FT& alpha, + const typename K::FT& beta, + const typename K::Vector_3* sides) +{ + switch ( AXE ) + { + case 0: + return -sides[SIDE].z()*alpha + sides[SIDE].y()*beta; + case 1: + return sides[SIDE].z()*alpha - sides[SIDE].x()*beta; + case 2: + return -sides[SIDE].y()*alpha + sides[SIDE].x()*beta; + default: + CGAL_error(); + return typename K::FT(0); + } +} + +//given a vector checks whether it is collinear to a base vector +//of the orthonormal frame. return -1 otherwise +template +inline +int +collinear_axis(typename K::Vector_3 side) +{ + if(certainly(side[0] == 0)) + { + if(certainly(side[1] == 0)) + return 2; + if(certainly(side[2] == 0)) + return 1; + } + else + { + if(certainly(side[1] == 0) && certainly(side[2] == 0)) + return 0; } - template - inline - Uncertain do_axis_intersect(const typename K::Triangle_3& triangle, - const typename K::Vector_3* sides, - const Box3& bbox) + return -1; +} + +template +inline +Uncertain do_axis_intersect(const typename K::Triangle_3& triangle, + const typename K::Vector_3* sides, + const Box3& bbox) +{ + const typename K::Point_3* j = & triangle.vertex(SIDE); + const typename K::Point_3* k = & triangle.vertex((SIDE+2)%3); + + typename K::Point_3 p_min, p_max; + get_min_max(AXE==0? 0: AXE==1? sides[SIDE].z(): -sides[SIDE].y(), + AXE==0? -sides[SIDE].z(): AXE==1? 0: sides[SIDE].x(), + AXE==0? sides[SIDE].y(): AXE==1? -sides[SIDE].x(): + typename K::FT(0), bbox, p_min, p_max); + + switch ( AXE ) { - const typename K::Point_3* j = & triangle.vertex(SIDE); - const typename K::Point_3* k = & triangle.vertex((SIDE+2)%3); - - typename K::Point_3 p_min, p_max; - get_min_max(AXE==0? 0: AXE==1? sides[SIDE].z(): -sides[SIDE].y(), - AXE==0? -sides[SIDE].z(): AXE==1? 0: sides[SIDE].x(), - AXE==0? sides[SIDE].y(): AXE==1? -sides[SIDE].x(): - typename K::FT(0), bbox, p_min, p_max); - - switch ( AXE ) - { case 0: { // t_max >= t_min Uncertain b = do_axis_intersect_aux(k->y()-j->y(), k->z()-j->z(), sides) >= 0; @@ -228,170 +230,168 @@ namespace internal { // Should not happen CGAL_error(); return make_uncertain(false); - } } +} - template - bool do_intersect_bbox_or_iso_cuboid(const typename K::Triangle_3& a_triangle, - const Box3& a_bbox, - const K& k) - { +template +bool do_intersect_bbox_or_iso_cuboid(const typename K::Triangle_3& a_triangle, + const Box3& a_bbox, + const K& k) +{ - if(certainly_not( do_bbox_intersect(a_triangle, a_bbox) )) - return false; + if(certainly_not( do_bbox_intersect(a_triangle, a_bbox) )) + return false; - if(certainly_not( do_intersect(a_triangle.supporting_plane(), a_bbox, k) )) - return false; + if(certainly_not( do_intersect(a_triangle.supporting_plane(), a_bbox, k) )) + return false; - typename K::Vector_3 sides[3]; - sides[0] = a_triangle[1] - a_triangle[0]; - sides[1] = a_triangle[2] - a_triangle[1]; - sides[2] = a_triangle[0] - a_triangle[2]; - int forbidden_axis=-1; - int forbidden_size=-1; - //determine whether one vector is collinear with an axis - int tmp=collinear_axis(sides[0]); + typename K::Vector_3 sides[3]; + sides[0] = a_triangle[1] - a_triangle[0]; + sides[1] = a_triangle[2] - a_triangle[1]; + sides[2] = a_triangle[0] - a_triangle[2]; + int forbidden_axis=-1; + int forbidden_size=-1; + //determine whether one vector is collinear with an axis + int tmp=collinear_axis(sides[0]); + if ( tmp!= -1){ + forbidden_axis=tmp; + forbidden_size=0; + } + else{ + tmp=collinear_axis(sides[1]); if ( tmp!= -1){ forbidden_axis=tmp; - forbidden_size=0; + forbidden_size=1; } else{ - tmp=collinear_axis(sides[1]); + tmp=collinear_axis(sides[2]); if ( tmp!= -1){ forbidden_axis=tmp; - forbidden_size=1; - } - else{ - tmp=collinear_axis(sides[2]); - if ( tmp!= -1){ - forbidden_axis=tmp; - forbidden_size=2; - } + forbidden_size=2; } } + } #if 0 - typename K::Point_3 p(a_bbox.xmin(), a_bbox.ymin(), a_bbox.zmin()); - typename K::Point_3 q(a_bbox.xmax(), a_bbox.ymax(), a_bbox.zmax()); + typename K::Point_3 p(a_bbox.xmin(), a_bbox.ymin(), a_bbox.zmin()); + typename K::Point_3 q(a_bbox.xmax(), a_bbox.ymax(), a_bbox.zmax()); - typename K::Point_3 m = CGAL::midpoint(p,q); - typename K::Vector_3 v = m - CGAL::ORIGIN; + typename K::Point_3 m = CGAL::midpoint(p,q); + typename K::Vector_3 v = m - CGAL::ORIGIN; - typename K::Triangle_3 triangle(a_triangle[0]-v, a_triangle[1]-v, a_triangle[2]-v); + typename K::Triangle_3 triangle(a_triangle[0]-v, a_triangle[1]-v, a_triangle[2]-v); - Box3 bbox( (p-v).bbox() + (q-v).bbox()); + Box3 bbox( (p-v).bbox() + (q-v).bbox()); #else - const typename K::Triangle_3& triangle = a_triangle; - const Box3& bbox = a_bbox; + const typename K::Triangle_3& triangle = a_triangle; + const Box3& bbox = a_bbox; #endif - // Create a "certainly true" - Uncertain ind_or_true = make_uncertain(true); + // Create a "certainly true" + Uncertain ind_or_true = make_uncertain(true); - if (forbidden_axis!=0){ - if (forbidden_size!=0){ - Uncertain b = do_axis_intersect(triangle, sides, bbox); - if(is_indeterminate(b)){ - ind_or_true = b; - } else if(! b){ - return false; - } - } - if (forbidden_size!=1){ - Uncertain b = do_axis_intersect(triangle, sides, bbox); - if(is_indeterminate(b)){ - ind_or_true = b; - } else if(! b){ - return false; - } - } - if (forbidden_size!=2){ - Uncertain b = do_axis_intersect(triangle, sides, bbox); - if(is_indeterminate(b)){ - ind_or_true = b; - } else if(! b){ - return false; - } + if (forbidden_axis!=0){ + if (forbidden_size!=0){ + Uncertain b = do_axis_intersect(triangle, sides, bbox); + if(is_indeterminate(b)){ + ind_or_true = b; + } else if(! b){ + return false; } } - - if (forbidden_axis!=1){ - if (forbidden_size!=0){ - Uncertain b = do_axis_intersect(triangle, sides, bbox); - if(is_indeterminate(b)){ - ind_or_true = b; - } else if(! b){ - return false; - } - } - if (forbidden_size!=1){ - Uncertain b = do_axis_intersect(triangle, sides, bbox); - if(is_indeterminate(b)){ - ind_or_true = b; - } else if(! b){ - return false; - } - } - if (forbidden_size!=2){ - Uncertain b = do_axis_intersect(triangle, sides, bbox); - if(is_indeterminate(b)){ - ind_or_true = b; - } else if(! b){ - return false; - } + if (forbidden_size!=1){ + Uncertain b = do_axis_intersect(triangle, sides, bbox); + if(is_indeterminate(b)){ + ind_or_true = b; + } else if(! b){ + return false; } } - - if (forbidden_axis!=2){ - if (forbidden_size!=0){ - Uncertain b = do_axis_intersect(triangle, sides, bbox); - if(is_indeterminate(b)){ - ind_or_true = b; - } else if(! b){ - return false; - } - } - if (forbidden_size!=1){ - Uncertain b = do_axis_intersect(triangle, sides, bbox); - if(is_indeterminate(b)){ - ind_or_true = b; - } else if(! b){ - return false; - } - } - if (forbidden_size!=2){ - Uncertain b = do_axis_intersect(triangle, sides, bbox); - if(is_indeterminate(b)){ - ind_or_true = b; - } else if(! b){ - return false; - } + if (forbidden_size!=2){ + Uncertain b = do_axis_intersect(triangle, sides, bbox); + if(is_indeterminate(b)){ + ind_or_true = b; + } else if(! b){ + return false; } } - return ind_or_true; // throws exception in case it is indeterminate } - template - bool do_intersect(const typename K::Triangle_3& triangle, - const CGAL::Bbox_3& bbox, - const K& k) - { - return do_intersect_bbox_or_iso_cuboid(triangle, bbox, k); + if (forbidden_axis!=1){ + if (forbidden_size!=0){ + Uncertain b = do_axis_intersect(triangle, sides, bbox); + if(is_indeterminate(b)){ + ind_or_true = b; + } else if(! b){ + return false; + } + } + if (forbidden_size!=1){ + Uncertain b = do_axis_intersect(triangle, sides, bbox); + if(is_indeterminate(b)){ + ind_or_true = b; + } else if(! b){ + return false; + } + } + if (forbidden_size!=2){ + Uncertain b = do_axis_intersect(triangle, sides, bbox); + if(is_indeterminate(b)){ + ind_or_true = b; + } else if(! b){ + return false; + } + } } - template - bool do_intersect(const CGAL::Bbox_3& bbox, - const typename K::Triangle_3& triangle, - const K& k) - { - return do_intersect_bbox_or_iso_cuboid(triangle, bbox, k); + if (forbidden_axis!=2){ + if (forbidden_size!=0){ + Uncertain b = do_axis_intersect(triangle, sides, bbox); + if(is_indeterminate(b)){ + ind_or_true = b; + } else if(! b){ + return false; + } + } + if (forbidden_size!=1){ + Uncertain b = do_axis_intersect(triangle, sides, bbox); + if(is_indeterminate(b)){ + ind_or_true = b; + } else if(! b){ + return false; + } + } + if (forbidden_size!=2){ + Uncertain b = do_axis_intersect(triangle, sides, bbox); + if(is_indeterminate(b)){ + ind_or_true = b; + } else if(! b){ + return false; + } + } } + return ind_or_true; // throws exception in case it is indeterminate +} + +template +bool do_intersect(const typename K::Triangle_3& triangle, + const CGAL::Bbox_3& bbox, + const K& k) +{ + return do_intersect_bbox_or_iso_cuboid(triangle, bbox, k); +} + +template +bool do_intersect(const CGAL::Bbox_3& bbox, + const typename K::Triangle_3& triangle, + const K& k) +{ + return do_intersect_bbox_or_iso_cuboid(triangle, bbox, k); +} } // namespace internal } // namespace Intersections -} //namespace CGAL +} // namespace CGAL -#include - -#endif // CGAL_INTERNAL_INTERSECTIONS_3_BBOX_3_TRIANGLE_3_DO_INTERSECT_H +#endif // CGAL_INTERNAL_INTERSECTIONS_3_BBOX_3_TRIANGLE_3_DO_INTERSECT_H diff --git a/Intersections_3/include/CGAL/Intersections_3/internal/Iso_cuboid_3_Iso_cuboid_3_do_intersect.h b/Intersections_3/include/CGAL/Intersections_3/internal/Iso_cuboid_3_Iso_cuboid_3_do_intersect.h new file mode 100644 index 00000000000..3cdf1025537 --- /dev/null +++ b/Intersections_3/include/CGAL/Intersections_3/internal/Iso_cuboid_3_Iso_cuboid_3_do_intersect.h @@ -0,0 +1,54 @@ +// Copyright (c) 2008 INRIA Sophia-Antipolis (France), ETH Zurich (Switzerland). +// All rights reserved. +// +// This file is part of CGAL (www.cgal.org) +// +// $URL$ +// $Id$ +// SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-Commercial +// +// +// Author(s) : Andreas Fabri + +#ifndef CGAL_INTERNAL_INTERSECTIONS_3_ISO_CUBOID_3_ISO_CUBOID_3_DO_INTERSECT_H +#define CGAL_INTERNAL_INTERSECTIONS_3_ISO_CUBOID_3_ISO_CUBOID_3_DO_INTERSECT_H + +namespace CGAL { +namespace Intersections { +namespace internal { + +template +inline bool +do_intersect(const typename K::Iso_cuboid_3& icub1, + const typename K::Iso_cuboid_3& icub2, + const K&) +{ + typedef typename K::Point_3 Point_3; + + Point_3 min_points[2]; + Point_3 max_points[2]; + min_points[0] = (icub1.min)(); + min_points[1] = (icub2.min)(); + max_points[0] = (icub1.max)(); + max_points[1] = (icub2.max)(); + const int DIM = 3; + int min_idx[DIM]; + int max_idx[DIM]; + + for(int dim = 0; dim < DIM; ++dim) + { + min_idx[dim] = min_points[0].cartesian(dim) >= min_points[1].cartesian(dim) ? 0 : 1; + max_idx[dim] = max_points[0].cartesian(dim) <= max_points[1].cartesian(dim) ? 0 : 1; + if(min_idx[dim] != max_idx[dim] && + max_points[max_idx[dim]].cartesian(dim) < min_points[min_idx[dim]].cartesian(dim)) + return false; + } + + return true; +} + +} // namespace internal +} // namespace Intersections +} // namespace CGAL + +#endif // CGAL_INTERNAL_INTERSECTIONS_3_ISO_CUBOID_3_ISO_CUBOID_3_DO_INTERSECT_H diff --git a/Intersections_3/include/CGAL/Intersections_3/internal/Iso_cuboid_3_Iso_cuboid_3_intersection.h b/Intersections_3/include/CGAL/Intersections_3/internal/Iso_cuboid_3_Iso_cuboid_3_intersection.h new file mode 100644 index 00000000000..558924acf5d --- /dev/null +++ b/Intersections_3/include/CGAL/Intersections_3/internal/Iso_cuboid_3_Iso_cuboid_3_intersection.h @@ -0,0 +1,92 @@ +// Copyright (c) 2008 INRIA Sophia-Antipolis (France), ETH Zurich (Switzerland). +// All rights reserved. +// +// This file is part of CGAL (www.cgal.org) +// +// $URL$ +// $Id$ +// SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-Commercial +// +// +// Author(s) : Andreas Fabri + +#ifndef CGAL_INTERNAL_INTERSECTIONS_3_ISO_CUBOID_3_ISO_CUBOID_3_INTERSECTION_H +#define CGAL_INTERNAL_INTERSECTIONS_3_ISO_CUBOID_3_ISO_CUBOID_3_INTERSECTION_H + +#include + +#include +#include + +namespace CGAL { +namespace Intersections { +namespace internal { + +template +typename Intersection_traits::result_type +intersection(const typename K::Iso_cuboid_3& icub1, + const typename K::Iso_cuboid_3& icub2, + const K& k) +{ + typedef typename K::Point_3 Point_3; + + Point_3 min_points[2]; + Point_3 max_points[2]; + min_points[0] = (icub1.min)(); + min_points[1] = (icub2.min)(); + max_points[0] = (icub1.max)(); + max_points[1] = (icub2.max)(); + const int DIM = 3; + int min_idx[DIM]; + int max_idx[DIM]; + + Point_3 newmin; + Point_3 newmax; + for(int dim = 0; dim < DIM; ++dim) + { + min_idx[dim] = min_points[0].cartesian(dim) >= min_points[1].cartesian(dim) ? 0 : 1; + max_idx[dim] = max_points[0].cartesian(dim) <= max_points[1].cartesian(dim) ? 0 : 1; + if(min_idx[dim] != max_idx[dim] && + max_points[max_idx[dim]].cartesian(dim) < min_points[min_idx[dim]].cartesian(dim)) + return intersection_return(); + } + + if(min_idx[0] == min_idx[1] && min_idx[0] == min_idx[2]) + { + newmin = min_points[min_idx[0]]; + } + else + { + newmin = Point_3(min_idx[0] == 0 ? wmult_hw((K*)0, min_points[0].hx(), min_points[1]) + : wmult_hw((K*)0, min_points[1].hx(), min_points[0]), + min_idx[1] == 0 ? wmult_hw((K*)0, min_points[0].hy(), min_points[1]) + : wmult_hw((K*)0, min_points[1].hy(), min_points[0]), + min_idx[2] == 0 ? wmult_hw((K*)0, min_points[0].hz(), min_points[1]) + : wmult_hw((K*)0, min_points[1].hz(), min_points[0]), + wmult_hw((K*)0, min_points[0].hw(), min_points[1])); + } + + if(max_idx[0] == max_idx[1] && max_idx[0] == max_idx[2]) + { + newmax = max_points[max_idx[0]]; + } + else + { + newmax = Point_3(max_idx[0] == 0 ? wmult_hw((K*)0, max_points[0].hx(), max_points[1]) + : wmult_hw((K*)0, max_points[1].hx(), max_points[0]), + max_idx[1] == 0 ? wmult_hw((K*)0, max_points[0].hy(), max_points[1]) + : wmult_hw((K*)0, max_points[1].hy(), max_points[0]), + max_idx[2] == 0 ? wmult_hw((K*)0, max_points[0].hz(), max_points[1]) + : wmult_hw((K*)0, max_points[1].hz(), max_points[0]), + wmult_hw((K*)0, max_points[0].hw(), max_points[1])); + } + + return intersection_return( + k.construct_iso_cuboid_3_object()(newmin, newmax)); +} + +} // namespace internal +} // namespace Intersections +} // namespace CGAL + +#endif // CGAL_INTERNAL_INTERSECTIONS_3_ISO_CUBOID_3_ISO_CUBOID_3_INTERSECTION_H diff --git a/Intersections_3/include/CGAL/Intersections_3/internal/Iso_cuboid_3_Line_3_do_intersect.h b/Intersections_3/include/CGAL/Intersections_3/internal/Iso_cuboid_3_Line_3_do_intersect.h new file mode 100644 index 00000000000..a9095b41d31 --- /dev/null +++ b/Intersections_3/include/CGAL/Intersections_3/internal/Iso_cuboid_3_Line_3_do_intersect.h @@ -0,0 +1,95 @@ +// Copyright (c) 2008 INRIA Sophia-Antipolis (France), ETH Zurich (Switzerland). +// All rights reserved. +// +// This file is part of CGAL (www.cgal.org) +// +// $URL$ +// $Id$ +// SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-Commercial +// +// +// Author(s) : Geert-Jan Giezeman + +#ifndef CGAL_INTERNAL_INTERSECTIONS_3_ISO_CUBOID_3_LINE_3_DO_INTERSECT_H +#define CGAL_INTERNAL_INTERSECTIONS_3_ISO_CUBOID_3_LINE_3_DO_INTERSECT_H + +#include +#include + +namespace CGAL { +namespace Intersections { +namespace internal { + +template +inline bool +do_intersect(const typename K::Line_3& line, + const typename K::Iso_cuboid_3& box, + const K&) +{ + typedef typename K::Point_3 Point_3; + typedef typename K::Vector_3 Vector_3; + typedef typename K::FT FT; + + bool all_values = true; + FT _min = 0, _max = 0; // initialization to stop compiler warning + FT _denum; + const Point_3& _ref_point = line.point(); + const Vector_3& _dir = line.direction().vector(); + const Point_3& _iso_min = (box.min)(); + const Point_3& _iso_max = (box.max)(); + + for(int i=0; i< _ref_point.dimension(); ++i) { + if(_dir.homogeneous(i) == 0) { + if(_ref_point.cartesian(i) < _iso_min.cartesian(i)) + return false; + + if(_ref_point.cartesian(i) > _iso_max.cartesian(i)) + return false; + } else { + FT newmin, newmax; + FT newdenum = _dir.cartesian(i); + if(_dir.homogeneous(i) > 0) { + newmin = (_iso_min.cartesian(i) - _ref_point.cartesian(i)); + newmax = (_iso_max.cartesian(i) - _ref_point.cartesian(i)); + } else { + newmin = (_iso_max.cartesian(i) - _ref_point.cartesian(i)); + newmax = (_iso_min.cartesian(i) - _ref_point.cartesian(i)); + } + + if(all_values) { + _min = newmin; + _max = newmax; + _denum = newdenum; + } else { + if(compare_quotients(newmin, newdenum, _min, _denum) == LARGER) + _min = newmin; + if(compare_quotients(newmax, newdenum, _max, _denum) == LARGER) + _max = newmax; + if(compare_quotients(_max, _denum, _min, _denum) == SMALLER) + return false; + + _denum = newdenum; + + } + all_values = false; + } + } + + CGAL_kernel_assertion(!all_values); + return true; +} + +template +inline bool +do_intersect(const typename K::Iso_cuboid_3& ic, + const typename K::Line_3& l, + const K& k) +{ + return do_intersect(l, ic, k); +} + +} // namespace internal +} // namespace Intersections +} // namespace CGAL + +#endif // CGAL_INTERNAL_INTERSECTIONS_3_ISO_CUBOID_3_LINE_3_DO_INTERSECT_H diff --git a/Intersections_3/include/CGAL/Intersections_3/internal/Iso_cuboid_3_Line_3_intersection.h b/Intersections_3/include/CGAL/Intersections_3/internal/Iso_cuboid_3_Line_3_intersection.h new file mode 100644 index 00000000000..d09b930cabe --- /dev/null +++ b/Intersections_3/include/CGAL/Intersections_3/internal/Iso_cuboid_3_Line_3_intersection.h @@ -0,0 +1,102 @@ +// Copyright (c) 2008 INRIA Sophia-Antipolis (France), ETH Zurich (Switzerland). +// All rights reserved. +// +// This file is part of CGAL (www.cgal.org) +// +// $URL$ +// $Id$ +// SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-Commercial +// +// +// Author(s) : Geert-Jan Giezeman + +#ifndef CGAL_INTERNAL_INTERSECTIONS_3_ISO_CUBOID_3_LINE_3_INTERSECTION_H +#define CGAL_INTERNAL_INTERSECTIONS_3_ISO_CUBOID_3_LINE_3_INTERSECTION_H + +#include + +#include +#include + +namespace CGAL { +namespace Intersections { +namespace internal { + +template +typename Intersection_traits::result_type +intersection(const typename K::Line_3 &line, + const typename K::Iso_cuboid_3 &box, + const K& k) +{ + typedef typename K::Point_3 Point_3; + typedef typename K::Vector_3 Vector_3; + typedef typename K::FT FT; + + bool all_values = true; + FT _min = 0, _max = 0; // initialization to stop compiler warning + const Point_3& _ref_point = line.point(); + const Vector_3& _dir = line.direction().vector(); + const Point_3& _iso_min = (box.min)(); + const Point_3& _iso_max = (box.max)(); + + for(int i=0; i< _ref_point.dimension(); ++i) { + if(_dir.homogeneous(i) == 0) { + if(_ref_point.cartesian(i) < _iso_min.cartesian(i)) + return intersection_return(); + + if(_ref_point.cartesian(i) > _iso_max.cartesian(i)) + return intersection_return(); + } else { + FT newmin, newmax; + if(_dir.homogeneous(i) > 0) { + newmin = (_iso_min.cartesian(i) - _ref_point.cartesian(i)) / _dir.cartesian(i); + newmax = (_iso_max.cartesian(i) - _ref_point.cartesian(i)) / _dir.cartesian(i); + } else { + newmin = (_iso_max.cartesian(i) - _ref_point.cartesian(i)) / _dir.cartesian(i); + newmax = (_iso_min.cartesian(i) - _ref_point.cartesian(i)) / _dir.cartesian(i); + } + + if(all_values) { + _min = newmin; + _max = newmax; + } else { + if(newmin > _min) + _min = newmin; + if(newmax < _max) + _max = newmax; + if(_max < _min) + return intersection_return(); + } + all_values = false; + } + } + + CGAL_kernel_assertion(!all_values); + if(_max == _min) + return intersection_return( + k.construct_translated_point_3_object()(_ref_point, + k.construct_scaled_vector_3_object()(_dir, _min))); + + return intersection_return( + k.construct_segment_3_object()( + k.construct_translated_point_3_object()(_ref_point, + k.construct_scaled_vector_3_object()(_dir, _min)), + k.construct_translated_point_3_object()(_ref_point, + k.construct_scaled_vector_3_object()(_dir, _max)))); +} + +template +inline +typename Intersection_traits::result_type +intersection(const typename K::Iso_cuboid_3& box, + const typename K::Line_3& line, + const K& k) +{ + return intersection(line, box, k); +} + +} // namespace internal +} // namespace Intersections +} // namespace CGAL + +#endif // CGAL_INTERNAL_INTERSECTIONS_3_ISO_CUBOID_3_LINE_3_INTERSECTION_H diff --git a/Intersections_3/include/CGAL/Intersections_3/internal/Iso_cuboid_3_Plane_3_do_intersect.h b/Intersections_3/include/CGAL/Intersections_3/internal/Iso_cuboid_3_Plane_3_do_intersect.h new file mode 100644 index 00000000000..17af49e0246 --- /dev/null +++ b/Intersections_3/include/CGAL/Intersections_3/internal/Iso_cuboid_3_Plane_3_do_intersect.h @@ -0,0 +1,136 @@ +// Copyright (c) 2008 INRIA Sophia-Antipolis (France), ETH Zurich (Switzerland). +// All rights reserved. +// +// This file is part of CGAL (www.cgal.org) +// +// $URL$ +// $Id$ +// SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-Commercial +// +// +// Author(s) : Camille Wormser, Jane Tournois, Pierre Alliez + + +#ifndef CGAL_INTERNAL_INTERSECTIONS_3_ISO_CUBOID_3_PLANE_3_DO_INTERSECT_H +#define CGAL_INTERNAL_INTERSECTIONS_3_ISO_CUBOID_3_PLANE_3_DO_INTERSECT_H + +#include +#include + +namespace CGAL { +namespace Intersections { +namespace internal { + +template // Iso_cuboid_3 or Bbox_3 +Uncertain get_min_max(const typename K::Vector_3& p, + const Box3& bbox, + typename K::Point_3& p_min, + typename K::Point_3& p_max) +{ + if(certainly(p.x() > 0)) { + if(certainly(p.y() > 0)) { + if(certainly(p.z() > 0)) { + p_min = typename K::Point_3(bbox.xmin(), bbox.ymin(),bbox.zmin()); + p_max = typename K::Point_3(bbox.xmax(), bbox.ymax(),bbox.zmax()); + return true; + } else if(certainly(p.z() <= 0)) { + p_min = typename K::Point_3(bbox.xmin(), bbox.ymin(),bbox.zmax()); + p_max = typename K::Point_3(bbox.xmax(), bbox.ymax(),bbox.zmin()); + return true; + } + } else if(certainly(p.y() <= 0)) { + if(certainly(p.z() > 0)) { + p_min = typename K::Point_3(bbox.xmin(), bbox.ymax(),bbox.zmin()); + p_max = typename K::Point_3(bbox.xmax(), bbox.ymin(),bbox.zmax()); + return true; + } else if(certainly(p.z() <= 0)) { + p_min = typename K::Point_3(bbox.xmin(), bbox.ymax(),bbox.zmax()); + p_max = typename K::Point_3(bbox.xmax(), bbox.ymin(),bbox.zmin()); + return true; + } + } + } + else if(certainly(p.x() <= 0)) { + if(certainly(p.y() > 0)) { + if(certainly(p.z() > 0)) { + p_min = typename K::Point_3(bbox.xmax(), bbox.ymin(),bbox.zmin()); + p_max = typename K::Point_3(bbox.xmin(), bbox.ymax(),bbox.zmax()); + return true; + } else if(certainly(p.z() <= 0)) { + p_min = typename K::Point_3(bbox.xmax(), bbox.ymin(),bbox.zmax()); + p_max = typename K::Point_3(bbox.xmin(), bbox.ymax(),bbox.zmin()); + return true; + } + } + else if(certainly(p.y() <= 0)) { + if(certainly(p.z() > 0)) { + p_min = typename K::Point_3(bbox.xmax(), bbox.ymax(),bbox.zmin()); + p_max = typename K::Point_3(bbox.xmin(), bbox.ymin(),bbox.zmax()); + return true; + } else if(certainly(p.z() <= 0)) { + p_min = typename K::Point_3(bbox.xmax(), bbox.ymax(),bbox.zmax()); + p_max = typename K::Point_3(bbox.xmin(), bbox.ymin(),bbox.zmin()); + return true; + } + } + } + + return Uncertain::indeterminate(); +} + +template // Iso_cuboid_3 or Bbox_3 +bool do_intersect_plane_box(const typename K::Plane_3& plane, + const Box3& bbox, + const K&) +{ + typedef typename K::Point_3 Point_3; + + Point_3 p_max, p_min; + Uncertain b = get_min_max(plane.orthogonal_vector(), bbox, p_min, p_max); + if(is_certain(b)){ + return ! (plane.oriented_side(p_max) == ON_NEGATIVE_SIDE || + plane.oriented_side(p_min) == ON_POSITIVE_SIDE); + } + + CGAL::Oriented_side side = plane.oriented_side(Point_3(bbox.xmin(), bbox.ymin(),bbox.zmin())); + if(side == ON_ORIENTED_BOUNDARY) return true; + + CGAL::Oriented_side s = plane.oriented_side(Point_3(bbox.xmax(), bbox.ymax(),bbox.zmax())); + if(s != side) return true; + s = plane.oriented_side(Point_3(bbox.xmin(), bbox.ymin(),bbox.zmax())); + if(s != side) return true; + s = plane.oriented_side(Point_3(bbox.xmax(), bbox.ymax(),bbox.zmin())); + if(s != side) return true; + s = plane.oriented_side(Point_3(bbox.xmin(), bbox.ymax(),bbox.zmin())); + if(s != side) return true; + s = plane.oriented_side(Point_3(bbox.xmax(), bbox.ymin(),bbox.zmax())); + if(s != side) return true; + s = plane.oriented_side(Point_3(bbox.xmin(), bbox.ymax(),bbox.zmax())); + if(s != side) return true; + s = plane.oriented_side(Point_3(bbox.xmax(), bbox.ymin(),bbox.zmin())); + if(s != side) return true; + + return false; +} + +template +bool do_intersect(const typename K::Plane_3& plane, + const typename K::Iso_cuboid_3& bbox, + const K& k) +{ + return do_intersect_plane_box(plane, bbox, k); +} + +template +bool do_intersect(const typename K::Iso_cuboid_3& bbox, + const typename K::Plane_3& plane, + const K& k) +{ + return do_intersect_plane_box(plane, bbox, k); +} + +} // namespace internal +} // namespace Intersections +} // namespace CGAL + +#endif // CGAL_INTERNAL_INTERSECTIONS_3_ISO_CUBOID_3_PLANE_3_DO_INTERSECT_H diff --git a/Intersections_3/include/CGAL/Intersections_3/internal/Iso_cuboid_3_Plane_3_intersection.h b/Intersections_3/include/CGAL/Intersections_3/internal/Iso_cuboid_3_Plane_3_intersection.h index 270693f2fb9..1f544221ad7 100644 --- a/Intersections_3/include/CGAL/Intersections_3/internal/Iso_cuboid_3_Plane_3_intersection.h +++ b/Intersections_3/include/CGAL/Intersections_3/internal/Iso_cuboid_3_Plane_3_intersection.h @@ -14,10 +14,13 @@ #ifndef CGAL_INTERNAL_INTERSECTIONS_3_ISO_CUBOID_3_PLANE_3_INTERSECTION_H #define CGAL_INTERNAL_INTERSECTIONS_3_ISO_CUBOID_3_PLANE_3_INTERSECTION_H +#include #include #include #include +#include + #include #include @@ -28,8 +31,7 @@ namespace internal { //Iso_cuboid_3 Plane_3 template typename Intersection_traits::result_type -intersection( - const typename K::Iso_cuboid_3& cub, +intersection(const typename K::Iso_cuboid_3& cub, const typename K::Plane_3& plane, const K& k) { @@ -80,13 +82,12 @@ intersection( edge_ipt_id.fill(-1); auto inter_pt_index = - [&plane, &corners, &edge_ipt_id](int i, int j, int edge_id) + [&k, &plane, &corners, &edge_ipt_id](int i, int j, int edge_id) { if (edge_ipt_id[edge_id]==-1) { edge_ipt_id[edge_id] = static_cast (corners.size()); - corners.push_back(typename K::Construct_plane_line_intersection_point_3() - (plane, corners[i], corners[j])); + corners.push_back(k.construct_plane_line_intersection_point_3_object()(plane, corners[i], corners[j])); } return edge_ipt_id[edge_id]; @@ -95,7 +96,7 @@ intersection( bool all_in = true; bool all_out = true; - std::vector> neighbor_ids(14, {-1,-1}); + std::vector > neighbor_ids(14, {-1,-1}); auto add_neighbor = [&neighbor_ids](int i, int j) { @@ -132,8 +133,7 @@ intersection( // check for intersection of the edge if (orientations[next_id] == ON_POSITIVE_SIDE) { - ids.push_back( - inter_pt_index(current_id, next_id, edge_id)); + ids.push_back(inter_pt_index(current_id, next_id, edge_id)); } break; } @@ -179,24 +179,27 @@ intersection( } } - if (all_in || all_out) return boost::none; - if (start_id == -1) return { result_type(corners[solo_id]) }; + if (all_in || all_out) + return boost::none; + if (start_id == -1) + return { result_type(corners[solo_id]) }; int prv_id = -1; int cur_id = start_id; std::vector res; res.reserve(6); - do { + + for (;;) { res.push_back(corners[cur_id]); int nxt_id = neighbor_ids[cur_id][0] == prv_id ? neighbor_ids[cur_id][1] : neighbor_ids[cur_id][0]; - if (nxt_id == -1 || nxt_id == start_id){ - if(res.size() == 2){ + if (nxt_id == -1 || nxt_id == start_id) { + if(res.size() == 2) { typename K::Segment_3 seg(res[0], res[1]); return result_type(seg); } - if(res.size() == 3){ + if(res.size() == 3) { typename K::Triangle_3 tr(res[0], res[1], res[2]); return result_type(tr); } @@ -204,19 +207,20 @@ intersection( } prv_id = cur_id; cur_id = nxt_id; - } while (true); + } } template typename Intersection_traits::result_type -intersection( - const typename K::Plane_3 &pl, - const typename K::Iso_cuboid_3 &cub, - const K& k) +intersection(const typename K::Plane_3& pl, + const typename K::Iso_cuboid_3& cub, + const K& k) { return intersection(cub, pl, k); } -}}} +} // namespace internal +} // namespace Intersections +} // namespace CGAL #endif // CGAL_INTERNAL_INTERSECTIONS_3_ISO_CUBOID_3_PLANE_3_INTERSECTION_H diff --git a/Intersections_3/include/CGAL/Intersections_3/internal/Iso_cuboid_3_Point_3_do_intersect.h b/Intersections_3/include/CGAL/Intersections_3/internal/Iso_cuboid_3_Point_3_do_intersect.h new file mode 100644 index 00000000000..bafe971d903 --- /dev/null +++ b/Intersections_3/include/CGAL/Intersections_3/internal/Iso_cuboid_3_Point_3_do_intersect.h @@ -0,0 +1,44 @@ +// Copyright (c) 2008 INRIA Sophia-Antipolis (France), ETH Zurich (Switzerland). +// All rights reserved. +// +// This file is part of CGAL (www.cgal.org) +// +// $URL$ +// $Id$ +// SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-Commercial +// +// +// Author(s) : Maxime Gimeno + +#ifndef CGAL_INTERNAL_INTERSECTIONS_3_ISO_CUBOID_3_POINT_3_DO_INTERSECT_H +#define CGAL_INTERNAL_INTERSECTIONS_3_ISO_CUBOID_3_POINT_3_DO_INTERSECT_H + +namespace CGAL { +namespace Intersections { +namespace internal { + +template +inline +bool +do_intersect(const typename K::Point_3& pt, + const typename K::Iso_cuboid_3& iso, + const K& k) +{ + return !k.has_on_unbounded_side_3_object()(iso, pt); +} + +template +inline +bool +do_intersect(const typename K::Iso_cuboid_3& iso, + const typename K::Point_3& pt, + const K& k) +{ + return !k.has_on_unbounded_side_3_object()(iso, pt); +} + +} // namespace internal +} // namespace Intersections +} // namespace CGAL + +#endif // CGAL_INTERNAL_INTERSECTIONS_3_ISO_CUBOID_3_POINT_3_DO_INTERSECT_H diff --git a/Intersections_3/include/CGAL/Intersections_3/internal/Iso_cuboid_3_Point_3_intersection.h b/Intersections_3/include/CGAL/Intersections_3/internal/Iso_cuboid_3_Point_3_intersection.h new file mode 100644 index 00000000000..ebfc4858d9b --- /dev/null +++ b/Intersections_3/include/CGAL/Intersections_3/internal/Iso_cuboid_3_Point_3_intersection.h @@ -0,0 +1,51 @@ +// Copyright (c) 2018 INRIA Sophia-Antipolis (France) +// All rights reserved. +// +// This file is part of CGAL (www.cgal.org) +// +// $URL$ +// $Id$ +// SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-Commercial +// +// +// Author(s) : Maxime Gimeno + +#ifndef CGAL_INTERNAL_INTERSECTIONS_3_ISO_CUBOID_3_POINT_3_INTERSECTION_H +#define CGAL_INTERNAL_INTERSECTIONS_3_ISO_CUBOID_3_POINT_3_INTERSECTION_H + +#include +#include + +#include + +namespace CGAL { +namespace Intersections { +namespace internal { + +template +typename CGAL::Intersection_traits::result_type +intersection(const typename K::Point_3& pt, + const typename K::Iso_cuboid_3 &iso, + const K& k) +{ + if(internal::do_intersect(pt,iso,k)) + return intersection_return(pt); + + return intersection_return(); +} + +template +typename CGAL::Intersection_traits +::result_type +intersection(const typename K::Iso_cuboid_3 &iso, + const typename K::Point_3& pt, + const K& k) +{ + return internal::intersection(pt, iso, k); +} + +} // namespace internal +} // namespace Intersections +} // namespace CGAL + +#endif // CGAL_INTERNAL_INTERSECTIONS_3_ISO_CUBOID_3_POINT_3_INTERSECTION_H diff --git a/Intersections_3/include/CGAL/Intersections_3/internal/Iso_cuboid_3_Ray_3_do_intersect.h b/Intersections_3/include/CGAL/Intersections_3/internal/Iso_cuboid_3_Ray_3_do_intersect.h index 42f4cea03b5..e467d7ea327 100644 --- a/Intersections_3/include/CGAL/Intersections_3/internal/Iso_cuboid_3_Ray_3_do_intersect.h +++ b/Intersections_3/include/CGAL/Intersections_3/internal/Iso_cuboid_3_Ray_3_do_intersect.h @@ -17,15 +17,13 @@ #include #include -#include +#include // for CGAL::internal::do_intersect_bbox_segment_aux // inspired from http://cag.csail.mit.edu/~amy/papers/box-jgt.pdf namespace CGAL { - namespace Intersections { - namespace internal { template @@ -40,27 +38,27 @@ bool do_intersect(const typename K::Ray_3& ray, const Point_3& point_on_ray = ray.second_point(); return do_intersect_bbox_segment_aux - // do not use static filters - ( - source.x(), source.y(), source.z(), - point_on_ray.x(), point_on_ray.y(), point_on_ray.z(), - (ic.min)().x(), (ic.min)().y(), (ic.min)().z(), - (ic.max)().x(), (ic.max)().y(), (ic.max)().z() - ); + // do not use static filters + ( + source.x(), source.y(), source.z(), + point_on_ray.x(), point_on_ray.y(), point_on_ray.z(), + (ic.min)().x(), (ic.min)().y(), (ic.min)().z(), + (ic.max)().x(), (ic.max)().y(), (ic.max)().z() + ); } template bool do_intersect(const typename K::Iso_cuboid_3& ic, const typename K::Ray_3& ray, - const K&) { - return do_intersect(ray, ic, K()); + const K& k) { + return do_intersect(ray, ic, k); } } // namespace internal } // namespace Intersections -} //namespace CGAL +} // namespace CGAL -#endif // CGAL_INTERNAL_INTERSECTIONS_3_ISO_CUBOID_3_RAY_3_DO_INTERSECT_H +#endif // CGAL_INTERNAL_INTERSECTIONS_3_ISO_CUBOID_3_RAY_3_DO_INTERSECT_H diff --git a/Intersections_3/include/CGAL/Intersections_3/internal/Iso_cuboid_3_Ray_3_intersection.h b/Intersections_3/include/CGAL/Intersections_3/internal/Iso_cuboid_3_Ray_3_intersection.h new file mode 100644 index 00000000000..0a88d57df8f --- /dev/null +++ b/Intersections_3/include/CGAL/Intersections_3/internal/Iso_cuboid_3_Ray_3_intersection.h @@ -0,0 +1,94 @@ +// Copyright (c) 2001 ETH Zurich (Switzerland) +// All rights reserved. +// +// This file is part of CGAL (www.cgal.org) +// +// $URL$ +// $Id$ +// SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-Commercial +// +// +// Author(s) : Geert-Jan Giezeman + +#ifndef CGAL_INTERNAL_INTERSECTIONS_3_ISO_CUBOID_3_RAY_3_INTERSECTION_H +#define CGAL_INTERNAL_INTERSECTIONS_3_ISO_CUBOID_3_RAY_3_INTERSECTION_H + +#include + +#include + +namespace CGAL { +namespace Intersections { +namespace internal { + +template +typename Intersection_traits::result_type +intersection(const typename K::Ray_3& ray, + const typename K::Iso_cuboid_3& box, + const K&) +{ + typedef typename K::Point_3 Point_3; + typedef typename K::Vector_3 Vector_3; + typedef typename K::Segment_3 Segment_3; + typedef typename K::FT FT; + + bool all_values = true; + FT _min = 0, _max = 0; // initialization to prevent compiler warning + const Point_3& _ref_point = ray.source(); + const Vector_3& _dir = ray.direction().vector(); + const Point_3& _iso_min = (box.min)(); + const Point_3& _iso_max = (box.max)(); + + for (int i=0; i< _ref_point.dimension(); ++i) { + if (_dir.homogeneous(i) == 0) { + if (_ref_point.cartesian(i) < _iso_min.cartesian(i)) { + return intersection_return(); + } + if (_ref_point.cartesian(i) > _iso_max.cartesian(i)) { + return intersection_return(); + } + } else { + FT newmin, newmax; + if (_dir.homogeneous(i) > 0) { + newmin = (_iso_min.cartesian(i) - _ref_point.cartesian(i)) / _dir.cartesian(i); + newmax = (_iso_max.cartesian(i) - _ref_point.cartesian(i)) / _dir.cartesian(i); + } else { + newmin = (_iso_max.cartesian(i) - _ref_point.cartesian(i)) / _dir.cartesian(i); + newmax = (_iso_min.cartesian(i) - _ref_point.cartesian(i)) / _dir.cartesian(i); + } + if (all_values) { + _max = newmax; + } else { + if (newmax < _max) + _max = newmax; + } + if (newmin > _min) + _min = newmin; + if (_max < _min) + return intersection_return(); + all_values = false; + } + } + CGAL_kernel_assertion(!all_values); + if (_max == _min) { + return intersection_return(Point_3(_ref_point + _dir * _min )); + } + return intersection_return( + Segment_3(_ref_point + _dir*_min, _ref_point + _dir*_max)); +} + +template +inline +typename Intersection_traits::result_type +intersection(const typename K::Iso_cuboid_3& box, + const typename K::Ray_3& ray, + const K& k) +{ + return intersection(ray, box, k); +} + +} // namespace internal +} // namespace Intersections +} // namespace CGAL + +#endif // CGAL_INTERNAL_INTERSECTIONS_3_ISO_CUBOID_3_RAY_3_INTERSECTION_H diff --git a/Intersections_3/include/CGAL/Intersections_3/internal/Iso_cuboid_3_Segment_3_do_intersect.h b/Intersections_3/include/CGAL/Intersections_3/internal/Iso_cuboid_3_Segment_3_do_intersect.h index c39b58d6122..3c42487730f 100644 --- a/Intersections_3/include/CGAL/Intersections_3/internal/Iso_cuboid_3_Segment_3_do_intersect.h +++ b/Intersections_3/include/CGAL/Intersections_3/internal/Iso_cuboid_3_Segment_3_do_intersect.h @@ -14,18 +14,13 @@ #ifndef CGAL_INTERNAL_INTERSECTIONS_3_ISO_CUBOID_3_SEGMENT_3_DO_INTERSECT_H #define CGAL_INTERNAL_INTERSECTIONS_3_ISO_CUBOID_3_SEGMENT_3_DO_INTERSECT_H -#include -#include +// inspired from http://cag.csail.mit.edu/~amy/papers/box-jgt.pdf #include // for CGAL::internal::do_intersect_bbox_segment_aux -// inspired from http://cag.csail.mit.edu/~amy/papers/box-jgt.pdf - namespace CGAL { - namespace Intersections { - namespace internal { template @@ -55,12 +50,13 @@ bool do_intersect(const typename K::Segment_3& seg, template bool do_intersect(const typename K::Iso_cuboid_3& ic, const typename K::Segment_3& seg, - const K&) { - return do_intersect(seg, ic, K()); + const K& k) +{ + return do_intersect(seg, ic, k); } } // namespace internal } // namespace Intersections -} //namespace CGAL +} // namespace CGAL -#endif // CGAL_INTERNAL_INTERSECTIONS_3_ISO_CUBOID_3_SEGMENT_3_DO_INTERSECT_H +#endif // CGAL_INTERNAL_INTERSECTIONS_3_ISO_CUBOID_3_SEGMENT_3_DO_INTERSECT_H diff --git a/Intersections_3/include/CGAL/Intersections_3/internal/Iso_cuboid_3_Segment_3_intersection.h b/Intersections_3/include/CGAL/Intersections_3/internal/Iso_cuboid_3_Segment_3_intersection.h new file mode 100644 index 00000000000..4d8c0f9bf24 --- /dev/null +++ b/Intersections_3/include/CGAL/Intersections_3/internal/Iso_cuboid_3_Segment_3_intersection.h @@ -0,0 +1,96 @@ +// Copyright (c) 2008 ETH Zurich (Switzerland) +// Copyright (c) 2008-2009 INRIA Sophia-Antipolis (France) +// All rights reserved. +// +// This file is part of CGAL (www.cgal.org) +// +// $URL$ +// $Id$ +// SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-Commercial +// +// +// Author(s) : Geert-Jan Giezeman + +#ifndef CGAL_INTERNAL_INTERSECTIONS_3_ISO_CUBOID_3_SEGMENT_3_INTERSECTION_H +#define CGAL_INTERNAL_INTERSECTIONS_3_ISO_CUBOID_3_SEGMENT_3_INTERSECTION_H + +#include + +#include +#include + +namespace CGAL { +namespace Intersections { +namespace internal { + +template +typename Intersection_traits::result_type +intersection(const typename K::Segment_3& seg, + const typename K::Iso_cuboid_3& box, + const K&) +{ + typedef typename K::Point_3 Point_3; + typedef typename K::Vector_3 Vector_3; + typedef typename K::Segment_3 Segment_3; + typedef typename K::FT FT; + + FT _min = 0, _max; + const Point_3& _ref_point = seg.source(); + const Vector_3& _dir = seg.direction().vector(); + const Point_3& _iso_min = (box.min)(); + const Point_3& _iso_max = (box.max)(); + int main_dir = (CGAL_NTS abs(_dir.x()) > CGAL_NTS abs(_dir.y()) ) + ? (CGAL_NTS abs(_dir.x()) > CGAL_NTS abs(_dir.z()) ? 0 : 2) + : (CGAL_NTS abs(_dir.y()) > CGAL_NTS abs(_dir.z()) ? 1 : 2); + _max = (seg.target().cartesian(main_dir)-_ref_point.cartesian(main_dir)) / _dir.cartesian(main_dir); + + for(int i=0; i< _ref_point.dimension(); ++i) { + if(_dir.homogeneous(i) == 0) { + if(_ref_point.cartesian(i) < _iso_min.cartesian(i)) { + return intersection_return(); + } + if(_ref_point.cartesian(i) > _iso_max.cartesian(i)) { + return intersection_return(); + } + } else { + FT newmin, newmax; + if(_dir.homogeneous(i) > 0) { + newmin = (_iso_min.cartesian(i) - _ref_point.cartesian(i)) / _dir.cartesian(i); + newmax = (_iso_max.cartesian(i) - _ref_point.cartesian(i)) / _dir.cartesian(i); + } else { + newmin = (_iso_max.cartesian(i) - _ref_point.cartesian(i)) / _dir.cartesian(i); + newmax = (_iso_min.cartesian(i) - _ref_point.cartesian(i)) / _dir.cartesian(i); + } + + if(newmax < _max) + _max = newmax; + if(newmin > _min) + _min = newmin; + if(_max < _min) + return intersection_return(); + } + } + + if(_max == _min) + return intersection_return( + Point_3{_ref_point + _dir * _min }); + + return intersection_return( + Segment_3{_ref_point + _dir*_min, _ref_point + _dir*_max}); +} + +template +inline +typename Intersection_traits::result_type +intersection(const typename K::Iso_cuboid_3& box, + const typename K::Segment_3& seg, + const K& k) +{ + return intersection(seg, box, k); +} + +} // namespace internal +} // namespace Intersections +} // namespace CGAL + +#endif // CGAL_INTERNAL_INTERSECTIONS_3_ISO_CUBOID_3_SEGMENT_3_INTERSECTION_H diff --git a/Intersections_3/include/CGAL/Intersections_3/internal/Iso_cuboid_3_Sphere_3_do_intersect.h b/Intersections_3/include/CGAL/Intersections_3/internal/Iso_cuboid_3_Sphere_3_do_intersect.h index 3391f501c26..fc64cbde6d5 100644 --- a/Intersections_3/include/CGAL/Intersections_3/internal/Iso_cuboid_3_Sphere_3_do_intersect.h +++ b/Intersections_3/include/CGAL/Intersections_3/internal/Iso_cuboid_3_Sphere_3_do_intersect.h @@ -10,51 +10,120 @@ // // Author(s) : Camille Wormser, Jane Tournois, Pierre Alliez - #ifndef CGAL_INTERNAL_INTERSECTIONS_3_ISO_CUBOID_3_SPHERE_3_DO_INTERSECT_H #define CGAL_INTERNAL_INTERSECTIONS_3_ISO_CUBOID_3_SPHERE_3_DO_INTERSECT_H -#include -#include -#include +#include +#include namespace CGAL { - namespace Intersections { - namespace internal { +template // Iso_cuboid_3 or Bbox_3 +bool do_intersect_sphere_box_3(const typename K::Sphere_3& sphere, + const Box3& bbox, + const K&) +{ + typedef typename K::FT FT; + typedef typename K::Point_3 Point; + + FT d = FT(0); + FT distance = FT(0); + FT sr = sphere.squared_radius(); + + const Point& center = sphere.center(); + + if(center.x() < FT{bbox.xmin()}) + { + d = FT{bbox.xmin()} - center.x(); + d = square(d); + if(certainly(d > sr)) + return false; + + distance = d; + } + else if(center.x() > FT{bbox.xmax()}) + { + d = center.x() - FT{bbox.xmax()}; + d = square(d); + if(certainly(d > sr)) + return false; + + distance = d; + } + + if(center.y() < FT{bbox.ymin()}) + { + d = FT{bbox.ymin()} - center.y(); + d = square(d); + if(certainly(d > sr)) + return false; + + distance += d; + } + else if(center.y() > FT{bbox.ymax()}) + { + d = center.y() - FT{bbox.ymax()}; + d = square(d); + if(certainly(d > sr)) + return false; + + distance += d; + } + + if(center.z() < FT{bbox.zmin()}) + { + d = FT{bbox.zmin()} - center.z(); + d = square(d); + distance += d; + } + else if(center.z() > FT{bbox.zmax()}) + { + d = center.z() - FT{bbox.zmax()}; + d = square(d); + distance += d; + } + +// For unknown reasons this causes a syntax error on VC2005 +// but compiles fine on Linux and MAC +// +// int i; +// for(i = 0; i < 3; ++i) +// { +// if(center[i] < (FT)bbox.min(i)) +// { +// d = (FT)bbox.min(i) - center[i]; +// distance += d * d; +// } +// else if(center[i] > (FT)bbox.max(i)) +// { +// d = center[i] - (FT)bbox.max(i); +// distance += d * d; +// } +// } + + return distance <= sr; +} + template bool do_intersect(const typename K::Iso_cuboid_3& ic, const typename K::Sphere_3& sphere, - const K&) + const K& k) { - return do_intersect_sphere_box_3(sphere, ic, K()); + return do_intersect_sphere_box_3(sphere, ic, k); } template bool do_intersect(const typename K::Sphere_3& sphere, const typename K::Iso_cuboid_3& ic, - const K&) + const K& k) { - return do_intersect_sphere_box_3(sphere, ic, K()); + return do_intersect_sphere_box_3(sphere, ic, k); } } // namespace internal } // namespace Intersections +} // namespace CGAL -template -bool do_intersect(const Iso_cuboid_3& a, - const Sphere_3& b) { - return K().do_intersect_3_object()(a, b); -} - -template -bool do_intersect(const Sphere_3& a, - const Iso_cuboid_3& b) { - return K().do_intersect_3_object()(a, b); -} - -} //namespace CGAL - -#endif // CGAL_INTERNAL_INTERSECTIONS_3_ISO_CUBOID_3_SPHERE_3_DO_INTERSECT_H +#endif // CGAL_INTERNAL_INTERSECTIONS_3_ISO_CUBOID_3_SPHERE_3_DO_INTERSECT_H diff --git a/Intersections_3/include/CGAL/Intersections_3/internal/Iso_cuboid_3_Tetrahedron_3_do_intersect.h b/Intersections_3/include/CGAL/Intersections_3/internal/Iso_cuboid_3_Tetrahedron_3_do_intersect.h new file mode 100644 index 00000000000..06da65836c4 --- /dev/null +++ b/Intersections_3/include/CGAL/Intersections_3/internal/Iso_cuboid_3_Tetrahedron_3_do_intersect.h @@ -0,0 +1,46 @@ +// Copyright (c) 2018 GeometryFactory +// All rights reserved. +// +// This file is part of CGAL (www.cgal.org) +// +// $URL$ +// $Id$ +// SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-Commercial +// +// +// Author(s) : Andreas Fabri + +#ifndef CGAL_INTERNAL_INTERSECTIONS_3_ISO_CUBOID_3_TETRAHEDRON_3_DO_INTERSECT_H +#define CGAL_INTERNAL_INTERSECTIONS_3_ISO_CUBOID_3_TETRAHEDRON_3_DO_INTERSECT_H + +#include + +namespace CGAL { +namespace Intersections { +namespace internal { + +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); +} + +} // namespace internal +} // namespace Intersections +} // namespace CGAL + +#endif // CGAL_INTERNAL_INTERSECTIONS_3_ISO_CUBOID_3_TETRAHEDRON_3_DO_INTERSECT_H diff --git a/Intersections_3/include/CGAL/Intersections_3/internal/Iso_cuboid_3_Triangle_3_do_intersect.h b/Intersections_3/include/CGAL/Intersections_3/internal/Iso_cuboid_3_Triangle_3_do_intersect.h index 87d65914cf2..723ef269306 100644 --- a/Intersections_3/include/CGAL/Intersections_3/internal/Iso_cuboid_3_Triangle_3_do_intersect.h +++ b/Intersections_3/include/CGAL/Intersections_3/internal/Iso_cuboid_3_Triangle_3_do_intersect.h @@ -14,20 +14,10 @@ #ifndef CGAL_INTERNAL_INTERSECTIONS_3_ISO_CUBOID_3_TRIANGLE_3_DO_INTERSECT_H #define CGAL_INTERNAL_INTERSECTIONS_3_ISO_CUBOID_3_TRIANGLE_3_DO_INTERSECT_H -#include -#include - -// Fast Triangle-Cuboid intersection test, following Tomas Akenine-Moeller description. -// The code looks slightly different from his code because we avoid the translation at -// a minimal cost (and we use C++ ;). - -#include #include namespace CGAL { - namespace Intersections { - namespace internal { template @@ -51,6 +41,6 @@ bool do_intersect(const typename K::Iso_cuboid_3& bbox, -} //namespace CGAL +} // namespace CGAL -#endif // CGAL_INTERNAL_INTERSECTIONS_3_ISO_CUBOID_3_TRIANGLE_3_DO_INTERSECT_H +#endif // CGAL_INTERNAL_INTERSECTIONS_3_ISO_CUBOID_3_TRIANGLE_3_DO_INTERSECT_H diff --git a/Intersections_3/include/CGAL/Intersections_3/internal/Iso_cuboid_3_Triangle_3_intersection.h b/Intersections_3/include/CGAL/Intersections_3/internal/Iso_cuboid_3_Triangle_3_intersection.h index ea8155daf58..ccdba585679 100644 --- a/Intersections_3/include/CGAL/Intersections_3/internal/Iso_cuboid_3_Triangle_3_intersection.h +++ b/Intersections_3/include/CGAL/Intersections_3/internal/Iso_cuboid_3_Triangle_3_intersection.h @@ -121,7 +121,7 @@ template typename Intersection_traits::result_type intersection( const typename K::Iso_cuboid_3 &cub, - const typename K::Triangle_3 &tr, + const typename K::Triangle_3& tr, const K& k) { typedef typename K::Point_3 Point; @@ -203,7 +203,7 @@ intersection( template typename Intersection_traits::result_type intersection( - const typename K::Triangle_3 &tr, + const typename K::Triangle_3& tr, const typename K::Iso_cuboid_3 &cub, const K& k) { diff --git a/Intersections_3/include/CGAL/Intersections_3/internal/Line_3_Line_3_do_intersect.h b/Intersections_3/include/CGAL/Intersections_3/internal/Line_3_Line_3_do_intersect.h new file mode 100644 index 00000000000..5da82672621 --- /dev/null +++ b/Intersections_3/include/CGAL/Intersections_3/internal/Line_3_Line_3_do_intersect.h @@ -0,0 +1,47 @@ +// Copyright (c) 2008 INRIA Sophia-Antipolis (France), ETH Zurich (Switzerland). +// All rights reserved. +// +// This file is part of CGAL (www.cgal.org) +// +// $URL$ +// $Id$ +// SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-Commercial +// +// +// Author(s) : Pedro Machado Manhaes de Castro + +#ifndef CGAL_INTERNAL_INTERSECTIONS_3_LINE_3_LINE_3_DO_INTERSECT_H +#define CGAL_INTERNAL_INTERSECTIONS_3_LINE_3_LINE_3_DO_INTERSECT_H + +namespace CGAL { +namespace Intersections { +namespace internal { + +template +bool +do_intersect(const typename K::Line_3& l1, + const typename K::Line_3& l2, + const K& k) +{ + typedef typename K::Point_3 Point_3; + typedef typename K::Vector_3 Vector_3; + + if(k.has_on_3_object()(l1, l2.point())) + return true; + if(k.are_parallel_3_object()(l1,l2)) + return false; + + const Point_3& p1 = l1.point(); + const Point_3& p3 = l2.point(); + const Vector_3 &v1 = l1.to_vector(); + const Vector_3& v2 = l2.to_vector(); + const Point_3 p2 = p1 + v1; + const Point_3 p4 = p2 + v2; + return k.coplanar_3_object()(p1,p2,p3,p4); +} + +} // namespace internal +} // namespace Intersections +} // namespace CGAL + +#endif // CGAL_INTERNAL_INTERSECTIONS_3_LINE_3_LINE_3_DO_INTERSECT_H diff --git a/Intersections_3/include/CGAL/Intersections_3/internal/Line_3_Line_3_intersection.h b/Intersections_3/include/CGAL/Intersections_3/internal/Line_3_Line_3_intersection.h new file mode 100644 index 00000000000..d2fe3e1a170 --- /dev/null +++ b/Intersections_3/include/CGAL/Intersections_3/internal/Line_3_Line_3_intersection.h @@ -0,0 +1,74 @@ +// Copyright (c) 2008 INRIA Sophia-Antipolis (France), ETH Zurich (Switzerland). +// Copyright (c) 2010, 2014 GeometryFactory Sarl (France). +// All rights reserved. +// +// This file is part of CGAL (www.cgal.org) +// +// $URL$ +// $Id$ +// SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-Commercial +// +// +// Author(s) : Camille Wormser, Jane Tournois, Pierre Alliez + +#ifndef CGAL_INTERNAL_INTERSECTIONS_3_LINE_3_LINE_3_INTERSECTION_H +#define CGAL_INTERNAL_INTERSECTIONS_3_LINE_3_LINE_3_INTERSECTION_H + +#include + +#include +#include + +namespace CGAL { +namespace Intersections { +namespace internal { + +template +typename Intersection_traits::result_type +intersection(const typename K::Line_3& l1, + const typename K::Line_3& l2, + const K& k) +{ + typedef typename K::FT FT; + typedef typename K::Point_3 Point_3; + typedef typename K::Vector_3 Vector_3; + + if(k.has_on_3_object()(l1, l2.point())) + { + const Vector_3& v1 = l1.to_vector(); + const Vector_3& v2 = l2.to_vector(); + if((v1.x() * v2.y() == v1.y() * v2.x()) && + (v1.x() * v2.z() == v1.z() * v2.x()) && + (v1.y() * v2.z() == v1.z() * v2.y())) + return intersection_return(l1); + } + + if(k.are_parallel_3_object()(l1,l2)) + return intersection_return(); + + const Point_3& p1 = l1.point(); + const Point_3& p3 = l2.point(); + const Vector_3& v1 = l1.to_vector(); + const Vector_3& v2 = l2.to_vector(); + const Point_3 p2 = p1 + v1; + const Point_3 p4 = p2 + v2; + if(!k.coplanar_3_object()(p1,p2,p3,p4)) + return intersection_return(); + + const Vector_3 v3 = p3 - p1; + const Vector_3 v3v2 = cross_product(v3,v2); + const Vector_3 v1v2 = cross_product(v1,v2); + const FT sl = v1v2.squared_length(); + if(certainly(is_zero(sl))) + return intersection_return(); + + const FT t = ((v3v2.x()*v1v2.x()) + (v3v2.y()*v1v2.y()) + (v3v2.z()*v1v2.z())) / sl; + + return intersection_return(p1 + (v1 * t)); +} + +} // namespace internal +} // namespace Intersections +} // namespace CGAL + +#endif // CGAL_INTERNAL_INTERSECTIONS_3_LINE_3_LINE_3_INTERSECTION_H diff --git a/Intersections_3/include/CGAL/Intersections_3/internal/Line_3_Plane_3_do_intersect.h b/Intersections_3/include/CGAL/Intersections_3/internal/Line_3_Plane_3_do_intersect.h new file mode 100644 index 00000000000..2dc5b2122cd --- /dev/null +++ b/Intersections_3/include/CGAL/Intersections_3/internal/Line_3_Plane_3_do_intersect.h @@ -0,0 +1,63 @@ +// Copyright (c) 2008 INRIA Sophia-Antipolis (France), ETH Zurich (Switzerland). +// All rights reserved. +// +// This file is part of CGAL (www.cgal.org) +// +// $URL$ +// $Id$ +// SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-Commercial +// +// +// Author(s) : Geert-Jan Giezeman, +// Sylvain Pion + +#ifndef CGAL_INTERNAL_INTERSECTIONS_3_LINE_3_PLANE_3_DO_INTERSECT_H +#define CGAL_INTERNAL_INTERSECTIONS_3_LINE_3_PLANE_3_DO_INTERSECT_H + +#include + +namespace CGAL { +namespace Intersections { +namespace internal { + +template +bool +do_intersect(const typename K::Plane_3& plane, + const typename K::Line_3& line, + const K&) +{ + typedef typename K::Point_3 Point_3; + typedef typename K::Direction_3 Direction_3; + typedef typename K::RT RT; + + const Point_3& line_pt = line.point(); + const Direction_3& line_dir = line.direction(); + + RT den = plane.a()*line_dir.dx() + plane.b()*line_dir.dy() + plane.c()*line_dir.dz(); + if(den != 0) + return true; + + RT num = plane.a()*line_pt.hx() + plane.b()*line_pt.hy() + + plane.c()*line_pt.hz() + wmult_hw((K*)0, plane.d(), line_pt); + + if(num == RT(0)) // all line + return true; + else // no intersection + return false; +} + +template +inline +bool +do_intersect(const typename K::Line_3& line, + const typename K::Plane_3& plane, + const K& k) +{ + return do_intersect(plane, line, k); +} + +} // namespace internal +} // namespace Intersections +} // namespace CGAL + +#endif // CGAL_INTERNAL_INTERSECTIONS_3_LINE_3_PLANE_3_DO_INTERSECT_H diff --git a/Intersections_3/include/CGAL/Intersections_3/internal/Line_3_Plane_3_intersection.h b/Intersections_3/include/CGAL/Intersections_3/internal/Line_3_Plane_3_intersection.h new file mode 100644 index 00000000000..d14c119b56e --- /dev/null +++ b/Intersections_3/include/CGAL/Intersections_3/internal/Line_3_Plane_3_intersection.h @@ -0,0 +1,100 @@ +// Copyright (c) 2008 INRIA Sophia-Antipolis (France), ETH Zurich (Switzerland). +// Copyright (c) 2010, 2014 GeometryFactory Sarl (France). +// All rights reserved. +// +// This file is part of CGAL (www.cgal.org) +// +// $URL$ +// $Id$ +// SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-Commercial +// +// +// Author(s) : Geert-Jan Giezeman, +// Sylvain Pion + +#ifndef CGAL_INTERNAL_INTERSECTIONS_3_LINE_3_PLANE_3_INTERSECTION_H +#define CGAL_INTERNAL_INTERSECTIONS_3_LINE_3_PLANE_3_INTERSECTION_H + +#include + +#include + +namespace CGAL { +namespace Intersections { +namespace internal { + +template +boost::optional +intersection_point(const typename K::Plane_3& plane, + const typename K::Line_3& line, + const K& /*k*/) +{ + typedef typename K::Point_3 Point_3; + typedef typename K::Direction_3 Direction_3; + typedef typename K::RT RT; + + const Point_3& line_pt = line.point(); + const Direction_3& line_dir = line.direction(); + + RT num = plane.a()*line_pt.hx() + plane.b()*line_pt.hy() + + plane.c()*line_pt.hz() + wmult_hw((K*)0, plane.d(), line_pt); + RT den = plane.a()*line_dir.dx() + plane.b()*line_dir.dy() + + plane.c()*line_dir.dz(); + if(den == 0) + return boost::none; + + return boost::make_optional(Point_3(den*line_pt.hx()-num*line_dir.dx(), + den*line_pt.hy()-num*line_dir.dy(), + den*line_pt.hz()-num*line_dir.dz(), + wmult_hw((K*)0, den, line_pt))); +} + +template +typename Intersection_traits::result_type +intersection(const typename K::Plane_3& plane, + const typename K::Line_3& line, + const K& /*k*/) +{ + typedef typename K::Point_3 Point_3; + typedef typename K::Direction_3 Direction_3; + typedef typename K::RT RT; + + const Point_3& line_pt = line.point(); + const Direction_3& line_dir = line.direction(); + + RT num = plane.a()*line_pt.hx() + plane.b()*line_pt.hy() + + plane.c()*line_pt.hz() + wmult_hw((K*)0, plane.d(), line_pt); + RT den = plane.a()*line_dir.dx() + plane.b()*line_dir.dy() + + plane.c()*line_dir.dz(); + + if (den == 0) { + if (num == 0) { + // all line + return intersection_return(line); + } else { + // no intersection + return intersection_return(); + } + } + return intersection_return( + Point_3{den*line_pt.hx() - num*line_dir.dx(), + den*line_pt.hy() - num*line_dir.dy(), + den*line_pt.hz() - num*line_dir.dz(), + wmult_hw((K*)0, den, line_pt)}); +} + +template +inline +typename Intersection_traits::result_type +intersection(const typename K::Line_3& line, + const typename K::Plane_3& plane, + const K& k) +{ + return intersection(plane, line, k); +} + +} // namespace internal +} // namespace Intersections +} // namespace CGAL + +#endif // CGAL_INTERNAL_INTERSECTIONS_3_LINE_3_PLANE_3_INTERSECTION_H diff --git a/Intersections_3/include/CGAL/Intersections_3/internal/Line_3_Point_3_do_intersect.h b/Intersections_3/include/CGAL/Intersections_3/internal/Line_3_Point_3_do_intersect.h new file mode 100644 index 00000000000..b4a0cf92113 --- /dev/null +++ b/Intersections_3/include/CGAL/Intersections_3/internal/Line_3_Point_3_do_intersect.h @@ -0,0 +1,42 @@ +// Copyright (c) 2018 INRIA Sophia-Antipolis (France) +// All rights reserved. +// +// This file is part of CGAL (www.cgal.org) +// +// $URL$ +// $Id$ +// SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-Commercial +// +// +// Author(s) : Maxime Gimeno + +#ifndef CGAL_INTERNAL_INTERSECTIONS_3_LINE_3_POINT_3_DO_INTERSECT_H +#define CGAL_INTERNAL_INTERSECTIONS_3_LINE_3_POINT_3_DO_INTERSECT_H + +namespace CGAL { +namespace Intersections { +namespace internal { + +template +inline bool +do_intersect(const typename K::Point_3& pt, + const typename K::Line_3& line, + const K& k) +{ + return k.has_on_3_object()(line, pt); +} + +template +inline bool +do_intersect(const typename K::Line_3& line, + const typename K::Point_3& pt, + const K& k) +{ + return k.has_on_3_object()(line, pt); +} + +} // namespace internal +} // namespace Intersections +} // namespace CGAL + +#endif // CGAL_INTERNAL_INTERSECTIONS_3_LINE_3_POINT_3_DO_INTERSECT_H diff --git a/Intersections_3/include/CGAL/Intersections_3/internal/Line_3_Point_3_intersection.h b/Intersections_3/include/CGAL/Intersections_3/internal/Line_3_Point_3_intersection.h new file mode 100644 index 00000000000..85f0a8416b0 --- /dev/null +++ b/Intersections_3/include/CGAL/Intersections_3/internal/Line_3_Point_3_intersection.h @@ -0,0 +1,48 @@ +// Copyright (c) 2018 INRIA Sophia-Antipolis (France) +// All rights reserved. +// +// This file is part of CGAL (www.cgal.org) +// +// $URL$ +// $Id$ +// SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-Commercial +// +// +// Author(s) : Maxime Gimeno + +#ifndef CGAL_INTERNAL_INTERSECTIONS_3_LINE_3_POINT_3_INTERSECTION_H +#define CGAL_INTERNAL_INTERSECTIONS_3_LINE_3_POINT_3_INTERSECTION_H + +#include +#include + +namespace CGAL { +namespace Intersections { +namespace internal { + +template +typename CGAL::Intersection_traits::result_type +intersection(const typename K::Point_3& pt, + const typename K::Line_3& line, + const K& k) +{ + if(do_intersect(pt,line,k)) + return intersection_return(pt); + + return intersection_return(); +} + +template +typename CGAL::Intersection_traits::result_type +intersection(const typename K::Line_3& line, + const typename K::Point_3& pt, + const K& k) +{ + return intersection(pt, line, k); +} + +} // namespace internal +} // namespace Intersections +} // namespace CGAL + +#endif // CGAL_INTERNAL_INTERSECTIONS_3_LINE_3_POINT_3_INTERSECTION_H diff --git a/Intersections_3/include/CGAL/Intersections_3/internal/Line_3_Ray_3_do_intersect.h b/Intersections_3/include/CGAL/Intersections_3/internal/Line_3_Ray_3_do_intersect.h new file mode 100644 index 00000000000..e6e125107f0 --- /dev/null +++ b/Intersections_3/include/CGAL/Intersections_3/internal/Line_3_Ray_3_do_intersect.h @@ -0,0 +1,62 @@ +// Copyright (c) 2018 INRIA Sophia-Antipolis (France) +// All rights reserved. +// +// This file is part of CGAL (www.cgal.org) +// +// $URL$ +// $Id$ +// SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-Commercial +// +// +// Author(s) : Sébastien Loriot + +#ifndef CGAL_INTERNAL_INTERSECTIONS_3_LINE_3_RAY_3_DO_INTERSECT_H +#define CGAL_INTERNAL_INTERSECTIONS_3_LINE_3_RAY_3_DO_INTERSECT_H + +#include + +#include + +namespace CGAL { +namespace Intersections { +namespace internal { + +template +inline +bool +do_intersect(const typename K::Line_3& l, + const typename K::Ray_3& r, + const K& k) +{ + CGAL_precondition(!l.is_degenerate() && !r.is_degenerate()); + + if(!do_intersect(l, r.supporting_line())) + return false; + + typename K::Coplanar_orientation_3 pred = k.coplanar_orientation_3_object(); + CGAL::Orientation p0p1s = pred(l.point(0), l.point(1), r.source()); + if(p0p1s == COLLINEAR) + return true; + + CGAL::Orientation stp0 = pred(r.source(), r.second_point(), l.point(0)); + if(stp0 == COLLINEAR) + return Ray_3_has_on_collinear_Point_3(r,l.point(0),k); + + return (p0p1s != stp0); +} + +template +inline +bool +do_intersect(const typename K::Ray_3& r, + const typename K::Line_3& l, + const K& k) +{ + return do_intersect(l,r,k); +} + +} // namespace internal +} // namespace Intersections +} // namespace CGAL + +#endif // CGAL_INTERNAL_INTERSECTIONS_3_LINE_3_RAY_3_DO_INTERSECT_H diff --git a/Intersections_3/include/CGAL/Intersections_3/internal/Line_3_Ray_3_intersection.h b/Intersections_3/include/CGAL/Intersections_3/internal/Line_3_Ray_3_intersection.h new file mode 100644 index 00000000000..e9cbf2ca895 --- /dev/null +++ b/Intersections_3/include/CGAL/Intersections_3/internal/Line_3_Ray_3_intersection.h @@ -0,0 +1,64 @@ +// Copyright (c) 2018 INRIA Sophia-Antipolis (France) +// All rights reserved. +// +// This file is part of CGAL (www.cgal.org) +// +// $URL$ +// $Id$ +// SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-Commercial +// +// +// Author(s) : Sébastien Loriot + +#ifndef CGAL_INTERNAL_INTERSECTIONS_3_LINE_3_RAY_3_INTERSECTION_H +#define CGAL_INTERNAL_INTERSECTIONS_3_LINE_3_RAY_3_INTERSECTION_H + +#include +#include +#include + +namespace CGAL { +namespace Intersections { +namespace internal { + +template +typename Intersection_traits::result_type +intersection(const typename K::Line_3& l, + const typename K::Ray_3& r, + const K& k) +{ + CGAL_precondition(!l.is_degenerate() && !r.is_degenerate()); + + typename Intersection_traits::result_type + v = internal::intersection(l, r.supporting_line(), k); + + if(v) + { + if(const typename K::Point_3* p = intersect_get(v)) + { + if(Ray_3_has_on_collinear_Point_3(r, *p, k)) + return intersection_return(*p); + } + else if(intersect_get(v)) + { + return intersection_return(r); + } + } + + return intersection_return(); +} + +template +typename Intersection_traits::result_type +intersection(const typename K::Ray_3& r, + const typename K::Line_3& l, + const K& k) +{ + return intersection(l, r, k); +} + +} // namespace internal +} // namespace Intersections +} // namespace CGAL + +#endif // CGAL_INTERNAL_INTERSECTIONS_3_LINE_3_RAY_3_INTERSECTION_H diff --git a/Intersections_3/include/CGAL/Intersections_3/internal/Line_3_Segment_3_do_intersect.h b/Intersections_3/include/CGAL/Intersections_3/internal/Line_3_Segment_3_do_intersect.h new file mode 100644 index 00000000000..d03d33e76e7 --- /dev/null +++ b/Intersections_3/include/CGAL/Intersections_3/internal/Line_3_Segment_3_do_intersect.h @@ -0,0 +1,67 @@ +// Copyright (c) 2018 INRIA Sophia-Antipolis (France) +// All rights reserved. +// +// This file is part of CGAL (www.cgal.org) +// +// $URL$ +// $Id$ +// SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-Commercial +// +// +// Author(s) : Sébastien Loriot + +#ifndef CGAL_INTERNAL_INTERSECTIONS_3_LINE_3_SEGMENT_3_DO_INTERSECT_H +#define CGAL_INTERNAL_INTERSECTIONS_3_LINE_3_SEGMENT_3_DO_INTERSECT_H + +#include + +#include +#include + +namespace CGAL { +namespace Intersections { +namespace internal { + +template +inline +bool +do_intersect(const typename K::Line_3& l, + const typename K::Segment_3& s, + const K& k) +{ + CGAL_precondition(!l.is_degenerate() && !s.is_degenerate()); + + bool b = do_intersect(l, s.supporting_line(), k); + if(b) + { + // supporting_line intersects: points are coplanar + typename K::Coplanar_orientation_3 cpl_orient = k.coplanar_orientation_3_object(); + const typename K::Point_3& p1 = l.point(0); + const typename K::Point_3& p2 = l.point(1); + ::CGAL::Orientation or1 = cpl_orient(p1, p2, s[0]); + + if(or1 == COLLINEAR) + return true; + + ::CGAL::Orientation or2 = cpl_orient(p1, p2, s[1]); + return (or1 != or2); + } + + return false; +} + +template +inline +bool +do_intersect(const typename K::Segment_3& s, + const typename K::Line_3& l, + const K& k) +{ + return do_intersect(l,s,k); +} + +} // namespace internal +} // namespace Intersections +} // namespace CGAL + +#endif // CGAL_INTERNAL_INTERSECTIONS_3_LINE_3_SEGMENT_3_DO_INTERSECT_H diff --git a/Intersections_3/include/CGAL/Intersections_3/internal/Line_3_Segment_3_intersection.h b/Intersections_3/include/CGAL/Intersections_3/internal/Line_3_Segment_3_intersection.h new file mode 100644 index 00000000000..1fa52872968 --- /dev/null +++ b/Intersections_3/include/CGAL/Intersections_3/internal/Line_3_Segment_3_intersection.h @@ -0,0 +1,62 @@ +// Copyright (c) 2018 INRIA Sophia-Antipolis (France) +// All rights reserved. +// +// This file is part of CGAL (www.cgal.org) +// +// $URL$ +// $Id$ +// SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-Commercial +// +// +// Author(s) : Sébastien Loriot + +#ifndef CGAL_INTERNAL_INTERSECTIONS_3_LINE_3_SEGMENT_3_INTERSECTION_H +#define CGAL_INTERNAL_INTERSECTIONS_3_LINE_3_SEGMENT_3_INTERSECTION_H + +#include +#include + +namespace CGAL { +namespace Intersections { +namespace internal { + +template +typename Intersection_traits::result_type +intersection(const typename K::Line_3& l, + const typename K::Segment_3& s, + const K& k) +{ + CGAL_precondition(!l.is_degenerate() && !s.is_degenerate()); + + typename Intersection_traits::result_type + v = internal::intersection(l, s.supporting_line(), k); + + if(v) + { + if(const typename K::Point_3* p = intersect_get (v)) + { + typename K::Collinear_are_ordered_along_line_3 cln_order = k.collinear_are_ordered_along_line_3_object(); + if(cln_order(s[0], *p, s[1])) + return intersection_return(*p); + } else { + return intersection_return(s); + } + } + + return intersection_return(); +} + +template +typename Intersection_traits::result_type +intersection(const typename K::Segment_3& s, + const typename K::Line_3& l, + const K& k) +{ + return intersection(l, s, k); +} + +} // namespace internal +} // namespace Intersections +} // namespace CGAL + +#endif // CGAL_INTERNAL_INTERSECTIONS_3_LINE_3_SEGMENT_3_INTERSECTION_H diff --git a/Intersections_3/include/CGAL/Intersections_3/internal/Line_3_Sphere_3_do_intersect.h b/Intersections_3/include/CGAL/Intersections_3/internal/Line_3_Sphere_3_do_intersect.h new file mode 100644 index 00000000000..17cb1c2761c --- /dev/null +++ b/Intersections_3/include/CGAL/Intersections_3/internal/Line_3_Sphere_3_do_intersect.h @@ -0,0 +1,53 @@ +// Copyright (c) 2018 INRIA Sophia-Antipolis (France) +// All rights reserved. +// +// This file is part of CGAL (www.cgal.org) +// +// $URL$ +// $Id$ +// SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-Commercial +// +// +// Author(s) : Andreas Fabri + +#ifndef CGAL_INTERNAL_INTERSECTIONS_3_LINE_3_SPHERE_3_DO_INTERSECT_H +#define CGAL_INTERNAL_INTERSECTIONS_3_LINE_3_SPHERE_3_DO_INTERSECT_H + +#include +#include + +namespace CGAL { +namespace Intersections { +namespace internal { + +template +inline +typename K::Boolean +do_intersect(const typename K::Line_3& lin, + const typename K::Sphere_3& sp, + const K& k) +{ + typedef typename K::RT RT; + RT num, den; + + CGAL::internal::squared_distance_RT(sp.center(), lin, num, den, k); + return !(compare_quotients(num, den, + Rational_traits().numerator(sp.squared_radius()), + Rational_traits().denominator(sp.squared_radius())) == LARGER); +} + +template +inline +typename K::Boolean +do_intersect(const typename K::Sphere_3& sp, + const typename K::Line_3& lin, + const K& k) +{ + return do_intersect(lin, sp, k); +} + +} // namespace internal +} // namespace Intersections +} // namespace CGAL + +#endif // CGAL_INTERNAL_INTERSECTIONS_3_LINE_3_SPHERE_3_DO_INTERSECT_H diff --git a/Intersections_3/include/CGAL/Intersections_3/internal/Line_3_Tetrahedron_3_do_intersect.h b/Intersections_3/include/CGAL/Intersections_3/internal/Line_3_Tetrahedron_3_do_intersect.h new file mode 100644 index 00000000000..253f1e8a7fa --- /dev/null +++ b/Intersections_3/include/CGAL/Intersections_3/internal/Line_3_Tetrahedron_3_do_intersect.h @@ -0,0 +1,45 @@ +// Copyright (c) 2019 GeometryFactory(France). +// All rights reserved. +// +// This file is part of CGAL (www.cgal.org) +// +// $URL$ +// $Id$ +// SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-Commercial +// +// +// Author(s) : Andreas Fabri, +// Laurent Rineau + +#ifndef CGAL_INTERNAL_INTERSECTIONS_3_LINE_3_TETRAHEDRON_3_DO_INTERSECT_H +#define CGAL_INTERNAL_INTERSECTIONS_3_LINE_3_TETRAHEDRON_3_DO_INTERSECT_H + +#include + +namespace CGAL { +namespace Intersections { +namespace internal { + +template +typename K::Boolean +do_intersect(const typename K::Line_3& unb, + const typename K::Tetrahedron_3& tet, + const K& k) +{ + return do_intersect_tetrahedron_unbounded(tet, unb, k); +} + +template +typename K::Boolean +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); +} + +} // namespace internal +} // namespace Intersections +} // namespace CGAL + +#endif // CGAL_INTERNAL_INTERSECTIONS_3_LINE_3_TETRAHEDRON_3_DO_INTERSECT_H diff --git a/Intersections_3/include/CGAL/Intersections_3/internal/Tetrahedron_3_Line_3_intersection.h b/Intersections_3/include/CGAL/Intersections_3/internal/Line_3_Tetrahedron_3_intersection.h similarity index 50% rename from Intersections_3/include/CGAL/Intersections_3/internal/Tetrahedron_3_Line_3_intersection.h rename to Intersections_3/include/CGAL/Intersections_3/internal/Line_3_Tetrahedron_3_intersection.h index a36871403a7..f1d8bdff1fd 100644 --- a/Intersections_3/include/CGAL/Intersections_3/internal/Tetrahedron_3_Line_3_intersection.h +++ b/Intersections_3/include/CGAL/Intersections_3/internal/Line_3_Tetrahedron_3_intersection.h @@ -11,50 +11,37 @@ // Author(s) : Maxime Gimeno // -#ifndef CGAL_INTERNAL_INTERSECTIONS_3_TETRAHEDRON_3_LINE_3_INTERSECTION_H -#define CGAL_INTERNAL_INTERSECTIONS_3_TETRAHEDRON_3_LINE_3_INTERSECTION_H +#ifndef CGAL_INTERNAL_INTERSECTIONS_3_LINE_3_TETRAHEDRON_3_INTERSECTION_H +#define CGAL_INTERNAL_INTERSECTIONS_3_LINE_3_TETRAHEDRON_3_INTERSECTION_H -#include -#include +#include #include namespace CGAL { - namespace Intersections { - namespace internal { template struct Tetrahedron_Line_intersection_3 - :public Tetrahedron_lines_intersection_3_base > + : public Tetrahedron_lines_intersection_3_base > { - typedef Tetrahedron_lines_intersection_3_base > Base; + typedef Tetrahedron_lines_intersection_3_base > Base; typedef typename Base::Result_type Result_type; - Tetrahedron_Line_intersection_3( - const typename K::Tetrahedron_3& tet, - const typename K::Line_3& o):Base(tet,o) + + Tetrahedron_Line_intersection_3(const typename K::Tetrahedron_3& tet, + const typename K::Line_3& l) + : Base(tet, l) {} - bool all_inside_test() - { - return false; - } - - bool are_extremities_inside_test() - { - return false; - } - + bool all_inside_test() { return false; } + bool are_extremities_inside_test() { return false; } }; -//Tetrahedron_3 Line_3 template typename Intersection_traits::result_type -intersection( - const typename K::Tetrahedron_3 &tet, - const typename K::Line_3 &line, - const K&) +intersection(const typename K::Tetrahedron_3& tet, + const typename K::Line_3& line, + const K&) { Tetrahedron_Line_intersection_3 solver(tet, line); solver.do_procede(); @@ -63,13 +50,15 @@ intersection( template typename Intersection_traits::result_type -intersection( - const typename K::Line_3 &line, - const typename K::Tetrahedron_3 &tet, - const K& k) +intersection(const typename K::Line_3& line, + const typename K::Tetrahedron_3& tet, + const K& k) { return intersection(tet, line, k); } -}}} -#endif // CGAL_INTERNAL_INTERSECTIONS_3_TETRAHEDRON_3_LINE_3_INTERSECTION_H +} // namespace internal +} // namespace Intersections +} // namespace CGAL + +#endif // CGAL_INTERNAL_INTERSECTIONS_3_LINE_3_TETRAHEDRON_3_INTERSECTION_H diff --git a/Intersections_3/include/CGAL/Intersections_3/internal/Line_3_Triangle_3_do_intersect.h b/Intersections_3/include/CGAL/Intersections_3/internal/Line_3_Triangle_3_do_intersect.h new file mode 100644 index 00000000000..4b2635a3153 --- /dev/null +++ b/Intersections_3/include/CGAL/Intersections_3/internal/Line_3_Triangle_3_do_intersect.h @@ -0,0 +1,87 @@ +// Copyright (c) 2003 INRIA Sophia-Antipolis (France). +// All rights reserved. +// +// This file is part of CGAL (www.cgal.org) +// +// $URL$ +// $Id$ +// SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-Commercial +// +// +// Author(s) : Philippe Guigue + +#ifndef CGAL_INTERNAL_INTERSECTIONS_LINE_3_TRIANGLE_3_DO_INTERSECT_H +#define CGAL_INTERNAL_INTERSECTIONS_LINE_3_TRIANGLE_3_DO_INTERSECT_H + +#include +#include + +namespace CGAL { +namespace Intersections { +namespace internal { + +template +bool do_intersect(const typename K::Triangle_3& t, + const typename K::Line_3& l, + const K& k) +{ + CGAL_kernel_precondition(!k.is_degenerate_3_object()(t)); + CGAL_kernel_precondition(!k.is_degenerate_3_object()(l)); + + typedef typename K::Point_3 Point_3; + + typename K::Construct_point_on_3 point_on = k.construct_point_on_3_object(); + typename K::Construct_vertex_3 vertex_on = k.construct_vertex_3_object(); + typename K::Orientation_3 orientation = k.orientation_3_object(); + typename K::Coplanar_orientation_3 coplanar_orientation = k.coplanar_orientation_3_object(); + + const Point_3& a = vertex_on(t,0); + const Point_3& b = vertex_on(t,1); + const Point_3& c = vertex_on(t,2); + const Point_3& p = point_on(l,0); + const Point_3& q = point_on(l,1); + + if((orientation(a,b,c,p) != COPLANAR) || (orientation(a,b,c,q) != COPLANAR)) + { + const Orientation pqab = orientation(p,q,a,b); + const Orientation pqbc = orientation(p,q,b,c); + + switch(pqab) + { + case POSITIVE: return (pqbc != NEGATIVE) && (orientation(p,q,c,a) != NEGATIVE); + case NEGATIVE: return (pqbc != POSITIVE) && (orientation(p,q,c,a) != POSITIVE); + case COPLANAR: + switch(pqbc) + { + case POSITIVE: return (orientation(p,q,c,a) != NEGATIVE); + case NEGATIVE: return (orientation(p,q,c,a) != POSITIVE); + case COPLANAR: return true; + default: // should not happen. + CGAL_kernel_assertion(false); + return false; + } + default: // should not happen. + CGAL_kernel_assertion(false); + return false; + } + } + + // Coplanar case + const Orientation pqa = coplanar_orientation(p,q,a); + return (coplanar_orientation(p,q,b) != pqa) || (coplanar_orientation(p,q,c) != pqa); +} + +template +inline +bool do_intersect(const typename K::Line_3& l, + const typename K::Triangle_3& t, + const K& k) +{ + return do_intersect(t, l, k); +} + +} // namespace internal +} // namespace Intersections +} // namespace CGAL + +#endif // CGAL_INTERNAL_INTERSECTIONS_LINE_3_TRIANGLE_3_DO_INTERSECT_H diff --git a/Intersections_3/include/CGAL/Intersections_3/internal/Triangle_3_Line_3_intersection.h b/Intersections_3/include/CGAL/Intersections_3/internal/Line_3_Triangle_3_intersection.h similarity index 92% rename from Intersections_3/include/CGAL/Intersections_3/internal/Triangle_3_Line_3_intersection.h rename to Intersections_3/include/CGAL/Intersections_3/internal/Line_3_Triangle_3_intersection.h index 0d0ac3cfc48..8f0bd531ce7 100644 --- a/Intersections_3/include/CGAL/Intersections_3/internal/Triangle_3_Line_3_intersection.h +++ b/Intersections_3/include/CGAL/Intersections_3/internal/Line_3_Triangle_3_intersection.h @@ -104,12 +104,12 @@ t3l3_intersection_coplanar_aux(const typename K::Point_3& a, template typename Intersection_traits::result_type -intersection_coplanar(const typename K::Triangle_3 &t, - const typename K::Line_3 &l, - const K & k ) +intersection_coplanar(const typename K::Triangle_3& t, + const typename K::Line_3& l, + const K& k) { - CGAL_kernel_precondition( ! k.is_degenerate_3_object()(t) ) ; - CGAL_kernel_precondition( ! k.is_degenerate_3_object()(l) ) ; + CGAL_kernel_precondition(!k.is_degenerate_3_object()(t) ); + CGAL_kernel_precondition(!k.is_degenerate_3_object()(l) ); typedef typename K::Point_3 Point_3; @@ -125,12 +125,12 @@ intersection_coplanar(const typename K::Triangle_3 &t, typename K::Construct_segment_3 segment = k.construct_segment_3_object(); - const Point_3 & p = point_on(l,0); - const Point_3 & q = point_on(l,1); + const Point_3& p = point_on(l,0); + const Point_3& q = point_on(l,1); - const Point_3 & A = vertex_on(t,0); - const Point_3 & B = vertex_on(t,1); - const Point_3 & C = vertex_on(t,2); + const Point_3& A = vertex_on(t,0); + const Point_3& B = vertex_on(t,1); + const Point_3& C = vertex_on(t,2); int k0 = 0; int k1 = 1; @@ -305,16 +305,16 @@ intersection_coplanar(const typename K::Triangle_3 &t, template inline typename CGAL::Intersection_traits::result_type -t3l3_intersection_aux(const typename K::Triangle_3 &t, - const typename K::Line_3 &l, - const K&) +t3l3_intersection_aux(const typename K::Triangle_3& t, + const typename K::Line_3& l, + const K& k) { // typename K::Intersect_3 intersection = // k.intersect_3_object(); // The intersection between a Line and Plane is either Point or Line typename Intersection_traits::result_type - v = internal::intersection(l,t.supporting_plane(), K()); + v = internal::intersection(l,t.supporting_plane(), k); // Intersection should be a point (because of orientation test done before) if(v) { @@ -331,12 +331,12 @@ t3l3_intersection_aux(const typename K::Triangle_3 &t, template typename CGAL::Intersection_traits::result_type -intersection(const typename K::Triangle_3 &t, - const typename K::Line_3 &l, +intersection(const typename K::Triangle_3& t, + const typename K::Line_3& l, const K& k) { - CGAL_kernel_precondition( ! k.is_degenerate_3_object()(t) ) ; - CGAL_kernel_precondition( ! k.is_degenerate_3_object()(l) ) ; + CGAL_kernel_precondition(!k.is_degenerate_3_object()(t) ); + CGAL_kernel_precondition(!k.is_degenerate_3_object()(l) ); typedef typename K::Point_3 Point_3; @@ -349,11 +349,11 @@ intersection(const typename K::Triangle_3 &t, typename K::Orientation_3 orientation = k.orientation_3_object(); - const Point_3 & a = vertex_on(t,0); - const Point_3 & b = vertex_on(t,1); - const Point_3 & c = vertex_on(t,2); - const Point_3 & p = point_on(l,0); - const Point_3 & q = point_on(l,1); + const Point_3& a = vertex_on(t,0); + const Point_3& b = vertex_on(t,1); + const Point_3& c = vertex_on(t,2); + const Point_3& p = point_on(l,0); + const Point_3& q = point_on(l,1); if ( ( orientation(a,b,c,p) != COPLANAR ) || ( orientation(a,b,c,q) != COPLANAR ) ) @@ -405,15 +405,15 @@ intersection(const typename K::Triangle_3 &t, template typename CGAL::Intersection_traits::result_type intersection(const typename K::Line_3 &l, - const typename K::Triangle_3 &t, + const typename K::Triangle_3& t, const K& k) { return internal::intersection(t,l,k); } -} // end namespace internal +} // namespace internal } // namespace Intersections -} // end namespace CGAL +} // namespace CGAL #endif // CGAL_INTERNAL_INTERSECTIONS_3_TRIANGLE_3_LINE_3_INTERSECTION_H diff --git a/Intersections_3/include/CGAL/Intersections_3/internal/Plane_3_Plane_3_Plane_3_do_intersect.h b/Intersections_3/include/CGAL/Intersections_3/internal/Plane_3_Plane_3_Plane_3_do_intersect.h new file mode 100644 index 00000000000..2884506fc20 --- /dev/null +++ b/Intersections_3/include/CGAL/Intersections_3/internal/Plane_3_Plane_3_Plane_3_do_intersect.h @@ -0,0 +1,69 @@ +// Copyright (c) 2008 INRIA(France). +// All rights reserved. +// +// This file is part of CGAL (www.cgal.org) +// +// $URL$ +// $Id$ +// SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-Commercial +// +// +// Author(s) : Geert-Jan Giezeman, +// Andreas Fabri + +#ifndef CGAL_INTERNAL_INTERSECTIONS_3_PLANE_3_PLANE_3_PLANE_3_DO_INTERSECT_H +#define CGAL_INTERNAL_INTERSECTIONS_3_PLANE_3_PLANE_3_PLANE_3_DO_INTERSECT_H + +#include +#include +#include + +namespace CGAL { +namespace Intersections { +namespace internal { + +template +inline bool +do_intersect(const typename K::Plane_3& plane1, + const typename K::Plane_3& plane2, + const typename K::Plane_3& plane3, + const K&) +{ + typedef typename K::RT RT; + + if(!is_zero(determinant(plane1.a(), plane1.b(), plane1.c(), + plane2.a(), plane2.b(), plane2.c(), + plane3.a(), plane3.b(), plane3.c()))) + return true; + + int pcount = 0; + bool b12, b13,b23; + if((b12 = parallel(plane1, plane2))) pcount++; + if((b13 = parallel(plane1, plane3))) pcount++; + if((b23 = parallel(plane2, plane3))) pcount++; + + if(pcount == 3) + { + return (((plane1 == plane2) || (plane1 == plane2.opposite())) && + ((plane1 == plane3) || (plane1 == plane3.opposite()))); + } + + if(pcount == 1) + { + if(b12 && ((plane1 == plane2)||(plane1 == plane2.opposite()))) return true; + if(b13 && ((plane1 == plane3)||(plane1 == plane3.opposite()))) return true; + if(b23 && ((plane2 == plane3)||(plane2 == plane3.opposite()))) return true; + } + + int rd = rank_34(plane1.a(), plane1.b(), plane1.c(), plane1.d(), + plane2.a(), plane2.b(), plane2.c(), plane2.d(), + plane3.a(), plane3.b(), plane3.c(), plane3.d()); + + return (rd == 2); +} + +} // namespace internal +} // namespace Intersections +} // namespace CGAL + +#endif // CGAL_INTERNAL_INTERSECTIONS_3_PLANE_3_PLANE_3_PLANE_3_DO_INTERSECT_H diff --git a/Intersections_3/include/CGAL/Intersections_3/internal/Plane_3_Plane_3_Plane_3_intersection.h b/Intersections_3/include/CGAL/Intersections_3/internal/Plane_3_Plane_3_Plane_3_intersection.h new file mode 100644 index 00000000000..be6ca11f069 --- /dev/null +++ b/Intersections_3/include/CGAL/Intersections_3/internal/Plane_3_Plane_3_Plane_3_intersection.h @@ -0,0 +1,133 @@ +// Copyright (c) 2008 INRIA(France). +// All rights reserved. +// +// This file is part of CGAL (www.cgal.org) +// +// $URL$ +// $Id$ +// SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-Commercial +// +// +// Author(s) : Geert-Jan Giezeman, +// Sylvain Pion + +#ifndef CGAL_INTERNAL_INTERSECTIONS_3_PLANE_3_PLANE_3_PLANE_3_INTERSECTION_H +#define CGAL_INTERNAL_INTERSECTIONS_3_PLANE_3_PLANE_3_PLANE_3_INTERSECTION_H + +#include +#include +#include + +#include +#include + +namespace CGAL { +namespace Intersections { +namespace internal { + +// triple plane intersection +template +boost::optional +intersection_point(const typename K::Plane_3& plane1, + const typename K::Plane_3& plane2, + const typename K::Plane_3& plane3, + const K&) +{ + typedef typename K::FT FT; + + const FT& m00 = plane1.a(); + const FT& m01 = plane1.b(); + const FT& m02 = plane1.c(); + const FT& b0 = - plane1.d(); + const FT& m10 = plane2.a(); + const FT& m11 = plane2.b(); + const FT& m12 = plane2.c(); + const FT& b1 = - plane2.d(); + const FT& m20 = plane3.a(); + const FT& m21 = plane3.b(); + const FT& m22 = plane3.c(); + const FT& b2 = - plane3.d(); + + // Minors common to two determinants + const FT minor_0 = m00*m11 - m10*m01; + const FT minor_1 = m00*m21 - m20*m01; + const FT minor_2 = m10*m21 - m20*m11; + + const FT den = minor_0*m22 - minor_1*m12 + minor_2*m02; // determinant of M + + if(is_zero(den)){ + return boost::none; + } + + const FT num3 = minor_0*b2 - minor_1*b1 + minor_2*b0; // determinant of M with M[x:2] swapped with [b0,b1,b2] + + // Minors common to two determinants + const FT minor_3 = b0*m12 - b1*m02; + const FT minor_4 = b0*m22 - b2*m02; + const FT minor_5 = b1*m22 - b2*m12; + + // num1 has opposite signs because b0 and M[:1] have been swapped + const FT num1 = - minor_3*m21 + minor_4*m11 - minor_5*m01; // determinant of M with M[x:0] swapped with [b0,b1,b2] + const FT num2 = minor_3*m20 - minor_4*m10 + minor_5*m00; // determinant of M with M[x:1] swapped with [b0,b1,b2] + + return boost::make_optional(typename K::Point_3(num1/den, num2/den, num3/den)); +} + +template +boost::optional > +intersection(const typename K::Plane_3& plane1, + const typename K::Plane_3& plane2, + const typename K::Plane_3& plane3, + const K& k) +{ + typedef typename boost::optional > result_type; + + typedef typename K::Point_3 Point_3; + typedef typename K::Line_3 Line_3; + typedef typename K::Plane_3 Plane_3; + + // Intersection between plane1 and plane2 can either be + // a line, a plane, or empty. + typename Intersection_traits::result_type + o12 = internal::intersection(plane1, plane2, k); + + if(o12) + { + if(const Line_3* l = intersect_get(o12)) + { + // either point or line + typename Intersection_traits::result_type + v = internal::intersection(plane3, *l, k); + if(v) + { + if(const Point_3* p = intersect_get(v)) + return result_type(*p); + else if(const Line_3* l = intersect_get(v)) + return result_type(*l); + } + } + else if(const Plane_3 *pl = intersect_get(o12)) + { + // either line or plane + typename Intersection_traits::result_type + v = internal::intersection(plane3, *pl, k); + if(v) + { + if(const Plane_3* p = intersect_get(v)) + return result_type(*p); + else if(const Line_3* l = intersect_get(v)) + return result_type(*l); + } + } + } + + return result_type(); +} + +} // namespace internal +} // namespace Intersections +} // namespace CGAL + +#endif // CGAL_INTERNAL_INTERSECTIONS_3_PLANE_3_PLANE_3_PLANE_3_INTERSECTION_H diff --git a/Intersections_3/include/CGAL/Intersections_3/internal/Plane_3_Plane_3_do_intersect.h b/Intersections_3/include/CGAL/Intersections_3/internal/Plane_3_Plane_3_do_intersect.h new file mode 100644 index 00000000000..fc984e41dcf --- /dev/null +++ b/Intersections_3/include/CGAL/Intersections_3/internal/Plane_3_Plane_3_do_intersect.h @@ -0,0 +1,68 @@ +// Copyright (c) 2008 INRIA(France). +// All rights reserved. +// +// This file is part of CGAL (www.cgal.org) +// +// $URL$ +// $Id$ +// SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-Commercial +// +// +// Author(s) : Geert-Jan Giezeman, +// Sylvain Pion +// + +#ifndef CGAL_INTERNAL_INTERSECTIONS_3_PLANE_3_PLANE_3_DO_INTERSECT_H +#define CGAL_INTERNAL_INTERSECTIONS_3_PLANE_3_PLANE_3_DO_INTERSECT_H + +namespace CGAL { +namespace Intersections { +namespace internal { + +template +inline bool +do_intersect(const typename K::Plane_3& plane1, + const typename K::Plane_3& plane2, + const K&) +{ + typedef typename K::RT RT; + + const RT& a = plane1.a(); + const RT& b = plane1.b(); + const RT& c = plane1.c(); + const RT& d = plane1.d(); + const RT& p = plane2.a(); + const RT& q = plane2.b(); + const RT& r = plane2.c(); + const RT& s = plane2.d(); + + RT det = a*q-p*b; + if(det != 0) + return true; + + det = a*r-p*c; + if(det != 0) + return true; + + det = b*r-c*q; + if(det != 0) + return true; + + // degenerate case + if(a!=0 || p!=0) + return (a*s == p*d); + + if(b!=0 || q!=0) + return (b*s == q*d); + + if(c!=0 || r!=0) + return (c*s == r*d); + + return true; +} + +} // namespace internal +} // namespace Intersections +} // namespace CGAL + +#endif // CGAL_INTERNAL_INTERSECTIONS_3_PLANE_3_PLANE_3_DO_INTERSECT_H diff --git a/Intersections_3/include/CGAL/Intersections_3/internal/Plane_3_Plane_3_intersection.h b/Intersections_3/include/CGAL/Intersections_3/internal/Plane_3_Plane_3_intersection.h new file mode 100644 index 00000000000..148152385b6 --- /dev/null +++ b/Intersections_3/include/CGAL/Intersections_3/internal/Plane_3_Plane_3_intersection.h @@ -0,0 +1,99 @@ +// Copyright (c) 2008 INRIA(France). +// All rights reserved. +// +// This file is part of CGAL (www.cgal.org) +// +// $URL$ +// $Id$ +// SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-Commercial +// +// +// Author(s) : Geert-Jan Giezeman, +// Sylvain Pion + +#ifndef CGAL_INTERNAL_INTERSECTIONS_3_PLANE_3_PLANE_3_INTERSECTION_H +#define CGAL_INTERNAL_INTERSECTIONS_3_PLANE_3_PLANE_3_INTERSECTION_H + +#include + +namespace CGAL { +namespace Intersections { +namespace internal { + +template +typename Intersection_traits::result_type +intersection(const typename K::Plane_3& plane1, + const typename K::Plane_3& plane2, + const K&) +{ + typedef typename K::RT RT; + typedef typename K::Point_3 Point_3; + typedef typename K::Direction_3 Direction_3; + typedef typename K::Line_3 Line_3; + + const RT& a = plane1.a(); + const RT& b = plane1.b(); + const RT& c = plane1.c(); + const RT& d = plane1.d(); + const RT& p = plane2.a(); + const RT& q = plane2.b(); + const RT& r = plane2.c(); + const RT& s = plane2.d(); + + RT det = a*q-p*b; + if(det != 0) + { + Point_3 is_pt = Point_3(b*s-d*q, p*d-a*s, 0, det); + Direction_3 is_dir = Direction_3(b*r-c*q, p*c-a*r, det); + return intersection_return(Line_3(is_pt, is_dir)); + } + + det = a*r-p*c; + if(det != 0) + { + Point_3 is_pt = Point_3(c*s-d*r, 0, p*d-a*s, det); + Direction_3 is_dir = Direction_3(c*q-b*r, det, p*b-a*q); + return intersection_return(Line_3(is_pt, is_dir)); + } + + det = b*r-c*q; + if(det != 0) + { + Point_3 is_pt = Point_3(0, c*s-d*r, d*q-b*s, det); + Direction_3 is_dir = Direction_3(det, c*p-a*r, a*q-b*p); + return intersection_return(Line_3(is_pt, is_dir)); + } + + // degenerate case + if(a!=0 || p!=0) + { + if(a*s == p*d) + return intersection_return(plane1); + else + return intersection_return(); + } + + if(b!=0 || q!=0) + { + if(b*s == q*d) + return intersection_return(plane1); + else + return intersection_return(); + } + + if(c!=0 || r!=0) + { + if(c*s == r*d) + return intersection_return(plane1); + else + return intersection_return(); + } + + return intersection_return(plane1); +} + +} // namespace internal +} // namespace Intersections +} // namespace CGAL + +#endif // CGAL_INTERNAL_INTERSECTIONS_3_PLANE_3_PLANE_3_INTERSECTION_H diff --git a/Intersections_3/include/CGAL/Intersections_3/internal/Plane_3_Point_3_do_intersect.h b/Intersections_3/include/CGAL/Intersections_3/internal/Plane_3_Point_3_do_intersect.h new file mode 100644 index 00000000000..f53221b5700 --- /dev/null +++ b/Intersections_3/include/CGAL/Intersections_3/internal/Plane_3_Point_3_do_intersect.h @@ -0,0 +1,42 @@ +// Copyright (c) 2019 GeometryFactory(France). +// All rights reserved. +// +// This file is part of CGAL (www.cgal.org) +// +// $URL$ +// $Id$ +// SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-Commercial +// +// +// Author(s) : Maxime Gimeno + +#ifndef CGAL_INTERNAL_INTERSECTIONS_3_PLANE_3_POINT_3_DO_INTERSECT_H +#define CGAL_INTERNAL_INTERSECTIONS_3_PLANE_3_POINT_3_DO_INTERSECT_H + +namespace CGAL { +namespace Intersections { +namespace internal { + +template +inline bool +do_intersect(const typename K::Point_3& pt, + const typename K::Plane_3& plane, + const K& k) +{ + return k.has_on_3_object()(plane,pt); +} + +template +inline bool +do_intersect(const typename K::Plane_3& plane, + const typename K::Point_3& pt, + const K& k) +{ + return k.has_on_3_object()(plane, pt); +} + +} // namespace internal +} // namespace Intersections +} // namespace CGAL + +#endif // CGAL_INTERNAL_INTERSECTIONS_3_PLANE_3_POINT_3_DO_INTERSECT_H diff --git a/Intersections_3/include/CGAL/Intersections_3/internal/Plane_3_Point_3_intersection.h b/Intersections_3/include/CGAL/Intersections_3/internal/Plane_3_Point_3_intersection.h new file mode 100644 index 00000000000..ac6696ff929 --- /dev/null +++ b/Intersections_3/include/CGAL/Intersections_3/internal/Plane_3_Point_3_intersection.h @@ -0,0 +1,48 @@ +// Copyright (c) 2019 GeometryFactory(France). +// All rights reserved. +// +// This file is part of CGAL (www.cgal.org) +// +// $URL$ +// $Id$ +// SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-Commercial +// +// +// Author(s) : Maxime Gimeno + +#ifndef CGAL_INTERNAL_INTERSECTIONS_3_PLANE_3_POINT_3_INTERSECTION_H +#define CGAL_INTERNAL_INTERSECTIONS_3_PLANE_3_POINT_3_INTERSECTION_H + +#include +#include + +namespace CGAL { +namespace Intersections { +namespace internal { + +template +typename CGAL::Intersection_traits::result_type +intersection(const typename K::Point_3& pt, + const typename K::Plane_3& plane, + const K& k) +{ + if(do_intersect(pt, plane, k)) + return intersection_return(pt); + + return intersection_return(); +} + +template +typename CGAL::Intersection_traits::result_type +intersection(const typename K::Plane_3& plane, + const typename K::Point_3& pt, + const K& k) +{ + return internal::intersection(pt, plane,k); +} + +} // namespace internal +} // namespace Intersections +} // namespace CGAL + +#endif // CGAL_INTERNAL_INTERSECTIONS_3_PLANE_3_POINT_3_INTERSECTION_H diff --git a/Intersections_3/include/CGAL/Intersections_3/internal/Plane_3_Ray_3_do_intersect.h b/Intersections_3/include/CGAL/Intersections_3/internal/Plane_3_Ray_3_do_intersect.h new file mode 100644 index 00000000000..d254bc3f367 --- /dev/null +++ b/Intersections_3/include/CGAL/Intersections_3/internal/Plane_3_Ray_3_do_intersect.h @@ -0,0 +1,55 @@ +// Copyright (c) 1997-2010 +// Utrecht University (The Netherlands), +// ETH Zurich (Switzerland), +// INRIA Sophia-Antipolis (France), +// Max-Planck-Institute Saarbruecken (Germany), +// and Tel-Aviv University (Israel). All rights reserved. +// +// This file is part of CGAL (www.cgal.org) +// +// $URL$ +// $Id$ +// SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-Commercial +// +// +// Author(s) : Geert-Jan Giezeman + +#ifndef CGAL_INTERNAL_INTERSECTIONS_3_PLANE_3_RAY_3_DO_INTERSECT_H +#define CGAL_INTERNAL_INTERSECTIONS_3_PLANE_3_RAY_3_DO_INTERSECT_H + +#include +#include + +namespace CGAL { +namespace Intersections { +namespace internal { + +template +bool +do_intersect(const typename K::Plane_3& plane, + const typename K::Ray_3& ray, + const K& k) +{ + typename K::Oriented_side_3 oriented_side_3 = k.oriented_side_3_object(); + CGAL::Oriented_side os = oriented_side_3(plane, ray.source()); + if(os == ON_ORIENTED_BOUNDARY) + return true; + + return (sign(ray.to_vector()* plane.orthogonal_vector()) * os == -1); +} + +template +inline +bool +do_intersect(const typename K::Ray_3& ray, + const typename K::Plane_3& plane, + const K& k) +{ + return do_intersect(plane, ray, k); +} + +} // namespace internal +} // namespace Intersections +} // namespace CGAL + +#endif // CGAL_INTERNAL_INTERSECTIONS_3_PLANE_3_RAY_3_DO_INTERSECT_H diff --git a/Intersections_3/include/CGAL/Intersections_3/internal/Plane_3_Ray_3_intersection.h b/Intersections_3/include/CGAL/Intersections_3/internal/Plane_3_Ray_3_intersection.h new file mode 100644 index 00000000000..7b361d877d9 --- /dev/null +++ b/Intersections_3/include/CGAL/Intersections_3/internal/Plane_3_Ray_3_intersection.h @@ -0,0 +1,70 @@ +// Copyright (c) 1997-2010 +// Utrecht University (The Netherlands), +// ETH Zurich (Switzerland), +// INRIA Sophia-Antipolis (France), +// Max-Planck-Institute Saarbruecken (Germany), +// and Tel-Aviv University (Israel). All rights reserved. +// +// This file is part of CGAL (www.cgal.org) +// +// $URL$ +// $Id$ +// SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-Commercial +// +// +// Author(s) : Geert-Jan Giezeman + +#ifndef CGAL_INTERNAL_INTERSECTIONS_3_PLANE_3_RAY_3_INTERSECTION_H +#define CGAL_INTERNAL_INTERSECTIONS_3_PLANE_3_RAY_3_INTERSECTION_H + +#include +#include + +namespace CGAL { +namespace Intersections { +namespace internal { + +template +typename Intersection_traits::result_type +intersection(const typename K::Plane_3& plane, + const typename K::Ray_3& ray, + const K& k) +{ + typedef typename K::Point_3 Point_3; + + typename Intersection_traits::result_type + v = internal::intersection(plane, ray.supporting_line(), k); + + if(v) + { + if(const Point_3* p = intersect_get(v)) + { + if(ray.collinear_has_on(*p)) + return intersection_return(*p); + else + return intersection_return(); + } + } + else + { + return intersection_return(); + } + + return intersection_return(ray); +} + +template +inline +typename Intersection_traits::result_type +intersection(const typename K::Ray_3& ray, + const typename K::Plane_3& plane, + const K& k) +{ + return intersection(plane, ray, k); +} + +} // namespace internal +} // namespace Intersections +} // namespace CGAL + +#endif // CGAL_INTERNAL_INTERSECTIONS_3_PLANE_3_RAY_3_INTERSECTION_H diff --git a/Intersections_3/include/CGAL/Intersections_3/internal/Plane_3_Segment_3_do_intersect.h b/Intersections_3/include/CGAL/Intersections_3/internal/Plane_3_Segment_3_do_intersect.h new file mode 100644 index 00000000000..581a9cfa9a8 --- /dev/null +++ b/Intersections_3/include/CGAL/Intersections_3/internal/Plane_3_Segment_3_do_intersect.h @@ -0,0 +1,56 @@ +// Copyright (c) 2001 GeometryFactory(France). +// All rights reserved. +// +// This file is part of CGAL (www.cgal.org) +// +// $URL$ +// $Id$ +// SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-Commercial +// +// +// Author(s) : Geert-Jan Giezeman + +#ifndef CGAL_INTERNAL_INTERSECTIONS_3_PLANE_3_SEGMENT_3_DO_INTERSECT_H +#define CGAL_INTERNAL_INTERSECTIONS_3_PLANE_3_SEGMENT_3_DO_INTERSECT_H + +#include + +namespace CGAL { +namespace Intersections { +namespace internal { + +template +bool +do_intersect(const typename K::Plane_3& plane, + const typename K::Segment_3& seg, + const K&) +{ + typedef typename K::Point_3 Point_3; + + const Point_3& source = seg.source(); + const Point_3& target = seg.target(); + + CGAL::Oriented_side source_side = plane.oriented_side(source); + CGAL::Oriented_side target_side = plane.oriented_side(target); + + if(source_side == target_side && target_side != ON_ORIENTED_BOUNDARY) + return false; + + return true; +} + +template +inline +bool +do_intersect(const typename K::Segment_3& seg, + const typename K::Plane_3& plane, + const K& k) +{ + return do_intersect(plane, seg, k); +} + +} // namespace internal +} // namespace Intersections +} // namespace CGAL + +#endif // CGAL_INTERNAL_INTERSECTIONS_3_PLANE_3_SEGMENT_3_DO_INTERSECT_H diff --git a/Intersections_3/include/CGAL/Intersections_3/internal/Plane_3_Segment_3_intersection.h b/Intersections_3/include/CGAL/Intersections_3/internal/Plane_3_Segment_3_intersection.h new file mode 100644 index 00000000000..3b5c7fc7094 --- /dev/null +++ b/Intersections_3/include/CGAL/Intersections_3/internal/Plane_3_Segment_3_intersection.h @@ -0,0 +1,120 @@ +// Copyright (c) 2019 GeometryFactory(France). +// All rights reserved. +// +// This file is part of CGAL (www.cgal.org) +// +// $URL$ +// $Id$ +// SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-Commercial +// +// +// Author(s) : Geert-Jan Giezeman + +#ifndef CGAL_INTERNAL_INTERSECTIONS_3_PLANE_3_SEGMENT_3_INTERSECTION_H +#define CGAL_INTERNAL_INTERSECTIONS_3_PLANE_3_SEGMENT_3_INTERSECTION_H + +#include +#include + +#include +#include + +namespace CGAL { +namespace Intersections { +namespace internal { + +template +typename Intersection_traits::result_type +intersection(const typename K::Plane_3& plane, + const typename K::Segment_3& seg, + const K& k) +{ + typedef typename K::Point_3 Point_3; + + const Point_3& source = seg.source(); + const Point_3& target = seg.target(); + + CGAL::Oriented_side source_side = plane.oriented_side(source); + CGAL::Oriented_side target_side = plane.oriented_side(target); + + switch(source_side) + { + case ON_ORIENTED_BOUNDARY: + if (target_side == ON_ORIENTED_BOUNDARY) + return intersection_return(seg); + else + return intersection_return(source); + case ON_POSITIVE_SIDE: + switch(target_side) + { + case ON_ORIENTED_BOUNDARY: + return intersection_return(target); + case ON_POSITIVE_SIDE: + return intersection_return(); + default: // ON_NEGATIVE_SIDE: + { + // intersection object should be a point, but rounding errors + // could lead to: + // - a line: in such case, return seg, + // - the empty set: return the empty set. + typename Intersection_traits::result_type + v = internal::intersection(plane, seg.supporting_line(), k); + if(v) + { + if(const typename K::Point_3* p = intersect_get(v)) + return intersection_return(*p); + else + return intersection_return(seg); + } + else + { + return intersection_return(); + } + } + } + case ON_NEGATIVE_SIDE: + switch(target_side) + { + case ON_ORIENTED_BOUNDARY: + return intersection_return(target); + case ON_POSITIVE_SIDE: + { + // intersection object should be a point, but rounding errors + // could lead to: + // - a line: in such case, return seg, + // - the empty set: return the empty set. + typename Intersection_traits::result_type + v = internal::intersection(plane, seg.supporting_line(), k); + if(v) { + if(const typename K::Point_3* p = intersect_get(v)) + return intersection_return(*p); + else + return intersection_return(seg); + } + else + return intersection_return(); + } + case ON_NEGATIVE_SIDE: + return intersection_return(); + } + } + + CGAL_kernel_assertion_msg(false, "Supposedly unreachable code."); + return intersection_return(); +} + +template +inline +typename Intersection_traits::result_type +intersection(const typename K::Segment_3& seg, + const typename K::Plane_3& plane, + const K& k) +{ + return intersection(plane, seg, k); +} + +} // namespace internal +} // namespace Intersections +} // namespace CGAL + +#endif // CGAL_INTERNAL_INTERSECTIONS_3_PLANE_3_SEGMENT_3_INTERSECTION_H diff --git a/Intersections_3/include/CGAL/Intersections_3/internal/Plane_3_Sphere_3_do_intersect.h b/Intersections_3/include/CGAL/Intersections_3/internal/Plane_3_Sphere_3_do_intersect.h new file mode 100644 index 00000000000..df7b7c738ae --- /dev/null +++ b/Intersections_3/include/CGAL/Intersections_3/internal/Plane_3_Sphere_3_do_intersect.h @@ -0,0 +1,52 @@ +// Copyright (c) 2003 INRIA Sophia-Antipolis (France). +// All rights reserved. +// +// This file is part of CGAL (www.cgal.org) +// +// $URL$ +// $Id$ +// SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-Commercial +// +// +// Author(s) : Pedro Machado Manhaes de Castro + +#ifndef CGAL_INTERNAL_INTERSECTIONS_PLANE_3_SPHERE_3_DO_INTERSECT_H +#define CGAL_INTERNAL_INTERSECTIONS_PLANE_3_SPHERE_3_DO_INTERSECT_H + +#include + +namespace CGAL { +namespace Intersections { +namespace internal { + +template +inline +bool +do_intersect(const typename K::Plane_3& p, + const typename K::Sphere_3& s, + const K&) +{ + typedef typename K::FT FT; + + const FT d2 = CGAL::square(p.a()*s.center().x() + + p.b()*s.center().y() + + p.c()*s.center().z() + p.d()); + + return (d2 <= s.squared_radius() * (square(p.a()) + square(p.b()) + square(p.c()))); +} + +template +inline +bool +do_intersect(const typename K::Sphere_3& s, + const typename K::Plane_3& p, + const K&) +{ + return do_intersect(p,s); +} + +} // namespace internal +} // namespace Intersections +} // namespace CGAL + +#endif // CGAL_INTERNAL_INTERSECTIONS_PLANE_3_SPHERE_3_DO_INTERSECT_H diff --git a/Intersections_3/include/CGAL/Intersections_3/internal/Plane_3_Sphere_3_intersection.h b/Intersections_3/include/CGAL/Intersections_3/internal/Plane_3_Sphere_3_intersection.h new file mode 100644 index 00000000000..c76c2ed54e8 --- /dev/null +++ b/Intersections_3/include/CGAL/Intersections_3/internal/Plane_3_Sphere_3_intersection.h @@ -0,0 +1,71 @@ +// Copyright (c) 2003 INRIA Sophia-Antipolis (France). +// All rights reserved. +// +// This file is part of CGAL (www.cgal.org) +// +// $URL$ +// $Id$ +// SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-Commercial +// +// +// Author(s) : Pedro Machado Manhaes de Castro + +#ifndef CGAL_INTERNAL_INTERSECTIONS_PLANE_3_SPHERE_3_INTERSECTION_H +#define CGAL_INTERNAL_INTERSECTIONS_PLANE_3_SPHERE_3_INTERSECTION_H + +#include + +#include + +namespace CGAL { +namespace Intersections { +namespace internal { + +template +typename Intersection_traits::result_type +intersection(const typename K::Plane_3& p, + const typename K::Sphere_3& s, + const K&) +{ + typedef typename K::FT FT; + typedef typename K::Point_3 Point_3; + typedef typename K::Circle_3 Circle_3; + + const FT d2 = CGAL::square(p.a()*s.center().x() + + p.b()*s.center().y() + + p.c()*s.center().z() + p.d()) / + (square(p.a()) + square(p.b()) + square(p.c())); + + const FT cmp = d2 - s.squared_radius(); + + if(CGAL_NTS is_zero(cmp)) // tangent + { + return intersection_return( + p.projection(s.center())); + } + else if(CGAL_NTS is_negative(cmp)) // intersect + { + Point_3 center = p.projection(s.center()); + return intersection_return( + Circle_3{center, s.squared_radius() - d2, p}); + } + + // do not intersect + return intersection_return(); +} + +template +inline +typename Intersection_traits::result_type +intersection(const typename K::Sphere_3& s, + const typename K::Plane_3& p, + const K& k) +{ + return intersection(p, s, k); +} + +} // namespace internal +} // namespace Intersections +} // namespace CGAL + +#endif // CGAL_INTERNAL_INTERSECTIONS_PLANE_3_SPHERE_3_INTERSECTION_H diff --git a/Intersections_3/include/CGAL/Intersections_3/internal/Plane_3_Tetrahedron_3_do_intersect.h b/Intersections_3/include/CGAL/Intersections_3/internal/Plane_3_Tetrahedron_3_do_intersect.h new file mode 100644 index 00000000000..69bef4348bf --- /dev/null +++ b/Intersections_3/include/CGAL/Intersections_3/internal/Plane_3_Tetrahedron_3_do_intersect.h @@ -0,0 +1,44 @@ +// Copyright (c) 2003 INRIA Sophia-Antipolis (France). +// All rights reserved. +// +// This file is part of CGAL (www.cgal.org) +// +// $URL$ +// $Id$ +// SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-Commercial +// +// +// Author(s) : Philippe Guigue + +#ifndef CGAL_INTERNAL_INTERSECTIONS_PLANE_3_TETRAHEDRON_3_DO_INTERSECT_H +#define CGAL_INTERNAL_INTERSECTIONS_PLANE_3_TETRAHEDRON_3_DO_INTERSECT_H + +#include + +namespace CGAL { +namespace Intersections { +namespace internal { + +template +typename K::Boolean +do_intersect(const typename K::Plane_3& pl, + const typename K::Tetrahedron_3& tet, + const K& k) +{ + return do_intersect_tetrahedron_unbounded(tet, pl, k); +} + +template +typename K::Boolean +do_intersect(const typename K::Tetrahedron_3& tet, + const typename K::Plane_3& pl, + const K& k) +{ + return do_intersect_tetrahedron_unbounded(tet, pl, k); +} + +} // namespace internal +} // namespace Intersections +} // namespace CGAL + +#endif // CGAL_INTERNAL_INTERSECTIONS_PLANE_3_TETRAHEDRON_3_DO_INTERSECT_H diff --git a/Intersections_3/include/CGAL/Intersections_3/internal/Tetrahedron_3_Plane_3_intersection.h b/Intersections_3/include/CGAL/Intersections_3/internal/Plane_3_Tetrahedron_3_intersection.h similarity index 86% rename from Intersections_3/include/CGAL/Intersections_3/internal/Tetrahedron_3_Plane_3_intersection.h rename to Intersections_3/include/CGAL/Intersections_3/internal/Plane_3_Tetrahedron_3_intersection.h index 498ab69a56e..d8e8fa27fc7 100644 --- a/Intersections_3/include/CGAL/Intersections_3/internal/Tetrahedron_3_Plane_3_intersection.h +++ b/Intersections_3/include/CGAL/Intersections_3/internal/Plane_3_Tetrahedron_3_intersection.h @@ -17,23 +17,21 @@ #include #include -#include +#include #include + #include + namespace CGAL { - namespace Intersections { - namespace internal { - //Tetrahedron_3 Plane_3 template typename Intersection_traits::result_type -intersection( - const typename K::Tetrahedron_3 &tet, - const typename K::Plane_3 &plane, - const K& k) +intersection(const typename K::Tetrahedron_3& tet, + const typename K::Plane_3& plane, + const K& k) { typedef typename K::Point_3 Point_3; typedef typename K::Triangle_3 Triangle_3; @@ -71,13 +69,12 @@ intersection( edge_ipt_id.fill(-1); auto inter_pt_index = - [&plane, &corners, &edge_ipt_id](int i, int j, int edge_id) + [&k, &plane, &corners, &edge_ipt_id](int i, int j, int edge_id) { if (edge_ipt_id[edge_id]==-1) { edge_ipt_id[edge_id] = static_cast (corners.size()); - corners.push_back(typename K::Construct_plane_line_intersection_point_3() - (plane, corners[i], corners[j])); + corners.push_back(k.construct_plane_line_intersection_point_3_object()(plane, corners[i], corners[j])); } return edge_ipt_id[edge_id]; @@ -86,7 +83,7 @@ intersection( bool all_in = true; bool all_out = true; - std::vector> neighbor_ids(8, {-1,-1}); + std::vector > neighbor_ids(8, {-1,-1}); auto add_neighbor = [&neighbor_ids](int i, int j) { @@ -110,7 +107,6 @@ intersection( ids.clear(); for (int k = 0; k < 3; ++k) { - int current_id = face_indices[3 * i + k]; int next_id = face_indices[3 * i + (k + 1) % 3]; int edge_id = edge_indices[3 * i + k]; @@ -169,14 +165,16 @@ intersection( } } - if (all_in || all_out) return boost::none; - if (start_id == -1) return { result_type(corners[solo_id]) }; + if (all_in || all_out) + return boost::none; + if (start_id == -1) + return { result_type(corners[solo_id]) }; int prv_id = -1; int cur_id = start_id; std::vector res; res.reserve(4); - do { + for(;;) { res.push_back(corners[cur_id]); int nxt_id = neighbor_ids[cur_id][0] == prv_id ? neighbor_ids[cur_id][1] @@ -186,27 +184,30 @@ intersection( typename K::Segment_3 seg(res[0], res[1]); return result_type(seg); } + if(res.size() == 3){ typename K::Triangle_3 tr(res[0], res[1], res[2]); return result_type(tr); } + return result_type(res); } prv_id = cur_id; cur_id = nxt_id; - } while (true); - + } } template typename Intersection_traits::result_type -intersection( - const typename K::Plane_3 &pl, - const typename K::Tetrahedron_3 &tet, - const K& k) +intersection(const typename K::Plane_3& pl, + const typename K::Tetrahedron_3& tet, + const K& k) { return intersection(tet, pl, k); } -}}} +} // namespace internal +} // namespace Intersections +} // namespace CGAL + #endif // CGAL_INTERNAL_INTERSECTIONS_3_TETRAHEDRON_3_PLANE_3_INTERSECTIONS_H diff --git a/Intersections_3/include/CGAL/Intersections_3/internal/Plane_3_Triangle_3_do_intersect.h b/Intersections_3/include/CGAL/Intersections_3/internal/Plane_3_Triangle_3_do_intersect.h new file mode 100644 index 00000000000..2d7cd516900 --- /dev/null +++ b/Intersections_3/include/CGAL/Intersections_3/internal/Plane_3_Triangle_3_do_intersect.h @@ -0,0 +1,63 @@ +// Copyright (c) 2003 INRIA Sophia-Antipolis (France). +// All rights reserved. +// +// This file is part of CGAL (www.cgal.org) +// +// $URL$ +// $Id$ +// SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-Commercial +// +// +// Author(s) : Philippe Guigue + +#ifndef CGAL_INTERNAL_INTERSECTIONS_PLANE_3_TRIANGLE_3_DO_INTERSECT_H +#define CGAL_INTERNAL_INTERSECTIONS_PLANE_3_TRIANGLE_3_DO_INTERSECT_H + +#include +#include + +namespace CGAL { +namespace Intersections { +namespace internal { + +template +bool do_intersect(const typename K::Triangle_3& t, + const typename K::Plane_3& h, + const K& k) +{ + CGAL_kernel_precondition(!k.is_degenerate_3_object()(t)); + CGAL_kernel_precondition(!k.is_degenerate_3_object()(h)); + + typename K::Construct_vertex_3 vertex_on = k.construct_vertex_3_object(); + typename K::Oriented_side_3 oriented_side = k.oriented_side_3_object(); + + switch(oriented_side(h,vertex_on(t,0))) + { + case ON_POSITIVE_SIDE: + return (oriented_side(h,vertex_on(t,1)) != ON_POSITIVE_SIDE) || + (oriented_side(h,vertex_on(t,2)) != ON_POSITIVE_SIDE); + case ON_NEGATIVE_SIDE: + return (oriented_side(h,vertex_on(t,1)) != ON_NEGATIVE_SIDE) || + (oriented_side(h,vertex_on(t,2)) != ON_NEGATIVE_SIDE); + case ON_ORIENTED_BOUNDARY: + return true; + default:// should not happen. + CGAL_kernel_assertion(false); + return false; + } +} + +template +inline +bool do_intersect(const typename K::Plane_3& h, + const typename K::Triangle_3& t, + const K& k) +{ + return do_intersect(t, h, k); +} + +} // namespace internal +} // namespace Intersections +} // namespace CGAL + +#endif // CGAL_INTERNAL_INTERSECTIONS_PLANE_3_TRIANGLE_3_DO_INTERSECT_H diff --git a/Intersections_3/include/CGAL/Intersections_3/internal/Plane_3_Triangle_3_intersection.h b/Intersections_3/include/CGAL/Intersections_3/internal/Plane_3_Triangle_3_intersection.h new file mode 100644 index 00000000000..7f76c9d6000 --- /dev/null +++ b/Intersections_3/include/CGAL/Intersections_3/internal/Plane_3_Triangle_3_intersection.h @@ -0,0 +1,161 @@ +// Copyright (c) 2003 INRIA Sophia-Antipolis (France). +// All rights reserved. +// +// This file is part of CGAL (www.cgal.org) +// +// $URL$ +// $Id$ +// SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-Commercial +// +// +// Author(s) : Philippe Guigue + +#ifndef CGAL_INTERNAL_INTERSECTIONS_PLANE_3_TRIANGLE_3_INTERSECTION_H +#define CGAL_INTERNAL_INTERSECTIONS_PLANE_3_TRIANGLE_3_INTERSECTION_H + +#include +#include + +#include +#include + +namespace CGAL { +namespace Intersections { +namespace internal { + +template +inline +typename Intersection_traits::result_type +intersection(const typename K::Plane_3& plane, + const typename K::Triangle_3& tri, + const K& k) +{ + typedef typename Intersection_traits::result_type pl_res; + + typename K::Construct_vertex_3 vertex_on = k.construct_vertex_3_object(); + + CGAL::Oriented_side or0 = plane.oriented_side(vertex_on(tri, 0)); + CGAL::Oriented_side or1 = plane.oriented_side(vertex_on(tri, 1)); + CGAL::Oriented_side or2 = plane.oriented_side(vertex_on(tri, 2)); + + if(or0 == ON_ORIENTED_BOUNDARY) + { + if(or1 == ON_ORIENTED_BOUNDARY) + { + if(or2 == ON_ORIENTED_BOUNDARY) + return intersection_return(tri); + else + return intersection_return( + k.construct_segment_3_object()(tri.vertex(0), tri.vertex(1))); + } + else + { + if(or2 == ON_ORIENTED_BOUNDARY) + { + return intersection_return( + k.construct_segment_3_object()(tri.vertex(0), tri.vertex(2))); + } + else + { + if(or1 == or2) + { + return intersection_return(tri.vertex(0)); + } + else + { + pl_res v = internal::intersection(plane, k.construct_line_3_object()(tri.vertex(1), tri.vertex(2)), k); + const typename K::Point_3* p = intersect_get(v); + CGAL_kernel_assertion(p!=nullptr); + return intersection_return( + k.construct_segment_3_object()(*p, tri.vertex(0))); + } + } + } + } + + if(or1 == ON_ORIENTED_BOUNDARY) + { + if(or2 == ON_ORIENTED_BOUNDARY) + return intersection_return( + k.construct_segment_3_object()(tri.vertex(1), tri.vertex(2))); + if(or2 == or0) + { + return intersection_return(tri.vertex(1)); + } + else + { + pl_res v = intersection(plane, k.construct_line_3_object()(tri.vertex(0), tri.vertex(2)), k); + const typename K::Point_3* p = intersect_get(v); + CGAL_kernel_assertion(p!=nullptr); + return intersection_return( + k.construct_segment_3_object()(*p, tri.vertex(1))); + } + } + + if(or2 == ON_ORIENTED_BOUNDARY) + { + if(or1 == or0) + { + return intersection_return(tri.vertex(2)); + } + else + { + pl_res v = intersection(plane, k.construct_line_3_object()(tri.vertex(0),tri.vertex(1)), k); + const typename K::Point_3* p = intersect_get(v); + CGAL_kernel_assertion(p!=nullptr); + return intersection_return( + k.construct_segment_3_object()(*p,tri.vertex(2))); + } + } + + //triangle vertices are not in the plane + std::vector pts; + pts.reserve(2); + if(or0 != or1) + { + pl_res v = intersection(plane, k.construct_line_3_object()(tri.vertex(0),tri.vertex(1)), k); + const typename K::Point_3* pt_ptr = intersect_get(v); + CGAL_kernel_assertion(pt_ptr != nullptr); + pts.push_back(*pt_ptr); + } + + if(or0 != or2) + { + pl_res v = intersection(plane, k.construct_line_3_object()(tri.vertex(0),tri.vertex(2)), k); + const typename K::Point_3* pt_ptr = intersect_get(v); + CGAL_kernel_assertion(pt_ptr != nullptr); + pts.push_back(*pt_ptr); + } + + if(or1 != or2) + { + pl_res v = intersection(plane, k.construct_line_3_object()(tri.vertex(1),tri.vertex(2)), k); + const typename K::Point_3* pt_ptr = intersect_get(v); + CGAL_kernel_assertion(pt_ptr != nullptr); + pts.push_back(*pt_ptr); + } + + if(pts.empty()) + return intersection_return(); + + CGAL_kernel_assertion(pts.size() == 2); + + return intersection_return( + k.construct_segment_3_object()(*pts.begin(), *boost::prior(pts.end()))); +} + +template +inline +typename Intersection_traits::result_type +intersection(const typename K::Triangle_3& triangle, + const typename K::Plane_3& plane, + const K& k) +{ + return intersection(plane, triangle, k); +} + +} // namespace internal +} // namespace Intersections +} // namespace CGAL + +#endif // CGAL_INTERNAL_INTERSECTIONS_PLANE_3_TRIANGLE_3_INTERSECTION_H diff --git a/Intersections_3/include/CGAL/Intersections_3/internal/Point_3_Point_3_do_intersect.h b/Intersections_3/include/CGAL/Intersections_3/internal/Point_3_Point_3_do_intersect.h new file mode 100644 index 00000000000..6eac676ed77 --- /dev/null +++ b/Intersections_3/include/CGAL/Intersections_3/internal/Point_3_Point_3_do_intersect.h @@ -0,0 +1,33 @@ +// Copyright (c) 2003 INRIA Sophia-Antipolis (France). +// All rights reserved. +// +// This file is part of CGAL (www.cgal.org) +// +// $URL$ +// $Id$ +// SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-Commercial +// +// +// Author(s) : Sébastien Loriot + +#ifndef CGAL_INTERNAL_INTERSECTIONS_POINT_3_POINT_3_DO_INTERSECT_H +#define CGAL_INTERNAL_INTERSECTIONS_POINT_3_POINT_3_DO_INTERSECT_H + +namespace CGAL { +namespace Intersections { +namespace internal { + +template +inline bool +do_intersect(const typename K::Point_3& pt1, + const typename K::Point_3& pt2, + const K& k) +{ + return k.equal_3_object()(pt1, pt2); +} + +} // namespace internal +} // namespace Intersections +} // namespace CGAL + +#endif // CGAL_INTERNAL_INTERSECTIONS_POINT_3_POINT_3_DO_INTERSECT_H diff --git a/Intersections_3/include/CGAL/Intersections_3/internal/Point_3_Point_3_intersection.h b/Intersections_3/include/CGAL/Intersections_3/internal/Point_3_Point_3_intersection.h new file mode 100644 index 00000000000..72acae95324 --- /dev/null +++ b/Intersections_3/include/CGAL/Intersections_3/internal/Point_3_Point_3_intersection.h @@ -0,0 +1,39 @@ +// Copyright (c) 2003 INRIA Sophia-Antipolis (France). +// All rights reserved. +// +// This file is part of CGAL (www.cgal.org) +// +// $URL$ +// $Id$ +// SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-Commercial +// +// +// Author(s) : Sébastien Loriot + +#ifndef CGAL_INTERNAL_INTERSECTIONS_POINT_3_POINT_3_INTERSECTION_H +#define CGAL_INTERNAL_INTERSECTIONS_POINT_3_POINT_3_INTERSECTION_H + +#include +#include + +namespace CGAL { +namespace Intersections { +namespace internal { + +template +typename CGAL::Intersection_traits::result_type +intersection(const typename K::Point_3& pt1, + const typename K::Point_3& pt2, + const K& k) +{ + if(do_intersect(pt1, pt2, k)) + return intersection_return(pt1); + + return intersection_return(); +} + +} // namespace internal +} // namespace Intersections +} // namespace CGAL + +#endif // CGAL_INTERNAL_INTERSECTIONS_POINT_3_POINT_3_INTERSECTION_H diff --git a/Intersections_3/include/CGAL/Intersections_3/internal/Point_3_Ray_3_do_intersect.h b/Intersections_3/include/CGAL/Intersections_3/internal/Point_3_Ray_3_do_intersect.h new file mode 100644 index 00000000000..0aec93a129c --- /dev/null +++ b/Intersections_3/include/CGAL/Intersections_3/internal/Point_3_Ray_3_do_intersect.h @@ -0,0 +1,57 @@ +// Copyright (c) 2003 INRIA Sophia-Antipolis (France). +// All rights reserved. +// +// This file is part of CGAL (www.cgal.org) +// +// $URL$ +// $Id$ +// SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-Commercial +// +// +// Author(s) : Sébastien Loriot + +#ifndef CGAL_INTERNAL_INTERSECTIONS_POINT_3_RAY_3_DO_INTERSECT_H +#define CGAL_INTERNAL_INTERSECTIONS_POINT_3_RAY_3_DO_INTERSECT_H + +namespace CGAL { +namespace Intersections { +namespace internal { + +template +inline +bool +do_intersect(const typename K::Point_3& pt, + const typename K::Ray_3& ray, + const K& k) +{ + return k.has_on_3_object()(ray, pt); +} + +template +inline +bool +do_intersect(const typename K::Ray_3& ray, + const typename K::Point_3& pt, + const K& k) +{ + return k.has_on_3_object()(ray, pt); +} + + +template +bool +Ray_3_has_on_collinear_Point_3(const typename K::Ray_3& r, + const typename K::Point_3& p, + const K& k) +{ + return k.equal_3_object()(r.source(), p) || + k.equal_3_object()( + k.construct_direction_3_object()( + k.construct_vector_3_object()(r.source(), p)), r.direction()); +} + +} // namespace internal +} // namespace Intersections +} // namespace CGAL + +#endif // CGAL_INTERNAL_INTERSECTIONS_POINT_3_RAY_3_DO_INTERSECT_H diff --git a/Intersections_3/include/CGAL/Intersections_3/internal/Point_3_Ray_3_intersection.h b/Intersections_3/include/CGAL/Intersections_3/internal/Point_3_Ray_3_intersection.h new file mode 100644 index 00000000000..ced9622eaea --- /dev/null +++ b/Intersections_3/include/CGAL/Intersections_3/internal/Point_3_Ray_3_intersection.h @@ -0,0 +1,47 @@ +// Copyright (c) 2003 INRIA Sophia-Antipolis (France). +// All rights reserved. +// +// This file is part of CGAL (www.cgal.org) +// +// $URL$ +// $Id$ +// SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-Commercial +// +// +// Author(s) : Sébastien Loriot + +#ifndef CGAL_INTERNAL_INTERSECTIONS_POINT_3_RAY_3_INTERSECTION_H +#define CGAL_INTERNAL_INTERSECTIONS_POINT_3_RAY_3_INTERSECTION_H + +#include + +namespace CGAL { +namespace Intersections { +namespace internal { + +template +typename CGAL::Intersection_traits::result_type +intersection(const typename K::Point_3& pt, + const typename K::Ray_3& ray, + const K& k) +{ + if(do_intersect(pt, ray, k)) + return intersection_return(pt); + + return intersection_return(); +} + +template +typename CGAL::Intersection_traits::result_type +intersection(const typename K::Ray_3& ray, + const typename K::Point_3& pt, + const K& k) +{ + return internal::intersection(pt, ray, k); +} + +} // namespace internal +} // namespace Intersections +} // namespace CGAL + +#endif // CGAL_INTERNAL_INTERSECTIONS_POINT_3_RAY_3_INTERSECTION_H diff --git a/Intersections_3/include/CGAL/Intersections_3/internal/Point_3_Segment_3_do_intersect.h b/Intersections_3/include/CGAL/Intersections_3/internal/Point_3_Segment_3_do_intersect.h new file mode 100644 index 00000000000..2872694d6af --- /dev/null +++ b/Intersections_3/include/CGAL/Intersections_3/internal/Point_3_Segment_3_do_intersect.h @@ -0,0 +1,44 @@ +// Copyright (c) 2003 INRIA Sophia-Antipolis (France). +// All rights reserved. +// +// This file is part of CGAL (www.cgal.org) +// +// $URL$ +// $Id$ +// SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-Commercial +// +// +// Author(s) : Sébastien Loriot + +#ifndef CGAL_INTERNAL_INTERSECTIONS_POINT_3_SEGMENT_3_DO_INTERSECT_H +#define CGAL_INTERNAL_INTERSECTIONS_POINT_3_SEGMENT_3_DO_INTERSECT_H + +namespace CGAL { +namespace Intersections { +namespace internal { + +template +inline +bool +do_intersect(const typename K::Point_3& pt, + const typename K::Segment_3& seg, + const K& k) +{ + return k.has_on_3_object()(seg, pt); +} + +template +inline +bool +do_intersect(const typename K::Segment_3& seg, + const typename K::Point_3& pt, + const K& k) +{ + return k.has_on_3_object()(seg, pt); +} + +} // namespace internal +} // namespace Intersections +} // namespace CGAL + +#endif // CGAL_INTERNAL_INTERSECTIONS_POINT_3_SEGMENT_3_DO_INTERSECT_H diff --git a/Intersections_3/include/CGAL/Intersections_3/internal/Point_3_Segment_3_intersection.h b/Intersections_3/include/CGAL/Intersections_3/internal/Point_3_Segment_3_intersection.h new file mode 100644 index 00000000000..fd5ba348b65 --- /dev/null +++ b/Intersections_3/include/CGAL/Intersections_3/internal/Point_3_Segment_3_intersection.h @@ -0,0 +1,50 @@ +// Copyright (c) 2003 INRIA Sophia-Antipolis (France). +// All rights reserved. +// +// This file is part of CGAL (www.cgal.org) +// +// $URL$ +// $Id$ +// SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-Commercial +// +// +// Author(s) : Sébastien Loriot + +#ifndef CGAL_INTERNAL_INTERSECTIONS_POINT_3_SEGMENT_3_INTERSECTION_H +#define CGAL_INTERNAL_INTERSECTIONS_POINT_3_SEGMENT_3_INTERSECTION_H + +#include +#include + +namespace CGAL { +namespace Intersections { +namespace internal { + +template +inline +typename CGAL::Intersection_traits::result_type +intersection(const typename K::Point_3& pt, + const typename K::Segment_3& seg, + const K& k) +{ + if(do_intersect(pt, seg, k)) + return intersection_return(pt); + + return intersection_return(); +} + +template +inline +typename CGAL::Intersection_traits::result_type +intersection( const typename K::Segment_3& seg, + const typename K::Point_3& pt, + const K& k) +{ + return intersection(pt, seg, k); +} + +} // namespace internal +} // namespace Intersections +} // namespace CGAL + +#endif // CGAL_INTERNAL_INTERSECTIONS_POINT_3_SEGMENT_3_INTERSECTION_H diff --git a/Intersections_3/include/CGAL/Intersections_3/internal/Point_3_Sphere_3_do_intersect.h b/Intersections_3/include/CGAL/Intersections_3/internal/Point_3_Sphere_3_do_intersect.h new file mode 100644 index 00000000000..d825e2ff820 --- /dev/null +++ b/Intersections_3/include/CGAL/Intersections_3/internal/Point_3_Sphere_3_do_intersect.h @@ -0,0 +1,44 @@ +// Copyright (c) 2003 INRIA Sophia-Antipolis (France). +// All rights reserved. +// +// This file is part of CGAL (www.cgal.org) +// +// $URL$ +// $Id$ +// SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-Commercial +// +// +// Author(s) : Andreas Fabri + +#ifndef CGAL_INTERNAL_INTERSECTIONS_3_POINT_3_SPHERE_3_INTERSECTION_H +#define CGAL_INTERNAL_INTERSECTIONS_3_POINT_3_SPHERE_3_INTERSECTION_H + +namespace CGAL { +namespace Intersections { +namespace internal { + +template +inline +bool +do_intersect(const typename K::Point_3& pt, + const typename K::Sphere_3& sphere, + const K& k) +{ + return k.has_on_boundary_3_object()(sphere, pt); +} + +template +inline +bool +do_intersect(const typename K::Sphere_3& sphere, + const typename K::Point_3& pt, + const K& k) +{ + return k.has_on_boundary_3_object()(sphere, pt); +} + +} // namespace internal +} // namespace Intersections +} // namespace CGAL + +#endif // CGAL_INTERNAL_INTERSECTIONS_3_POINT_3_SPHERE_3_INTERSECTION_H diff --git a/Intersections_3/include/CGAL/Intersections_3/internal/Point_3_Sphere_3_intersection.h b/Intersections_3/include/CGAL/Intersections_3/internal/Point_3_Sphere_3_intersection.h new file mode 100644 index 00000000000..51abbc4629e --- /dev/null +++ b/Intersections_3/include/CGAL/Intersections_3/internal/Point_3_Sphere_3_intersection.h @@ -0,0 +1,48 @@ +// Copyright (c) 2003 INRIA Sophia-Antipolis (France). +// All rights reserved. +// +// This file is part of CGAL (www.cgal.org) +// +// $URL$ +// $Id$ +// SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-Commercial +// +// +// Author(s) : Andreas Fabri + +#ifndef CGAL_POINT_3_SPHERE_3_INTERSECTION_H +#define CGAL_POINT_3_SPHERE_3_INTERSECTION_H + +#include +#include + +namespace CGAL { +namespace Intersections { +namespace internal { + +template +typename CGAL::Intersection_traits::result_type +intersection(const typename K::Point_3& pt, + const typename K::Sphere_3& sphere, + const K& k) +{ + if(do_intersect(pt, sphere, k)) + return intersection_return(pt); + + return intersection_return(); +} + +template +typename CGAL::Intersection_traits::result_type +intersection(const typename K::Sphere_3& sphere, + const typename K::Point_3& pt, + const K& k) +{ + return internal::intersection(pt, sphere, k); +} + +} // namespace internal +} // namespace Intersections +} // namespace CGAL + +#endif // CGAL_POINT_3_SPHERE_3_INTERSECTION_H diff --git a/Intersections_3/include/CGAL/Intersections_3/internal/Point_3_Tetrahedron_3_do_intersect.h b/Intersections_3/include/CGAL/Intersections_3/internal/Point_3_Tetrahedron_3_do_intersect.h new file mode 100644 index 00000000000..0518a305073 --- /dev/null +++ b/Intersections_3/include/CGAL/Intersections_3/internal/Point_3_Tetrahedron_3_do_intersect.h @@ -0,0 +1,44 @@ +// Copyright (c) 2003 INRIA Sophia-Antipolis (France). +// All rights reserved. +// +// This file is part of CGAL (www.cgal.org) +// +// $URL$ +// $Id$ +// SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-Commercial +// +// +// Author(s) : Andreas Fabri + +#ifndef CGAL_INTERNAL_INTERSECTIONS_POINT_3_TETRAHEDRON_3_DO_INTERSECT_H +#define CGAL_INTERNAL_INTERSECTIONS_POINT_3_TETRAHEDRON_3_DO_INTERSECT_H + +namespace CGAL { +namespace Intersections { +namespace internal { + +template +inline +bool +do_intersect(const typename K::Point_3& pt, + const typename K::Tetrahedron_3& tetrahedron, + const K& k) +{ + return !k.has_on_unbounded_side_3_object()(tetrahedron, pt); +} + +template +inline +bool +do_intersect(const typename K::Tetrahedron_3& tetrahedron, + const typename K::Point_3& pt, + const K& k) +{ + return !k.has_on_unbounded_side_3_object()(tetrahedron, pt); +} + +} // namespace internal +} // namespace Intersections +} // namespace CGAL + +#endif // CGAL_INTERNAL_INTERSECTIONS_POINT_3_TETRAHEDRON_3_DO_INTERSECT_H diff --git a/Intersections_3/include/CGAL/Intersections_3/internal/Point_3_Tetrahedron_3_intersection.h b/Intersections_3/include/CGAL/Intersections_3/internal/Point_3_Tetrahedron_3_intersection.h new file mode 100644 index 00000000000..2c740e1040b --- /dev/null +++ b/Intersections_3/include/CGAL/Intersections_3/internal/Point_3_Tetrahedron_3_intersection.h @@ -0,0 +1,48 @@ +// Copyright (c) 2003 INRIA Sophia-Antipolis (France). +// All rights reserved. +// +// This file is part of CGAL (www.cgal.org) +// +// $URL$ +// $Id$ +// SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-Commercial +// +// +// Author(s) : Andreas Fabri + +#ifndef CGAL_INTERNAL_INTERSECTIONS_POINT_3_TETRAHEDRON_3_INTERSECTION_H +#define CGAL_INTERNAL_INTERSECTIONS_POINT_3_TETRAHEDRON_3_INTERSECTION_H + +#include +#include + +namespace CGAL { +namespace Intersections { +namespace internal { + +template +typename CGAL::Intersection_traits::result_type +intersection(const typename K::Point_3& pt, + const typename K::Tetrahedron_3& tetrahedron, + const K& k) +{ + if(do_intersect(pt,tetrahedron, k)) + return intersection_return(pt); + + return intersection_return(); +} + +template +typename CGAL::Intersection_traits::result_type +intersection(const typename K::Tetrahedron_3& tetrahedron, + const typename K::Point_3& pt, + const K& k) +{ + return intersection(pt, tetrahedron, k); +} + +} // namespace internal +} // namespace Intersections +} // namespace CGAL + +#endif // CGAL_INTERNAL_INTERSECTIONS_POINT_3_TETRAHEDRON_3_INTERSECTION_H diff --git a/Intersections_3/include/CGAL/Intersections_3/internal/Point_3_Triangle_3_do_intersect.h b/Intersections_3/include/CGAL/Intersections_3/internal/Point_3_Triangle_3_do_intersect.h new file mode 100644 index 00000000000..a116b4617a9 --- /dev/null +++ b/Intersections_3/include/CGAL/Intersections_3/internal/Point_3_Triangle_3_do_intersect.h @@ -0,0 +1,82 @@ +// Copyright (c) 2003 INRIA Sophia-Antipolis (France). +// All rights reserved. +// +// This file is part of CGAL (www.cgal.org) +// +// $URL$ +// $Id$ +// SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-Commercial +// +// +// Author(s) : Mariette Yvinec + +#ifndef CGAL_INTERNAL_INTERSECTIONS_POINT_3_TRIANGLE_3_DO_INTERSECT_H +#define CGAL_INTERNAL_INTERSECTIONS_POINT_3_TRIANGLE_3_DO_INTERSECT_H + +#include +#include + +namespace CGAL { +namespace Intersections { +namespace internal { + +template +bool do_intersect(const typename K::Triangle_3& t, + const typename K::Point_3& p, + const K& k) +{ + CGAL_kernel_precondition(!k.is_degenerate_3_object()(t)); + + typedef typename K::Point_3 Point_3; + + typename K::Construct_vertex_3 vertex_on = k.construct_vertex_3_object(); + typename K::Orientation_3 orientation = k.orientation_3_object(); + typename K::Coplanar_orientation_3 coplanar_orientation = k.coplanar_orientation_3_object(); + + const Point_3& a = vertex_on(t,0); + const Point_3& b = vertex_on(t,1); + const Point_3& c = vertex_on(t,2); + + if(orientation(a,b,c,p) != COPLANAR) + return false; + + const CGAL::Orientation abp = coplanar_orientation(a,b,p); + const CGAL::Orientation bcp = coplanar_orientation(b,c,p); + + switch(abp) + { + case POSITIVE: + return (bcp != NEGATIVE) && (coplanar_orientation(c,a,p) != NEGATIVE); + case NEGATIVE: + return (bcp != POSITIVE) && (coplanar_orientation(c,a,p) != POSITIVE); + case COLLINEAR: + switch (bcp) + { + case POSITIVE: + return (coplanar_orientation(c,a,p) != NEGATIVE); + case NEGATIVE: + return (coplanar_orientation(c,a,p) != POSITIVE); + case COLLINEAR: return true; + default: // should not happen. + CGAL_kernel_assertion(false); + return false; + } + default: // should not happen. + CGAL_kernel_assertion(false); + return false; + } +} + +template +bool do_intersect(const typename K::Point_3& p, + const typename K::Triangle_3& t, + const K& k) +{ + return do_intersect(t, p, k); +} + +} // namespace internal +} // namespace Intersections +} // namespace CGAL + +#endif // CGAL_INTERNAL_INTERSECTIONS_POINT_3_TRIANGLE_3_DO_INTERSECT_H diff --git a/Intersections_3/include/CGAL/Intersections_3/internal/Point_3_Triangle_3_intersection.h b/Intersections_3/include/CGAL/Intersections_3/internal/Point_3_Triangle_3_intersection.h new file mode 100644 index 00000000000..40314aaeab8 --- /dev/null +++ b/Intersections_3/include/CGAL/Intersections_3/internal/Point_3_Triangle_3_intersection.h @@ -0,0 +1,50 @@ +// Copyright (c) 2003 INRIA Sophia-Antipolis (France). +// All rights reserved. +// +// This file is part of CGAL (www.cgal.org) +// +// $URL$ +// $Id$ +// SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-Commercial +// +// +// Author(s) : Mariette Yvinec + +#ifndef CGAL_POINT_3_TRIANGLE_3_INTERSECTION_H +#define CGAL_POINT_3_TRIANGLE_3_INTERSECTION_H + +#include +#include + +namespace CGAL { +namespace Intersections { +namespace internal { + +template +inline +typename CGAL::Intersection_traits::result_type +intersection(const typename K::Point_3& pt, + const typename K::Triangle_3& tr, + const K& k) +{ + if(do_intersect(pt, tr, k)) + return intersection_return(pt); + + return intersection_return(); +} + +template +inline +typename CGAL::Intersection_traits::result_type +intersection( const typename K::Triangle_3& tr, + const typename K::Point_3& pt, + const K& k) +{ + return internal::intersection(pt, tr, k); +} + +} // namespace internal +} // namespace Intersections +} // namespace CGAL + +#endif // CGAL_POINT_3_TRIANGLE_3_INTERSECTION_H diff --git a/Intersections_3/include/CGAL/Intersections_3/internal/Ray_3_Ray_3_do_intersect.h b/Intersections_3/include/CGAL/Intersections_3/internal/Ray_3_Ray_3_do_intersect.h new file mode 100644 index 00000000000..45a2f9dd9fb --- /dev/null +++ b/Intersections_3/include/CGAL/Intersections_3/internal/Ray_3_Ray_3_do_intersect.h @@ -0,0 +1,61 @@ +// Copyright (c) 2003 INRIA Sophia-Antipolis (France). +// All rights reserved. +// +// This file is part of CGAL (www.cgal.org) +// +// $URL$ +// $Id$ +// SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-Commercial +// +// +// Author(s) : Sébastien Loriot + +#ifndef CGAL_INTERNAL_INTERSECTIONS_RAY_3_RAY_3_DO_INTERSECT_H +#define CGAL_INTERNAL_INTERSECTIONS_RAY_3_RAY_3_DO_INTERSECT_H + +#include +#include + +#include + +namespace CGAL { +namespace Intersections { +namespace internal { + +template +inline +bool +do_intersect(const typename K::Ray_3& r1, + const typename K::Ray_3& r2, + const K& k) +{ + CGAL_precondition(!r1.is_degenerate() && !r2.is_degenerate()); + + if(!do_intersect(r1, r2.supporting_line(), k)) + return false; + + typename K::Coplanar_orientation_3 pred = k.coplanar_orientation_3_object(); + + CGAL::Orientation p0p1s = pred(r1.point(0), r1.point(1), r2.source()); + CGAL::Orientation stp0 = pred(r2.source(), r2.second_point(), r1.point(0)); + + if(p0p1s == COLLINEAR) + { + if(stp0 == COLLINEAR) + return Ray_3_has_on_collinear_Point_3(r2, r1.source(), k) || + Ray_3_has_on_collinear_Point_3(r1, r2.source(), k); + else + return true; + } + + if(stp0 == COLLINEAR) + return Ray_3_has_on_collinear_Point_3(r2, r1.point(0), k); + + return (p0p1s != stp0); +} + +} // namespace internal +} // namespace Intersections +} // namespace CGAL + +#endif // CGAL_INTERNAL_INTERSECTIONS_RAY_3_RAY_3_DO_INTERSECT_H diff --git a/Intersections_3/include/CGAL/Intersections_3/internal/Ray_3_Ray_3_intersection.h b/Intersections_3/include/CGAL/Intersections_3/internal/Ray_3_Ray_3_intersection.h new file mode 100644 index 00000000000..aff74078732 --- /dev/null +++ b/Intersections_3/include/CGAL/Intersections_3/internal/Ray_3_Ray_3_intersection.h @@ -0,0 +1,81 @@ +// Copyright (c) 2003 INRIA Sophia-Antipolis (France). +// All rights reserved. +// +// This file is part of CGAL (www.cgal.org) +// +// $URL$ +// $Id$ +// SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-Commercial +// +// +// Author(s) : Sébastien Loriot + +#ifndef CGAL_RAY_3_RAY_3_INTERSECTION_H +#define CGAL_RAY_3_RAY_3_INTERSECTION_H + +#include + +#include + +namespace CGAL { +namespace Intersections { +namespace internal { + +template +typename Intersection_traits::result_type +intersection(const typename K::Ray_3& r1, + const typename K::Ray_3& r2, + const K& k) +{ + CGAL_precondition(!r1.is_degenerate() && !r2.is_degenerate()); + + typename Intersection_traits::result_type + v = internal::intersection(r1.supporting_line(), r2, k); + + if(v) + { + if(const typename K::Point_3* p = intersect_get(v)) + { + if(Ray_3_has_on_collinear_Point_3(r1,*p,k)) + return intersection_return(*p); + } + else if(const typename K::Ray_3* r = intersect_get(v)) + { + bool r1_has_s2 = Ray_3_has_on_collinear_Point_3(r1,r2.source(),k); + bool r2_has_s1 = Ray_3_has_on_collinear_Point_3(r2,r1.source(),k); + + if(r1_has_s2) + { + if(r2_has_s1) + { + if(k.equal_3_object()(r1.source(),r2.source())) + { + return intersection_return(r1.source()); + } + else + { + return intersection_return( + k.construct_segment_3_object()(r1.source(), r2.source())); + } + } + else + { + return intersection_return(*r); + } + } + else + { + if(r2_has_s1) + return intersection_return(r1); + } + } + } + + return intersection_return(); +} + +} // namespace internal +} // namespace Intersections +} // namespace CGAL + +#endif // CGAL_RAY_3_RAY_3_INTERSECTION_H diff --git a/Intersections_3/include/CGAL/Intersections_3/internal/Ray_3_Segment_3_do_intersect.h b/Intersections_3/include/CGAL/Intersections_3/internal/Ray_3_Segment_3_do_intersect.h new file mode 100644 index 00000000000..bf57d977f0c --- /dev/null +++ b/Intersections_3/include/CGAL/Intersections_3/internal/Ray_3_Segment_3_do_intersect.h @@ -0,0 +1,71 @@ +// Copyright (c) 2003 INRIA Sophia-Antipolis (France). +// All rights reserved. +// +// This file is part of CGAL (www.cgal.org) +// +// $URL$ +// $Id$ +// SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-Commercial +// +// +// Author(s) : Sébastien Loriot + +#ifndef CGAL_INTERNAL_INTERSECTIONS_3_RAY_3_SEGMENT_3_DO_INTERSECT_H +#define CGAL_INTERNAL_INTERSECTIONS_3_RAY_3_SEGMENT_3_DO_INTERSECT_H + +#include +#include + +#include + +namespace CGAL { +namespace Intersections { +namespace internal { + +template +inline +bool +do_intersect(const typename K::Segment_3& s, + const typename K::Ray_3& r, + const K& k) +{ + CGAL_precondition(!s.is_degenerate() && !r.is_degenerate()); + + if(!do_intersect(s, r.supporting_line(), k)) + return false; + + typename K::Coplanar_orientation_3 pred = k.coplanar_orientation_3_object(); + + CGAL::Orientation p0p1s = pred(s.point(0), s.point(1), r.source()); + CGAL::Orientation stp0 = pred(r.source(), r.second_point(), s.point(0)); + + if(p0p1s == COLLINEAR) //s belongs to the supporting line of p0p1 + { + if(stp0 == COLLINEAR )//st and p0p1 have the same supporting line + return Ray_3_has_on_collinear_Point_3(r, s.point(0), k) || + Ray_3_has_on_collinear_Point_3(r, s.point(1), k); + else + return true; + } + + if(stp0 == COLLINEAR) + return Ray_3_has_on_collinear_Point_3(r, s.point(0), k); + + return (p0p1s != stp0); +} + +template +inline +bool +do_intersect(const typename K::Ray_3& r, + const typename K::Segment_3& s, + const K& k) +{ + return do_intersect(s, r, k); +} + +} // namespace internal +} // namespace Intersections +} // namespace CGAL + +#endif // CGAL_INTERNAL_INTERSECTIONS_3_RAY_3_SEGMENT_3_DO_INTERSECT_H diff --git a/Intersections_3/include/CGAL/Intersections_3/internal/Ray_3_Segment_3_intersection.h b/Intersections_3/include/CGAL/Intersections_3/internal/Ray_3_Segment_3_intersection.h new file mode 100644 index 00000000000..af91cbbe6d8 --- /dev/null +++ b/Intersections_3/include/CGAL/Intersections_3/internal/Ray_3_Segment_3_intersection.h @@ -0,0 +1,91 @@ +// Copyright (c) 2003 INRIA Sophia-Antipolis (France). +// All rights reserved. +// +// This file is part of CGAL (www.cgal.org) +// +// $URL$ +// $Id$ +// SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-Commercial +// +// +// Author(s) : Sébastien Loriot + +#ifndef CGAL_INTERNAL_INTERSECTIONS_3_RAY_3_SEGMENT_3_INTERSECTION_H +#define CGAL_INTERNAL_INTERSECTIONS_3_RAY_3_SEGMENT_3_INTERSECTION_H + +#include +#include +#include + +namespace CGAL { +namespace Intersections { +namespace internal { + +template +typename Intersection_traits::result_type +intersection(const typename K::Segment_3& s, + const typename K::Ray_3& r, + const K& k) +{ + CGAL_precondition(!s.is_degenerate() && !r.is_degenerate()); + + typename Intersection_traits::result_type + v = internal::intersection(r.supporting_line(), s, k); + + if(v) + { + if(const typename K::Point_3* p = intersect_get(v)) + { + if(Ray_3_has_on_collinear_Point_3(r, *p, k)) + return intersection_return(*p); + } + else if(const typename K::Segment_3* s2 = intersect_get(v)) + { + bool has_source = Ray_3_has_on_collinear_Point_3(r, s.source(), k); + bool has_target = Ray_3_has_on_collinear_Point_3(r, s.target(), k); + if(has_source) + { + if(has_target) + { + return intersection_return(*s2); + } + else + { + if(k.equal_3_object()(r.source(), s.source())) + return intersection_return(r.source()); + else + return intersection_return( + k.construct_segment_3_object()(r.source(), s.source())); + } + } + else + { + if(has_target) + { + if(k.equal_3_object()(r.source(), s.target())) + return intersection_return(r.source()); + else + return intersection_return( + k.construct_segment_3_object()(r.source(), s.target())); + } + } + } + } + + return intersection_return(); +} + +template +typename Intersection_traits::result_type +intersection(const typename K::Ray_3& r, + const typename K::Segment_3& s, + const K& k) +{ + return intersection(s, r, k); +} + +} // namespace internal +} // namespace Intersections +} // namespace CGAL + +#endif // CGAL_INTERNAL_INTERSECTIONS_3_RAY_3_SEGMENT_3_INTERSECTION_H diff --git a/Intersections_3/include/CGAL/Intersections_3/internal/Ray_3_Sphere_3_do_intersect.h b/Intersections_3/include/CGAL/Intersections_3/internal/Ray_3_Sphere_3_do_intersect.h new file mode 100644 index 00000000000..eea104dd7f5 --- /dev/null +++ b/Intersections_3/include/CGAL/Intersections_3/internal/Ray_3_Sphere_3_do_intersect.h @@ -0,0 +1,53 @@ +// Copyright (c) 2003 INRIA Sophia-Antipolis (France). +// All rights reserved. +// +// This file is part of CGAL (www.cgal.org) +// +// $URL$ +// $Id$ +// SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-Commercial +// +// +// Author(s) : Philippe Guigue + +#ifndef CGAL_INTERNAL_INTERSECTIONS_RAY_3_SPHERE_3_DO_INTERSECT_H +#define CGAL_INTERNAL_INTERSECTIONS_RAY_3_SPHERE_3_DO_INTERSECT_H + +#include +#include + +namespace CGAL { +namespace Intersections { +namespace internal { + +template +inline +typename K::Boolean +do_intersect(const typename K::Sphere_3& sp, + const typename K::Ray_3& ray, + const K& k) +{ + typedef typename K::RT RT; + RT num, den; + + CGAL::internal::squared_distance_RT(sp.center(), ray, num, den, k); + return !(compare_quotients(num, den, + Rational_traits().numerator(sp.squared_radius()), + Rational_traits().denominator(sp.squared_radius())) == LARGER); +} + +template +inline +typename K::Boolean +do_intersect(const typename K::Ray_3& ray, + const typename K::Sphere_3& sp, + const K& k) +{ + return do_intersect(sp, ray, k); +} + +} // namespace internal +} // namespace Intersections +} // namespace CGAL + +#endif // CGAL_INTERNAL_INTERSECTIONS_RAY_3_SPHERE_3_DO_INTERSECT_H diff --git a/Intersections_3/include/CGAL/Intersections_3/internal/Ray_3_Tetrahedron_3_do_intersect.h b/Intersections_3/include/CGAL/Intersections_3/internal/Ray_3_Tetrahedron_3_do_intersect.h new file mode 100644 index 00000000000..93b7eb43472 --- /dev/null +++ b/Intersections_3/include/CGAL/Intersections_3/internal/Ray_3_Tetrahedron_3_do_intersect.h @@ -0,0 +1,45 @@ +// Copyright (c) 2019 GeometryFactory(France). +// All rights reserved. +// +// This file is part of CGAL (www.cgal.org) +// +// $URL$ +// $Id$ +// SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-Commercial +// +// +// Author(s) : Maxime Gimeno +// + +#ifndef CGAL_INTERNAL_INTERSECTIONS_3_RAY_3_TETRAHEDRON_3_DO_INTERSECT_H +#define CGAL_INTERNAL_INTERSECTIONS_3_RAY_3_TETRAHEDRON_3_DO_INTERSECT_H + +#include + +namespace CGAL { +namespace Intersections { +namespace internal { + +template +typename K::Boolean +do_intersect(const typename K::Ray_3& unb, + const typename K::Tetrahedron_3& tet, + const K& k) +{ + return do_intersect_tetrahedron_unbounded(tet, unb, k); +} + +template +typename K::Boolean +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 +} // namespace Intersections +} // namespace CGAL + +#endif // CGAL_INTERNAL_INTERSECTIONS_3_RAY_3_TETRAHEDRON_3_DO_INTERSECT_H diff --git a/Intersections_3/include/CGAL/Intersections_3/internal/Tetrahedron_3_Ray_3_intersection.h b/Intersections_3/include/CGAL/Intersections_3/internal/Ray_3_Tetrahedron_3_intersection.h similarity index 63% rename from Intersections_3/include/CGAL/Intersections_3/internal/Tetrahedron_3_Ray_3_intersection.h rename to Intersections_3/include/CGAL/Intersections_3/internal/Ray_3_Tetrahedron_3_intersection.h index 4738c5e3a71..ebbb9f513e5 100644 --- a/Intersections_3/include/CGAL/Intersections_3/internal/Tetrahedron_3_Ray_3_intersection.h +++ b/Intersections_3/include/CGAL/Intersections_3/internal/Ray_3_Tetrahedron_3_intersection.h @@ -11,31 +11,31 @@ // Author(s) : Maxime Gimeno // -#ifndef CGAL_INTERNAL_INTERSECTIONS_3_TETRAHEDRON_3_RAY_3_INTERSECTION_H -#define CGAL_INTERNAL_INTERSECTIONS_3_TETRAHEDRON_3_RAY_3_INTERSECTION_H +#ifndef CGAL_INTERNAL_INTERSECTIONS_3_RAY_3_TETRAHEDRON_3_INTERSECTION_H +#define CGAL_INTERNAL_INTERSECTIONS_3_RAY_3_TETRAHEDRON_3_INTERSECTION_H -#include -#include +#include #include +#include + namespace CGAL { - namespace Intersections { - namespace internal { template struct Tetrahedron_ray_intersection_3 - :public Tetrahedron_lines_intersection_3_base > + : public Tetrahedron_lines_intersection_3_base > { typedef typename K::Ray_3 O; - typedef Tetrahedron_lines_intersection_3_base > Base; + typedef Tetrahedron_lines_intersection_3_base > Base; typedef typename Base::Result_type Result_type; Tetrahedron_ray_intersection_3(const typename K::Tetrahedron_3& tet, - const O& o):Base(tet,o) {} + const O& o) + : + Base(tet, o) + { } bool are_extremities_inside_test() { @@ -50,14 +50,11 @@ struct Tetrahedron_ray_intersection_3 } }; - -//Tetrahedron_3 Ray_3 template typename Intersection_traits::result_type -intersection( - const typename K::Tetrahedron_3 &tet, - const typename K::Ray_3 &ray, - const K&) +intersection(const typename K::Tetrahedron_3& tet, + const typename K::Ray_3& ray, + const K&) { Tetrahedron_ray_intersection_3 solver(tet, ray); solver.do_procede(); @@ -66,13 +63,15 @@ intersection( template typename Intersection_traits::result_type -intersection( - const typename K::Ray_3 &seg, - const typename K::Tetrahedron_3 &tet, - const K& k) +intersection(const typename K::Ray_3& ray, + const typename K::Tetrahedron_3& tet, + const K& k) { - return intersection(tet, seg, k); + return intersection(tet, ray, k); } -}}} -#endif // CGAL_INTERNAL_INTERSECTIONS_3_TETRAHEDRON_3_RAY_3_INTERSECTION_H +} // namespace internal +} // namespace Intersections +} // namespace CGAL + +#endif // CGAL_INTERNAL_INTERSECTIONS_3_RAY_3_TETRAHEDRON_3_INTERSECTION_H diff --git a/Intersections_3/include/CGAL/Intersections_3/internal/Triangle_3_Ray_3_do_intersect.h b/Intersections_3/include/CGAL/Intersections_3/internal/Ray_3_Triangle_3_do_intersect.h similarity index 60% rename from Intersections_3/include/CGAL/Intersections_3/internal/Triangle_3_Ray_3_do_intersect.h rename to Intersections_3/include/CGAL/Intersections_3/internal/Ray_3_Triangle_3_do_intersect.h index 7ca2caa176c..f0d6ea725d3 100644 --- a/Intersections_3/include/CGAL/Intersections_3/internal/Triangle_3_Ray_3_do_intersect.h +++ b/Intersections_3/include/CGAL/Intersections_3/internal/Ray_3_Triangle_3_do_intersect.h @@ -10,56 +10,58 @@ // // Author(s) : Philippe Guigue -#ifndef CGAL_TRIANGLE_3_RAY_3_DO_INTERSECT_H -#define CGAL_TRIANGLE_3_RAY_3_DO_INTERSECT_H +#ifndef CGAL_INTERNAL_INTERSECTIONS_RAY_3_TRIANGLE_3_DO_INTERSECT_H +#define CGAL_INTERNAL_INTERSECTIONS_RAY_3_TRIANGLE_3_DO_INTERSECT_H #include #include -#include namespace CGAL { - - template - class Triangle_3; - - template - class Ray_3; - - namespace Intersections { namespace internal { -namespace R3T3_intersection{ - enum type {COPLANAR_RAY=3,ENDPOINT_IN_TRIANGLE=4,CROSS_SEGMENT=1,CROSS_VERTEX=2,CROSS_FACET=0}; -} //R3T3_intersection +namespace R3T3_intersection { -struct r3t3_do_intersect_empty_visitor{ +enum type { + COPLANAR_RAY = 3, + ENDPOINT_IN_TRIANGLE = 4, + CROSS_SEGMENT = 1, + CROSS_VERTEX = 2, + CROSS_FACET = 0 +}; + +} // namespace R3T3_intersection + +struct r3t3_do_intersect_empty_visitor +{ typedef bool result_type; - result_type result(bool b){return b;} + result_type result(bool b){ return b; } void update(Orientation){} void ray_coplanar(){} void end_point_in_triangle(){} }; -struct r3t3_do_intersect_endpoint_position_visitor{ +struct r3t3_do_intersect_endpoint_position_visitor +{ int m_intersection_type; - r3t3_do_intersect_endpoint_position_visitor(): - m_intersection_type(0){} + + r3t3_do_intersect_endpoint_position_visitor() : m_intersection_type(0) { } + typedef std::pair result_type; - result_type result(bool b){ + result_type result(bool b) + { CGAL_assertion(m_intersection_type>-1 && m_intersection_type<5); return std::make_pair(b,enum_cast(m_intersection_type)); } + void update(Orientation orient) { - if (orient==ZERO) ++m_intersection_type; - } - void ray_coplanar(){ - m_intersection_type=3; - } - void end_point_in_triangle(){ - m_intersection_type=4; + if (orient==ZERO) + ++m_intersection_type; } + + void ray_coplanar(){ m_intersection_type = 3; } + void end_point_in_triangle(){ m_intersection_type = 4; } }; //the template parameter Visitor here is used to offer the posibility to use @@ -72,56 +74,167 @@ struct r3t3_do_intersect_endpoint_position_visitor{ template typename Visitor::result_type -do_intersect_coplanar(const typename K::Triangle_3 &t, - const typename K::Ray_3 &r, - const K & k, - Visitor visitor); - -template -typename Visitor::result_type - do_intersect(const typename K::Triangle_3 &t, - const typename K::Ray_3 &r, - const K & k, - Visitor visitor) +do_intersect_coplanar(const typename K::Triangle_3& t, + const typename K::Ray_3& r, + const K& k, + Visitor visitor) { - - CGAL_kernel_precondition( ! k.is_degenerate_3_object()(t) ) ; - CGAL_kernel_precondition( ! k.is_degenerate_3_object()(r) ) ; + visitor.ray_coplanar(); + CGAL_kernel_precondition(!k.is_degenerate_3_object()(t)); + CGAL_kernel_precondition(!k.is_degenerate_3_object()(r)); typedef typename K::Point_3 Point_3; - typename K::Construct_vertex_3 vertex_on = - k.construct_vertex_3_object(); + typename K::Construct_point_on_3 point_on = k.construct_point_on_3_object(); + typename K::Construct_vertex_3 vertex_on = k.construct_vertex_3_object(); + typename K::Coplanar_orientation_3 coplanar_orientation = k.coplanar_orientation_3_object(); - typename K::Orientation_3 orientation = - k.orientation_3_object(); + const Point_3& p = point_on(r,0); + const Point_3& q = point_on(r,1); + const Point_3& A = vertex_on(t,0); + const Point_3& B = vertex_on(t,1); + const Point_3& C = vertex_on(t,2); - const Point_3 & a = vertex_on(t,0); - const Point_3 & b = vertex_on(t,1); - const Point_3 & c = vertex_on(t,2); + const Point_3* a = &A; + const Point_3* b = &B; + const Point_3* c = &C; - typename K::Construct_vector_3 construct_vector = - k.construct_vector_3_object(); + // Determine the orientation of the triangle in the common plane + if (coplanar_orientation(A,B,C) != POSITIVE) + { + // The triangle is not counterclockwise oriented + // swap two vertices. + b = &C; + c = &B; + } - typename K::Construct_ray_3 construct_ray = - k.construct_ray_3_object(); + // Test whether the ray's supporting line intersects the + // triangle in the common plane - typename K::Construct_point_on_3 point_on = - k.construct_point_on_3_object(); + const Orientation pqa = coplanar_orientation(p,q,*a); + const Orientation pqb = coplanar_orientation(p,q,*b); + const Orientation pqc = coplanar_orientation(p,q,*c); - const Point_3 & p = point_on(r,0); - const Point_3 & q = point_on(r,1); + switch ( pqa ) { + case POSITIVE: + switch ( pqb ) { + case POSITIVE: + if (pqc == POSITIVE) + // the triangle lies in the positive halfspace + // defined by the ray's supporting line. + return visitor.result(false); + // c is isolated on the negative side + return visitor.result(coplanar_orientation(*a,*c,p) != POSITIVE); + case NEGATIVE: + if (pqc == POSITIVE) // b is isolated on the negative side + return visitor.result(coplanar_orientation(*c,*b,p) != POSITIVE); + // a is isolated on the positive side + return visitor.result(coplanar_orientation(*a,*c,p) != POSITIVE); + + case COLLINEAR: + if (pqc == POSITIVE) // b is isolated on the negative side + return visitor.result(coplanar_orientation(*c,*b,p) != POSITIVE); + // a is isolated on the positive side + return visitor.result(coplanar_orientation(*a,*c,p) != POSITIVE); + + default: // should not happen. + CGAL_kernel_assertion(false); + return visitor.result(false); + } + + case NEGATIVE: + switch ( pqb ) { + case POSITIVE: + if (pqc == POSITIVE) // a is isolated on the negative side + return visitor.result(coplanar_orientation(*b,*a,p) != POSITIVE); + // b is isolated on the positive side + return visitor.result(coplanar_orientation(*b,*a,p) != POSITIVE); + + case NEGATIVE: + if (pqc == NEGATIVE) + // the triangle lies in the negative halfspace + // defined by the ray's supporting line. + return visitor.result( false); + // c is isolated on the positive side + return visitor.result(coplanar_orientation(*c,*b,p) != POSITIVE); + case COLLINEAR: + if (pqc == NEGATIVE) // b is isolated on the positive side + return visitor.result(coplanar_orientation(*b,*a,p) != POSITIVE); + // a is isolated on the negative side + return visitor.result(coplanar_orientation(*b,*a,p) != POSITIVE); + + default: // should not happen. + CGAL_kernel_assertion(false); + return visitor.result(false); + } + + case COLLINEAR: + switch ( pqb ) { + case POSITIVE: + if (pqc == POSITIVE) // a is isolated on the negative side + return visitor.result(coplanar_orientation(*b,*a,p) != POSITIVE); + // b is isolated on the positive side + return visitor.result(coplanar_orientation(*b,*a,p) != POSITIVE); + case NEGATIVE: + if (pqc == NEGATIVE) // a is isolated on the positive side + return visitor.result(coplanar_orientation(*a,*c,p) != POSITIVE); + // b is isolated on the negative side + return visitor.result(coplanar_orientation(*c,*b,p) != POSITIVE); + + case COLLINEAR: + if (pqc == POSITIVE) // c is isolated on the positive side + return visitor.result(coplanar_orientation(*c,*b,p) != POSITIVE); + // c is isolated on the negative side + return visitor.result(coplanar_orientation(*a,*c,p) != POSITIVE); + // case pqc == COLLINEAR is imposiible + + default: // should not happen. + CGAL_kernel_assertion(false); + return visitor.result(false); + } + + default: // should not happen. + CGAL_kernel_assertion(false); + return visitor.result(false); + } +} + +template +typename Visitor::result_type +do_intersect(const typename K::Triangle_3& t, + const typename K::Ray_3 &r, + const K& k, + Visitor visitor) +{ + CGAL_kernel_precondition(!k.is_degenerate_3_object()(t)); + CGAL_kernel_precondition(!k.is_degenerate_3_object()(r)); + + typedef typename K::Point_3 Point_3; + + typename K::Construct_vertex_3 vertex_on = k.construct_vertex_3_object(); + typename K::Orientation_3 orientation = k.orientation_3_object(); + + const Point_3& a = vertex_on(t,0); + const Point_3& b = vertex_on(t,1); + const Point_3& c = vertex_on(t,2); + + typename K::Construct_vector_3 construct_vector = k.construct_vector_3_object(); + typename K::Construct_ray_3 construct_ray = k.construct_ray_3_object(); + typename K::Construct_point_on_3 point_on = k.construct_point_on_3_object(); + + const Point_3& p = point_on(r,0); + const Point_3& q = point_on(r,1); const Orientation ray_direction = orientation(a,b,c,point_on(construct_ray(a, construct_vector(r)),1)); - if (ray_direction == COPLANAR ) { - if (orientation(a,b,c,p) == COPLANAR) - return do_intersect_coplanar(t,r,k,visitor); - else return visitor.result(false); - } + if (ray_direction == COPLANAR ) { + if (orientation(a,b,c,p) == COPLANAR) + return do_intersect_coplanar(t,r,k,visitor); + else return visitor.result(false); + } const Orientation abcp = orientation(a,b,c,p); @@ -211,169 +324,28 @@ typename Visitor::result_type default: // should not happen. CGAL_kernel_assertion(false); return visitor.result(false); - } } template -bool do_intersect(const typename K::Triangle_3 &t, - const typename K::Ray_3 &r, - const K & k) +bool do_intersect(const typename K::Triangle_3& t, + const typename K::Ray_3& r, + const K& k) { - return do_intersect(t,r,k,r3t3_do_intersect_empty_visitor()); + return do_intersect(t, r, k, r3t3_do_intersect_empty_visitor()); } - template inline -bool do_intersect(const typename K::Ray_3 &r, - const typename K::Triangle_3 &t, - const K & k) +bool do_intersect(const typename K::Ray_3& r, + const typename K::Triangle_3& t, + const K& k) { - return do_intersect(t,r, k); + return do_intersect(t, r, k); } - -template -typename Visitor::result_type -do_intersect_coplanar(const typename K::Triangle_3 &t, - const typename K::Ray_3 &r, - const K & k, - Visitor visitor) -{ - visitor.ray_coplanar(); - CGAL_kernel_precondition( ! k.is_degenerate_3_object()(t) ) ; - CGAL_kernel_precondition( ! k.is_degenerate_3_object()(r) ) ; - - typedef typename K::Point_3 Point_3; - - typename K::Construct_point_on_3 point_on = - k.construct_point_on_3_object(); - - typename K::Construct_vertex_3 vertex_on = - k.construct_vertex_3_object(); - - typename K::Coplanar_orientation_3 coplanar_orientation = - k.coplanar_orientation_3_object(); - - - const Point_3 & p = point_on(r,0); - const Point_3 & q = point_on(r,1); - - const Point_3 & A = vertex_on(t,0); - const Point_3 & B = vertex_on(t,1); - const Point_3 & C = vertex_on(t,2); - - - const Point_3 * a = &A; - const Point_3 * b = &B; - const Point_3 * c = &C; - // Determine the orientation of the triangle in the common plane - - if (coplanar_orientation(A,B,C) != POSITIVE) - { - // The triangle is not counterclockwise oriented - // swap two vertices. - b = &C; - c = &B; - } - - // Test whether the ray's supporting line intersects the - // triangle in the common plane - - const Orientation pqa = coplanar_orientation(p,q,*a); - const Orientation pqb = coplanar_orientation(p,q,*b); - const Orientation pqc = coplanar_orientation(p,q,*c); - - - switch ( pqa ) { - case POSITIVE: - switch ( pqb ) { - case POSITIVE: - if (pqc == POSITIVE) - // the triangle lies in the positive halfspace - // defined by the ray's supporting line. - return visitor.result(false); - // c is isolated on the negative side - return visitor.result( coplanar_orientation(*a,*c,p) != POSITIVE ); - - case NEGATIVE: - if (pqc == POSITIVE) // b is isolated on the negative side - return visitor.result( coplanar_orientation(*c,*b,p) != POSITIVE ); - // a is isolated on the positive side - return visitor.result( coplanar_orientation(*a,*c,p) != POSITIVE ); - - case COLLINEAR: - if (pqc == POSITIVE) // b is isolated on the negative side - return visitor.result( coplanar_orientation(*c,*b,p) != POSITIVE ); - // a is isolated on the positive side - return visitor.result( coplanar_orientation(*a,*c,p) != POSITIVE ); - - default: // should not happen. - CGAL_kernel_assertion(false); - return visitor.result(false); - } - - case NEGATIVE: - switch ( pqb ) { - case POSITIVE: - if (pqc == POSITIVE) // a is isolated on the negative side - return visitor.result( coplanar_orientation(*b,*a,p) != POSITIVE ); - // b is isolated on the positive side - return visitor.result( coplanar_orientation(*b,*a,p) != POSITIVE ); - - case NEGATIVE: - if (pqc == NEGATIVE) - // the triangle lies in the negative halfspace - // defined by the ray's supporting line. - return visitor.result( false ); - // c is isolated on the positive side - return visitor.result( coplanar_orientation(*c,*b,p) != POSITIVE ); - case COLLINEAR: - if (pqc == NEGATIVE) // b is isolated on the positive side - return visitor.result( coplanar_orientation(*b,*a,p) != POSITIVE ); - // a is isolated on the negative side - return visitor.result( coplanar_orientation(*b,*a,p) != POSITIVE ); - - default: // should not happen. - CGAL_kernel_assertion(false); - return visitor.result(false); - } - - case COLLINEAR: - switch ( pqb ) { - case POSITIVE: - if (pqc == POSITIVE) // a is isolated on the negative side - return visitor.result( coplanar_orientation(*b,*a,p) != POSITIVE ); - // b is isolated on the positive side - return visitor.result( coplanar_orientation(*b,*a,p) != POSITIVE ); - case NEGATIVE: - if (pqc == NEGATIVE) // a is isolated on the positive side - return visitor.result( coplanar_orientation(*a,*c,p) != POSITIVE ); - // b is isolated on the negative side - return visitor.result( coplanar_orientation(*c,*b,p) != POSITIVE ); - - case COLLINEAR: - if (pqc == POSITIVE) // c is isolated on the positive side - return visitor.result( coplanar_orientation(*c,*b,p) != POSITIVE ); - // c is isolated on the negative side - return visitor.result( coplanar_orientation(*a,*c,p) != POSITIVE ); - // case pqc == COLLINEAR is imposiible - - default: // should not happen. - CGAL_kernel_assertion(false); - return visitor.result(false); - } - - default: // should not happen. - CGAL_kernel_assertion(false); - return visitor.result(false); - } -} - - } // namespace internal } // namespace Intersections -} //namespace CGAL +} // namespace CGAL -#endif // CGAL_TRIANGLE_3_RAY_3_DO_INTERSECT_H +#endif // CGAL_INTERNAL_INTERSECTIONS_RAY_3_TRIANGLE_3_DO_INTERSECT_H diff --git a/Intersections_3/include/CGAL/Intersections_3/internal/Triangle_3_Ray_3_intersection.h b/Intersections_3/include/CGAL/Intersections_3/internal/Ray_3_Triangle_3_intersection.h similarity index 87% rename from Intersections_3/include/CGAL/Intersections_3/internal/Triangle_3_Ray_3_intersection.h rename to Intersections_3/include/CGAL/Intersections_3/internal/Ray_3_Triangle_3_intersection.h index 66bb3ba8300..635e9e45453 100644 --- a/Intersections_3/include/CGAL/Intersections_3/internal/Triangle_3_Ray_3_intersection.h +++ b/Intersections_3/include/CGAL/Intersections_3/internal/Ray_3_Triangle_3_intersection.h @@ -10,18 +10,19 @@ // // Author(s) : Laurent Rineau, Stephane Tayeb // -// Note: This implementation is adapted from Triangle_3_Ray_3_do_intersect.h. +// Note: This implementation is adapted from RAY_3_Triangle_3_do_intersect.h. -#ifndef CGAL_INTERNAL_INTERSECTIONS_3_TRIANGLE_3_RAY_3_INTERSECTION_H -#define CGAL_INTERNAL_INTERSECTIONS_3_TRIANGLE_3_RAY_3_INTERSECTION_H +#ifndef CGAL_INTERNAL_INTERSECTIONS_3_RAY_3_TRIANGLE_3_INTERSECTION_H +#define CGAL_INTERNAL_INTERSECTIONS_3_RAY_3_TRIANGLE_3_INTERSECTION_H -#include -#include +#include +#include + +#include +#include namespace CGAL { - namespace Intersections { - namespace internal { template @@ -40,17 +41,12 @@ t3r3_intersection_coplanar_aux(const typename K::Point_3& p, typedef typename K::Vector_3 Vector_3; typedef typename K::FT FT; - typename K::Construct_vector_3 vector = - k.construct_vector_3_object(); - - typename K::Construct_cross_product_vector_3 cross_product = - k.construct_cross_product_vector_3_object(); - - typename K::Compute_scalar_product_3 scalar_product = - k.compute_scalar_product_3_object(); - - typename K::Compute_squared_length_3 sq_length = - k.compute_squared_length_3_object(); + typename K::Construct_vector_3 vector = k.construct_vector_3_object(); + typename K::Construct_cross_product_vector_3 cross_product = k.construct_cross_product_vector_3_object(); + typename K::Compute_scalar_product_3 scalar_product = k.compute_scalar_product_3_object(); + typename K::Construct_scaled_vector_3 sc = k.construct_scaled_vector_3_object(); + typename K::Compute_squared_length_3 sq_length = k.compute_squared_length_3_object(); + typename K::Construct_translated_point_3 trans = k.construct_translated_point_3_object(); const Vector_3 ab = vector(a,b); const Vector_3 pa = vector(p,a); @@ -60,10 +56,9 @@ t3r3_intersection_coplanar_aux(const typename K::Point_3& p, const FT t = scalar_product(pa_ab,v_ab) / sq_length(v_ab); - return ( p + t*v ); + return trans(p, sc(v, t)); // p + t*v } - template typename Intersection_traits::result_type t3r3_intersection_coplanar_aux(const typename K::Point_3& a, @@ -89,14 +84,9 @@ t3r3_intersection_coplanar_aux(const typename K::Point_3& a, typedef typename K::Point_3 Point_3; typedef typename K::Vector_3 Vector_3; - typename K::Coplanar_orientation_3 coplanar_orientation = - k.coplanar_orientation_3_object(); - - typename K::Construct_segment_3 segment = - k.construct_segment_3_object(); - - typename K::Construct_point_on_3 point_on = - k.construct_point_on_3_object(); + typename K::Coplanar_orientation_3 coplanar_orientation = k.coplanar_orientation_3_object(); + typename K::Construct_segment_3 segment = k.construct_segment_3_object(); + typename K::Construct_point_on_3 point_on = k.construct_point_on_3_object(); const Point_3& p = point_on(r,0); @@ -105,7 +95,6 @@ t3r3_intersection_coplanar_aux(const typename K::Point_3& a, : coplanar_orientation(b,c,p); switch ( cap ) { - case NEGATIVE: // p is bellow [c,a] return intersection_return(); @@ -157,37 +146,27 @@ t3r3_intersection_coplanar_aux(const typename K::Point_3& a, template typename Intersection_traits::result_type -intersection_coplanar(const typename K::Triangle_3 &t, +intersection_coplanar(const typename K::Triangle_3& t, const typename K::Ray_3 &r, - const K & k ) + const K& k ) { - CGAL_kernel_precondition( ! k.is_degenerate_3_object()(t) ) ; - CGAL_kernel_precondition( ! k.is_degenerate_3_object()(r) ) ; + CGAL_kernel_precondition(!k.is_degenerate_3_object()(t)); + CGAL_kernel_precondition(!k.is_degenerate_3_object()(r)); typedef typename K::Point_3 Point_3; - typename K::Construct_point_on_3 point_on = - k.construct_point_on_3_object(); + typename K::Construct_point_on_3 point_on = k.construct_point_on_3_object(); + typename K::Construct_vertex_3 vertex_on = k.construct_vertex_3_object(); + typename K::Coplanar_orientation_3 coplanar_orientation = k.coplanar_orientation_3_object(); + typename K::Construct_segment_3 segment = k.construct_segment_3_object(); + typename K::Collinear_are_ordered_along_line_3 collinear_ordered = k.collinear_are_ordered_along_line_3_object(); - typename K::Construct_vertex_3 vertex_on = - k.construct_vertex_3_object(); + const Point_3& p = point_on(r,0); + const Point_3& q = point_on(r,1); - typename K::Coplanar_orientation_3 coplanar_orientation = - k.coplanar_orientation_3_object(); - - typename K::Construct_segment_3 segment = - k.construct_segment_3_object(); - - typename K::Collinear_are_ordered_along_line_3 collinear_ordered = - k.collinear_are_ordered_along_line_3_object(); - - - const Point_3 & p = point_on(r,0); - const Point_3 & q = point_on(r,1); - - const Point_3 & A = vertex_on(t,0); - const Point_3 & B = vertex_on(t,1); - const Point_3 & C = vertex_on(t,2); + const Point_3& A = vertex_on(t,0); + const Point_3& B = vertex_on(t,1); + const Point_3& C = vertex_on(t,2); int k0 = 0; int k1 = 1; @@ -415,50 +394,41 @@ intersection_coplanar(const typename K::Triangle_3 &t, } } - template inline typename boost::optional -t3r3_intersection_aux(const typename K::Triangle_3 &t, - const typename K::Ray_3 &r, +t3r3_intersection_aux(const typename K::Triangle_3& t, + const typename K::Ray_3& r, const K& k) { - typename Intersection_traits - ::result_type - v = internal::intersection(r.supporting_line(),t.supporting_plane(), k); + typename Intersection_traits::result_type + v = internal::intersection(r.supporting_line(), t.supporting_plane(), k); - if(v) { + if(v) + { if(const typename K::Point_3* p = intersect_get(v)) return *p; } + return boost::optional(); } - template typename Intersection_traits::result_type -intersection(const typename K::Triangle_3 &t, - const typename K::Ray_3 &r, +intersection(const typename K::Triangle_3& t, + const typename K::Ray_3& r, const K& k) { - CGAL_kernel_precondition( ! k.is_degenerate_3_object()(t) ) ; - CGAL_kernel_precondition( ! k.is_degenerate_3_object()(r) ) ; + CGAL_kernel_precondition(!k.is_degenerate_3_object()(t)); + CGAL_kernel_precondition(!k.is_degenerate_3_object()(r)); typedef typename K::Point_3 Point_3; - typename K::Construct_vertex_3 vertex_on = - k.construct_vertex_3_object(); - - typename K::Orientation_3 orientation = - k.orientation_3_object(); - - typename K::Construct_ray_3 ray = - k.construct_ray_3_object(); - - typename K::Construct_point_on_3 point_on = - k.construct_point_on_3_object(); - + typename K::Construct_vertex_3 vertex_on = k.construct_vertex_3_object(); + typename K::Orientation_3 orientation = k.orientation_3_object(); + typename K::Construct_ray_3 ray = k.construct_ray_3_object(); + typename K::Construct_point_on_3 point_on = k.construct_point_on_3_object(); const Point_3& a = vertex_on(t,0); const Point_3& b = vertex_on(t,1); @@ -466,7 +436,7 @@ intersection(const typename K::Triangle_3 &t, const Point_3& p = point_on(r,0); const Point_3& q = point_on(r,1); - Point_3 d = point_on(ray(a,r.to_vector()),1); + Point_3 d = point_on(ray(a, r.to_vector()), 1); const Orientation ray_direction = orientation(a,b,c,d); const Orientation abcp = orientation(a,b,c,p); @@ -569,13 +539,14 @@ intersection(const typename K::Triangle_3 &t, template typename Intersection_traits::result_type intersection(const typename K::Ray_3 &r, - const typename K::Triangle_3 &t, - const K& k) { - return Intersections::internal::intersection(t, r, k); + const typename K::Triangle_3& t, + const K& k) +{ + return intersection(t, r, k); } -} // end namespace internal +} // namespace internal } // namespace Intersections -} // end namespace CGAL +} // namespace CGAL -#endif // CGAL_INTERNAL_INTERSECTIONS_3_TRIANGLE_3_RAY_3_INTERSECTION_H +#endif // CGAL_INTERNAL_INTERSECTIONS_3_RAY_3_TRIANGLE_3_INTERSECTION_H diff --git a/Intersections_3/include/CGAL/Intersections_3/internal/Segment_3_Segment_3_do_intersect.h b/Intersections_3/include/CGAL/Intersections_3/internal/Segment_3_Segment_3_do_intersect.h new file mode 100644 index 00000000000..317e531eda0 --- /dev/null +++ b/Intersections_3/include/CGAL/Intersections_3/internal/Segment_3_Segment_3_do_intersect.h @@ -0,0 +1,64 @@ +// Copyright (c) 2003 INRIA Sophia-Antipolis (France). +// All rights reserved. +// +// This file is part of CGAL (www.cgal.org) +// +// $URL$ +// $Id$ +// SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-Commercial +// +// +// Author(s) : Philippe Guigue + +#ifndef CGAL_INTERNAL_INTERSECTIONS_SEGMENT_3_SEGMENT_3_DO_INTERSECT_H +#define CGAL_INTERNAL_INTERSECTIONS_SEGMENT_3_SEGMENT_3_DO_INTERSECT_H + +#include + +#include + +namespace CGAL { +namespace Intersections { +namespace internal { + +template +inline +bool +do_intersect(const typename K::Segment_3& s1, + const typename K::Segment_3& s2, + const K& k) +{ + CGAL_precondition(!s1.is_degenerate() && !s2.is_degenerate()); + + bool b = do_intersect(s1.supporting_line(), s2.supporting_line(), k); + if(b) + { + // supporting_line intersects: points are coplanar + typename K::Coplanar_orientation_3 cpl_orient=k.coplanar_orientation_3_object(); + ::CGAL::Orientation or1 = cpl_orient(s1[0], s1[1], s2[0]); + ::CGAL::Orientation or2 = cpl_orient(s1[0], s1[1], s2[1]); + + if(or1 == COLLINEAR && or2 == COLLINEAR) + { + // segments are collinear + typename K::Collinear_are_ordered_along_line_3 cln_order = k.collinear_are_ordered_along_line_3_object(); + return (cln_order(s1[0], s2[0], s1[1]) || + cln_order(s1[0], s2[1], s1[1]) || + cln_order(s2[0], s1[0], s2[1])); + } + + if(or1 != or2) + { + or1 = cpl_orient(s2[0], s2[1], s1[0]); + return (or1 == COLLINEAR || or1 != cpl_orient(s2[0], s2[1], s1[1])); + } + } + + return false; +} + +} // namespace internal +} // namespace Intersections +} // namespace CGAL + +#endif //CGAL_INTERNAL_INTERSECTIONS_SEGMENT_3_SEGMENT_3_DO_INTERSECT_H diff --git a/Intersections_3/include/CGAL/Intersections_3/internal/Segment_3_Segment_3_intersection.h b/Intersections_3/include/CGAL/Intersections_3/internal/Segment_3_Segment_3_intersection.h new file mode 100644 index 00000000000..9bf2ed97ac7 --- /dev/null +++ b/Intersections_3/include/CGAL/Intersections_3/internal/Segment_3_Segment_3_intersection.h @@ -0,0 +1,129 @@ +// Copyright (c) 2009 GeometryFactory (France), INRIA Sophia-Antipolis (France). +// All rights reserved. +// +// This file is part of CGAL (www.cgal.org) +// +// $URL$ +// $Id$ +// SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-Commercial +// +// +// Author(s) : Sébastien Loriot +// +#ifndef CGAL_INTERNAL_INTERSECTIONS_3_SEGMENT_3_SEGMENT_3_INTERSECTION_H +#define CGAL_INTERNAL_INTERSECTIONS_3_SEGMENT_3_SEGMENT_3_INTERSECTION_H + +#include +#include + +namespace CGAL { +namespace Intersections { +namespace internal { + +template +typename Intersection_traits::result_type +intersection_collinear_segments(const typename K::Segment_3& s1, + const typename K::Segment_3& s2, + const K& k) +{ + CGAL_precondition(!s1.is_degenerate() && !s2.is_degenerate()); + + const typename K::Point_3& p=s1[0], q=s1[1], r=s2[0], s=s2[1]; + + typename K::Collinear_are_ordered_along_line_3 cln_order=k.collinear_are_ordered_along_line_3_object(); + + if(cln_order(p,r,q)) + { + if(cln_order(p,s,q)) + return intersection_return(s2); + + if(cln_order(r,p,s)) + { + if(r != p) + return intersection_return( typename K::Segment_3(r,p) ); + + if(cln_order(r,q,s)) + return intersection_return(s1); + + return intersection_return(p); + } + + return (r != q) ? intersection_return( typename K::Segment_3(r,q) ) + : intersection_return(q); + } + + if(cln_order(p,s,q)) + { + if(cln_order(r,p,s)) + { + if(s != p) + return intersection_return( typename K::Segment_3(s,p) ); + if(cln_order(r,q,s)) + return intersection_return(s1); + + return intersection_return(p); + } + + return (s != q) ? intersection_return( typename K::Segment_3(s,q) ) + : intersection_return(q); + } + + if(cln_order(r,p,s)) + return intersection_return(s1); + + return intersection_return(); +} + +template +struct L_p_visitor + : public boost::static_visitor< + typename Intersection_traits::result_type> +{ + typedef typename Intersection_traits::result_type result_type; + + L_p_visitor(const typename K::Segment_3& s1, + const typename K::Segment_3& s2) + : s1(s1), s2(s2) + { } + + const typename K::Segment_3& s1; + const typename K::Segment_3& s2; + + result_type operator()(const typename K::Point_3& p) const + { + typename K::Collinear_are_ordered_along_line_3 cln_order = K().collinear_are_ordered_along_line_3_object(); + + if(cln_order(s1[0],p,s1[1]) && cln_order(s2[0],p,s2[1])) + return intersection_return(p); + else + return intersection_return(); + } + + result_type operator()(const typename K::Line_3&) const + { + return intersection_collinear_segments(s1,s2,K()); + } +}; + +template +typename Intersection_traits::result_type +intersection(const typename K::Segment_3& s1, + const typename K::Segment_3& s2, + const K& k) +{ + CGAL_precondition(!s1.is_degenerate() && !s2.is_degenerate()); + + typename Intersection_traits::result_type + v = internal::intersection(s1.supporting_line(), s2.supporting_line(), k); + + if(v) + return apply_visitor(L_p_visitor(s1, s2) , *v); + + return intersection_return(); +} + +} // namespace internal +} // namespace Intersections +} // namespace CGAL + +#endif // CGAL_INTERNAL_INTERSECTIONS_3_SEGMENT_3_SEGMENT_3_INTERSECTION_H diff --git a/Intersections_3/include/CGAL/Intersections_3/internal/Segment_3_Sphere_3_do_intersect.h b/Intersections_3/include/CGAL/Intersections_3/internal/Segment_3_Sphere_3_do_intersect.h new file mode 100644 index 00000000000..ff1a7ffb4eb --- /dev/null +++ b/Intersections_3/include/CGAL/Intersections_3/internal/Segment_3_Sphere_3_do_intersect.h @@ -0,0 +1,53 @@ +// Copyright (c) 2003 INRIA Sophia-Antipolis (France). +// All rights reserved. +// +// This file is part of CGAL (www.cgal.org) +// +// $URL$ +// $Id$ +// SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-Commercial +// +// +// Author(s) : Andreas Fabri + +#ifndef CGAL_INTERNAL_INTERSECTIONS_SEGMENT_3_SPHERE_3_DO_INTERSECT_H +#define CGAL_INTERNAL_INTERSECTIONS_SEGMENT_3_SPHERE_3_DO_INTERSECT_H + +#include +#include + +namespace CGAL { +namespace Intersections { +namespace internal { + +template +inline +typename K::Boolean +do_intersect(const typename K::Sphere_3& sp, + const typename K::Segment_3& seg, + const K& k) +{ + typedef typename K::RT RT; + RT num, den; + + CGAL::internal::squared_distance_RT(sp.center(), seg, num, den, k); + return !(compare_quotients(num, den, + Rational_traits().numerator(sp.squared_radius()), + Rational_traits().denominator(sp.squared_radius())) == LARGER); +} + +template +inline +typename K::Boolean +do_intersect(const typename K::Segment_3& seg, + const typename K::Sphere_3& sp, + const K& k) +{ + return do_intersect(sp, seg, k); +} + +} // namespace internal +} // namespace Intersections +} // namespace CGAL + +#endif // CGAL_INTERNAL_INTERSECTIONS_SEGMENT_3_SPHERE_3_DO_INTERSECT_H diff --git a/Intersections_3/include/CGAL/Intersections_3/internal/Segment_3_Tetrahedron_3_do_intersect.h b/Intersections_3/include/CGAL/Intersections_3/internal/Segment_3_Tetrahedron_3_do_intersect.h new file mode 100644 index 00000000000..1b78b45b1ad --- /dev/null +++ b/Intersections_3/include/CGAL/Intersections_3/internal/Segment_3_Tetrahedron_3_do_intersect.h @@ -0,0 +1,46 @@ +// Copyright (c) 2001 GeometryFactory(France). +// All rights reserved. +// +// This file is part of CGAL (www.cgal.org) +// +// $URL$ +// $Id$ +// SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-Commercial +// +// +// Author(s) : Nico Kruithof + +#ifndef CGAL_INTERNAL_INTERSECTIONS_3_SEGMENT_3_TETRAHEDRON_3_DO_INTERSECT_H +#define CGAL_INTERNAL_INTERSECTIONS_3_SEGMENT_3_TETRAHEDRON_3_DO_INTERSECT_H + +#include + +namespace CGAL { +namespace Intersections { +namespace internal { + +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); +} + +} // namespace internal +} // namespace Intersections +} // namespace CGAL + +#endif // CGAL_INTERNAL_INTERSECTIONS_3_SEGMENT_3_TETRAHEDRON_3_DO_INTERSECT_H diff --git a/Intersections_3/include/CGAL/Intersections_3/internal/Tetrahedron_3_Segment_3_intersection.h b/Intersections_3/include/CGAL/Intersections_3/internal/Segment_3_Tetrahedron_3_intersection.h similarity index 73% rename from Intersections_3/include/CGAL/Intersections_3/internal/Tetrahedron_3_Segment_3_intersection.h rename to Intersections_3/include/CGAL/Intersections_3/internal/Segment_3_Tetrahedron_3_intersection.h index a79424649f6..590e083447a 100644 --- a/Intersections_3/include/CGAL/Intersections_3/internal/Tetrahedron_3_Segment_3_intersection.h +++ b/Intersections_3/include/CGAL/Intersections_3/internal/Segment_3_Tetrahedron_3_intersection.h @@ -14,34 +14,34 @@ #ifndef CGAL_INTERNAL_INTERSECTIONS_3_TETRAHEDRON_3_SEGMENT_3_INTERSECTION_H #define CGAL_INTERNAL_INTERSECTIONS_3_TETRAHEDRON_3_SEGMENT_3_INTERSECTION_H -#include -#include +#include #include +#include + namespace CGAL { - namespace Intersections { - namespace internal { template struct Tetrahedron_segment_intersection_3 - :public Tetrahedron_lines_intersection_3_base > + : public Tetrahedron_lines_intersection_3_base > { typedef typename K::Segment_3 O; - typedef Tetrahedron_lines_intersection_3_base > Base; + typedef Tetrahedron_lines_intersection_3_base > Base; typedef typename Base::Result_type result_type; Tetrahedron_segment_intersection_3(const typename K::Tetrahedron_3& tet, - const O& o):Base(tet,o) {} + const O& o) + : Base(tet, o) + { } bool all_inside_test() { //if both segment extremities are inside tet, return the input segment. - if(this->tet.has_on_bounded_side(this->o.source()) - && this->tet.has_on_bounded_side(this->o.target())){ + if(this->tet.has_on_bounded_side(this->o.source()) && + this->tet.has_on_bounded_side(this->o.target())) + { typename K::Segment_3 result = this->o; this->output = result_type(std::forward(result)); return true; @@ -58,7 +58,8 @@ struct Tetrahedron_segment_intersection_3 this->output = result_type(std::forward(result)); return true; } - else if(this->tet.has_on_bounded_side(this->o.target())){ + else if(this->tet.has_on_bounded_side(this->o.target())) + { typename K::Segment_3 result(this->res_points.front(), this->o.target()); this->output = result_type(std::forward(result)); return true; @@ -67,30 +68,28 @@ struct Tetrahedron_segment_intersection_3 } }; - -//Tetrahedron_3 Segment_3 template typename Intersection_traits::result_type -intersection( - const typename K::Tetrahedron_3 &tet, - const typename K::Segment_3 &seg, - const K&) +intersection(const typename K::Tetrahedron_3& tet, + const typename K::Segment_3& seg, + const K&) { Tetrahedron_segment_intersection_3 solver(tet, seg); solver.do_procede(); return solver.output; - } template typename Intersection_traits::result_type -intersection( - const typename K::Segment_3 &seg, - const typename K::Tetrahedron_3 &tet, - const K& k) +intersection(const typename K::Segment_3& seg, + const typename K::Tetrahedron_3& tet, + const K& k) { return intersection(tet, seg, k); } -}}} +} // namespace internal +} // namespace Intersections +} // namespace CGAL + #endif // CGAL_INTERNAL_INTERSECTIONS_3_TETRAHEDRON_3_Segment_3_INTERSECTION_H diff --git a/Intersections_3/include/CGAL/Intersections_3/internal/Triangle_3_Segment_3_do_intersect.h b/Intersections_3/include/CGAL/Intersections_3/internal/Segment_3_Triangle_3_do_intersect.h similarity index 51% rename from Intersections_3/include/CGAL/Intersections_3/internal/Triangle_3_Segment_3_do_intersect.h rename to Intersections_3/include/CGAL/Intersections_3/internal/Segment_3_Triangle_3_do_intersect.h index 6ad3b59f185..70c0f3e0813 100644 --- a/Intersections_3/include/CGAL/Intersections_3/internal/Triangle_3_Segment_3_do_intersect.h +++ b/Intersections_3/include/CGAL/Intersections_3/internal/Segment_3_Triangle_3_do_intersect.h @@ -10,86 +10,40 @@ // // Author(s) : Philippe Guigue -#ifndef CGAL_TRIANGLE_3_SEGMENT_3_DO_INTERSECT_H -#define CGAL_TRIANGLE_3_SEGMENT_3_DO_INTERSECT_H +#ifndef CGAL_INTERNAL_INTERSECTIONS_SEGMENT_3_TRIANGLE_3_DO_INTERSECT_H +#define CGAL_INTERNAL_INTERSECTIONS_SEGMENT_3_TRIANGLE_3_DO_INTERSECT_H #include #include -#include namespace CGAL { - - template - class Triangle_3; - - template - class Segment_3; - namespace Intersections { - namespace internal { template -bool do_intersect_coplanar( const typename K::Point_3& A, - const typename K::Point_3& B, - const typename K::Point_3& C, - const typename K::Point_3 & p, - const typename K::Point_3 & q, const K & k ); - -template -bool do_intersect_coplanar(const typename K::Triangle_3 &t, - const typename K::Segment_3 &s, - const K & k ) -{ - - CGAL_kernel_precondition( ! k.is_degenerate_3_object()(t) ) ; - CGAL_kernel_precondition( ! k.is_degenerate_3_object()(s) ) ; - - typedef typename K::Point_3 Point_3; - - - typename K::Construct_point_on_3 point_on = - k.construct_point_on_3_object(); - - typename K::Construct_vertex_3 vertex_on = - k.construct_vertex_3_object(); - - const Point_3 & p = point_on(s,0); - const Point_3 & q = point_on(s,1); - - const Point_3 & A = vertex_on(t,0); - const Point_3 & B = vertex_on(t,1); - const Point_3 & C = vertex_on(t,2); - - return do_intersect_coplanar(A,B,C,p,q,k); -} - - -template -bool do_intersect_coplanar( const typename K::Point_3& A, - const typename K::Point_3& B, - const typename K::Point_3& C, - const typename K::Point_3 & p, - const typename K::Point_3 & q, const K & k ) +bool do_intersect_coplanar(const typename K::Point_3& A, + const typename K::Point_3& B, + const typename K::Point_3& C, + const typename K::Point_3& p, + const typename K::Point_3& q, const K& k) { typedef typename K::Point_3 Point_3; - typename K::Coplanar_orientation_3 coplanar_orientation = - k.coplanar_orientation_3_object(); + typename K::Coplanar_orientation_3 coplanar_orientation = k.coplanar_orientation_3_object(); - const Point_3 * a = &A; - const Point_3 * b = &B; - const Point_3 * c = &C; + const Point_3* a = &A; + const Point_3* b = &B; + const Point_3* c = &C; // Determine the orientation of the triangle in the common plane if (coplanar_orientation(A,B,C) != POSITIVE) - { - // The triangle is not counterclockwise oriented - // swap two vertices. - b = &C; - c = &B; - } + { + // The triangle is not counterclockwise oriented + // swap two vertices. + b = &C; + c = &B; + } // Test whether the segment's supporting line intersects the // triangle in the common plane @@ -98,93 +52,89 @@ bool do_intersect_coplanar( const typename K::Point_3& A, const Orientation pqb = coplanar_orientation(p,q,*b); const Orientation pqc = coplanar_orientation(p,q,*c); - switch ( pqa ) { case POSITIVE: switch ( pqb ) { case POSITIVE: - if (pqc == POSITIVE) return false; + if (pqc == POSITIVE) + return false; + // the triangle lies in the positive halfspace // defined by the segment's supporting line. // c is isolated on the negative side - return coplanar_orientation(*b,*c,q) != NEGATIVE - && coplanar_orientation(*c,*a,p) != NEGATIVE ; - + return coplanar_orientation(*b,*c,q) != NEGATIVE + && coplanar_orientation(*c,*a,p) != NEGATIVE; case NEGATIVE: if (pqc == POSITIVE) // b is isolated on the negative side return coplanar_orientation(*a,*b,q) != NEGATIVE - && coplanar_orientation(*b,*c,p) != NEGATIVE ; + && coplanar_orientation(*b,*c,p) != NEGATIVE; // a is isolated on the positive side - return coplanar_orientation(*a,*b,q) != NEGATIVE - && coplanar_orientation(*c,*a,p) != NEGATIVE ; + return coplanar_orientation(*a,*b,q) != NEGATIVE + && coplanar_orientation(*c,*a,p) != NEGATIVE; case COLLINEAR: if (pqc == POSITIVE) // b is isolated on the negative side - return coplanar_orientation(*a,*b,q) != NEGATIVE - && coplanar_orientation(*b,*c,p) != NEGATIVE ; + return coplanar_orientation(*a,*b,q) != NEGATIVE + && coplanar_orientation(*b,*c,p) != NEGATIVE; // a is isolated on the positive side - return coplanar_orientation(*a,*b,q) != NEGATIVE - && coplanar_orientation(*c,*a,p) != NEGATIVE ; + return coplanar_orientation(*a,*b,q) != NEGATIVE + && coplanar_orientation(*c,*a,p) != NEGATIVE; default:// should not happen. CGAL_kernel_assertion(false); return false; - } case NEGATIVE: switch ( pqb ) { case POSITIVE: if (pqc == POSITIVE) // a is isolated on the negative side - return coplanar_orientation(*a,*b,p) != NEGATIVE - && coplanar_orientation(*c,*a,q) != NEGATIVE ; + return coplanar_orientation(*a,*b,p) != NEGATIVE + && coplanar_orientation(*c,*a,q) != NEGATIVE; // b is isolated on the positive side - return coplanar_orientation(*a,*b,p) != NEGATIVE - && coplanar_orientation(*b,*c,q) != NEGATIVE ; - + return coplanar_orientation(*a,*b,p) != NEGATIVE + && coplanar_orientation(*b,*c,q) != NEGATIVE; case NEGATIVE: - if (pqc == NEGATIVE) return false; + if (pqc == NEGATIVE) + return false; + // the triangle lies in the negative halfspace // defined by the segment's supporting line. // c is isolated on the positive side - return coplanar_orientation(*b,*c,p) != NEGATIVE - && coplanar_orientation(*c,*a,q) != NEGATIVE ; - + return coplanar_orientation(*b,*c,p) != NEGATIVE + && coplanar_orientation(*c,*a,q) != NEGATIVE; case COLLINEAR: if (pqc == NEGATIVE) // b is isolated on the positive side - return coplanar_orientation(*a,*b,p) != NEGATIVE - && coplanar_orientation(*b,*c,q) != NEGATIVE ; + return coplanar_orientation(*a,*b,p) != NEGATIVE + && coplanar_orientation(*b,*c,q) != NEGATIVE; // a is isolated on the negative side - return coplanar_orientation(*a,*b,p) != NEGATIVE - && coplanar_orientation(*c,*a,q) != NEGATIVE ; + return coplanar_orientation(*a,*b,p) != NEGATIVE + && coplanar_orientation(*c,*a,q) != NEGATIVE; default:// should not happen. CGAL_kernel_assertion(false); return false; - } case COLLINEAR: switch ( pqb ) { case POSITIVE: if (pqc == POSITIVE) // a is isolated on the negative side - return coplanar_orientation(*a,*b,p) != NEGATIVE - && coplanar_orientation(*c,*a,q) != NEGATIVE ; + return coplanar_orientation(*a,*b,p) != NEGATIVE + && coplanar_orientation(*c,*a,q) != NEGATIVE; // b is isolated on the positive side - return coplanar_orientation(*a,*b,p) != NEGATIVE - && coplanar_orientation(*b,*c,q) != NEGATIVE ; - + return coplanar_orientation(*a,*b,p) != NEGATIVE + && coplanar_orientation(*b,*c,q) != NEGATIVE; case NEGATIVE: if (pqc == NEGATIVE) // a is isolated on the positive side return coplanar_orientation(*a,*b,q) != NEGATIVE - && coplanar_orientation(*c,*a,p) != NEGATIVE ; + && coplanar_orientation(*c,*a,p) != NEGATIVE; // b is isolated on the negative side - return coplanar_orientation(*a,*b,q) != NEGATIVE - && coplanar_orientation(*b,*c,p) != NEGATIVE ; - + return coplanar_orientation(*a,*b,q) != NEGATIVE + && coplanar_orientation(*b,*c,p) != NEGATIVE; case COLLINEAR: if (pqc == POSITIVE) // c is isolated on the positive side - return coplanar_orientation(*b,*c,p) != NEGATIVE - && coplanar_orientation(*c,*a,q) != NEGATIVE ; + return coplanar_orientation(*b,*c,p) != NEGATIVE + && coplanar_orientation(*c,*a,q) != NEGATIVE; // c is isolated on the negative side - return coplanar_orientation(*b,*c,q) != NEGATIVE - && coplanar_orientation(*c,*a,p) != NEGATIVE ; + return coplanar_orientation(*b,*c,q) != NEGATIVE + && coplanar_orientation(*c,*a,p) != NEGATIVE; // case pqc == COLLINEAR is impossible since the triangle is // assumed to be non flat @@ -196,43 +146,55 @@ bool do_intersect_coplanar( const typename K::Point_3& A, default:// should not happen. CGAL_kernel_assertion(false); return false; - } } - template -bool do_intersect(const typename K::Triangle_3 &t, - const typename K::Segment_3 &s, - const K & k) +bool do_intersect_coplanar(const typename K::Triangle_3& t, + const typename K::Segment_3 &s, + const K& k ) { - - CGAL_kernel_precondition( ! k.is_degenerate_3_object()(t) ) ; - CGAL_kernel_precondition( ! k.is_degenerate_3_object()(s) ) ; + CGAL_kernel_precondition(!k.is_degenerate_3_object()(t)); + CGAL_kernel_precondition(!k.is_degenerate_3_object()(s)); typedef typename K::Point_3 Point_3; + typename K::Construct_point_on_3 point_on = k.construct_point_on_3_object(); + typename K::Construct_vertex_3 vertex_on = k.construct_vertex_3_object(); - typename K::Construct_point_on_3 point_on = - k.construct_point_on_3_object(); + const Point_3& p = point_on(s,0); + const Point_3& q = point_on(s,1); - typename K::Construct_vertex_3 vertex_on = - k.construct_vertex_3_object(); + const Point_3& A = vertex_on(t,0); + const Point_3& B = vertex_on(t,1); + const Point_3& C = vertex_on(t,2); - typename K::Orientation_3 orientation = - k.orientation_3_object(); + return do_intersect_coplanar(A,B,C,p,q,k); +} - const Point_3 & a = vertex_on(t,0); - const Point_3 & b = vertex_on(t,1); - const Point_3 & c = vertex_on(t,2); - const Point_3 & p = point_on(s,0); - const Point_3 & q = point_on(s,1); +template +bool do_intersect(const typename K::Triangle_3& t, + const typename K::Segment_3& s, + const K& k) +{ + CGAL_kernel_precondition(!k.is_degenerate_3_object()(t) ); + CGAL_kernel_precondition(!k.is_degenerate_3_object()(s) ); + typedef typename K::Point_3 Point_3; + + typename K::Construct_point_on_3 point_on = k.construct_point_on_3_object(); + typename K::Construct_vertex_3 vertex_on = k.construct_vertex_3_object(); + typename K::Orientation_3 orientation = k.orientation_3_object(); + + const Point_3& a = vertex_on(t,0); + const Point_3& b = vertex_on(t,1); + const Point_3& c = vertex_on(t,2); + const Point_3& p = point_on(s,0); + const Point_3& q = point_on(s,1); const Orientation abcp = orientation(a,b,c,p); const Orientation abcq = orientation(a,b,c,q); - switch ( abcp ) { case POSITIVE: switch ( abcq ) { @@ -240,20 +202,17 @@ bool do_intersect(const typename K::Triangle_3 &t, // the segment lies in the positive open halfspaces defined by the // triangle's supporting plane return false; - case NEGATIVE: // p sees the triangle in counterclockwise order return orientation(p,q,a,b) != POSITIVE - && orientation(p,q,b,c) != POSITIVE - && orientation(p,q,c,a) != POSITIVE; - + && orientation(p,q,b,c) != POSITIVE + && orientation(p,q,c,a) != POSITIVE; case COPLANAR: // q belongs to the triangle's supporting plane // p sees the triangle in counterclockwise order return orientation(p,q,a,b) != POSITIVE - && orientation(p,q,b,c) != POSITIVE - && orientation(p,q,c,a) != POSITIVE; - + && orientation(p,q,b,c) != POSITIVE + && orientation(p,q,c,a) != POSITIVE; default: // should not happen. CGAL_kernel_assertion(false); return false; @@ -263,20 +222,18 @@ bool do_intersect(const typename K::Triangle_3 &t, case POSITIVE: // q sees the triangle in counterclockwise order return orientation(q,p,a,b) != POSITIVE - && orientation(q,p,b,c) != POSITIVE - && orientation(q,p,c,a) != POSITIVE; - + && orientation(q,p,b,c) != POSITIVE + && orientation(q,p,c,a) != POSITIVE; case NEGATIVE: // the segment lies in the negative open halfspaces defined by the // triangle's supporting plane return false; - case COPLANAR: // q belongs to the triangle's supporting plane // p sees the triangle in clockwise order return orientation(q,p,a,b) != POSITIVE - && orientation(q,p,b,c) != POSITIVE - && orientation(q,p,c,a) != POSITIVE; + && orientation(q,p,b,c) != POSITIVE + && orientation(q,p,c,a) != POSITIVE; default: // should not happen. CGAL_kernel_assertion(false); @@ -287,14 +244,13 @@ bool do_intersect(const typename K::Triangle_3 &t, case POSITIVE: // q sees the triangle in counterclockwise order return orientation(q,p,a,b) != POSITIVE - && orientation(q,p,b,c) != POSITIVE - && orientation(q,p,c,a) != POSITIVE; - + && orientation(q,p,b,c) != POSITIVE + && orientation(q,p,c,a) != POSITIVE; case NEGATIVE: // q sees the triangle in clockwise order return orientation(p,q,a,b) != POSITIVE - && orientation(p,q,b,c) != POSITIVE - && orientation(p,q,c,a) != POSITIVE; + && orientation(p,q,b,c) != POSITIVE + && orientation(p,q,c,a) != POSITIVE; case COPLANAR: // the segment is coplanar with the triangle's supporting plane // we test whether the segment intersects the triangle in the common @@ -311,18 +267,17 @@ bool do_intersect(const typename K::Triangle_3 &t, } } - template inline -bool do_intersect(const typename K::Segment_3 &s, - const typename K::Triangle_3 &t, - const K & k) +bool do_intersect(const typename K::Segment_3& s, + const typename K::Triangle_3& t, + const K& k) { return do_intersect(t, s, k); } } // namespace internal } // namespace Intersections -} //namespace CGAL +} // namespace CGAL -#endif //CGAL_TRIANGLE_3_SEGMENT_3_DO_INTERSECT_H +#endif //CGAL_INTERNAL_INTERSECTIONS_SEGMENT_3_TRIANGLE_3_DO_INTERSECT_H diff --git a/Intersections_3/include/CGAL/Intersections_3/internal/Triangle_3_Segment_3_intersection.h b/Intersections_3/include/CGAL/Intersections_3/internal/Segment_3_Triangle_3_intersection.h similarity index 70% rename from Intersections_3/include/CGAL/Intersections_3/internal/Triangle_3_Segment_3_intersection.h rename to Intersections_3/include/CGAL/Intersections_3/internal/Segment_3_Triangle_3_intersection.h index aed2a2559be..929ffc1a40e 100644 --- a/Intersections_3/include/CGAL/Intersections_3/internal/Triangle_3_Segment_3_intersection.h +++ b/Intersections_3/include/CGAL/Intersections_3/internal/Segment_3_Triangle_3_intersection.h @@ -10,18 +10,19 @@ // // Author(s) : Laurent Rineau, Stephane Tayeb // -// Note: This implementation is adapted from Triangle_3_Segment_3_do_intersect.h +// Note: This implementation is adapted from Segment_3_Triangle_3_do_intersect.h -#ifndef CGAL_INTERNAL_INTERSECTIONS_3_TRIANGLE_3_SEGMENT_3_INTERSECTION_H -#define CGAL_INTERNAL_INTERSECTIONS_3_TRIANGLE_3_SEGMENT_3_INTERSECTION_H +#ifndef CGAL_INTERNAL_INTERSECTIONS_3_SEGMENT_3_TRIANGLE_3_INTERSECTION_H +#define CGAL_INTERNAL_INTERSECTIONS_3_SEGMENT_3_TRIANGLE_3_INTERSECTION_H +#include +#include + +#include #include -#include namespace CGAL { - namespace Intersections { - namespace internal { template @@ -40,17 +41,10 @@ t3s3_intersection_coplanar_aux(const typename K::Point_3& p, typedef typename K::Vector_3 Vector_3; typedef typename K::FT FT; - typename K::Construct_vector_3 vector = - k.construct_vector_3_object(); - - typename K::Construct_cross_product_vector_3 cross_product = - k.construct_cross_product_vector_3_object(); - - typename K::Compute_scalar_product_3 scalar_product = - k.compute_scalar_product_3_object(); - - typename K::Compute_squared_length_3 sq_length = - k.compute_squared_length_3_object(); + typename K::Construct_cross_product_vector_3 cross_product = k.construct_cross_product_vector_3_object(); + typename K::Construct_vector_3 vector = k.construct_vector_3_object(); + typename K::Compute_scalar_product_3 scalar_product = k.compute_scalar_product_3_object(); + typename K::Compute_squared_length_3 sq_length = k.compute_squared_length_3_object(); const Vector_3 pq = vector(p,q); const Vector_3 ab = vector(a,b); @@ -61,10 +55,9 @@ t3s3_intersection_coplanar_aux(const typename K::Point_3& p, const FT t = scalar_product(pa_ab,pq_ab) / sq_length(pq_ab); - return ( p + t*pq ); + return (p + t*pq); } - template typename Intersection_traits::result_type t3s3_intersection_coplanar_aux(const typename K::Point_3& a, @@ -90,77 +83,78 @@ t3s3_intersection_coplanar_aux(const typename K::Point_3& a, typedef typename K::Point_3 Point_3; - typename K::Coplanar_orientation_3 coplanar_orientation = - k.coplanar_orientation_3_object(); - - typename K::Construct_segment_3 segment = - k.construct_segment_3_object(); + typename K::Coplanar_orientation_3 coplanar_orientation = k.coplanar_orientation_3_object(); + typename K::Construct_segment_3 segment = k.construct_segment_3_object(); const Orientation bcq = coplanar_orientation(b,c,q); const Orientation cap = coplanar_orientation(c,a,p); - if ( NEGATIVE == bcq || NEGATIVE == cap ) + if(NEGATIVE == bcq || NEGATIVE == cap) + { return intersection_return(); - else if ( COLLINEAR == bcq ) + } + else if(COLLINEAR == bcq) + { // q is inside [c,b], p is outside t (because of pqc) return intersection_return(q); - else if ( COLLINEAR == cap ) + } + else if(COLLINEAR == cap) + { // p is inside [c,a], q is outside t (because of pqc) return intersection_return(p); + } else // bcq == POSITIVE && cap == POSITIVE { // Here we know the intersection is not empty // Let's get the intersection points Point_3 p_side_end_point(p); - if ( NEGATIVE == coplanar_orientation(b,c,p) ) - { + if(NEGATIVE == coplanar_orientation(b,c,p)) p_side_end_point = t3s3_intersection_coplanar_aux(p,q,b,c,k); - } Point_3 q_side_end_point(q); - if ( NEGATIVE == coplanar_orientation(c,a,q) ) - { + if(NEGATIVE == coplanar_orientation(c,a,q)) q_side_end_point = t3s3_intersection_coplanar_aux(p,q,c,a,k); - } - if ( negative_side ) + if(negative_side) return intersection_return(segment(p_side_end_point, q_side_end_point)); else return intersection_return(segment(q_side_end_point, p_side_end_point)); } } - template typename Intersection_traits::result_type t3s3_intersection_collinear_aux(const typename K::Point_3& a, - const typename K::Point_3& b, - const typename K::Point_3& p, - const typename K::Point_3& q, - const K& k) + const typename K::Point_3& b, + const typename K::Point_3& p, + const typename K::Point_3& q, + const K& k) { // Builds resulting segment of intersection of [a,b] and [p,q] // Precondition: [a,b] and [p,q] have the same direction - typename K::Construct_segment_3 segment = - k.construct_segment_3_object(); - - typename K::Collinear_are_ordered_along_line_3 collinear_ordered = - k.collinear_are_ordered_along_line_3_object(); + typename K::Construct_segment_3 segment = k.construct_segment_3_object(); + typename K::Collinear_are_ordered_along_line_3 collinear_ordered = k.collinear_are_ordered_along_line_3_object(); typename K::Equal_3 equals = k.equal_3_object(); // possible orders: [p,a,b,q], [p,a,q,b], [p,q,a,b], [a,p,b,q], [a,p,q,b], [a,b,p,q] - if ( collinear_ordered(p,a,b) ) + if(collinear_ordered(p,a,b)) { // p is before a //possible orders: [p,a,b,q], [p,a,q,b], [p,q,a,b] - if ( collinear_ordered(a,b,q) ) + if(collinear_ordered(a,b,q)) + { return intersection_return(segment(a,b)); //[p,a,b,q] - else{ - if ( collinear_ordered(q,a,b) ) - return equals(a,q)? //[p,q,a,b] - intersection_return(a): - intersection_return(); + } + else + { + if(collinear_ordered(q,a,b)) + { + return equals(a,q) ? //[p,q,a,b] + intersection_return(a) + : intersection_return(); + } + return intersection_return(segment(a,q)); } } @@ -168,15 +162,21 @@ t3s3_intersection_collinear_aux(const typename K::Point_3& a, { // p is after a //possible orders: [a,p,b,q], [a,p,q,b], [a,b,p,q] - if ( collinear_ordered(p,b,q) ) + if(collinear_ordered(p,b,q)) + { return equals(p,b)? // [a,p,b,q] - intersection_return(p): - intersection_return(segment(p,b)); - else{ - if ( collinear_ordered(a,b,p) ) - return equals(p,b)? // [a,b,p,q] - intersection_return(p) : - intersection_return(); + intersection_return(p): + intersection_return(segment(p,b)); + } + else + { + if(collinear_ordered(a,b,p)) + { + return equals(p,b) ? // [a,b,p,q] + intersection_return(p) + : intersection_return(); + } + return intersection_return(segment(p,q)); // [a,p,q,b] } } @@ -185,34 +185,26 @@ t3s3_intersection_collinear_aux(const typename K::Point_3& a, template typename Intersection_traits::result_type -intersection_coplanar(const typename K::Triangle_3 &t, - const typename K::Segment_3 &s, - const K & k ) +intersection_coplanar(const typename K::Triangle_3& t, + const typename K::Segment_3& s, + const K& k) { - - CGAL_kernel_precondition( ! k.is_degenerate_3_object()(t) ) ; - CGAL_kernel_precondition( ! k.is_degenerate_3_object()(s) ) ; + CGAL_kernel_precondition(!k.is_degenerate_3_object()(t)); + CGAL_kernel_precondition(!k.is_degenerate_3_object()(s)); typedef typename K::Point_3 Point_3; - typename K::Construct_point_on_3 point_on = - k.construct_point_on_3_object(); + typename K::Construct_point_on_3 point_on = k.construct_point_on_3_object(); + typename K::Construct_vertex_3 vertex_on = k.construct_vertex_3_object(); + typename K::Coplanar_orientation_3 coplanar_orientation = k.coplanar_orientation_3_object(); + typename K::Collinear_are_ordered_along_line_3 collinear_ordered = k.collinear_are_ordered_along_line_3_object(); - typename K::Construct_vertex_3 vertex_on = - k.construct_vertex_3_object(); + const Point_3& p = point_on(s,0); + const Point_3& q = point_on(s,1); - typename K::Coplanar_orientation_3 coplanar_orientation = - k.coplanar_orientation_3_object(); - - typename K::Collinear_are_ordered_along_line_3 collinear_ordered = - k.collinear_are_ordered_along_line_3_object(); - - const Point_3 & p = point_on(s,0); - const Point_3 & q = point_on(s,1); - - const Point_3 & A = vertex_on(t,0); - const Point_3 & B = vertex_on(t,1); - const Point_3 & C = vertex_on(t,2); + const Point_3& A = vertex_on(t,0); + const Point_3& B = vertex_on(t,1); + const Point_3& C = vertex_on(t,2); int k0 = 0; int k1 = 1; @@ -236,14 +228,17 @@ intersection_coplanar(const typename K::Triangle_3 &t, const Orientation pqb = coplanar_orientation(p,q,b); const Orientation pqc = coplanar_orientation(p,q,c); - switch ( pqa ) { + switch(pqa) + { // ----------------------------------- // pqa POSITIVE // ----------------------------------- case POSITIVE: - switch ( pqb ) { + switch(pqb) + { case POSITIVE: - switch ( pqc ) { + switch(pqc) + { case POSITIVE: // the triangle lies in the positive halfspace // defined by the segment's supporting line. @@ -252,22 +247,23 @@ intersection_coplanar(const typename K::Triangle_3 &t, // c is isolated on the negative side return t3s3_intersection_coplanar_aux(a,b,c,p,q,true,k); default: // COLLINEAR - if ( collinear_ordered(p,c,q) ) // c is inside [p,q] + if(collinear_ordered(p,c,q)) // c is inside [p,q] return intersection_return(c); else return intersection_return(); } case NEGATIVE: - if ( POSITIVE == pqc ) + if(POSITIVE == pqc) // b is isolated on the negative side return t3s3_intersection_coplanar_aux(c,a,b,p,q,true,k); else // a is isolated on the positive side return t3s3_intersection_coplanar_aux(b,c,a,q,p,false,k); case COLLINEAR: - switch ( pqc ) { + switch(pqc) + { case POSITIVE: - if ( collinear_ordered(p,b,q) ) // b is inside [p,q] + if(collinear_ordered(p,b,q)) // b is inside [p,q] return intersection_return(b); else return intersection_return(); @@ -283,13 +279,14 @@ intersection_coplanar(const typename K::Triangle_3 &t, return intersection_return(); } - // ----------------------------------- - // pqa NEGATIVE - // ----------------------------------- + // ----------------------------------- + // pqa NEGATIVE + // ----------------------------------- case NEGATIVE: - switch ( pqb ) { + switch(pqb) + { case POSITIVE: - if ( POSITIVE == pqc ) + if(POSITIVE == pqc) // a is isolated on the negative side return t3s3_intersection_coplanar_aux(b,c,a,p,q,true,k); else @@ -297,7 +294,8 @@ intersection_coplanar(const typename K::Triangle_3 &t, return t3s3_intersection_coplanar_aux(c,a,b,q,p,false,k); case NEGATIVE: - switch ( pqc ) { + switch(pqc) + { case POSITIVE: // c is isolated on the positive side return t3s3_intersection_coplanar_aux(a,b,c,q,p,false,k); @@ -306,19 +304,20 @@ intersection_coplanar(const typename K::Triangle_3 &t, // defined by the segment's supporting line. return intersection_return(); default: // COLLINEAR - if ( collinear_ordered(p,c,q) ) // c is inside [p,q] + if(collinear_ordered(p,c,q)) // c is inside [p,q] return intersection_return(c); else return intersection_return(); } case COLLINEAR: - switch ( pqc ) { + switch(pqc) + { case POSITIVE: // a is isolated on the negative side return t3s3_intersection_coplanar_aux(b,c,a,p,q,true,k); case NEGATIVE: - if ( collinear_ordered(p,b,q) ) // b is inside [p,q] + if(collinear_ordered(p,b,q)) // b is inside [p,q] return intersection_return(b); else return intersection_return(); @@ -332,15 +331,17 @@ intersection_coplanar(const typename K::Triangle_3 &t, return intersection_return(); } - // ----------------------------------- - // pqa COLLINEAR - // ----------------------------------- + // ----------------------------------- + // pqa COLLINEAR + // ----------------------------------- case COLLINEAR: - switch ( pqb ) { + switch(pqb) + { case POSITIVE: - switch ( pqc ) { + switch(pqc) + { case POSITIVE: - if ( collinear_ordered(p,a,q) ) // a is inside [p,q] + if(collinear_ordered(p,a,q)) // a is inside [p,q] return intersection_return(a); else return intersection_return(); @@ -353,12 +354,13 @@ intersection_coplanar(const typename K::Triangle_3 &t, } case NEGATIVE: - switch ( pqc ) { + switch(pqc) + { case POSITIVE: // b is isolated on the negative side return t3s3_intersection_coplanar_aux(c,a,b,p,q,true,k); case NEGATIVE: - if ( collinear_ordered(p,a,q) ) // a is inside [p,q] + if(collinear_ordered(p,a,q)) // a is inside [p,q] return intersection_return(a); else return intersection_return(); @@ -368,14 +370,15 @@ intersection_coplanar(const typename K::Triangle_3 &t, } case COLLINEAR: - switch ( pqc ) { + switch(pqc) + { case POSITIVE: // a,b,p,q are aligned, [p,q]&[a,b] have the same direction return t3s3_intersection_collinear_aux(a,b,p,q,k); case NEGATIVE: // a,b,p,q are aligned, [p,q]&[b,a] have the same direction return t3s3_intersection_collinear_aux(b,a,p,q,k); - default: // COLLINEAR + default: // COLLINEAR // case pqc == COLLINEAR is impossible since the triangle is // assumed to be non flat CGAL_error(); @@ -393,39 +396,35 @@ intersection_coplanar(const typename K::Triangle_3 &t, } } - template typename Intersection_traits::result_type -intersection(const typename K::Triangle_3 &t, - const typename K::Segment_3 &s, - const K & k) +intersection(const typename K::Triangle_3& t, + const typename K::Segment_3& s, + const K& k) { - CGAL_kernel_precondition( ! k.is_degenerate_3_object()(t) ) ; - CGAL_kernel_precondition( ! k.is_degenerate_3_object()(s) ) ; + CGAL_kernel_precondition(!k.is_degenerate_3_object()(t)); + CGAL_kernel_precondition(!k.is_degenerate_3_object()(s)); typedef typename K::Point_3 Point_3; - typename K::Construct_point_on_3 point_on = - k.construct_point_on_3_object(); + typename K::Construct_point_on_3 point_on = k.construct_point_on_3_object(); + typename K::Construct_vertex_3 vertex_on = k.construct_vertex_3_object(); + typename K::Orientation_3 orientation = k.orientation_3_object(); - typename K::Construct_vertex_3 vertex_on = - k.construct_vertex_3_object(); - - typename K::Orientation_3 orientation = - k.orientation_3_object(); - - const Point_3 & a = vertex_on(t,0); - const Point_3 & b = vertex_on(t,1); - const Point_3 & c = vertex_on(t,2); - const Point_3 & p = point_on(s,0); - const Point_3 & q = point_on(s,1); + const Point_3& a = vertex_on(t,0); + const Point_3& b = vertex_on(t,1); + const Point_3& c = vertex_on(t,2); + const Point_3& p = point_on(s,0); + const Point_3& q = point_on(s,1); const Orientation abcp = orientation(a,b,c,p); const Orientation abcq = orientation(a,b,c,q); - switch ( abcp ) { + switch(abcp) + { case POSITIVE: - switch ( abcq ) { + switch(abcq) + { case POSITIVE: // the segment lies in the positive open halfspaces defined by the // triangle's supporting plane @@ -433,33 +432,36 @@ intersection(const typename K::Triangle_3 &t, case NEGATIVE: // p sees the triangle in counterclockwise order - if ( orientation(p,q,a,b) != POSITIVE - && orientation(p,q,b,c) != POSITIVE - && orientation(p,q,c,a) != POSITIVE ) + if(orientation(p,q,a,b) != POSITIVE && + orientation(p,q,b,c) != POSITIVE && + orientation(p,q,c,a) != POSITIVE) { // The intersection should be a point - - typename Intersection_traits - ::result_type - v = internal::intersection(s.supporting_line(),t.supporting_plane(), K()); - if(v) { + typename Intersection_traits::result_type + v = internal::intersection(s.supporting_line(),t.supporting_plane(), k); + if(v) + { if(const Point_3* res = intersect_get(v)) return intersection_return(*res); - else + else return intersection_return(); - } else { + } + else + { return intersection_return(); } } else + { return intersection_return(); + } case COPLANAR: // q belongs to the triangle's supporting plane // p sees the triangle in counterclockwise order - if ( orientation(p,q,a,b) != POSITIVE - && orientation(p,q,b,c) != POSITIVE - && orientation(p,q,c,a) != POSITIVE ) + if(orientation(p,q,a,b) != POSITIVE && + orientation(p,q,b,c) != POSITIVE && + orientation(p,q,c,a) != POSITIVE) return intersection_return(q); else return intersection_return(); @@ -469,25 +471,32 @@ intersection(const typename K::Triangle_3 &t, return intersection_return(); } case NEGATIVE: - switch ( abcq ) { + switch(abcq) + { case POSITIVE: // q sees the triangle in counterclockwise order - if ( orientation(q,p,a,b) != POSITIVE - && orientation(q,p,b,c) != POSITIVE - && orientation(q,p,c,a) != POSITIVE ) + if(orientation(q,p,a,b) != POSITIVE && + orientation(q,p,b,c) != POSITIVE && + orientation(q,p,c,a) != POSITIVE) { typename Intersection_traits::result_type - v = internal::intersection(s.supporting_line(),t.supporting_plane(), K()); - if(v) { + v = internal::intersection(s.supporting_line(),t.supporting_plane(), K()); + if(v) + { if(const Point_3* res = intersect_get(v)) return intersection_return(*res); - else + else return intersection_return(); - } else { + } + else + { return intersection_return(); + } } - } else + else + { return intersection_return(); + } case NEGATIVE: // the segment lies in the negative open halfspaces defined by the // triangle's supporting plane @@ -496,9 +505,9 @@ intersection(const typename K::Triangle_3 &t, case COPLANAR: // q belongs to the triangle's supporting plane // p sees the triangle in clockwise order - if ( orientation(q,p,a,b) != POSITIVE - && orientation(q,p,b,c) != POSITIVE - && orientation(q,p,c,a) != POSITIVE ) + if(orientation(q,p,a,b) != POSITIVE && + orientation(q,p,b,c) != POSITIVE && + orientation(q,p,c,a) != POSITIVE) return intersection_return(q); else return intersection_return(); @@ -508,21 +517,21 @@ intersection(const typename K::Triangle_3 &t, return intersection_return(); } case COPLANAR: // p belongs to the triangle's supporting plane - switch ( abcq ) { + switch(abcq) { case POSITIVE: // q sees the triangle in counterclockwise order - if ( orientation(q,p,a,b) != POSITIVE - && orientation(q,p,b,c) != POSITIVE - && orientation(q,p,c,a) != POSITIVE ) + if(orientation(q,p,a,b) != POSITIVE && + orientation(q,p,b,c) != POSITIVE && + orientation(q,p,c,a) != POSITIVE) return intersection_return(p); else return intersection_return(); case NEGATIVE: // q sees the triangle in clockwise order - if ( orientation(p,q,a,b) != POSITIVE - && orientation(p,q,b,c) != POSITIVE - && orientation(p,q,c,a) != POSITIVE ) + if(orientation(p,q,a,b) != POSITIVE && + orientation(p,q,b,c) != POSITIVE && + orientation(p,q,c,a) != POSITIVE) return intersection_return(p); else return intersection_return(); @@ -545,17 +554,16 @@ intersection(const typename K::Triangle_3 &t, template inline -typename Intersection_traits::result_type -intersection(const typename K::Segment_3 &s, - const typename K::Triangle_3 &t, - const K & k) +typename Intersection_traits::result_type +intersection(const typename K::Segment_3& s, + const typename K::Triangle_3& t, + const K& k) { - return internal::intersection(t,s,k); + return internal::intersection(t, s, k); } -} // end namespace internal +} // namespace internal } // namespace Intersections -} // end namespace CGAL +} // namespace CGAL -#endif // CGAL_INTERNAL_INTERSECTIONS_3_TRIANGLE_3_SEGMENT_3_INTERSECTION_H +#endif // CGAL_INTERNAL_INTERSECTIONS_3_SEGMENT_3_TRIANGLE_3_INTERSECTION_H diff --git a/Intersections_3/include/CGAL/Intersections_3/internal/Sphere_3_Sphere_3_do_intersect.h b/Intersections_3/include/CGAL/Intersections_3/internal/Sphere_3_Sphere_3_do_intersect.h new file mode 100644 index 00000000000..52976148c05 --- /dev/null +++ b/Intersections_3/include/CGAL/Intersections_3/internal/Sphere_3_Sphere_3_do_intersect.h @@ -0,0 +1,47 @@ +// Copyright (c) 2001 GeometryFactory(France). +// All rights reserved. +// +// This file is part of CGAL (www.cgal.org) +// +// $URL$ +// $Id$ +// SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-Commercial +// +// +// Author(s) : Pedro Machado Manhaes + +#ifndef CGAL_INTERNAL_INTERSECTIONS_3_SPHERE_3_SPHERE_3_DO_INTERSECT_H +#define CGAL_INTERNAL_INTERSECTIONS_3_SPHERE_3_SPHERE_3_DO_INTERSECT_H + +#include + +namespace CGAL { +namespace Intersections { +namespace internal { + +template +inline +bool +do_intersect(const typename K::Sphere_3& s1, + const typename K::Sphere_3& s2, + const K& k) +{ + typedef typename K::Plane_3 Plane_3; + + typename K::Construct_center_3 center = k.construct_center_3_object(); + typename K::Compute_squared_radius_3 sqr = k.compute_squared_radius_3_object(); + + // Weaker than s1 == s2 since it allows opposite orientations + if(k.equal_3_object()(center(s1), center(s2))) + return (sqr(s1) == sqr(s2)); + + Plane_3 pl = k.construct_radical_plane_3_object()(s1, s2); + + return do_intersect(pl, s1, k); +} + +} // namespace internal +} // namespace Intersections +} // namespace CGAL + +#endif // CGAL_INTERNAL_INTERSECTIONS_3_SPHERE_3_SPHERE_3_DO_INTERSECT_H diff --git a/Intersections_3/include/CGAL/Intersections_3/internal/Sphere_3_Sphere_3_intersection.h b/Intersections_3/include/CGAL/Intersections_3/internal/Sphere_3_Sphere_3_intersection.h new file mode 100644 index 00000000000..01afc6444c7 --- /dev/null +++ b/Intersections_3/include/CGAL/Intersections_3/internal/Sphere_3_Sphere_3_intersection.h @@ -0,0 +1,71 @@ +// Copyright (c) 2001 GeometryFactory(France). +// All rights reserved. +// +// This file is part of CGAL (www.cgal.org) +// +// $URL$ +// $Id$ +// SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-Commercial +// +// +// Author(s) : Pedro Machado Manhaes + +#ifndef CGAL_INTERNAL_INTERSECTIONS_3_SPHERE_3_SPHERE_3_INTERSECTION_H +#define CGAL_INTERNAL_INTERSECTIONS_3_SPHERE_3_SPHERE_3_INTERSECTION_H + +#include +#include + +#include + +namespace CGAL { +namespace Intersections { +namespace internal { + +template +inline +typename Intersection_traits::result_type +intersection(const typename K::Sphere_3& s1, + const typename K::Sphere_3& s2, + const K& k) +{ + typedef typename K::Plane_3 Plane_3; + + typename K::Construct_center_3 center = k.construct_center_3_object(); + typename K::Compute_squared_radius_3 sqr = k.compute_squared_radius_3_object(); + + if(k.equal_3_object()(center(s1), center(s2))) + { + if(sqr(s1) == sqr(s2)) + { + if(is_zero(sqr(s1))) + return intersection_return(s1.center()); + else + return intersection_return(s1); + } + else + { + // cocentrics + return intersection_return(); + } + } + + Plane_3 pl = k.construct_radical_plane_3_object()(s1,s2); + typename Intersection_traits::result_type v = intersection(pl, s1, k); + + if(v) + { + if(const typename K::Point_3* p = intersect_get(v)) + return intersection_return(*p); + else if(const typename K::Circle_3* c = intersect_get(v)) + return intersection_return(*c); + } + + return intersection_return(); +} + +} // namespace internal +} // namespace Intersections +} // namespace CGAL + +#endif // CGAL_INTERNAL_INTERSECTIONS_3_SPHERE_3_SPHERE_3_INTERSECTION_H diff --git a/Intersections_3/include/CGAL/Intersections_3/internal/Sphere_3_Tetrahedron_3_do_intersect.h b/Intersections_3/include/CGAL/Intersections_3/internal/Sphere_3_Tetrahedron_3_do_intersect.h new file mode 100644 index 00000000000..be1fb59bcc6 --- /dev/null +++ b/Intersections_3/include/CGAL/Intersections_3/internal/Sphere_3_Tetrahedron_3_do_intersect.h @@ -0,0 +1,46 @@ +// Copyright (c) 2001 GeometryFactory(France). +// All rights reserved. +// +// This file is part of CGAL (www.cgal.org) +// +// $URL$ +// $Id$ +// SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-Commercial +// +// +// Author(s) : Nico Kruithof + +#ifndef CGAL_INTERNAL_INTERSECTIONS_3_SPHERE_3_TETRAHEDRON_3_DO_INTERSECT_H +#define CGAL_INTERNAL_INTERSECTIONS_3_SPHERE_3_TETRAHEDRON_3_DO_INTERSECT_H + +#include + +namespace CGAL { +namespace Intersections { +namespace internal { + +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); +} + +} // namespace internal +} // namespace Intersections +} // namespace CGAL + +#endif // CGAL_INTERNAL_INTERSECTIONS_3_SPHERE_3_TETRAHEDRON_3_DO_INTERSECT_H diff --git a/Intersections_3/include/CGAL/Intersections_3/internal/Sphere_3_Triangle_3_do_intersect.h b/Intersections_3/include/CGAL/Intersections_3/internal/Sphere_3_Triangle_3_do_intersect.h new file mode 100644 index 00000000000..7357899bcdf --- /dev/null +++ b/Intersections_3/include/CGAL/Intersections_3/internal/Sphere_3_Triangle_3_do_intersect.h @@ -0,0 +1,53 @@ +// Copyright (c) 2018 GeometryFactory Sarl +// All rights reserved. +// +// This file is part of CGAL (www.cgal.org) +// +// $URL$ +// $Id$ +// SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-Commercial +// +// +// Author(s) : Andreas Fabri + +#ifndef CGAL_INTERNAL_INTERSECTIONS_SPHERE_3_TRIANGLE_3_DO_INTERSECT_H +#define CGAL_INTERNAL_INTERSECTIONS_SPHERE_3_TRIANGLE_3_DO_INTERSECT_H + +#include +#include + +namespace CGAL { +namespace Intersections { +namespace internal { + +template +inline +typename K::Boolean +do_intersect(const typename K::Sphere_3& sp, + const typename K::Triangle_3& tr, + const K& k) +{ + typedef typename K::RT RT; + RT num, den; + + CGAL::internal::squared_distance_RT(sp.center(), tr, num, den, k); + return !(compare_quotients(num, den, + Rational_traits().numerator(sp.squared_radius()), + Rational_traits().denominator(sp.squared_radius())) == LARGER); +} + +template +inline +typename K::Boolean +do_intersect(const typename K::Triangle_3& tr, + const typename K::Sphere_3& sp, + const K& k) +{ + return do_intersect(sp, tr, k); +} + +} // namespace internal +} // namespace Intersections +} // namespace CGAL + +#endif // CGAL_INTERNAL_INTERSECTIONS_SPHERE_3_TRIANGLE_3_DO_INTERSECT_H diff --git a/Intersections_3/include/CGAL/Intersections_3/internal/Tetrahedron_3_Bounded_3_do_intersect.h b/Intersections_3/include/CGAL/Intersections_3/internal/Tetrahedron_3_Bounded_3_do_intersect.h index 39ac2143812..ba45b8d0dd8 100644 --- a/Intersections_3/include/CGAL/Intersections_3/internal/Tetrahedron_3_Bounded_3_do_intersect.h +++ b/Intersections_3/include/CGAL/Intersections_3/internal/Tetrahedron_3_Bounded_3_do_intersect.h @@ -14,192 +14,68 @@ // // Author(s) : Nico Kruithof -#ifndef CGAL_TETRAHEDRON_3_BOUNDED_3_DO_INTERSECT_H -#define CGAL_TETRAHEDRON_3_BOUNDED_3_DO_INTERSECT_H +#ifndef CGAL_INTERNAL_INTERSECTIONS_TETRAHEDRON_3_BOUNDED_3_DO_INTERSECT_H +#define CGAL_INTERNAL_INTERSECTIONS_TETRAHEDRON_3_BOUNDED_3_DO_INTERSECT_H -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include namespace CGAL { - -template -class Tetrahedron_3; - namespace Intersections { - namespace internal { template +inline typename K::Boolean -do_intersect(const typename K::Tetrahedron_3 &tet, - const typename K::Triangle_3 &tr, - const K & k); +do_intersect(const typename K::Tetrahedron_3& tet, + const typename K::Triangle_3& tr, + const K& k); // This code is not optimized: - template +template typename K::Boolean -do_intersect_tetrahedron_bounded(const Bounded &tr, - const typename K::Tetrahedron_3 &tet, - const typename K::Point_3 &p, - const K & k) +do_intersect_tetrahedron_bounded(const Bounded& tr, + const typename K::Tetrahedron_3& tet, + const typename K::Point_3& p, + const K& k) { - typedef typename K::Triangle_3 Triangle; - typedef typename K::Boolean Boolean; + typedef typename K::Boolean Boolean; - CGAL_kernel_precondition( ! k.is_degenerate_3_object() (tr) ); - CGAL_kernel_precondition( ! k.is_degenerate_3_object() (tet) ); + CGAL_kernel_precondition(!k.is_degenerate_3_object()(tr)); + CGAL_kernel_precondition(!k.is_degenerate_3_object()(tet)); - Boolean result = false; - for (int i = 0; i < 4; ++i) - { - const Boolean b = do_intersect(tr, - Triangle(tet[i], - tet[(i+1)%4], - tet[(i+2)%4]), - k); - if(certainly(b)) return b; - if(is_indeterminate(b)) result = b; - } - const Boolean b = k.has_on_bounded_side_3_object()(tet, p); - if(certainly(b)) return b; - if(is_indeterminate(b)) result = b; - return result; -} + Boolean result = false; + for (int i = 0; i < 4; ++i) + { + const Boolean b = do_intersect(tr, + k.construct_triangle_3_object()(tet[i], + tet[(i+1)%4], + tet[(i+2)%4]), + k); + if(certainly(b)) + return b; + if(is_indeterminate(b)) + result = b; + } -template -inline -typename K::Boolean -do_intersect(const typename K::Tetrahedron_3 &tet, - const typename K::Triangle_3 &tr, - const K & k) -{ - return do_intersect_tetrahedron_bounded(tr, tet, tr[0], k); -} + const Boolean b = k.has_on_bounded_side_3_object()(tet, p); + if(certainly(b)) + return b; -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 &lh_tet, - const typename K::Tetrahedron_3 &rh_tet, - const K & k) -{ - return do_intersect_tetrahedron_bounded(lh_tet, rh_tet, lh_tet[0], k); -} - -// BBox_3 specific code since it is ok for BBox_3 to degenerate. -template -inline typename K::Boolean do_intersect(const CGAL::Bbox_3 &aabb, - const typename K::Tetrahedron_3 &tet, - const K &k) { - typename K::Construct_triangle_3 tr = k.construct_triangle_3_object(); - typename K::Boolean result = false; - typename K::Boolean b = false; - - b = do_intersect(aabb, tr(tet[0], tet[1], tet[2]), k); - if (certainly(b)) return b; - if (is_indeterminate(b)) result = b; - b = do_intersect(aabb, tr(tet[1], tet[2], tet[3]), k); - if (certainly(b)) return b; - if (is_indeterminate(b)) result = b; - b = do_intersect(aabb, tr(tet[2], tet[3], tet[0]), k); - if (certainly(b)) return b; - if (is_indeterminate(b)) result = b; - b = do_intersect(aabb, tr(tet[3], tet[0], tet[1]), k); - if (certainly(b)) return b; - if (is_indeterminate(b)) result = b; - - b = k.has_on_bounded_side_3_object()( - tet, k.construct_point_3_object()(aabb.xmin(), aabb.ymin(), aabb.zmin())); - if (certainly(b)) return b; - if (is_indeterminate(b)) result = b; + if(is_indeterminate(b)) + result = b; return result; } - -template -inline typename K::Boolean do_intersect(const typename K::Tetrahedron_3 &tet, - const CGAL::Bbox_3 &bb, const K &k) { - // Swap arguments. - return do_intersect(bb, tet, k); -} - } // namespace internal } // namespace Intersections -} //namespace CGAL +} // namespace CGAL -#endif // CGAL_TETRAHEDRON_3_BOUNDED_3_DO_INTERSECT_H +#endif // CGAL_INTERNAL_INTERSECTIONS_TETRAHEDRON_3_BOUNDED_3_DO_INTERSECT_H diff --git a/Intersections_3/include/CGAL/Intersections_3/internal/Tetrahedron_3_Tetrahedron_3_do_intersect.h b/Intersections_3/include/CGAL/Intersections_3/internal/Tetrahedron_3_Tetrahedron_3_do_intersect.h new file mode 100644 index 00000000000..e9fe68a7a36 --- /dev/null +++ b/Intersections_3/include/CGAL/Intersections_3/internal/Tetrahedron_3_Tetrahedron_3_do_intersect.h @@ -0,0 +1,40 @@ +// Copyright (c) 2005 +// Utrecht University (The Netherlands), +// ETH Zurich (Switzerland), +// INRIA Sophia-Antipolis (France), +// Max-Planck-Institute Saarbruecken (Germany), +// and Tel-Aviv University (Israel). All rights reserved. +// +// This file is part of CGAL (www.cgal.org) +// +// $URL$ +// $Id$ +// SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-Commercial +// +// +// Author(s) : Nico Kruithof + +#ifndef CGAL_INTERNAL_INTERSECTIONS_TETRAHEDRON_3_TETRAHEDRON_3_DO_INTERSECT_H +#define CGAL_INTERNAL_INTERSECTIONS_TETRAHEDRON_3_TETRAHEDRON_3_DO_INTERSECT_H + +#include + +namespace CGAL { +namespace Intersections { +namespace internal { + +template +inline +typename K::Boolean +do_intersect(const typename K::Tetrahedron_3& lh_tet, + const typename K::Tetrahedron_3& rh_tet, + const K& k) +{ + return do_intersect_tetrahedron_bounded(lh_tet, rh_tet, lh_tet[0], k); +} + +} // namespace internal +} // namespace Intersections +} // namespace CGAL + +#endif // CGAL_INTERNAL_INTERSECTIONS_TETRAHEDRON_3_TETRAHEDRON_3_DO_INTERSECT_H diff --git a/Intersections_3/include/CGAL/Intersections_3/internal/Tetrahedron_3_Triangle_3_do_intersect.h b/Intersections_3/include/CGAL/Intersections_3/internal/Tetrahedron_3_Triangle_3_do_intersect.h new file mode 100644 index 00000000000..5950d6a9f7d --- /dev/null +++ b/Intersections_3/include/CGAL/Intersections_3/internal/Tetrahedron_3_Triangle_3_do_intersect.h @@ -0,0 +1,53 @@ +// Copyright (c) 2001 GeometryFactory(France). +// All rights reserved. +// +// This file is part of CGAL (www.cgal.org) +// +// $URL$ +// $Id$ +// SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-Commercial +// +// +// Author(s) : Nico Kruithof + +#ifndef CGAL_INTERNAL_INTERSECTIONS_3_TETRAHEDRON_3_TRIANGLE_3_DO_INTERSECT_H +#define CGAL_INTERNAL_INTERSECTIONS_3_TETRAHEDRON_3_TRIANGLE_3_DO_INTERSECT_H + +#include + +namespace CGAL { +namespace Intersections { +namespace internal { + +template +typename K::Boolean +do_intersect_tetrahedron_bounded(const Bounded& tr, + const typename K::Tetrahedron_3& tet, + const typename K::Point_3& p, + const K& k); + +template +inline +typename K::Boolean +do_intersect(const typename K::Tetrahedron_3& tet, + const typename K::Triangle_3& tr, + const K& 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); +} + +} // namespace internal +} // namespace Intersections +} // namespace CGAL + +#endif // CGAL_INTERNAL_INTERSECTIONS_3_TETRAHEDRON_3_TRIANGLE_3_DO_INTERSECT_H diff --git a/Intersections_3/include/CGAL/Intersections_3/internal/Tetrahedron_3_Triangle_3_intersection.h b/Intersections_3/include/CGAL/Intersections_3/internal/Tetrahedron_3_Triangle_3_intersection.h index 0a3839ec258..b0117ed27a7 100644 --- a/Intersections_3/include/CGAL/Intersections_3/internal/Tetrahedron_3_Triangle_3_intersection.h +++ b/Intersections_3/include/CGAL/Intersections_3/internal/Tetrahedron_3_Triangle_3_intersection.h @@ -15,282 +15,275 @@ #ifndef CGAL_INTERNAL_INTERSECTIONS_3_TETRAHEDRON_3_TRIANGLE_3_INTERSECTIONS_H #define CGAL_INTERNAL_INTERSECTIONS_3_TETRAHEDRON_3_TRIANGLE_3_INTERSECTIONS_H -#include -#include -#include -#include +#include #include +#include + +#include + +#include +#include +#include + namespace CGAL { - namespace Intersections { - namespace internal { -//Tetrahedron_3 Segment_3 template typename Intersection_traits::result_type -intersection( - const typename K::Tetrahedron_3 &tet, - const typename K::Triangle_3 &tr, - const K& k) +intersection(const typename K::Tetrahedron_3& tet, + const typename K::Triangle_3& tr, + const K& k) { - typedef typename Intersection_traits::result_type result_type; + typedef typename Intersection_traits::result_type result_type; + typedef typename Intersection_traits::result_type Inter_type; - typedef typename Intersection_traits::result_type Inter_type; - - typedef typename K::Segment_3 Segment_3; typedef typename K::Point_3 Point_3; + typedef typename K::Segment_3 Segment_3; typedef typename K::Triangle_3 Triangle_3; + typedef std::vector Poly; std::vector inside_points; for(int i = 0; i< 3; ++i) - { - if(tet.has_on_bounded_side(tr.vertex(i)) - || tet.has_on_boundary(tr.vertex(i))){ + if(tet.has_on_bounded_side(tr.vertex(i)) || tet.has_on_boundary(tr.vertex(i))) inside_points.push_back(tr.vertex(i)); - } - } + switch(inside_points.size()) { - case 0: - { - Inter_type intersections[4]; - std::vector segments; - std::vector seg_ids; - std::vector points; - for(std::size_t i = 0; i < 4; ++i) + case 0: { - const typename K::Triangle_3 triangle(tet.vertex((i+1)%4), - tet.vertex((i+2)%4), - tet.vertex((i+3)%4)); - intersections[i] = typename K::Intersect_3()(tr, triangle); - if(intersections[i]){ - //a face is inside the input tr - if(const Triangle_3* t = boost::get(&*intersections[i])) - { - Triangle_3 res = *t; - return result_type(std::forward(res)); - } - //get segs and pts to construct poly - else if( const Segment_3* s - = boost::get(&*intersections[i])) - { - segments.push_back(*s); - seg_ids.push_back(i); - } - else if( const typename K::Point_3* p - = boost::get(&*intersections[i])) - { - points.push_back(*p); - } - //if poly : then the input is in a supporting plane of a face, return the poly. - else if( const Poly* p - = boost::get(&*intersections[i])) - { - Poly res = *p; - return result_type(std::forward(res)); - } - } - } - if(segments.size() > 1) - { - std::vector filtered; - filter_segments(segments, filtered); - segments = filtered; - } - //if there are several segments, then we need to compute the polygone. - if(segments.size() > 1) - { - std::list tmp; - fill_segments_infos(segments,tmp, tr); - Poly res; - res.reserve(4); - for(const auto& p : tmp) - res.push_back(p); - return result_type(std::forward(res)); - } - //else it must be adjacent to an vertex, so we return the point - else if(segments.size() == 1) - { - //adjacency to an edge, return resulting segment. - return result_type(std::forward(segments.front())); - } - else - { - //no segment = adjacency to an vertex or an edge : return result point - return result_type(std::forward(points.front())); - - } - } - break; - case 1: - case 2: - { - //tricky cases - Inter_type intersections[4]; - std::vector points; - std::vector segments; - for(std::size_t i = 0; i < 4; ++i) - { - const typename K::Triangle_3 triangle(tet.vertex((i+1)%4), - tet.vertex((i+2)%4), - tet.vertex((i+3)%4)); - intersections[i] = typename K::Intersect_3()(tr, triangle); - if(intersections[i]){ - if(const Triangle_3* t = boost::get(&*intersections[i])) - { - Triangle_3 res = *t; - return result_type(std::forward(res)); - } - //get segs and pts to construct poly - else if( const Segment_3* s - = boost::get(&*intersections[i])) - { - segments.push_back(*s); - } - else if( const typename K::Point_3* p - = boost::get(&*intersections[i])) - { - points.push_back(*p); - } - //if poly : then the input is in a supporting plane of a face, return the poly. - else if( const Poly* p - = boost::get(&*intersections[i])) - { - Poly res = *p; - return result_type(std::forward(res)); - } - } - } - if(segments.empty()) - { - //then there is only one point of contact. Return it: - return result_type(std::forward(points.front())); - } - - if(segments.size() > 1) - { - std::vector filtered; - filter_segments(segments, filtered); - segments = filtered; - } - - switch(segments.size()) - { - case 1: - { - bool return_solo_seg = true; - //only one intersection, a triangle edge is one of the tet edges, and - //the 3rd point is outside. This is the only intersection. - for(const auto& p : inside_points) + Inter_type intersections[4]; + std::vector segments; + std::vector seg_ids; + std::vector points; + for(std::size_t i = 0; i < 4; ++i) { - if(!tet.has_on_boundary(p)) + const Triangle_3 triangle = k.construct_triangle_3_object()(tet.vertex((i+1)%4), + tet.vertex((i+2)%4), + tet.vertex((i+3)%4)); + intersections[i] = intersection(tr, triangle, k); + if(intersections[i]) { - return_solo_seg = false; - break; + //a face is inside the input tr + if(const Triangle_3* t = boost::get(&*intersections[i])) + { + Triangle_3 res = *t; + return result_type(std::forward(res)); + } + //get segs and pts to construct poly + else if(const Segment_3* s = boost::get(&*intersections[i])) + { + segments.push_back(*s); + seg_ids.push_back(i); + } + else if(const Point_3* p = boost::get(&*intersections[i])) + { + points.push_back(*p); + } + //if poly : then the input is in a supporting plane of a face, return the poly. + else if(const Poly* p = boost::get(&*intersections[i])) + { + Poly res = *p; + return result_type(std::forward(res)); + } } } - if(return_solo_seg) - { - return result_type(std::forward(segments.front())); - } - if(inside_points.size() == 1) + if(segments.size() > 1) { - Triangle_3 res(inside_points.front(), segments.front().source(), - segments.front().target()); - return result_type(std::forward(res)); + std::vector filtered; + filter_segments(segments, filtered); + segments = filtered; } - else //size 2 - { - Poly res(4); - res[0] = inside_points.front(); - res[1] = inside_points.back(); - if((inside_points.front() - inside_points.back()) * - (segments.front().source() - segments.front().target()) > 0) - { - res[2] = segments.front().target(); - res[3] = segments.front().source(); - } - else - { - res[3] = segments.front().target(); - res[2] = segments.front().source(); - } - return result_type(std::forward(res)); - } - } - break; - case 2: - case 3: - { - std::list segs(segments.begin(), segments.end()); - std::list tmp; - fill_points_list(segs, tmp); - if(inside_points.size() == 1) + + //if there are several segments, then we need to compute the polygone. + if(segments.size() > 1) { + std::list tmp; + fill_segments_infos(segments, tmp, tr); Poly res; res.reserve(4); - res.push_back(inside_points.front()); - for(const auto& p : tmp) + for(const Point_3& p : tmp) res.push_back(p); return result_type(std::forward(res)); } - else //size 2 + //else it must be adjacent to an vertex, so we return the point + else if(segments.size() == 1) { - Poly res; - res.reserve(5); - typename K::Compute_scalar_product_3 scalar = - k.compute_scalar_product_3_object(); - typename K::Construct_vector_3 construct_vector = - k.construct_vector_3_object(); - - if(scalar(construct_vector(inside_points.front(), inside_points.back()), - construct_vector(tmp.front(), tmp.back())) > 0) - { - res.push_back(inside_points.front()); - } - res.push_back(inside_points.back()); - for(const auto& p : tmp) - res.push_back(p); - return result_type(std::forward(res)); + //adjacency to an edge, return resulting segment. + return result_type(std::forward(segments.front())); } + else + { + CGAL_assertion(!points.empty()); + + //no segment = adjacency to an vertex or an edge : return result point + return result_type(std::forward(points.front())); + } + } + break; + case 1: + case 2: + { + //tricky cases + Inter_type intersections[4]; + std::vector points; + std::vector segments; + for(std::size_t i = 0; i < 4; ++i) + { + const Triangle_3 triangle = k.construct_triangle_3_object()(tet.vertex((i+1)%4), + tet.vertex((i+2)%4), + tet.vertex((i+3)%4)); + intersections[i] = intersection(tr, triangle, k); + if(intersections[i]){ + if(const Triangle_3* t = boost::get(&*intersections[i])) + { + Triangle_3 res = *t; + return result_type(std::forward(res)); + } + //get segs and pts to construct poly + else if(const Segment_3* s = boost::get(&*intersections[i])) + { + segments.push_back(*s); + } + else if(const Point_3* p = boost::get(&*intersections[i])) + { + points.push_back(*p); + } + //if poly : then the input is in a supporting plane of a face, return the poly. + else if(const Poly* p = boost::get(&*intersections[i])) + { + Poly res = *p; + return result_type(std::forward(res)); + } + } + } + + if(segments.empty()) // only one point of contact + return result_type(std::forward(points.front())); + + if(segments.size() > 1) + { + std::vector filtered; + filter_segments(segments, filtered); + segments = filtered; + } + + switch(segments.size()) + { + case 1: + { + bool return_solo_seg = true; + //only one intersection, a triangle edge is one of the tet edges, and + //the 3rd point is outside. This is the only intersection. + for(const Point_3& p : inside_points) + { + if(!tet.has_on_boundary(p)) + { + return_solo_seg = false; + break; + } + } + + if(return_solo_seg) + return result_type(std::forward(segments.front())); + + if(inside_points.size() == 1) + { + Triangle_3 res = k.construct_triangle_3_object()(inside_points.front(), + segments.front().source(), + segments.front().target()); + return result_type(std::forward(res)); + } + else //size 2 + { + Poly res(4); + res[0] = inside_points.front(); + res[1] = inside_points.back(); + if((inside_points.front() - inside_points.back()) * + (segments.front().source() - segments.front().target()) > 0) + { + res[2] = segments.front().target(); + res[3] = segments.front().source(); + } + else + { + res[3] = segments.front().target(); + res[2] = segments.front().source(); + } + + return result_type(std::forward(res)); + } + } + break; + case 2: + case 3: + { + std::list segs(segments.begin(), segments.end()); + std::list tmp; + fill_points_list(segs, tmp); + if(inside_points.size() == 1) + { + Poly res; + res.reserve(4); + res.push_back(inside_points.front()); + for(const Point_3& p : tmp) + res.push_back(p); + + return result_type(std::forward(res)); + } + else //size 2 + { + typename K::Compute_scalar_product_3 scalar = k.compute_scalar_product_3_object(); + typename K::Construct_vector_3 construct_vector = k.construct_vector_3_object(); + + Poly res; + res.reserve(5); + if(scalar(construct_vector(inside_points.front(), inside_points.back()), + construct_vector(tmp.front(), tmp.back())) > 0) + { + res.push_back(inside_points.front()); + } + res.push_back(inside_points.back()); + for(const Point_3& p : tmp) + res.push_back(p); + + return result_type(std::forward(res)); + } + } + break; + default: + //3 faces max if a point or more are inside tetrahedron + break; + } + } + break; + + case 3: + { + //triangle entirely inside tetra : return input triangle + return result_type(tr); } break; default: - //3 faces max if a point or more are inside tetrahedron + //never happens (only 3 pts in a tr) break; - } - } - break; - - case 3: - { - //triangle entirely inside tetra : return input triangle - return result_type(tr); - } - break; - default: - //never happens (only 3 pts in a tr) - break; } return result_type(); } template typename Intersection_traits::result_type -intersection( - const typename K::Triangle_3 &pl, - const typename K::Tetrahedron_3 &tet, - const K& k) +intersection(const typename K::Triangle_3& pl, + const typename K::Tetrahedron_3& tet, + const K& k) { return intersection(tet, pl, k); } -}}} +} // namespace internal +} // namespace Intersections +} // namespace CGAL + #endif // CGAL_INTERNAL_INTERSECTIONS_3_TETRAHEDRON_3_TRIANGLE_3_INTERSECTIONS_H diff --git a/Intersections_3/include/CGAL/Intersections_3/internal/Tetrahedron_3_Unbounded_3_do_intersect.h b/Intersections_3/include/CGAL/Intersections_3/internal/Tetrahedron_3_Unbounded_3_do_intersect.h index 122f646501f..c40411572f4 100644 --- a/Intersections_3/include/CGAL/Intersections_3/internal/Tetrahedron_3_Unbounded_3_do_intersect.h +++ b/Intersections_3/include/CGAL/Intersections_3/internal/Tetrahedron_3_Unbounded_3_do_intersect.h @@ -13,89 +13,41 @@ #ifndef CGAL_INTERNAL_INTERSECTIONS_3_TETRAHEDRON_3_DO_INTERSECT_H #define CGAL_INTERNAL_INTERSECTIONS_3_TETRAHEDRON_3_DO_INTERSECT_H -#include -#include -#include +#include +#include +#include +#include namespace CGAL { - namespace Intersections { - namespace internal { template typename K::Boolean do_intersect_tetrahedron_unbounded(const typename K::Tetrahedron_3& tet, const Unbounded& unb, - const K& k) { - typedef typename K::Triangle_3 Triangle; + const K& k) +{ typedef typename K::Boolean Boolean; + Boolean result = false; - for (int i = 0; i < 4; ++i) + for(int i = 0; i < 4; ++i) { const Boolean b = do_intersect(unb, - Triangle(tet[i], - tet[(i+1)%4], - tet[(i+2)%4]), + k.construct_triangle_3_object()(tet[i], + tet[(i+1)%4], + tet[(i+2)%4]), k); - if(certainly(b)) return b; - if(is_indeterminate(b)) result = b; + if(certainly(b)) + return b; + + if(is_indeterminate(b)) + result = b; } + return result; } - - -template -typename K::Boolean -do_intersect(const typename K::Plane_3& unb, - const typename K::Tetrahedron_3& tet, - const K& k) { - return do_intersect_tetrahedron_unbounded(tet, unb, k); -} - -template -typename K::Boolean -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 -typename K::Boolean -do_intersect(const typename K::Line_3& unb, - const typename K::Tetrahedron_3& tet, - const K& k) { - return do_intersect_tetrahedron_unbounded(tet, unb, k); -} - -template -typename K::Boolean -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 -typename K::Boolean -do_intersect(const typename K::Ray_3& unb, - const typename K::Tetrahedron_3& tet, - const K& k) { - return do_intersect_tetrahedron_unbounded(tet, unb, k); -} - -template -typename K::Boolean -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 } // namespace Intersections } // namespace CGAL diff --git a/Intersections_3/include/CGAL/Intersections_3/internal/Triangle_3_Line_3_do_intersect.h b/Intersections_3/include/CGAL/Intersections_3/internal/Triangle_3_Line_3_do_intersect.h deleted file mode 100644 index c42c00cfeea..00000000000 --- a/Intersections_3/include/CGAL/Intersections_3/internal/Triangle_3_Line_3_do_intersect.h +++ /dev/null @@ -1,117 +0,0 @@ -// Copyright (c) 2003 INRIA Sophia-Antipolis (France). -// All rights reserved. -// -// This file is part of CGAL (www.cgal.org) -// -// $URL$ -// $Id$ -// SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-Commercial -// -// -// Author(s) : Philippe Guigue - -#ifndef CGAL_TRIANGLE_3_LINE_3_DO_INTERSECT_H -#define CGAL_TRIANGLE_3_LINE_3_DO_INTERSECT_H - -#include -#include -#include - -namespace CGAL { - - template - class Triangle_3; - - template - class Line_3; - - -namespace Intersections { - -namespace internal { - -template -bool do_intersect(const typename K::Triangle_3 &t, - const typename K::Line_3 &l, - const K & k ) -{ - - CGAL_kernel_precondition( ! k.is_degenerate_3_object()(t) ) ; - CGAL_kernel_precondition( ! k.is_degenerate_3_object()(l) ) ; - - typedef typename K::Point_3 Point_3; - - - typename K::Construct_point_on_3 point_on = - k.construct_point_on_3_object(); - - typename K::Construct_vertex_3 vertex_on = - k.construct_vertex_3_object(); - - typename K::Orientation_3 orientation = - k.orientation_3_object(); - - typename K::Coplanar_orientation_3 coplanar_orientation = - k.coplanar_orientation_3_object(); - - - - const Point_3 & a = vertex_on(t,0); - const Point_3 & b = vertex_on(t,1); - const Point_3 & c = vertex_on(t,2); - const Point_3 & p = point_on(l,0); - const Point_3 & q = point_on(l,1); - - - - if ( ( orientation(a,b,c,p) != COPLANAR ) || - ( orientation(a,b,c,q) != COPLANAR ) ) - { - - const Orientation pqab = orientation(p,q,a,b); - const Orientation pqbc = orientation(p,q,b,c); - - - switch ( pqab ) { - case POSITIVE: return pqbc != NEGATIVE && - orientation(p,q,c,a) != NEGATIVE ; - case NEGATIVE: return pqbc != POSITIVE && - orientation(p,q,c,a) != POSITIVE ; - case COPLANAR: - switch ( pqbc ) { - case POSITIVE: return orientation(p,q,c,a) != NEGATIVE ; - case NEGATIVE: return orientation(p,q,c,a) != POSITIVE ; - case COPLANAR: return true; - default: // should not happen. - CGAL_kernel_assertion(false); - return false; - } - default: // should not happen. - CGAL_kernel_assertion(false); - return false; - } - } - - // Coplanar case - - const Orientation pqa = coplanar_orientation(p,q,a); - - return coplanar_orientation(p,q,b) != pqa - || coplanar_orientation(p,q,c) != pqa ; -} - - -template -inline -bool do_intersect(const typename K::Line_3 &l, - const typename K::Triangle_3 &t, - const K & k ) -{ - return do_intersect(t, l, k); -} - -} // namespace internal -} // namespace Intersections -} //namespace CGAL - -#endif //CGAL_TRIANGLE_3_LINE_3_DO_INTERSECT_H diff --git a/Intersections_3/include/CGAL/Intersections_3/internal/Triangle_3_Plane_3_do_intersect.h b/Intersections_3/include/CGAL/Intersections_3/internal/Triangle_3_Plane_3_do_intersect.h deleted file mode 100644 index 7aab8727523..00000000000 --- a/Intersections_3/include/CGAL/Intersections_3/internal/Triangle_3_Plane_3_do_intersect.h +++ /dev/null @@ -1,80 +0,0 @@ -// Copyright (c) 2003 INRIA Sophia-Antipolis (France). -// All rights reserved. -// -// This file is part of CGAL (www.cgal.org) -// -// $URL$ -// $Id$ -// SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-Commercial -// -// -// Author(s) : Philippe Guigue - -#ifndef CGAL_TRIANGLE_3_PLANE_3_DO_INTERSECT_H -#define CGAL_TRIANGLE_3_PLANE_3_DO_INTERSECT_H - -#include -#include -#include - -namespace CGAL { - - template - class Triangle_3; - - template - class Plane_3; - -namespace Intersections { - -namespace internal { - -template -bool do_intersect(const typename K::Triangle_3 &t, - const typename K::Plane_3 &h, - const K & k) -{ - - CGAL_kernel_precondition( ! k.is_degenerate_3_object()(t)) ; - CGAL_kernel_precondition( ! k.is_degenerate_3_object()(h)) ; - - - typename K::Construct_vertex_3 vertex_on = - k.construct_vertex_3_object(); - - typename K::Oriented_side_3 oriented_side = - k.oriented_side_3_object(); - - - - switch ( oriented_side(h,vertex_on(t,0)) ) { - case ON_POSITIVE_SIDE: - return oriented_side(h,vertex_on(t,1)) != ON_POSITIVE_SIDE - || oriented_side(h,vertex_on(t,2)) != ON_POSITIVE_SIDE; - case ON_NEGATIVE_SIDE: - return oriented_side(h,vertex_on(t,1)) != ON_NEGATIVE_SIDE - || oriented_side(h,vertex_on(t,2)) != ON_NEGATIVE_SIDE ; - case ON_ORIENTED_BOUNDARY: - return true; - default:// should not happen. - CGAL_kernel_assertion(false); - return false; - } -} - - -template -inline -bool do_intersect(const typename K::Plane_3 &h, - const typename K::Triangle_3 &t, - const K & k) -{ - return do_intersect(t, h, k); -} - - -} // namespace internal -} // namespace Intersections -} //namespace CGAL - -#endif //CGAL_TRIANGLE_3_PLANE_3_DO_INTERSECT_H diff --git a/Intersections_3/include/CGAL/Intersections_3/internal/Triangle_3_Sphere_3_do_intersect.h b/Intersections_3/include/CGAL/Intersections_3/internal/Triangle_3_Sphere_3_do_intersect.h deleted file mode 100644 index e35346a9d5a..00000000000 --- a/Intersections_3/include/CGAL/Intersections_3/internal/Triangle_3_Sphere_3_do_intersect.h +++ /dev/null @@ -1,148 +0,0 @@ -// Copyright (c) 2018 GeometryFactory Sarl -// All rights reserved. -// -// This file is part of CGAL (www.cgal.org) -// -// $URL$ -// $Id$ -// SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-Commercial -// -// -// Author(s) : Andreas Fabri - -#ifndef CGAL_TRIANGLE_3_SPHERE_3_DO_INTERSECT_H -#define CGAL_TRIANGLE_3_SPHERE_3_DO_INTERSECT_H - -#include -#include -#include -namespace CGAL { - -template -class Triangle_3; - -template -class Sphere_3; - -template -class Line_3; - -namespace Intersections { - -namespace internal { - -template -inline -typename K::Boolean -do_intersect(const typename K::Sphere_3 &sp, - const typename K::Triangle_3 &tr, - const K & k) -{ - typedef typename K::RT RT; - RT num, den; - - CGAL::internal::squared_distance_RT(sp.center(), tr, num, den, k); - return ! (compare_quotients(num, den, - Rational_traits().numerator(sp.squared_radius()), - Rational_traits().denominator(sp.squared_radius())) == LARGER); -} - -template -inline -typename K::Boolean -do_intersect(const typename K::Triangle_3 &tr, - const typename K::Sphere_3 &sp, - const K & k) -{ - return do_intersect(sp, tr, k); -} - - -template -inline -typename K::Boolean -do_intersect(const typename K::Line_3 &lin, - const typename K::Sphere_3 &sp, - const K & k) -{ - typedef typename K::RT RT; - RT num, den; - - CGAL::internal::squared_distance_RT(sp.center(), lin, num, den, k); - return ! (compare_quotients(num, den, - Rational_traits().numerator(sp.squared_radius()), - Rational_traits().denominator(sp.squared_radius())) == LARGER); - -} - -template -inline -typename K::Boolean -do_intersect(const typename K::Sphere_3 &sp, - const typename K::Line_3 &lin, - const K & k) -{ - return do_intersect(lin,sp,k); -} - - - -template -inline -typename K::Boolean -do_intersect(const typename K::Sphere_3 &sp, - const typename K::Ray_3 &ray, - const K & k) -{ - typedef typename K::RT RT; - RT num, den; - - CGAL::internal::squared_distance_RT(sp.center(), ray, num, den, k); - return ! (compare_quotients(num, den, - Rational_traits().numerator(sp.squared_radius()), - Rational_traits().denominator(sp.squared_radius())) == LARGER); -} - - -template -inline -typename K::Boolean -do_intersect(const typename K::Ray_3 &ray, - const typename K::Sphere_3 &sp, - const K & k) -{ - return do_intersect(sp,ray,k); -} - -template -inline -typename K::Boolean -do_intersect(const typename K::Sphere_3 &sp, - const typename K::Segment_3 &seg, - const K & k) -{ - typedef typename K::RT RT; - RT num, den; - - CGAL::internal::squared_distance_RT(sp.center(), seg, num, den, k); - return ! (compare_quotients(num, den, - Rational_traits().numerator(sp.squared_radius()), - Rational_traits().denominator(sp.squared_radius())) == LARGER); -} - - -template -inline -typename K::Boolean -do_intersect(const typename K::Segment_3 &seg, - const typename K::Sphere_3 &sp, - const K & k) -{ - return do_intersect(sp,seg,k); -} - -} // namespace internal -} // namespace Intersections -} // namespace CGAL - -#endif // CGAL_TRIANGLE_3_SPHERE_3_DO_INTERSECT_H diff --git a/Intersections_3/include/CGAL/Intersections_3/internal/Triangle_3_Triangle_3_do_intersect.h b/Intersections_3/include/CGAL/Intersections_3/internal/Triangle_3_Triangle_3_do_intersect.h index 3c36e14f11e..ce993540138 100644 --- a/Intersections_3/include/CGAL/Intersections_3/internal/Triangle_3_Triangle_3_do_intersect.h +++ b/Intersections_3/include/CGAL/Intersections_3/internal/Triangle_3_Triangle_3_do_intersect.h @@ -10,241 +10,223 @@ // // Author(s) : Philippe Guigue -#ifndef CGAL_TRIANGLE_3_TRIANGLE_3_DO_INTERSECT_H -#define CGAL_TRIANGLE_3_TRIANGLE_3_DO_INTERSECT_H +#ifndef CGAL_INTERNAL_INTERSECTIONS_3_TRIANGLE_3_TRIANGLE_3_DO_INTERSECT_H +#define CGAL_INTERNAL_INTERSECTIONS_3_TRIANGLE_3_TRIANGLE_3_DO_INTERSECT_H -#include #include #include -#include +#include namespace CGAL { - - template - class Triangle_3; - namespace Intersections { - namespace internal { template -bool _intersection_test_vertex(const typename K::Point_3 * p, - const typename K::Point_3 * q, - const typename K::Point_3 * r, - const typename K::Point_3 * a, - const typename K::Point_3 * b, - const typename K::Point_3 * c, - const K & k){ - - CGAL_kernel_precondition( k.coplanar_orientation_3_object() (*p,*q,*r) - == POSITIVE); - CGAL_kernel_precondition( k.coplanar_orientation_3_object() (*a,*b,*c) - == POSITIVE); - +bool _intersection_test_vertex(const typename K::Point_3* p, + const typename K::Point_3* q, + const typename K::Point_3* r, + const typename K::Point_3* a, + const typename K::Point_3* b, + const typename K::Point_3* c, + const K& k) +{ + CGAL_kernel_precondition(k.coplanar_orientation_3_object()(*p,*q,*r) == POSITIVE); + CGAL_kernel_precondition(k.coplanar_orientation_3_object()(*a,*b,*c) == POSITIVE); // Vertex p sees vertex c - typename K::Coplanar_orientation_3 coplanar_orientation = - k.coplanar_orientation_3_object(); + typename K::Coplanar_orientation_3 coplanar_orientation = k.coplanar_orientation_3_object(); + if(coplanar_orientation(*c,*a,*q) != NEGATIVE) + { + if(coplanar_orientation(*c,*b,*q) != POSITIVE) + { + if(coplanar_orientation(*p,*a,*q) == POSITIVE) + return (coplanar_orientation(*p,*b,*q) != POSITIVE); - if (coplanar_orientation(*c,*a,*q) != NEGATIVE) { - if (coplanar_orientation(*c,*b,*q) != POSITIVE) { - if (coplanar_orientation(*p,*a,*q) == POSITIVE) - return coplanar_orientation(*p,*b,*q) != POSITIVE; - - return coplanar_orientation(*p,*a,*r) != NEGATIVE - && coplanar_orientation(*q,*r,*a) != NEGATIVE; + return (coplanar_orientation(*p,*a,*r) != NEGATIVE) && (coplanar_orientation(*q,*r,*a) != NEGATIVE); } - if (coplanar_orientation(*p,*b,*q) != POSITIVE) - return coplanar_orientation(*c,*b,*r) != POSITIVE - && coplanar_orientation(*q,*r,*b) != NEGATIVE; + if(coplanar_orientation(*p,*b,*q) != POSITIVE) + return (coplanar_orientation(*c,*b,*r) != POSITIVE) && (coplanar_orientation(*q,*r,*b) != NEGATIVE); return false; - } - if (coplanar_orientation(*c,*a,*r) != NEGATIVE) { //qr straddles (ac) - if (coplanar_orientation(*q,*r,*c) != NEGATIVE) + if(coplanar_orientation(*c,*a,*r) != NEGATIVE) //qr straddles (ac) + { + if(coplanar_orientation(*q,*r,*c) != NEGATIVE) return (coplanar_orientation(*p,*a,*r) != NEGATIVE); - return coplanar_orientation(*q,*r,*b) != NEGATIVE - && coplanar_orientation(*c,*r,*b) != NEGATIVE; + return (coplanar_orientation(*q,*r,*b) != NEGATIVE) && (coplanar_orientation(*c,*r,*b) != NEGATIVE); } - return false; // ca separes + return false; // ca separes } - template -bool _intersection_test_edge(const typename K::Point_3 * p, - const typename K::Point_3 * q, - const typename K::Point_3 * r, - const typename K::Point_3 * a, - const typename K::Point_3 * CGAL_kernel_precondition_code(b), - const typename K::Point_3 * c, - const K & k){ - - CGAL_kernel_precondition( k.coplanar_orientation_3_object() (*p,*q,*r) - == POSITIVE); - CGAL_kernel_precondition( k.coplanar_orientation_3_object() (*a,*b,*c) - == POSITIVE); +bool _intersection_test_edge(const typename K::Point_3* p, + const typename K::Point_3* q, + const typename K::Point_3* r, + const typename K::Point_3* a, + const typename K::Point_3* CGAL_kernel_precondition_code(b), + const typename K::Point_3* c, + const K& k) +{ + CGAL_kernel_precondition(k.coplanar_orientation_3_object() (*p,*q,*r) == POSITIVE); + CGAL_kernel_precondition(k.coplanar_orientation_3_object() (*a,*b,*c) == POSITIVE); // Vertex p sees edge ca + typename K::Coplanar_orientation_3 coplanar_orientation = k.coplanar_orientation_3_object(); - typename K::Coplanar_orientation_3 coplanar_orientation = - k.coplanar_orientation_3_object(); + if(coplanar_orientation(*c,*a,*q) != NEGATIVE) //pq straddles (ac) + { + if(coplanar_orientation(*p,*a,*q) != NEGATIVE) + return (coplanar_orientation(*p,*q,*c) != NEGATIVE); - - - if (coplanar_orientation(*c,*a,*q) != NEGATIVE) { //pq straddles (ac) - if (coplanar_orientation(*p,*a,*q) != NEGATIVE) - return coplanar_orientation(*p,*q,*c) != NEGATIVE ; - - return coplanar_orientation(*q,*r,*a) != NEGATIVE - && coplanar_orientation(*r,*p,*a) != NEGATIVE; + return (coplanar_orientation(*q,*r,*a) != NEGATIVE) && (coplanar_orientation(*r,*p,*a) != NEGATIVE); } - if (coplanar_orientation(*c,*a,*r) != NEGATIVE) { + if(coplanar_orientation(*c,*a,*r) != NEGATIVE) + { // pr and qr straddle line (pr) - return coplanar_orientation(*p,*a,*r) != NEGATIVE - && ( coplanar_orientation(*p,*r,*c) != NEGATIVE - || coplanar_orientation(*q,*r,*c) != NEGATIVE ); + return (coplanar_orientation(*p,*a,*r) != NEGATIVE) && + (coplanar_orientation(*p,*r,*c) != NEGATIVE || coplanar_orientation(*q,*r,*c) != NEGATIVE); } - return false; //ac separes + return false; // ac separes } - template -bool do_intersect_coplanar(const typename K::Triangle_3 &t1, - const typename K::Triangle_3 &t2, - const K & k) +bool do_intersect_coplanar(const typename K::Triangle_3& t1, + const typename K::Triangle_3& t2, + const K& k) { - - CGAL_kernel_precondition( ! k.is_degenerate_3_object() (t1) ); - CGAL_kernel_precondition( ! k.is_degenerate_3_object() (t2) ); - typedef typename K::Point_3 Point_3; - typename K::Construct_vertex_3 vertex_on = - k.construct_vertex_3_object(); + CGAL_kernel_precondition(!k.is_degenerate_3_object() (t1)); + CGAL_kernel_precondition(!k.is_degenerate_3_object() (t2)); - typename K::Coplanar_orientation_3 coplanar_orientation = - k.coplanar_orientation_3_object(); + typename K::Construct_vertex_3 vertex_on = k.construct_vertex_3_object(); + typename K::Coplanar_orientation_3 coplanar_orientation = k.coplanar_orientation_3_object(); - const Point_3 & P = vertex_on(t1,0); - const Point_3 & Q = vertex_on(t1,1); - const Point_3 & R = vertex_on(t1,2); + const Point_3& P = vertex_on(t1,0); + const Point_3& Q = vertex_on(t1,1); + const Point_3& R = vertex_on(t1,2); - const Point_3 & A = vertex_on(t2,0); - const Point_3 & B = vertex_on(t2,1); - const Point_3 & C = vertex_on(t2,2); + const Point_3& A = vertex_on(t2,0); + const Point_3& B = vertex_on(t2,1); + const Point_3& C = vertex_on(t2,2); + const Point_3* p = &P; + const Point_3* q = &Q; + const Point_3* r = &R; - const Point_3 * p = &P; - const Point_3 * q = &Q; - const Point_3 * r = &R; + const Point_3* a = &A; + const Point_3* b = &B; + const Point_3* c = &C; - const Point_3 * a = &A; - const Point_3 * b = &B; - const Point_3 * c = &C; + // First we ensure that both triangles are counterclockwise + // oriented, t1 and t2 are supposed to be non flat. - // First we ensure that both triangles are counterclockwise - // oriented, t1 and t2 are supposed to be non flat. + if(coplanar_orientation(P,Q,R) == NEGATIVE) + { + q = &R; + r = &Q; + } - if ( coplanar_orientation(P,Q,R) == NEGATIVE ) { - q = &R; - r = &Q; + if(coplanar_orientation(A,B,C) == NEGATIVE) + { + b = &C; + c = &B; + } + + // Localization of p in the arrangement of the + // lines supporting abc's edges + + if(coplanar_orientation(*a,*b,*p) != NEGATIVE) + { + if(coplanar_orientation(*b,*c,*p) != NEGATIVE) + { + if(coplanar_orientation(*c,*a,*p) != NEGATIVE) + // p is inside triangle abc + return true; + + // p sees ac + return internal::_intersection_test_edge(p,q,r,a,b,c,k); } - if ( coplanar_orientation(A,B,C) == NEGATIVE ) { - b = &C; - c = &B; - } + if(coplanar_orientation(*c,*a,*p) != NEGATIVE )//p sees bc + return internal::_intersection_test_edge(p,q,r,c,a,b,k); + // p sees c + return internal::_intersection_test_vertex(p,q,r,a,b,c,k); + } - // Localization of p in the arrangement of the - // lines supporting abc's edges + if(coplanar_orientation(*b,*c,*p) != NEGATIVE ) + { + if(coplanar_orientation(*c,*a,*p) != NEGATIVE ) //p sees ab + return internal::_intersection_test_edge(p,q,r,b,c,a,k); - if ( coplanar_orientation(*a,*b,*p) != NEGATIVE ) { - if ( coplanar_orientation(*b,*c,*p) != NEGATIVE ) { - if ( coplanar_orientation(*c,*a,*p) != NEGATIVE ) - // p is inside triangle abc - return true; - // p sees ac - return internal::_intersection_test_edge(p,q,r,a,b,c,k); - } - if ( coplanar_orientation(*c,*a,*p) != NEGATIVE )//p sees bc - return internal::_intersection_test_edge(p,q,r,c,a,b,k); - // p sees c - return internal::_intersection_test_vertex(p,q,r,a,b,c,k); - - } - if ( coplanar_orientation(*b,*c,*p) != NEGATIVE ) { - if ( coplanar_orientation(*c,*a,*p) != NEGATIVE ) //p sees ab - return internal::_intersection_test_edge(p,q,r,b,c,a,k); - // p sees a - return internal::_intersection_test_vertex(p,q,r,b,c,a,k); - } - // p sees b - return internal::_intersection_test_vertex(p,q,r,c,a,b,k); + // p sees a + return internal::_intersection_test_vertex(p,q,r,b,c,a,k); + } + // p sees b + return internal::_intersection_test_vertex(p,q,r,c,a,b,k); } - template typename K::Boolean -do_intersect(const typename K::Triangle_3 &t1, - const typename K::Triangle_3 &t2, - const K & k) +do_intersect(const typename K::Triangle_3& t1, + const typename K::Triangle_3& t2, + const K& k) { - CGAL_kernel_precondition( ! k.is_degenerate_3_object() (t1) ); - CGAL_kernel_precondition( ! k.is_degenerate_3_object() (t2) ); - typedef typename K::Point_3 Point_3; - typename K::Construct_vertex_3 vertex_on = - k.construct_vertex_3_object(); + CGAL_kernel_precondition(!k.is_degenerate_3_object() (t1) ); + CGAL_kernel_precondition(!k.is_degenerate_3_object() (t2) ); - typename K::Orientation_3 orientation = - k.orientation_3_object(); + typename K::Construct_vertex_3 vertex_on = k.construct_vertex_3_object(); + typename K::Orientation_3 orientation = k.orientation_3_object(); + const Point_3& p = vertex_on(t1,0); + const Point_3& q = vertex_on(t1,1); + const Point_3& r = vertex_on(t1,2); + const Point_3& a = vertex_on(t2,0); + const Point_3& b = vertex_on(t2,1); + const Point_3& c = vertex_on(t2,2); - const Point_3 & p = vertex_on(t1,0); - const Point_3 & q = vertex_on(t1,1); - const Point_3 & r = vertex_on(t1,2); - const Point_3 & a = vertex_on(t2,0); - const Point_3 & b = vertex_on(t2,1); - const Point_3 & c = vertex_on(t2,2); + const Point_3* s_min1; + const Point_3* t_min1; + const Point_3* s_max1; + const Point_3* t_max1; + // Compute distance signs of p, q and r to the plane of triangle(a,b,c) + const Orientation dp = make_certain(orientation(a,b,c,p)); + const Orientation dq = make_certain(orientation(a,b,c,q)); + const Orientation dr = make_certain(orientation(a,b,c,r)); - const Point_3 * s_min1; - const Point_3 * t_min1; - const Point_3 * s_max1; - const Point_3 * t_max1; - - // Compute distance signs of p, q and r to the plane of triangle(a,b,c) - const Orientation dp = make_certain(orientation(a,b,c,p)); - const Orientation dq = make_certain(orientation(a,b,c,q)); - const Orientation dr = make_certain(orientation(a,b,c,r)); - - - switch ( dp ) { + switch(dp) + { case POSITIVE: - if ( dq == POSITIVE ) { - if ( dr == POSITIVE) + if(dq == POSITIVE) + { + if(dr == POSITIVE) // pqr lies in the open positive halfspace induced by // the plane of triangle(a,b,c) return false; // r is isolated on the negative side of the plane - s_min1 = &q ; t_min1 = &r ; s_max1 = &r ; t_max1 = &p; - - } else { - if ( dr == POSITIVE) { + s_min1 = &q; t_min1 = &r; s_max1 = &r; t_max1 = &p; + } + else + { + if(dr == POSITIVE) + { // q is isolated on the negative side of the plane s_min1 = &p; t_min1 = &q; s_max1 = &q; t_max1 = &r; - } else { + } + else + { // p is isolated on the positive side of the plane s_min1 = &p; t_min1 = &q; s_max1 = &r; t_max1 = &p; } @@ -252,16 +234,20 @@ do_intersect(const typename K::Triangle_3 &t1, break; case NEGATIVE: - if ( dq == NEGATIVE ) { - if ( dr == NEGATIVE ) + if(dq == NEGATIVE) + { + if(dr == NEGATIVE) // pqr lies in the open negative halfspace induced by // the plane of triangle(a,b,c) return false; // r is isolated on the positive side of the plane s_min1 = &r; t_min1 = &p; s_max1 = &q; t_max1 = &r; - } else { - if ( dr == NEGATIVE ) { + } + else + { + if(dr == NEGATIVE) + { // q is isolated on the positive side of the plane s_min1 = &q; t_min1 = &r; s_max1 = &p; t_max1 = &q; } else { @@ -272,88 +258,97 @@ do_intersect(const typename K::Triangle_3 &t1, break; case COPLANAR: - switch ( dq ) { - case POSITIVE: - if ( dr == POSITIVE ) { - // p is isolated on the negative side of the plane - s_min1 = &r; t_min1 = &p; s_max1 = &p; t_max1 = &q; - } else { - // q is isolated on the positive side of the plane - s_min1 = &q; t_min1 = &r; s_max1 = &p; t_max1 = &q; - } - break; - - case NEGATIVE: - if ( dr == NEGATIVE ) { - // p is isolated on the positive side of the plane - s_min1 = &p; t_min1 = &q; s_max1 = &r; t_max1 = &p; - } else { - // q is isolated on the negative side of the plane - s_min1 = &p; t_min1 = &q; s_max1 = &q; t_max1 = &r; - } - break; - - case COPLANAR: - switch ( dr ) { + switch(dq) + { case POSITIVE: - // r is isolated on the positive side of the plane - s_min1 = &r; t_min1 = &p; s_max1 = &q; t_max1 = &r; + if(dr == POSITIVE ) + { + // p is isolated on the negative side of the plane + s_min1 = &r; t_min1 = &p; s_max1 = &p; t_max1 = &q; + } + else + { + // q is isolated on the positive side of the plane + s_min1 = &q; t_min1 = &r; s_max1 = &p; t_max1 = &q; + } break; case NEGATIVE: - // r is isolated on the negative side of the plane - s_min1 = &q ; t_min1 = &r ; s_max1 = &r ; t_max1 = &p; + if(dr == NEGATIVE ) + { + // p is isolated on the positive side of the plane + s_min1 = &p; t_min1 = &q; s_max1 = &r; t_max1 = &p; + } + else + { + // q is isolated on the negative side of the plane + s_min1 = &p; t_min1 = &q; s_max1 = &q; t_max1 = &r; + } break; case COPLANAR: - return do_intersect_coplanar(t1,t2,k); + switch(dr) + { + case POSITIVE: + // r is isolated on the positive side of the plane + s_min1 = &r; t_min1 = &p; s_max1 = &q; t_max1 = &r; + break; + + case NEGATIVE: + // r is isolated on the negative side of the plane + s_min1 = &q; t_min1 = &r; s_max1 = &r; t_max1 = &p; + break; + + case COPLANAR: + return do_intersect_coplanar(t1,t2,k); + default: // should not happen. + CGAL_kernel_assertion(false); + return false; + } + break; + default: // should not happen. CGAL_kernel_assertion(false); return false; - - } - break; - - default: // should not happen. - CGAL_kernel_assertion(false); - return false; - } break; default: // should not happen. CGAL_kernel_assertion(false); return false; - } + } + const Point_3* s_min2; + const Point_3* t_min2; + const Point_3* s_max2; + const Point_3* t_max2; + // Compute distance signs of a, b and c to the plane of triangle(p,q,r) + const Orientation da = make_certain(orientation(p,q,r,a)); + const Orientation db = make_certain(orientation(p,q,r,b)); + const Orientation dc = make_certain(orientation(p,q,r,c)); - const Point_3 * s_min2; - const Point_3 * t_min2; - const Point_3 * s_max2; - const Point_3 * t_max2; - - // Compute distance signs of a, b and c to the plane of triangle(p,q,r) - const Orientation da = make_certain(orientation(p,q,r,a)); - const Orientation db = make_certain(orientation(p,q,r,b)); - const Orientation dc = make_certain(orientation(p,q,r,c)); - - - switch ( da ) { + switch(da) + { case POSITIVE: - if ( db == POSITIVE ) { - if ( dc == POSITIVE) + if(db == POSITIVE) + { + if(dc == POSITIVE) // abc lies in the open positive halfspace induced by // the plane of triangle(p,q,r) return false; // c is isolated on the negative side of the plane - s_min2 = &b ; t_min2 = &c ; s_max2 = &c ; t_max2 = &a; - - } else { - if ( dc == POSITIVE) { + s_min2 = &b; t_min2 = &c; s_max2 = &c; t_max2 = &a; + } + else + { + if(dc == POSITIVE) + { // b is isolated on the negative side of the plane s_min2 = &a; t_min2 = &b; s_max2 = &b; t_max2 = &c; - } else { + } + else + { // a is isolated on the positive side of the plane s_min2 = &a; t_min2 = &b; s_max2 = &c; t_max2 = &a; } @@ -361,89 +356,99 @@ do_intersect(const typename K::Triangle_3 &t1, break; case NEGATIVE: - if ( db == NEGATIVE ) { - if ( dc == NEGATIVE ) + if(db == NEGATIVE) + { + if(dc == NEGATIVE) // abc lies in the open negative halfspace induced by // the plane of triangle(p,q,r) return false; // c is isolated on the positive side of the plane - s_min2 = &c ; t_min2 = &a ; s_max2 = &b ; t_max2 = &c; + s_min2 = &c; t_min2 = &a; s_max2 = &b; t_max2 = &c; - } else { - if ( dc == NEGATIVE ) { + } + else + { + if(dc == NEGATIVE) + { // b is isolated on the positive side of the plane - s_min2 = &b ; t_min2 = &c ; s_max2 = &a ; t_max2 = &b; + s_min2 = &b; t_min2 = &c; s_max2 = &a; t_max2 = &b; } else { // a is isolated on the negative side of the plane - s_min2 = &c ; t_min2 = &a ; s_max2 = &a ; t_max2 = &b; + s_min2 = &c; t_min2 = &a; s_max2 = &a; t_max2 = &b; } } break; case COPLANAR: - switch ( db ) { - case POSITIVE: - if ( dc == POSITIVE ) { - // a is isolated on the negative side of the plane - s_min2 = &c ; t_min2 = &a ; s_max2 = &a ; t_max2 = &b; - } else { - // b is isolated on the positive side of the plane - s_min2 = &b ; t_min2 = &c ; s_max2 = &a ; t_max2 = &b; - } - break; - - case NEGATIVE: - if ( dc == NEGATIVE ) { - // a is isolated on the positive side of the plane - s_min2 = &a ; t_min2 = &b ; s_max2 = &c ; t_max2 = &a; - } else { - // b is isolated on the negative side of the plane - s_min2 = &a ; t_min2 = &b ; s_max2 = &b ; t_max2 = &c; - } - break; - - case COPLANAR: - switch ( dc ) { + switch(db) + { case POSITIVE: - // c is isolated on the positive side of the plane - s_min2 = &c ; t_min2 = &a ; s_max2 = &b ; t_max2 = &c; + if(dc == POSITIVE) + { + // a is isolated on the negative side of the plane + s_min2 = &c; t_min2 = &a; s_max2 = &a; t_max2 = &b; + } + else + { + // b is isolated on the positive side of the plane + s_min2 = &b; t_min2 = &c; s_max2 = &a; t_max2 = &b; + } break; case NEGATIVE: - // c is isolated on the negative side of the plane - s_min2 = &b ; t_min2 = &c ; s_max2 = &c ; t_max2 = &a; + if(dc == NEGATIVE) + { + // a is isolated on the positive side of the plane + s_min2 = &a; t_min2 = &b; s_max2 = &c; t_max2 = &a; + } + else + { + // b is isolated on the negative side of the plane + s_min2 = &a; t_min2 = &b; s_max2 = &b; t_max2 = &c; + } break; case COPLANAR: - // Supposed unreachable code - // since the triangles are assumed to be non-flat + switch(dc) + { + case POSITIVE: + // c is isolated on the positive side of the plane + s_min2 = &c; t_min2 = &a; s_max2 = &b; t_max2 = &c; + break; + + case NEGATIVE: + // c is isolated on the negative side of the plane + s_min2 = &b; t_min2 = &c; s_max2 = &c; t_max2 = &a; + break; + + case COPLANAR: + // Supposed unreachable code + // since the triangles are assumed to be non-flat + + return do_intersect_coplanar(t1,t2,k); + default: // should not happen. + CGAL_kernel_assertion(false); + return false; + } + break; - return do_intersect_coplanar(t1,t2,k); default: // should not happen. CGAL_kernel_assertion(false); return false; - - } - break; - - default: // should not happen. - CGAL_kernel_assertion(false); - return false; - } break; default: // should not happen. CGAL_kernel_assertion(false); return false; - } + } - return orientation(*s_min1,*t_min1,*s_min2,*t_min2) != POSITIVE - && orientation(*s_max1,*t_max1,*t_max2,*s_max2) != POSITIVE; + return (orientation(*s_min1,*t_min1,*s_min2,*t_min2) != POSITIVE) && + (orientation(*s_max1,*t_max1,*t_max2,*s_max2) != POSITIVE); } } // namespace internal } // namespace Intersections -} //namespace CGAL +} // namespace CGAL -#endif // CGAL_TRIANGLE_3_TRIANGLE_3_DO_INTERSECT_H +#endif // CGAL_INTERNAL_INTERSECTIONS_3_TRIANGLE_3_TRIANGLE_3_DO_INTERSECT_H diff --git a/Intersections_3/include/CGAL/Intersections_3/internal/Triangle_3_Triangle_3_intersection.h b/Intersections_3/include/CGAL/Intersections_3/internal/Triangle_3_Triangle_3_intersection.h index 17358b81ea5..fa148adcba2 100644 --- a/Intersections_3/include/CGAL/Intersections_3/internal/Triangle_3_Triangle_3_intersection.h +++ b/Intersections_3/include/CGAL/Intersections_3/internal/Triangle_3_Triangle_3_intersection.h @@ -11,74 +11,81 @@ // Author(s) : Sebastien Loriot // -#ifndef CGAL_TRIANGLE_3_TRIANGLE_3_INTERSECTION_H -#define CGAL_TRIANGLE_3_TRIANGLE_3_INTERSECTION_H +#ifndef CGAL_INTERNAL_INTERSECTIONS_TRIANGLE_3_TRIANGLE_3_INTERSECTION_H +#define CGAL_INTERNAL_INTERSECTIONS_TRIANGLE_3_TRIANGLE_3_INTERSECTION_H #include -#include +#include +#include +#include + +#include #include + #include -#include #include +#include namespace CGAL { - - template - class Triangle_3; - namespace Intersections { - namespace internal{ template -void intersection_coplanar_triangles_cutoff( - const typename Kernel::Point_3& p, - const typename Kernel::Point_3& q, - const typename Kernel::Point_3& r, - const Kernel& k, - std::list& inter_pts -) +void intersection_coplanar_triangles_cutoff(const typename Kernel::Point_3& p, + const typename Kernel::Point_3& q, + const typename Kernel::Point_3& r, + const Kernel& k, + std::list& inter_pts) { - if ( inter_pts.empty() ) return; typedef typename std::list::iterator Iterator; - typename Kernel::Coplanar_orientation_3 orient=k.coplanar_orientation_3_object(); - typename Kernel::Construct_line_3 Line_3=k.construct_line_3_object(); + + if(inter_pts.empty()) + return; + + typename Kernel::Coplanar_orientation_3 orient = k.coplanar_orientation_3_object(); + typename Kernel::Construct_line_3 line = k.construct_line_3_object(); + //orient(p,q,r,r) is POSITIVE std::map orientations; for (Iterator it=inter_pts.begin();it!=inter_pts.end();++it) orientations[ &(*it) ]=orient(p,q,r,*it); - int pt_added=0; + int pt_added = 0; const typename Kernel::Point_3* prev = &(*boost::prior(inter_pts.end())); Iterator stop = inter_pts.size() > 2 ? inter_pts.end() : boost::prior(inter_pts.end()); - for (Iterator it=inter_pts.begin();it!=stop;++it) + for(Iterator it=inter_pts.begin(); it!=stop; ++it) { - const typename Kernel::Point_3& curr=*it; - Orientation or_prev=orientations[prev],or_curr=orientations[&curr]; - if ( (or_prev==POSITIVE && or_curr==NEGATIVE) || (or_prev==NEGATIVE && or_curr==POSITIVE) ) + const typename Kernel::Point_3& curr = *it; + Orientation or_prev = orientations[prev], + or_curr = orientations[&curr]; + + if((or_prev == POSITIVE && or_curr == NEGATIVE) || + (or_prev == NEGATIVE && or_curr == POSITIVE)) { - typename Intersection_traits - ::result_type - obj = intersection(Line_3(p,q),Line_3(*prev,curr),k); + typename Intersection_traits::result_type + obj = intersection(line(p,q), line(*prev,curr), k); + // assert "not empty" CGAL_kernel_assertion(bool(obj)); - const typename Kernel::Point_3* inter=intersect_get(obj); - CGAL_kernel_assertion(inter!=nullptr); - prev=&(* inter_pts.insert(it,*inter) ); - orientations[prev]=COLLINEAR; + + const typename Kernel::Point_3* inter = intersect_get(obj); + CGAL_kernel_assertion(inter != nullptr); + + prev = &(*inter_pts.insert(it,*inter)); + orientations[prev] = COLLINEAR; ++pt_added; } - prev=&(*it); + + prev = &(*it); } CGAL_kernel_assertion(pt_added<3); - Iterator it=inter_pts.begin(); + Iterator it = inter_pts.begin(); while(it!=inter_pts.end()) { - if (orientations[&(*it)]==NEGATIVE) + if(orientations[&(*it)] == NEGATIVE) inter_pts.erase(it++); else ++it; @@ -87,12 +94,13 @@ void intersection_coplanar_triangles_cutoff( template typename Intersection_traits::result_type -intersection_coplanar_triangles( - const typename K::Triangle_3& t1, - const typename K::Triangle_3& t2, - const K& k) +intersection_coplanar_triangles(const typename K::Triangle_3& t1, + const typename K::Triangle_3& t2, + const K& k) { - const typename K::Point_3& p=t1.vertex(0),q=t1.vertex(1),r=t1.vertex(2); + const typename K::Point_3& p = t1.vertex(0), + q = t1.vertex(1), + r = t1.vertex(2); std::list inter_pts; inter_pts.push_back(t2.vertex(0)); @@ -104,55 +112,57 @@ intersection_coplanar_triangles( intersection_coplanar_triangles_cutoff(q,r,p,k,inter_pts); //line qr intersection_coplanar_triangles_cutoff(r,p,q,k,inter_pts); //line rp - switch ( inter_pts.size() ) { + switch(inter_pts.size()) + { case 0: return intersection_return(); case 1: - return intersection_return( * inter_pts.begin() ); + return intersection_return(*inter_pts.begin()); case 2: - return intersection_return( k.construct_segment_3_object()(*inter_pts.begin(), - *boost::next(inter_pts.begin())) ); + return intersection_return( + k.construct_segment_3_object()(*inter_pts.begin(), *boost::next(inter_pts.begin())) ); case 3: - return intersection_return( k.construct_triangle_3_object()(*inter_pts.begin(), - *boost::next(inter_pts.begin()), - *boost::prior(inter_pts.end())) ); + return intersection_return( + k.construct_triangle_3_object()(*inter_pts.begin(), *boost::next(inter_pts.begin()), *boost::prior(inter_pts.end())) ); default: - return intersection_return( std::vector(inter_pts.begin(),inter_pts.end()) ); + return intersection_return( + std::vector(inter_pts.begin(),inter_pts.end())); } } template -struct Triangle_Line_visitor { - typedef typename Intersection_traits - ::result_type result_type; +struct Triangle_Line_visitor +{ + typedef typename Intersection_traits::result_type result_type; - result_type - operator()(const typename K::Point_3& p, const typename K::Segment_3& s) const { - if ( typename K::Has_on_3()(s,p) ) + result_type operator()(const typename K::Point_3& p, const typename K::Segment_3& s) const + { + if(typename K::Has_on_3()(s, p)) return intersection_return(p); else return result_type(); } - result_type - operator()(const typename K::Segment_3& s, const typename K::Point_3& p) const { + result_type operator()(const typename K::Segment_3& s, const typename K::Point_3& p) const + { return operator()(p,s); } - result_type - operator()(const typename K::Point_3& p1, const typename K::Point_3& p2) const { - if (p1==p2) + result_type operator()(const typename K::Point_3& p1, const typename K::Point_3& p2) const + { + if(p1 == p2) return intersection_return(p1); else return result_type(); } - result_type - operator()(const typename K::Segment_3& s1, const typename K::Segment_3& s2) const { + result_type operator()(const typename K::Segment_3& s1, const typename K::Segment_3& s2) const + { typename Intersection_traits::result_type v = intersection_collinear_segments(s1,s2,K()); - if(v) { + if(v) + { if(const typename K::Segment_3* s = intersect_get(v)) return intersection_return(*s); if(const typename K::Point_3* p = intersect_get(v)) @@ -165,48 +175,48 @@ struct Triangle_Line_visitor { template typename Intersection_traits::result_type -intersection( - const typename K::Triangle_3& t1, - const typename K::Triangle_3& t2, - const K& k) +intersection(const typename K::Triangle_3& t1, + const typename K::Triangle_3& t2, + const K& k) { CGAL_precondition(!t1.is_degenerate() && !t2.is_degenerate()); typename Intersection_traits::result_type v = internal::intersection(t1.supporting_plane(), t2.supporting_plane(), k); - if(!v) { + if(!v) + { // empty plane plane intersection return intersection_return(); } - if(intersect_get(v)) { + if(intersect_get(v)) + { //coplanar triangles return intersection_coplanar_triangles(t1,t2,k); } - if(const typename K::Line_3* line=intersect_get(v)) { + if(const typename K::Line_3* line=intersect_get(v)) + { //The supporting planes of the triangles intersect along a line. - typedef - typename Intersection_traits::result_type - Triangle_Line_Inter; + typedef typename Intersection_traits::result_type Triangle_Line_Inter; Triangle_Line_Inter inter1 = intersection_coplanar(t1,*line,k); Triangle_Line_Inter inter2 = intersection_coplanar(t2,*line,k); - if(!inter1 || !inter2) { + if(!inter1 || !inter2) + { // one of the intersection is empty return intersection_return(); } + return boost::apply_visitor(Triangle_Line_visitor(), *inter1, *inter2); } + return intersection_return(); } -} //namespace internal +} // namespace internal } // namespace Intersections } // namespace CGAL - - - -#endif //CGAL_TRIANGLE_3_TRIANGLE_3_INTERSECTION_H +#endif // CGAL_INTERNAL_INTERSECTIONS_TRIANGLE_3_TRIANGLE_3_INTERSECTION_H diff --git a/Intersections_3/include/CGAL/Intersections_3/internal/bbox_intersection_3.h b/Intersections_3/include/CGAL/Intersections_3/internal/bbox_intersection_3.h deleted file mode 100644 index 4bfa6a2d882..00000000000 --- a/Intersections_3/include/CGAL/Intersections_3/internal/bbox_intersection_3.h +++ /dev/null @@ -1,172 +0,0 @@ -// Copyright (c) 1997 -// Utrecht University (The Netherlands), -// ETH Zurich (Switzerland), -// INRIA Sophia-Antipolis (France), -// Max-Planck-Institute Saarbruecken (Germany), -// and Tel-Aviv University (Israel). All rights reserved. -// -// This file is part of CGAL (www.cgal.org) -// -// $URL$ -// $Id$ -// SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-Commercial -// -// -// Author(s) : Geert-Jan Giezeman - - -#ifndef CGAL_BBOX_INTERSECTION_3_H -#define CGAL_BBOX_INTERSECTION_3_H - -#include -#include - -namespace CGAL { - -namespace Intersections { - - namespace internal { -// This function intersects a bbox with a ray, line or segment -// Its essentially a copy of the function that was in Bbox_3_intersections.cpp -// But it must be a template function since the original kernel must be -// taken into account. (Michael.Hemmer@sophia.inria.fr) -template -typename boost::optional< boost::variant< - typename K::Segment_3, - typename K::Point_3 > > -intersection_bl(const Bbox_3 &box, - double lpx, double lpy, double lpz, - double ldx, double ldy, double ldz, - bool min_infinite, bool max_infinite) -{ - typedef - typename - boost::optional< - boost::variant< typename K::Segment_3, - typename K::Point_3 > > - result_type; - - double seg_min = 0.0, seg_max = 1.0; - // first on x value - if (ldx == 0.0) { - if (lpx < box.xmin()) - return result_type(); - if (lpx > box.xmax()) - return result_type(); - } else { - double newmin, newmax; - if (ldx > 0.0) { - newmin = (box.xmin()-lpx)/ldx; - newmax = (box.xmax()-lpx)/ldx; - } else { - newmin = (box.xmax()-lpx)/ldx; - newmax = (box.xmin()-lpx)/ldx; - } - if (min_infinite) { - min_infinite = false; - seg_min = newmin; - } else { - if (newmin > seg_min) - seg_min = newmin; - } - if (max_infinite) { - max_infinite = false; - seg_max = newmax; - } else { - if (newmax < seg_max) - seg_max = newmax; - } - if (seg_max < seg_min) - return result_type(); - } -// now on y value - if (ldy == 0.0) { - if (lpy < box.ymin()) - return result_type(); - if (lpy > box.ymax()) - return result_type(); - } else { - double newmin, newmax; - if (ldy > 0.0) { - newmin = (box.ymin()-lpy)/ldy; - newmax = (box.ymax()-lpy)/ldy; - } else { - newmin = (box.ymax()-lpy)/ldy; - newmax = (box.ymin()-lpy)/ldy; - } - if (min_infinite) { - min_infinite = false; - seg_min = newmin; - } else { - if (newmin > seg_min) - seg_min = newmin; - } - if (max_infinite) { - max_infinite = false; - seg_max = newmax; - } else { - if (newmax < seg_max) - seg_max = newmax; - } - if (seg_max < seg_min) - return result_type(); - } -// now on z value - if (ldz == 0.0) { - if (lpz < box.zmin()) - return result_type(); - if (lpz > box.zmax()) - return result_type(); - } else { - double newmin, newmax; - if (ldz > 0.0) { - newmin = (box.zmin()-lpz)/ldz; - newmax = (box.zmax()-lpz)/ldz; - } else { - newmin = (box.zmax()-lpz)/ldz; - newmax = (box.zmin()-lpz)/ldz; - } - if (min_infinite) { - min_infinite = false; - seg_min = newmin; - } else { - if (newmin > seg_min) - seg_min = newmin; - } - if (max_infinite) { - max_infinite = false; - seg_max = newmax; - } else { - if (newmax < seg_max) - seg_max = newmax; - } - if (seg_max < seg_min) - return result_type(); - } - if (min_infinite || max_infinite) { - seg_max = 0.0; - CGAL_kernel_assertion_msg(true, - "Zero direction vector of line detected."); - } - - typedef typename K::FT FT; - typedef typename K::Point_3 Point_3; - typedef typename K::Vector_3 Vector_3; - typedef typename K::Segment_3 Segment_3; - - Point_3 ref_point = Point_3( FT(lpx), FT(lpy), FT(lpz)); - Vector_3 dir = Vector_3( FT(ldx), FT(ldy), FT(ldz)); - - if (seg_max == seg_min) { - return result_type(ref_point + dir * FT(seg_max)); - } - return result_type( - Segment_3(ref_point + dir*FT(seg_min), ref_point + dir*FT(seg_max))); -} - -} // namespace internal -} // namespace Intersections - -} //namespace CGAL - -#endif // CGAL_BBOX_INTERSECTION_3_H diff --git a/Intersections_3/include/CGAL/Intersections_3/internal/intersection_3_1_impl.h b/Intersections_3/include/CGAL/Intersections_3/internal/intersection_3_1_impl.h deleted file mode 100644 index 0c49c9e72b0..00000000000 --- a/Intersections_3/include/CGAL/Intersections_3/internal/intersection_3_1_impl.h +++ /dev/null @@ -1,1811 +0,0 @@ -// Copyright (c) 1997-2010 -// Utrecht University (The Netherlands), -// ETH Zurich (Switzerland), -// INRIA Sophia-Antipolis (France), -// Max-Planck-Institute Saarbruecken (Germany), -// and Tel-Aviv University (Israel). All rights reserved. -// -// This file is part of CGAL (www.cgal.org) -// -// $URL$ -// $Id$ -// SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-Commercial -// -// -// Author(s) : Geert-Jan Giezeman -// Sebastien Loriot - -#ifndef CGAL_INTERSECTIONS_3_INTERNAL_INTERSECTION_3_1_IMPL_H -#define CGAL_INTERSECTIONS_3_INTERNAL_INTERSECTION_3_1_IMPL_H - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -namespace CGAL { - - template - class Plane_3; - - template - class Line_3; - - template - class Segment_3; - - template - class Ray_3; - - template - class Sphere_3; - - template - class Triangle_3; - - template - class Iso_cuboid_3; - - template - class Point_3; - -// the special plane_3 function -template -inline -decltype(auto) -intersection(const Plane_3 &plane1, const Plane_3 &plane2, - const Plane_3 &plane3) -{ - return K().intersect_3_object()(plane1, plane2, plane3); -} - - - -template -inline bool -do_intersect(const Plane_3 &plane1, const Plane_3 &plane2, - const Plane_3 &plane3) { - return R().do_intersect_3_object()(plane1, plane2, plane3); -} - - - - -namespace Intersections { -namespace internal { - -template -boost::optional -intersection_point(const typename K::Plane_3 &plane, - const typename K::Line_3 &line, - const K& /*k*/) -{ - typedef typename K::Point_3 Point_3; - typedef typename K::Direction_3 Direction_3; - typedef typename K::RT RT; - - const Point_3 &line_pt = line.point(); - const Direction_3 &line_dir = line.direction(); - - RT num = plane.a()*line_pt.hx() + plane.b()*line_pt.hy() - + plane.c()*line_pt.hz() + wmult_hw((K*)0, plane.d(), line_pt); - RT den = plane.a()*line_dir.dx() + plane.b()*line_dir.dy() - + plane.c()*line_dir.dz(); - if (den == 0) { - return boost::none; - } - return boost::make_optional(Point_3(den*line_pt.hx()-num*line_dir.dx(), - den*line_pt.hy()-num*line_dir.dy(), - den*line_pt.hz()-num*line_dir.dz(), - wmult_hw((K*)0, den, line_pt))); -} - - -template -typename Intersection_traits::result_type -intersection(const typename K::Plane_3 &plane, - const typename K::Line_3 &line, - const K& /*k*/) -{ - typedef typename K::Point_3 Point_3; - typedef typename K::Direction_3 Direction_3; - typedef typename K::RT RT; - - const Point_3 &line_pt = line.point(); - const Direction_3 &line_dir = line.direction(); - - RT num = plane.a()*line_pt.hx() + plane.b()*line_pt.hy() - + plane.c()*line_pt.hz() + wmult_hw((K*)0, plane.d(), line_pt); - RT den = plane.a()*line_dir.dx() + plane.b()*line_dir.dy() - + plane.c()*line_dir.dz(); - if (den == 0) { - if (num == 0) { - // all line - return intersection_return(line); - } else { - // no intersection - return intersection_return(); - } - } - return intersection_return(Point_3( - den*line_pt.hx()-num*line_dir.dx(), - den*line_pt.hy()-num*line_dir.dy(), - den*line_pt.hz()-num*line_dir.dz(), - wmult_hw((K*)0, den, line_pt))); -} - -template -inline -typename Intersection_traits::result_type -intersection(const typename K::Line_3 &line, - const typename K::Plane_3 &plane, - const K& k) -{ - return intersection(plane, line, k); -} - -template -typename Intersection_traits::result_type -intersection(const typename K::Plane_3 &plane1, - const typename K::Plane_3 &plane2, - const K&) -{ - typedef typename K::Point_3 Point_3; - typedef typename K::Direction_3 Direction_3; - typedef typename K::Line_3 Line_3; - - typedef typename K::RT RT; - const RT &a = plane1.a(); - const RT &b = plane1.b(); - const RT &c = plane1.c(); - const RT &d = plane1.d(); - const RT &p = plane2.a(); - const RT &q = plane2.b(); - const RT &r = plane2.c(); - const RT &s = plane2.d(); - - RT det = a*q-p*b; - if (det != 0) { - Point_3 is_pt = Point_3(b*s-d*q, p*d-a*s, 0, det); - Direction_3 is_dir = Direction_3(b*r-c*q, p*c-a*r, det); - return intersection_return(Line_3(is_pt, is_dir)); - } - det = a*r-p*c; - if (det != 0) { - Point_3 is_pt = Point_3(c*s-d*r, 0, p*d-a*s, det); - Direction_3 is_dir = Direction_3(c*q-b*r, det, p*b-a*q); - return intersection_return(Line_3(is_pt, is_dir)); - } - det = b*r-c*q; - if (det != 0) { - Point_3 is_pt = Point_3(0, c*s-d*r, d*q-b*s, det); - Direction_3 is_dir = Direction_3(det, c*p-a*r, a*q-b*p); - return intersection_return(Line_3(is_pt, is_dir)); - } -// degenerate case - if (a!=0 || p!=0) { - if (a*s == p*d) - return intersection_return(plane1); - else - return intersection_return(); - } - if (b!=0 || q!=0) { - if (b*s == q*d) - return intersection_return(plane1); - else - return intersection_return(); - } - if (c!=0 || r!=0) { - if (c*s == r*d) - return intersection_return(plane1); - else - return intersection_return(); - } - return intersection_return(plane1); -} - - - // triple plane intersection -template -boost::optional -intersection_point(const typename K::Plane_3 &plane1, - const typename K::Plane_3 &plane2, - const typename K::Plane_3 &plane3, - const K&) -{ - typedef typename K::FT FT; - const FT &m00 = plane1.a(); - const FT &m01 = plane1.b(); - const FT &m02 = plane1.c(); - const FT &b0 = - plane1.d(); - const FT &m10 = plane2.a(); - const FT &m11 = plane2.b(); - const FT &m12 = plane2.c(); - const FT &b1 = - plane2.d(); - const FT &m20 = plane3.a(); - const FT &m21 = plane3.b(); - const FT &m22 = plane3.c(); - const FT &b2 = - plane3.d(); - - // Minors common to two determinants - const FT minor_0 = m00*m11 - m10*m01; - const FT minor_1 = m00*m21 - m20*m01; - const FT minor_2 = m10*m21 - m20*m11; - - const FT den = minor_0*m22 - minor_1*m12 + minor_2*m02; // determinant of M - - if(is_zero(den)){ - return boost::none; - } - - const FT num3 = minor_0*b2 - minor_1*b1 + minor_2*b0; // determinant of M with M[x:2] swapped with [b0,b1,b2] - - // Minors common to two determinants - const FT minor_3 = b0*m12 - b1*m02; - const FT minor_4 = b0*m22 - b2*m02; - const FT minor_5 = b1*m22 - b2*m12; - - // num1 has opposite signs because b0 and M[:1] have been swapped - const FT num1 = - minor_3*m21 + minor_4*m11 - minor_5*m01; // determinant of M with M[x:0] swapped with [b0,b1,b2] - const FT num2 = minor_3*m20 - minor_4*m10 + minor_5*m00; // determinant of M with M[x:1] swapped with [b0,b1,b2] - - return boost::make_optional(typename K::Point_3(num1/den, num2/den, num3/den)); -} - - -template -boost::optional< boost::variant > -intersection(const typename K::Plane_3 &plane1, - const typename K::Plane_3 &plane2, - const typename K::Plane_3 &plane3, - const K& k) -{ - typedef - typename boost::optional< - boost::variant > - result_type; - - typedef typename K::Point_3 Point_3; - typedef typename K::Line_3 Line_3; - typedef typename K::Plane_3 Plane_3; - - // Intersection between plane1 and plane2 can either be - // a line, a plane, or empty. - typename Intersection_traits::result_type - o12 = internal::intersection(plane1, plane2, k); - - if(o12) { - if(const Line_3* l = intersect_get(o12)) { - // either point or line - typename Intersection_traits::result_type - v = internal::intersection(plane3, *l, k); - if(v) { - if(const Point_3* p = intersect_get(v)) - return result_type(*p); - else if(const Line_3* l = intersect_get(v)) - return result_type(*l); - } - } else if(const Plane_3 *pl = intersect_get(o12)) { - // either line or plane - typename Intersection_traits::result_type - v = internal::intersection(plane3, *pl, k); - if(v) { - if(const Plane_3* p = intersect_get(v)) - return result_type(*p); - else if(const Line_3* l = intersect_get(v)) - return result_type(*l); - } - } - } - - return result_type(); -} - - -template -bool -do_intersect(const typename K::Plane_3 &plane, - const typename K::Line_3 &line, - const K&) -{ - typedef typename K::Point_3 Point_3; - typedef typename K::Direction_3 Direction_3; - typedef typename K::RT RT; - const Point_3 &line_pt = line.point(); - const Direction_3 &line_dir = line.direction(); - - RT den = plane.a()*line_dir.dx() + plane.b()*line_dir.dy() - + plane.c()*line_dir.dz(); - if (den != 0) - return true; - RT num = plane.a()*line_pt.hx() + plane.b()*line_pt.hy() - + plane.c()*line_pt.hz() + wmult_hw((K*)0, plane.d(), line_pt); - if (num == 0) { - // all line - return true; - } else { - // no intersection - return false; - } -} - -template -inline -bool -do_intersect(const typename K::Line_3 &line, - const typename K::Plane_3 &plane, - const K& k) -{ - return do_intersect(plane, line, k); -} - -template -typename Intersection_traits::result_type -intersection(const typename K::Line_3 &l1, - const typename K::Line_3 &l2, - const K&) -{ - typedef typename K::FT FT; - typedef typename K::Point_3 Point_3; - typedef typename K::Vector_3 Vector_3; - - if(K().has_on_3_object()(l1, l2.point())) { - const Vector_3& v1 = l1.to_vector(); - const Vector_3& v2 = l2.to_vector(); - if((v1.x() * v2.y() == v1.y() * v2.x()) && - (v1.x() * v2.z() == v1.z() * v2.x()) && - (v1.y() * v2.z() == v1.z() * v2.y())) - return intersection_return(l1); - } - - if(K().are_parallel_3_object()(l1,l2)) return intersection_return(); - const Point_3 &p1 = l1.point(); - const Point_3 &p3 = l2.point(); - const Vector_3 &v1 = l1.to_vector(); - const Vector_3 &v2 = l2.to_vector(); - const Point_3 p2 = p1 + v1; - const Point_3 p4 = p2 + v2; - if(!K().coplanar_3_object()(p1,p2,p3,p4)) return intersection_return(); - const Vector_3 v3 = p3 - p1; - const Vector_3 v3v2 = cross_product(v3,v2); - const Vector_3 v1v2 = cross_product(v1,v2); - const FT sl = v1v2.squared_length(); - if(certainly(is_zero(sl))) - return intersection_return(); - const FT t = ((v3v2.x()*v1v2.x()) + (v3v2.y()*v1v2.y()) + (v3v2.z()*v1v2.z())) / sl; - - return intersection_return(p1 + (v1 * t)); -} - -template -bool -do_intersect(const typename K::Line_3 &l1, - const typename K::Line_3 &l2, - const K&) -{ - typedef typename K::Point_3 Point_3; - typedef typename K::Vector_3 Vector_3; - - if(K().has_on_3_object()(l1, l2.point())) return true; - if(K().are_parallel_3_object()(l1,l2)) return false; - const Point_3 &p1 = l1.point(); - const Point_3 &p3 = l2.point(); - const Vector_3 &v1 = l1.to_vector(); - const Vector_3 &v2 = l2.to_vector(); - const Point_3 p2 = p1 + v1; - const Point_3 p4 = p2 + v2; - return K().coplanar_3_object()(p1,p2,p3,p4); -} - -template -typename Intersection_traits::result_type -intersection_collinear_segments(const typename K::Segment_3 &s1, - const typename K::Segment_3 &s2, - const K& k) -{ - CGAL_precondition(! s1.is_degenerate () && ! s2.is_degenerate () ); - - const typename K::Point_3& p=s1[0],q=s1[1],r=s2[0],s=s2[1]; - typename K::Collinear_are_ordered_along_line_3 cln_order=k.collinear_are_ordered_along_line_3_object(); - - if ( cln_order(p,r,q) ){ - if ( cln_order(p,s,q) ) - return intersection_return(s2); - if ( cln_order(r,p,s) ){ - if (r!=p) return intersection_return( typename K::Segment_3(r,p) ); - if ( cln_order(r,q,s) ) return intersection_return(s1); - return intersection_return(p); - } - return r!=q ? intersection_return( typename K::Segment_3(r,q) ) - : intersection_return(q); - } - - if ( cln_order(p,s,q) ){ - if ( cln_order(r,p,s) ){ - if (s!=p) return intersection_return( typename K::Segment_3(s,p) ); - if (cln_order(r,q,s)) return intersection_return(s1); - return intersection_return(p); - } - return s!=q ? intersection_return( typename K::Segment_3(s,q) ) - : intersection_return(q); - } - - if ( cln_order(r,p,s) ) - return intersection_return(s1); - return intersection_return(); -} - -template -struct L_p_visitor : public boost::static_visitor< - typename Intersection_traits::result_type - > -{ - - typedef typename Intersection_traits::result_type result_type; - L_p_visitor(const typename K::Segment_3& s1, const typename K::Segment_3& s2) : - s1(s1), s2(s2) { } - const typename K::Segment_3& s1; - const typename K::Segment_3& s2; - - result_type - operator()(const typename K::Point_3& p) const { - typename K::Collinear_are_ordered_along_line_3 cln_order=K().collinear_are_ordered_along_line_3_object(); - if ( cln_order(s1[0],p,s1[1]) && cln_order(s2[0],p,s2[1]) ) - return intersection_return(p); - else - return intersection_return(); -} - - result_type - operator()(const typename K::Line_3&) const { - return intersection_collinear_segments(s1,s2,K()); - } -}; - -template -typename Intersection_traits::result_type -intersection(const typename K::Segment_3 &s1, - const typename K::Segment_3 &s2, - const K&) -{ - CGAL_precondition(! s1.is_degenerate () && ! s2.is_degenerate () ); - - typename Intersection_traits::result_type - v = internal::intersection(s1.supporting_line(),s2.supporting_line(), K()); - - if(v) { - return apply_visitor(L_p_visitor(s1, s2) , *v); - } - return intersection_return(); -} - -template -inline -bool -do_intersect(const typename K::Segment_3 &s1, - const typename K::Segment_3 &s2, - const K & k) -{ - CGAL_precondition(! s1.is_degenerate () && ! s2.is_degenerate () ); - bool b=internal::do_intersect(s1.supporting_line(),s2.supporting_line(),k); - if (b) - { - //supporting_line intersects: points are coplanar - typename K::Coplanar_orientation_3 cpl_orient=k.coplanar_orientation_3_object(); - ::CGAL::Orientation or1 = cpl_orient(s1[0],s1[1],s2[0]); - ::CGAL::Orientation or2 = cpl_orient(s1[0],s1[1],s2[1]); - - if ( or1 == COLLINEAR && or2 ==COLLINEAR ) - { - //segments are collinear - typename K::Collinear_are_ordered_along_line_3 cln_order=k.collinear_are_ordered_along_line_3_object(); - return cln_order(s1[0],s2[0],s1[1]) || - cln_order(s1[0],s2[1],s1[1]) || - cln_order(s2[0],s1[0],s2[1]) ; - } - - if ( or1 != or2 ){ - or1=cpl_orient(s2[0],s2[1],s1[0]); - return (or1 == COLLINEAR || or1 != cpl_orient(s2[0],s2[1],s1[1])); - } - } - return false; -} - - -template -typename Intersection_traits::result_type -intersection(const typename K::Line_3 &l, - const typename K::Segment_3 &s, - const K& k) -{ - CGAL_precondition(! l.is_degenerate () && ! s.is_degenerate () ); - - typename Intersection_traits::result_type - v = internal::intersection(l,s.supporting_line(), K()); - - if(v) { - if(const typename K::Point_3* p = intersect_get (v)) { - typename K::Collinear_are_ordered_along_line_3 cln_order=k.collinear_are_ordered_along_line_3_object(); - if(cln_order(s[0],*p,s[1])) - return intersection_return(*p); - } else { - return intersection_return(s); - } - } - - return intersection_return(); -} - -template -typename Intersection_traits::result_type -intersection(const typename K::Segment_3 &s, - const typename K::Line_3 &l, - const K& k) -{ - return intersection(l,s,k); -} - -template -inline -bool -do_intersect(const typename K::Line_3 &l, - const typename K::Segment_3 &s, - const K & k) -{ - CGAL_precondition(! l.is_degenerate () && ! s.is_degenerate () ); - bool b=do_intersect(l,s.supporting_line(),k); - if (b) - { - //supporting_line intersects: points are coplanar - typename K::Coplanar_orientation_3 cpl_orient=k.coplanar_orientation_3_object(); - typename K::Point_3 p1=l.point(0); - typename K::Point_3 p2=l.point(1); - ::CGAL::Orientation or1 = cpl_orient(p1,p2,s[0]); - - if ( or1 == COLLINEAR ) return true; - - ::CGAL::Orientation or2 = cpl_orient(p1,p2,s[1]); - return or1!=or2; - } - return false; -} - -template -inline -bool -do_intersect(const typename K::Segment_3 &s, - const typename K::Line_3 &l, - const K & k) -{ - return do_intersect(l,s,k); -} - -template -bool -Ray_3_has_on_collinear_Point_3( - const typename K::Ray_3 &r, - const typename K::Point_3 &p, - const K& k) -{ - return - k.equal_3_object()(r.source(),p) - || - k.equal_3_object() ( - k.construct_direction_3_object()( k.construct_vector_3_object() (r.source(),p) ), - r.direction() - ); -} - -template -typename Intersection_traits::result_type -intersection(const typename K::Line_3 &l, - const typename K::Ray_3 &r, - const K& k) -{ - CGAL_precondition(! l.is_degenerate () && ! r.is_degenerate () ); - - typename Intersection_traits::result_type - v = internal::intersection(l,r.supporting_line(), k); - - if(v) { - if(const typename K::Point_3* p = intersect_get(v)) { - if( Ray_3_has_on_collinear_Point_3(r,*p,k) ) - return intersection_return(*p); - } else if(intersect_get(v)) { - return intersection_return(r); - } - } - return intersection_return(); -} - -template -typename Intersection_traits::result_type -intersection(const typename K::Ray_3 &r, - const typename K::Line_3 &l, - const K& k) -{ - return intersection(l,r,k); -} - -template -inline -bool -do_intersect(const typename K::Line_3 &l, - const typename K::Ray_3 &r, - const K & k) -{ - CGAL_precondition(! l.is_degenerate () && ! r.is_degenerate () ); - if ( !do_intersect(l,r.supporting_line()) ) return false; - typename K::Coplanar_orientation_3 pred=k.coplanar_orientation_3_object(); - Orientation p0p1s=pred(l.point(0),l.point(1),r.source()); - if ( p0p1s == COLLINEAR) return true; - Orientation stp0 =pred(r.source(),r.second_point(),l.point(0)); - if ( stp0 == COLLINEAR ) - return Ray_3_has_on_collinear_Point_3(r,l.point(0),k); - return p0p1s!=stp0; -} - -template -inline -bool -do_intersect(const typename K::Ray_3 &r, - const typename K::Line_3 &l, - const K & k) -{ - return do_intersect(l,r,k); -} - -template -typename Intersection_traits::result_type -intersection(const typename K::Segment_3 &s, - const typename K::Ray_3 &r, - const K& k) -{ - CGAL_precondition(! s.is_degenerate () && ! r.is_degenerate () ); - - typename Intersection_traits::result_type - v = internal::intersection(r.supporting_line(),s, K()); - - if(v) { - if(const typename K::Point_3* p = intersect_get(v)) { - if( Ray_3_has_on_collinear_Point_3(r,*p,k) ) - return intersection_return(*p); - } else if(const typename K::Segment_3* s2 = intersect_get(v)) { - bool has_source=Ray_3_has_on_collinear_Point_3(r,s.source(),k); - bool has_target=Ray_3_has_on_collinear_Point_3(r,s.target(),k); - if (has_source){ - if (has_target) - return intersection_return(*s2); - else - { - if (k.equal_3_object() (r.source(),s.source())) - return intersection_return(r.source()); - else - return intersection_return( - k.construct_segment_3_object()(r.source(),s.source())); - } - } - else{ - if (has_target){ - if (k.equal_3_object() (r.source(),s.target())) - return intersection_return(r.source()); - else - return intersection_return( - k.construct_segment_3_object()(r.source(),s.target())); - } - } - } - } - - return intersection_return(); -} - -template -typename Intersection_traits::result_type -intersection(const typename K::Ray_3 &r, - const typename K::Segment_3 &s, - const K& k) -{ - return intersection(s,r,k); -} - -template -inline -bool -do_intersect(const typename K::Segment_3 &s, - const typename K::Ray_3 &r, - const K & k) -{ - CGAL_precondition(! s.is_degenerate () && ! r.is_degenerate () ); - if ( !do_intersect(s,r.supporting_line()) ) return false; - typename K::Coplanar_orientation_3 pred=k.coplanar_orientation_3_object(); - Orientation p0p1s=pred(s.point(0),s.point(1),r.source()); - Orientation stp0 =pred(r.source(),r.second_point(),s.point(0)); - if ( p0p1s == COLLINEAR) //s belongs to the supporting line of p0p1 - { - if ( stp0 == COLLINEAR )//st and p0p1 have the same supporting line - return Ray_3_has_on_collinear_Point_3(r,s.point(0),k) || Ray_3_has_on_collinear_Point_3(r,s.point(1),k); - else - return true; - } - if ( stp0 == COLLINEAR ) - return Ray_3_has_on_collinear_Point_3(r,s.point(0),k); - return p0p1s!=stp0; -} - -template -inline -bool -do_intersect(const typename K::Ray_3 &r, - const typename K::Segment_3 &s, - const K & k) -{ - return do_intersect(s,r,k); -} - -template -typename Intersection_traits::result_type -intersection(const typename K::Ray_3 &r1, - const typename K::Ray_3 &r2, - const K& k) -{ - CGAL_precondition(! r1.is_degenerate () && ! r2.is_degenerate () ); - - typename Intersection_traits::result_type - v = internal::intersection(r1.supporting_line(),r2, k); - - if(v) { - if(const typename K::Point_3* p = intersect_get(v)) { - if(Ray_3_has_on_collinear_Point_3(r1,*p,k)) - return intersection_return(*p); - } else if(const typename K::Ray_3* r = intersect_get(v)) { - bool r1_has_s2=Ray_3_has_on_collinear_Point_3(r1,r2.source(),k); - bool r2_has_s1=Ray_3_has_on_collinear_Point_3(r2,r1.source(),k); - if (r1_has_s2){ - if (r2_has_s1) - { - if (k.equal_3_object()(r1.source(),r2.source())) - return intersection_return(r1.source()); - else { - return intersection_return( - k.construct_segment_3_object()(r1.source(),r2.source())); - } - } - else - return intersection_return(*r); - } - else{ - if (r2_has_s1) - return intersection_return(r1); - } - } - } - return intersection_return(); - -} - -template -inline -bool -do_intersect(const typename K::Ray_3 &r1, - const typename K::Ray_3 &r2, - const K & k) -{ - CGAL_precondition(! r1.is_degenerate () && ! r2.is_degenerate () ); - if ( !do_intersect(r1,r2.supporting_line()) ) return false; - typename K::Coplanar_orientation_3 pred=k.coplanar_orientation_3_object(); - Orientation p0p1s=pred(r1.point(0),r1.point(1),r2.source()); - Orientation stp0 =pred(r2.source(),r2.second_point(),r1.point(0)); - - if ( p0p1s == COLLINEAR){ - if(stp0 == COLLINEAR ) - return Ray_3_has_on_collinear_Point_3(r2,r1.source(),k) || - Ray_3_has_on_collinear_Point_3(r1,r2.source(),k); - else - return true; - } - if(stp0 == COLLINEAR ) - return Ray_3_has_on_collinear_Point_3(r2,r1.point(0),k); - return p0p1s!=stp0; -} - -template -typename Intersection_traits::result_type -intersection(const typename K::Plane_3 &p, - const typename K::Sphere_3 &s, - const K&) -{ - typedef typename K::Circle_3 Circle_3; - typedef typename K::Point_3 Point_3; - typedef typename K::FT FT; - const FT d2 = CGAL::square(p.a()*s.center().x() + - p.b()*s.center().y() + - p.c()*s.center().z() + p.d()) / - (square(p.a()) + square(p.b()) + square(p.c())); - const FT cmp = d2 - s.squared_radius(); - if(CGAL_NTS is_zero(cmp)) { // tangent - return intersection_return(p.projection(s.center())); - } else if(CGAL_NTS is_negative(cmp)) { // intersect - Point_3 center = p.projection(s.center()); - return intersection_return(Circle_3(center,s.squared_radius() - d2,p)); - } // do not intersect - return intersection_return(); -} - -template -inline -bool -do_intersect(const typename K::Plane_3 &p, - const typename K::Sphere_3 &s, - const K&) -{ - typedef typename K::FT FT; - const FT d2 = CGAL::square(p.a()*s.center().x() + - p.b()*s.center().y() + - p.c()*s.center().z() + p.d()); - - return d2 <= s.squared_radius() * (square(p.a()) + square(p.b()) + square(p.c())); -} - -template -inline -bool -do_intersect(const typename K::Sphere_3 &s, - const typename K::Plane_3 &p, - const K&) -{ - return do_intersect(p,s); -} - - -template -inline -typename Intersection_traits::result_type -intersection(const typename K::Sphere_3 &s, - const typename K::Plane_3 &p, - const K& k) -{ - return intersection(p, s, k); -} - -template -inline -typename Intersection_traits::result_type -intersection(const typename K::Sphere_3 &s1, - const typename K::Sphere_3 &s2, - const K& k) -{ - typedef typename K::Plane_3 Plane_3; - if(s1.center() == s2.center()) { - if(s1.squared_radius() == s2.squared_radius()) { - if(is_zero(s1.squared_radius())) return intersection_return(s1.center()); - else return intersection_return(s1); - } else return intersection_return(); // cocentrics - } - Plane_3 p = K().construct_radical_plane_3_object()(s1,s2); - - - typename Intersection_traits::result_type - v = intersection(p, s1, k); - - - if(v) { - if(const typename K::Point_3* p = intersect_get(v)) - return intersection_return(*p); - else if(const typename K::Circle_3* c = intersect_get(v)) - return intersection_return(*c); - } - - return intersection_return(); -} - -template -inline -bool -do_intersect(const typename K::Sphere_3 &s1, - const typename K::Sphere_3 &s2, - const K& k) -{ - typedef typename K::Plane_3 Plane_3; - if(s1.center() == s2.center()) { - return s1.squared_radius() == s2.squared_radius(); - } - Plane_3 p = K().construct_radical_plane_3_object()(s1,s2); - return do_intersect(p, s1, k); -} - -template -typename Intersection_traits::result_type -intersection(const typename K::Plane_3 &plane, - const typename K::Ray_3 &ray, - const K& k) -{ - typedef typename K::Point_3 Point_3; - - typename Intersection_traits::result_type - v = internal::intersection(plane, ray.supporting_line(), k); - - if(v) { - if(const Point_3* p = intersect_get(v)) { - if (ray.collinear_has_on(*p)) - return intersection_return(*p); - else - return intersection_return(); - } - } else { - return intersection_return(); - } - - return intersection_return(ray); -} - - -template -inline -typename Intersection_traits::result_type -intersection(const typename K::Ray_3 &ray, - const typename K::Plane_3 &plane, - const K& k) -{ - return intersection(plane, ray, k); -} - - - -template -bool -do_intersect(const typename K::Plane_3 &plane, - const typename K::Ray_3 &ray, - const K& ) -{ - typename K::Oriented_side_3 oriented_side_3; - - Oriented_side os = oriented_side_3(plane,ray.source()); - if(os == ON_ORIENTED_BOUNDARY){ - return true; - } - return sign(ray.to_vector()* plane.orthogonal_vector()) * os == -1; -} - - -template -inline -bool -do_intersect(const typename K::Ray_3 &ray, - const typename K::Plane_3 &plane, - const K& k) -{ - return do_intersect(plane, ray, k); -} - - -template -typename Intersection_traits::result_type -intersection(const typename K::Plane_3 &plane, - const typename K::Segment_3 &seg, - const K& k) -{ - typedef typename K::Point_3 Point_3; - const Point_3 &source = seg.source(); - const Point_3 &target = seg.target(); - - Oriented_side source_side = plane.oriented_side(source); - Oriented_side target_side = plane.oriented_side(target); - - switch (source_side) { - case ON_ORIENTED_BOUNDARY: - if (target_side == ON_ORIENTED_BOUNDARY) - return intersection_return(seg); - else - return intersection_return(source); - case ON_POSITIVE_SIDE: - switch (target_side) { - case ON_ORIENTED_BOUNDARY: - return intersection_return(target); - case ON_POSITIVE_SIDE: - return intersection_return(); - default: // ON_NEGATIVE_SIDE: - { - // intersection object should be a point, but rounding errors - // could lead to: - // - a line: in such case, return seg, - // - the empty set: return the empty set. - typename Intersection_traits::result_type - v = internal::intersection(plane, seg.supporting_line(), k); - if(v) { - if(const typename K::Point_3* p = intersect_get(v)) - return intersection_return(*p); - else - return intersection_return(seg); - } - else - return intersection_return(); - } - } - case ON_NEGATIVE_SIDE: - switch (target_side) { - case ON_ORIENTED_BOUNDARY: - return intersection_return(target); - case ON_POSITIVE_SIDE: - { - // intersection object should be a point, but rounding errors - // could lead to: - // - a line: in such case, return seg, - // - the empty set: return the empty set. - typename Intersection_traits::result_type - v = internal::intersection(plane, seg.supporting_line(), k); - if(v) { - if(const typename K::Point_3* p = intersect_get(v)) - return intersection_return(*p); - else - return intersection_return(seg); - } - else - return intersection_return(); - } - case ON_NEGATIVE_SIDE: - return intersection_return(); - } - } - CGAL_kernel_assertion_msg(false, "Supposedly unreachable code."); - return intersection_return(); -} - - -template -inline -typename Intersection_traits::result_type -intersection(const typename K::Segment_3 &seg, - const typename K::Plane_3 &plane, - const K& k) -{ - return intersection(plane, seg, k); -} - - -template -bool -do_intersect(const typename K::Plane_3 &plane, - const typename K::Segment_3 &seg, - const K&) -{ - typedef typename K::Point_3 Point_3; - const Point_3 &source = seg.source(); - const Point_3 &target = seg.target(); - - Oriented_side source_side = plane.oriented_side(source); - Oriented_side target_side = plane.oriented_side(target); - - if ( source_side == target_side - && target_side != ON_ORIENTED_BOUNDARY) { - return false; - } - return true; -} - - -template -inline -bool -do_intersect(const typename K::Segment_3 &seg, - const typename K::Plane_3 &plane, - const K& k) -{ - return do_intersect(plane, seg, k); -} - -template -inline -typename Intersection_traits::result_type -intersection(const typename K::Plane_3 &plane, - const typename K::Triangle_3 &tri, - const K& k) -{ - typedef - typename Intersection_traits::result_type - pl_res; - - typename K::Construct_vertex_3 vertex_on = - k.construct_vertex_3_object(); - - Oriented_side or0=plane.oriented_side(vertex_on(tri,0)); - Oriented_side or1=plane.oriented_side(vertex_on(tri,1)); - Oriented_side or2=plane.oriented_side(vertex_on(tri,2)); - - if (or0==ON_ORIENTED_BOUNDARY){ - if (or1==ON_ORIENTED_BOUNDARY){ - if (or2==ON_ORIENTED_BOUNDARY) - return intersection_return(tri); - else - return intersection_return(k.construct_segment_3_object() - (tri.vertex(0),tri.vertex(1))); - } - else{ - if (or2==ON_ORIENTED_BOUNDARY) - return intersection_return(k.construct_segment_3_object() - (tri.vertex(0),tri.vertex(2))); - else{ - if (or1==or2) - return intersection_return(tri.vertex(0)); - else{ - pl_res v = internal::intersection(plane, k.construct_line_3_object()(tri.vertex(1),tri.vertex(2)), k); - const typename K::Point_3* p = intersect_get(v); - CGAL_kernel_assertion(p!=nullptr); - return intersection_return(k.construct_segment_3_object() - (*p,tri.vertex(0))); - } - } - } - } - - if (or1==ON_ORIENTED_BOUNDARY){ - if (or2==ON_ORIENTED_BOUNDARY) - return intersection_return(k.construct_segment_3_object() - (tri.vertex(1),tri.vertex(2))); - if (or2==or0) - return intersection_return(tri.vertex(1)); - else{ - pl_res v = intersection(plane, k.construct_line_3_object()(tri.vertex(0),tri.vertex(2)), k); - const typename K::Point_3* p = intersect_get(v); - CGAL_kernel_assertion(p!=nullptr); - return intersection_return(k.construct_segment_3_object() - (*p,tri.vertex(1))); - } - } - - if (or2==ON_ORIENTED_BOUNDARY){ - if (or1==or0) - return intersection_return(tri.vertex(2)); - else{ - pl_res v = intersection(plane, k.construct_line_3_object()(tri.vertex(0),tri.vertex(1)), k); - const typename K::Point_3* p = intersect_get(v); - CGAL_kernel_assertion(p!=nullptr); - return intersection_return(k.construct_segment_3_object() - (*p,tri.vertex(2))); - } - } - - //triangle vertices are not in the plane - std::vector pts; - pts.reserve(2); - if (or0!=or1){ - pl_res v = intersection(plane, k.construct_line_3_object()(tri.vertex(0),tri.vertex(1)), k); - const typename K::Point_3* pt_ptr = intersect_get(v); - CGAL_kernel_assertion( pt_ptr!=nullptr ); - pts.push_back( *pt_ptr ); - } - if (or0!=or2){ - pl_res v = intersection(plane, k.construct_line_3_object()(tri.vertex(0),tri.vertex(2)), k); - const typename K::Point_3* pt_ptr = intersect_get(v); - CGAL_kernel_assertion( pt_ptr!=nullptr ); - pts.push_back( *pt_ptr ); - } - if (or1!=or2){ - pl_res v = intersection(plane, k.construct_line_3_object()(tri.vertex(1),tri.vertex(2)), k); - const typename K::Point_3* pt_ptr = intersect_get(v); - CGAL_kernel_assertion( pt_ptr!=nullptr ); - pts.push_back( *pt_ptr ); - } - - if (pts.empty()) return intersection_return(); - - CGAL_kernel_assertion(pts.size()==2); - - return intersection_return( k.construct_segment_3_object() - (*pts.begin(),*boost::prior(pts.end())) ); -} - -template -inline -typename Intersection_traits::result_type -intersection(const typename K::Triangle_3 &triangle, - const typename K::Plane_3 &plane, - const K& k) -{ - return intersection(plane, triangle, k); -} - -template -typename Intersection_traits::result_type -intersection(const typename K::Line_3 &line, - const Bbox_3 &box, - const K&) -{ - typedef typename K::Point_3 Point_3; - typedef typename K::Direction_3 Direction_3; - const Point_3 &linepoint = line.point(); - const Direction_3 &linedir = line.direction(); - return intersection_bl(box, - CGAL::to_double(linepoint.x()), - CGAL::to_double(linepoint.y()), - CGAL::to_double(linepoint.z()), - CGAL::to_double(linedir.dx()), - CGAL::to_double(linedir.dy()), - CGAL::to_double(linedir.dz()), - true, true - ); -} - - -template -inline -typename Intersection_traits::result_type -intersection(const Bbox_3 &box, - const typename K::Line_3 &line, - const K& k) -{ - return intersection(line, box, k); -} - - -template -typename Intersection_traits::result_type -intersection(const typename K::Ray_3 &ray, - const Bbox_3 &box, - const K&) -{ - typedef typename K::Point_3 Point_3; - typedef typename K::Direction_3 Direction_3; - const Point_3 &linepoint = ray.source(); - const Direction_3 &linedir = ray.direction(); - return intersection_bl(box, - CGAL::to_double(linepoint.x()), - CGAL::to_double(linepoint.y()), - CGAL::to_double(linepoint.z()), - CGAL::to_double(linedir.dx()), - CGAL::to_double(linedir.dy()), - CGAL::to_double(linedir.dz()), - false, true - ); -} - - -template -inline -typename Intersection_traits::result_type -intersection(const Bbox_3 &box, - const typename K::Ray_3 &ray, - const K& k) -{ - return intersection(ray, box, k); -} - - - -template -typename Intersection_traits::result_type -intersection(const typename K::Segment_3 &seg, - const Bbox_3 &box, - const K&) -{ - typedef typename K::Point_3 Point_3; - typedef typename K::Vector_3 Vector_3; - const Point_3 &linepoint = seg.source(); - const Vector_3 &diffvec = seg.target()-linepoint; - return intersection_bl(box, - CGAL::to_double(linepoint.x()), - CGAL::to_double(linepoint.y()), - CGAL::to_double(linepoint.z()), - CGAL::to_double(diffvec.x()), - CGAL::to_double(diffvec.y()), - CGAL::to_double(diffvec.z()), - false, false - ); -} - - -template -inline -typename Intersection_traits::result_type -intersection(const Bbox_3 &box, - const typename K::Segment_3 &seg, - const K& k) -{ - return intersection(seg, box, k); -} - -template -inline -typename Intersection_traits::result_type -intersection(const Bbox_3 &a, - const Bbox_3 &b, - const K&) -{ - return CGAL::intersection(a, b); -} - -template -typename Intersection_traits::result_type -intersection(const CGAL::Bbox_3 &box, - const typename K::Iso_cuboid_3 &cub, - const K&) -{ - typename K::Iso_cuboid_3 iso_cub(box); - return intersection(iso_cub, cub); -} - - -template -inline -typename Intersection_traits::result_type -intersection(const typename K::Iso_cuboid_3 &cub, - const CGAL::Bbox_3 &box, - const K& k) -{ - return intersection(box,cub, k); -} - - -template -typename Intersection_traits::result_type -intersection(const typename K::Line_3 &line, - const typename K::Iso_cuboid_3 &box, - const K&) -{ - typedef typename K::Point_3 Point_3; - typedef typename K::Vector_3 Vector_3; - typedef typename K::Segment_3 Segment_3; - typedef typename K::FT FT; - bool all_values = true; - FT _min = 0, _max = 0; // initialization to stop compiler warning - Point_3 const & _ref_point=line.point(); - Vector_3 const & _dir=line.direction().vector(); - Point_3 const & _iso_min=(box.min)(); - Point_3 const & _iso_max=(box.max)(); - for (int i=0; i< _ref_point.dimension(); i++) { - if (_dir.homogeneous(i) == 0) { - if (_ref_point.cartesian(i) < _iso_min.cartesian(i)) { - return intersection_return(); - } - if (_ref_point.cartesian(i) > _iso_max.cartesian(i)) { - return intersection_return(); - } - } else { - FT newmin, newmax; - if (_dir.homogeneous(i) > 0) { - newmin = (_iso_min.cartesian(i) - _ref_point.cartesian(i)) / - _dir.cartesian(i); - newmax = (_iso_max.cartesian(i) - _ref_point.cartesian(i)) / - _dir.cartesian(i); - } else { - newmin = (_iso_max.cartesian(i) - _ref_point.cartesian(i)) / - _dir.cartesian(i); - newmax = (_iso_min.cartesian(i) - _ref_point.cartesian(i)) / - _dir.cartesian(i); - } - if (all_values) { - _min = newmin; - _max = newmax; - } else { - if (newmin > _min) - _min = newmin; - if (newmax < _max) - _max = newmax; - if (_max < _min) { - return intersection_return(); - } - } - all_values = false; - } - } - CGAL_kernel_assertion(!all_values); - if (_max == _min) { - return intersection_return(Point_3(_ref_point + _dir * _min )); - } - return intersection_return( - Segment_3(_ref_point + _dir*_min, _ref_point + _dir*_max)); -} - - -template -inline -typename Intersection_traits::result_type -intersection(const typename K::Iso_cuboid_3 &box, - const typename K::Line_3 &line, - const K& k) -{ - return intersection(line, box, k); -} - - - -template -typename Intersection_traits::result_type -intersection(const typename K::Ray_3 &ray, - const typename K::Iso_cuboid_3 &box, - const K&) -{ - typedef typename K::Point_3 Point_3; - typedef typename K::Vector_3 Vector_3; - typedef typename K::Segment_3 Segment_3; - typedef typename K::FT FT; - bool all_values = true; - FT _min = 0, _max = 0; // initialization to prevent compiler warning - Point_3 const & _ref_point=ray.source(); - Vector_3 const & _dir=ray.direction().vector(); - Point_3 const & _iso_min=(box.min)(); - Point_3 const & _iso_max=(box.max)(); - - for (int i=0; i< _ref_point.dimension(); i++) { - if (_dir.homogeneous(i) == 0) { - if (_ref_point.cartesian(i) < _iso_min.cartesian(i)) { - return intersection_return(); - } - if (_ref_point.cartesian(i) > _iso_max.cartesian(i)) { - return intersection_return(); - } - } else { - FT newmin, newmax; - if (_dir.homogeneous(i) > 0) { - newmin = (_iso_min.cartesian(i) - _ref_point.cartesian(i)) / - _dir.cartesian(i); - newmax = (_iso_max.cartesian(i) - _ref_point.cartesian(i)) / - _dir.cartesian(i); - } else { - newmin = (_iso_max.cartesian(i) - _ref_point.cartesian(i)) / - _dir.cartesian(i); - newmax = (_iso_min.cartesian(i) - _ref_point.cartesian(i)) / - _dir.cartesian(i); - } - if (all_values) { - _max = newmax; - } else { - if (newmax < _max) - _max = newmax; - } - if (newmin > _min) - _min = newmin; - if (_max < _min) - return intersection_return(); - all_values = false; - } - } - CGAL_kernel_assertion(!all_values); - if (_max == _min) { - return intersection_return(Point_3(_ref_point + _dir * _min )); - } - return intersection_return( - Segment_3(_ref_point + _dir*_min, _ref_point + _dir*_max)); -} - - -template -inline -typename Intersection_traits::result_type -intersection(const typename K::Iso_cuboid_3 &box, - const typename K::Ray_3 &ray, - const K& k) -{ - return intersection(ray, box, k); -} - - -template -typename Intersection_traits::result_type -intersection(const typename K::Segment_3 &seg, - const typename K::Iso_cuboid_3 &box, - const K&) -{ - typedef typename K::Point_3 Point_3; - typedef typename K::Vector_3 Vector_3; - typedef typename K::Segment_3 Segment_3; - typedef typename K::FT FT; - FT _min = 0, _max; - - Point_3 const & _ref_point=seg.source(); - Vector_3 const & _dir=seg.direction().vector(); - Point_3 const & _iso_min=(box.min)(); - Point_3 const & _iso_max=(box.max)(); - int main_dir = - (CGAL_NTS abs(_dir.x()) > CGAL_NTS abs(_dir.y()) ) - ? (CGAL_NTS abs(_dir.x()) > CGAL_NTS abs(_dir.z()) ? 0 : 2) - : (CGAL_NTS abs(_dir.y()) > CGAL_NTS abs(_dir.z()) ? 1 : 2); - _max = (seg.target().cartesian(main_dir)-_ref_point.cartesian(main_dir)) / - _dir.cartesian(main_dir); - - for (int i=0; i< _ref_point.dimension(); i++) { - if (_dir.homogeneous(i) == 0) { - if (_ref_point.cartesian(i) < _iso_min.cartesian(i)) { - return intersection_return(); - } - if (_ref_point.cartesian(i) > _iso_max.cartesian(i)) { - return intersection_return(); - } - } else { - FT newmin, newmax; - if (_dir.homogeneous(i) > 0) { - newmin = (_iso_min.cartesian(i) - _ref_point.cartesian(i)) / - _dir.cartesian(i); - newmax = (_iso_max.cartesian(i) - _ref_point.cartesian(i)) / - _dir.cartesian(i); - } else { - newmin = (_iso_max.cartesian(i) - _ref_point.cartesian(i)) / - _dir.cartesian(i); - newmax = (_iso_min.cartesian(i) - _ref_point.cartesian(i)) / - _dir.cartesian(i); - } - if (newmax < _max) - _max = newmax; - if (newmin > _min) - _min = newmin; - if (_max < _min) - return intersection_return(); - } - } - if (_max == _min) { - return intersection_return(Point_3(_ref_point + _dir * _min )); - } - - return intersection_return( - Segment_3(_ref_point + _dir*_min, _ref_point + _dir*_max)); -} - - -template -inline -typename Intersection_traits::result_type -intersection(const typename K::Iso_cuboid_3 &box, - const typename K::Segment_3 &seg, - const K& k) -{ - return intersection(seg, box, k); -} - - -template -typename Intersection_traits::result_type -intersection( - const typename K::Iso_cuboid_3 &icub1, - const typename K::Iso_cuboid_3 &icub2, - const K&) -{ - typedef typename K::Point_3 Point_3; - typedef typename K::Iso_cuboid_3 Iso_cuboid_3; - - Point_3 min_points[2]; - Point_3 max_points[2]; - min_points[0] = (icub1.min)(); - min_points[1] = (icub2.min)(); - max_points[0] = (icub1.max)(); - max_points[1] = (icub2.max)(); - const int DIM = 3; - int min_idx[DIM]; - int max_idx[DIM]; - Point_3 newmin; - Point_3 newmax; - for (int dim = 0; dim < DIM; ++dim) { - min_idx[dim] = - min_points[0].cartesian(dim) >= min_points[1].cartesian(dim) ? 0 : 1; - max_idx[dim] = - max_points[0].cartesian(dim) <= max_points[1].cartesian(dim) ? 0 : 1; - if (min_idx[dim] != max_idx[dim] - && max_points[max_idx[dim]].cartesian(dim) - < min_points[min_idx[dim]].cartesian(dim)) - return intersection_return(); - } - if (min_idx[0] == min_idx[1] && min_idx[0] == min_idx[2]) { - newmin = min_points[min_idx[0]]; - } else { - newmin = Point_3( - min_idx[0] == 0 - ? wmult_hw((K*)0, min_points[0].hx(), min_points[1]) - : wmult_hw((K*)0, min_points[1].hx(), min_points[0]) - , - min_idx[1] == 0 - ? wmult_hw((K*)0, min_points[0].hy(), min_points[1]) - : wmult_hw((K*)0, min_points[1].hy(), min_points[0]) - , - min_idx[2] == 0 - ? wmult_hw((K*)0, min_points[0].hz(), min_points[1]) - : wmult_hw((K*)0, min_points[1].hz(), min_points[0]) - , - wmult_hw((K*)0, min_points[0].hw(), min_points[1]) ); - } - if (max_idx[0] == max_idx[1] && max_idx[0] == max_idx[2]) { - newmax = max_points[max_idx[0]]; - } else { - newmax = Point_3( - max_idx[0] == 0 - ? wmult_hw((K*)0, max_points[0].hx(), max_points[1]) - : wmult_hw((K*)0, max_points[1].hx(), max_points[0]) - , - max_idx[1] == 0 - ? wmult_hw((K*)0, max_points[0].hy(), max_points[1]) - : wmult_hw((K*)0, max_points[1].hy(), max_points[0]) - , - max_idx[2] == 0 - ? wmult_hw((K*)0, max_points[0].hz(), max_points[1]) - : wmult_hw((K*)0, max_points[1].hz(), max_points[0]) - , - wmult_hw((K*)0, max_points[0].hw(), max_points[1]) ); - } - return intersection_return(Iso_cuboid_3(newmin, newmax)); -} - -template -inline bool -do_intersect(const Plane_3& plane1, const Plane_3& plane2, const R&) -{ - typedef typename R::RT RT; - const RT &a = plane1.a(); - const RT &b = plane1.b(); - const RT &c = plane1.c(); - const RT &d = plane1.d(); - const RT &p = plane2.a(); - const RT &q = plane2.b(); - const RT &r = plane2.c(); - const RT &s = plane2.d(); - - RT det = a*q-p*b; - if (det != 0) { - return true; - } - det = a*r-p*c; - if (det != 0) { - return true; - } - det = b*r-c*q; - if (det != 0) { - return true; - } -// degenerate case - if (a!=0 || p!=0) { - return (a*s == p*d); - } - if (b!=0 || q!=0) { - return (b*s == q*d); - } - if (c!=0 || r!=0) { - return (c*s == r*d); - } - return true; -} - - -template -inline bool -do_intersect(const Plane_3 &plane1, const Plane_3 &plane2, - const Plane_3 &plane3, const R&) -{ - typedef typename R::RT RT; - - if(! is_zero(determinant(plane1.a(), plane1.b(), plane1.c(), - plane2.a(), plane2.b(), plane2.c(), - plane3.a(), plane3.b(), plane3.c()))){ - return true; - } - - int pcount = 0; - bool b12, b13,b23; - if((b12 = parallel(plane1,plane2))) pcount++; - if((b13 = parallel(plane1,plane3))) pcount++; - if((b23 = parallel(plane2,plane3))) pcount++; - - if(pcount == 3){ - return (( (plane1 == plane2) || (plane1 == plane2.opposite())) && ( (plane1 == plane3) || (plane1 == plane3.opposite()))); - } - - if(pcount == 1){ - if(b12 && ((plane1 == plane2)||(plane1 == plane2.opposite() ))) return true; - if(b13 && ((plane1 == plane3)||(plane1 == plane3.opposite() ))) return true; - if(b23 && ((plane2 == plane3)||(plane2 == plane3.opposite() ))) return true; - } - - int rd = rank_34(plane1.a(), plane1.b(), plane1.c(), plane1.d(), - plane2.a(), plane2.b(), plane2.c(), plane2.d(), - plane3.a(), plane3.b(), plane3.c(), plane3.d()); - - return rd == 2; -} - - -template -inline bool -do_intersect(const Iso_cuboid_3 &icub1, const Iso_cuboid_3 &icub2, const R&) -{ - typedef typename R::Point_3 Point_3; - - Point_3 min_points[2]; - Point_3 max_points[2]; - min_points[0] = (icub1.min)(); - min_points[1] = (icub2.min)(); - max_points[0] = (icub1.max)(); - max_points[1] = (icub2.max)(); - const int DIM = 3; - int min_idx[DIM]; - int max_idx[DIM]; - Point_3 newmin; - Point_3 newmax; - for (int dim = 0; dim < DIM; ++dim) { - min_idx[dim] = - min_points[0].cartesian(dim) >= min_points[1].cartesian(dim) ? 0 : 1; - max_idx[dim] = - max_points[0].cartesian(dim) <= max_points[1].cartesian(dim) ? 0 : 1; - if (min_idx[dim] != max_idx[dim] - && max_points[max_idx[dim]].cartesian(dim) - < min_points[min_idx[dim]].cartesian(dim)) - return false; - } - return true; - -} - -template -inline bool -do_intersect(const Line_3 &line, const Iso_cuboid_3 &box, const R&) -{ - typedef typename R::Point_3 Point_3; - typedef typename R::Vector_3 Vector_3; - typedef typename R::FT FT; - bool all_values = true; - FT _min = 0, _max = 0; // initialization to stop compiler warning - FT _denum; - Point_3 const & _ref_point=line.point(); - Vector_3 const & _dir=line.direction().vector(); - Point_3 const & _iso_min=(box.min)(); - Point_3 const & _iso_max=(box.max)(); - for (int i=0; i< _ref_point.dimension(); i++) { - if (_dir.homogeneous(i) == 0) { - if (_ref_point.cartesian(i) < _iso_min.cartesian(i)) { - return false; - } - if (_ref_point.cartesian(i) > _iso_max.cartesian(i)) { - return false; - } - } else { - FT newmin, newmax; - FT newdenum = _dir.cartesian(i); - if (_dir.homogeneous(i) > 0) { - newmin = (_iso_min.cartesian(i) - _ref_point.cartesian(i)); - newmax = (_iso_max.cartesian(i) - _ref_point.cartesian(i)); - } else { - newmin = (_iso_max.cartesian(i) - _ref_point.cartesian(i)); - newmax = (_iso_min.cartesian(i) - _ref_point.cartesian(i)); - } - if (all_values) { - _min = newmin; - _max = newmax; - _denum = newdenum; - } else { - - if (compare_quotients(newmin, newdenum, _min, _denum) == LARGER) - _min = newmin; - if (compare_quotients(newmax, newdenum, _max, _denum) == LARGER) - _max = newmax; - if (compare_quotients(_max, _denum, _min, _denum) == SMALLER) { - return false; - } - _denum = newdenum; - - } - all_values = false; - } - } - CGAL_kernel_assertion(!all_values); - return true; -} - - -template -inline bool -do_intersect(const Iso_cuboid_3 &j, const Line_3 &l, const R& r) -{ - return do_intersect(l, j, r); -} -} // namespace internal -} // namespace Intersections -} // namespace CGAL - -#endif // CGAL_INTERSECTIONS_3_INTERNAL_INTERSECTION_3_1_IMPL_H diff --git a/Intersections_3/include/CGAL/Intersections_3/internal/tetrahedron_intersection_helpers.h b/Intersections_3/include/CGAL/Intersections_3/internal/tetrahedron_intersection_helpers.h index b227f9e3918..ddcf2618003 100644 --- a/Intersections_3/include/CGAL/Intersections_3/internal/tetrahedron_intersection_helpers.h +++ b/Intersections_3/include/CGAL/Intersections_3/internal/tetrahedron_intersection_helpers.h @@ -15,6 +15,8 @@ #define CGAL_INTERNAL_TETRAHEDRON_INTERSECTION_HELPERS_H #include + +#include #include #include @@ -38,19 +40,21 @@ void filter_segments(const std::vector& input, { s_it = tmp.erase(s_it); } - else { + else + { ++s_it; } } output.push_back(s); - }while (!tmp.empty()); + } while (!tmp.empty()); } template void fill_segments_infos(std::vector& segments, - std::list& points, const Triangle& input_tr) + std::list& points, + const Triangle& input_tr) { struct Wrapped_segment { @@ -59,25 +63,28 @@ void fill_segments_infos(std::vector& segments, bool t_dangling; std::size_t s_neighbor; std::size_t t_neighbor; + Wrapped_segment(const Segment& s) - :segment(s), s_dangling(true), + : segment(s), s_dangling(true), t_dangling(true), s_neighbor(0), - t_neighbor(0){} + t_neighbor(0) + { } }; std::vector wrapped_segments; - - for(const Segment& s:segments) - wrapped_segments.push_back(Wrapped_segment(s)); + for(const Segment& s : segments) + wrapped_segments.emplace_back(s); std::vector bis = segments; while(!bis.empty()) { Segment s = bis.back(); bis.pop_back(); + Wrapped_segment& w_s = wrapped_segments.back(); if(!w_s.s_dangling && ! w_s.t_dangling) continue; + for(std::size_t i = 0; i< bis.size(); ++i) { const Segment& s2 = bis[i]; @@ -96,7 +103,6 @@ void fill_segments_infos(std::vector& segments, wrapped_segments[i].s_dangling = false; wrapped_segments[i].s_neighbor = bis.size(); wrapped_segments[i].segment = wrapped_segments[i].segment.opposite(); //also orient the structure - } else if(s2.source() == s.source()) { @@ -122,9 +128,8 @@ void fill_segments_infos(std::vector& segments, { Segment edge(input_tr.vertex(e_id), input_tr.vertex(e_id+1)); if(!edge.has_on(s.source())) - { continue; - } + for(std::size_t i = 0; i< bis.size(); ++i) { if(edge.has_on(bis[i].source())) @@ -147,15 +152,15 @@ void fill_segments_infos(std::vector& segments, } } } + if(w_s.t_dangling) { for(int e_id = 0; e_id < 3; ++e_id) { Segment edge(input_tr.vertex(e_id), input_tr.vertex(e_id+1)); if(!edge.has_on(s.target())) - { continue; - } + for(std::size_t i = 0; i< bis.size(); ++i) { if(edge.has_on(bis[i].source())) @@ -181,21 +186,24 @@ void fill_segments_infos(std::vector& segments, if(w_s.s_dangling || w_s.t_dangling) { - std::cerr<<"Error. Kernel must have exact constructions to compute this intersection."<& segments, std::list& points) points.push_back(seg_it->source()); found = true; } + if(found) - { break; - } } + if(!found) { std::cerr<<"Error. Kernel must have exact constructions to compute this intersection."< +#include + #include -#include +#include +#include + +#include +#include namespace CGAL { namespace Intersections { @@ -25,13 +30,8 @@ namespace internal { template struct Tetrahedron_lines_intersection_3_base { - typedef typename Intersection_traits, - O>::result_type Result_type; - - typedef typename Intersection_traits, - O>::result_type Inter_type; + typedef typename Intersection_traits, O>::result_type Result_type; + typedef typename Intersection_traits, O>::result_type Inter_type; const typename K::Tetrahedron_3& tet; const O& o; @@ -68,7 +68,7 @@ struct Tetrahedron_lines_intersection_3_base if(do_intersect(o, triangle)) { tr_seg[i] = typename K::Intersect_3()(o, triangle); - if( boost::get(&*tr_seg[i]) != nullptr) + if(boost::get(&*tr_seg[i]) != nullptr) { res_id = i; break; @@ -77,7 +77,7 @@ struct Tetrahedron_lines_intersection_3_base } //if there is a segment in the intersections, then we return it - if(res_id !=-1) + if(res_id != -1) { output = tr_seg[res_id]; return; @@ -91,13 +91,14 @@ struct Tetrahedron_lines_intersection_3_base { if(tr_seg[i]) { - if (const typename K::Point_3* p = boost::get(&*tr_seg[i])) + if(const typename K::Point_3* p = boost::get(&*tr_seg[i])) { if(res_points.empty()) { res_id = i; } - else { + else + { if(*p != res_points.front()) { res_id = -1; @@ -109,9 +110,7 @@ struct Tetrahedron_lines_intersection_3_base } if(res_points.empty()) - { return; - } if(res_id != -1) { @@ -127,7 +126,7 @@ struct Tetrahedron_lines_intersection_3_base std::size_t res_id_2 = -1; std::vector > sq_distances(res_points.size()); - for(std::size_t i = 0; i< res_points.size(); ++i) + for(std::size_t i = 0; i - #ifndef CGAL_INTERSECTION_3_H #define CGAL_INTERSECTION_3_H -#include - #include #include #include @@ -52,6 +50,7 @@ #include #include +#include #include #include #include @@ -83,10 +82,7 @@ #include #include -#include #include -#include - #endif // CGAL_INTERSECTION_3_H diff --git a/Intersections_3/include/CGAL/intersection_3_1.h b/Intersections_3/include/CGAL/intersection_3_1.h deleted file mode 100644 index 74e79f1c7fa..00000000000 --- a/Intersections_3/include/CGAL/intersection_3_1.h +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright (c) 2010 -// GeometryFactory (France). -// Copyright (c) 1997-2004 Utrecht University (The Netherlands), -// ETH Zurich (Switzerland), -// INRIA Sophia-Antipolis (France), -// Max-Planck-Institute Saarbruecken (Germany), -// and Tel-Aviv University (Israel). All rights reserved. -// -// This file is part of CGAL (www.cgal.org) -// -// $URL$ -// $Id$ -// SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-Commercial -// -// -// Author(s) : Geert-Jan Giezeman -// Sebastien Loriot - -#ifndef CGAL_INTERSECTION_3_1_H -#define CGAL_INTERSECTION_3_1_H - -#include -#include - -#endif // CGAL_INTERSECTION_3_1_H diff --git a/Intersections_3/include/CGAL/intersections.h b/Intersections_3/include/CGAL/intersections.h index 05db0997f9a..5955c7d5e3f 100644 --- a/Intersections_3/include/CGAL/intersections.h +++ b/Intersections_3/include/CGAL/intersections.h @@ -1,9 +1,11 @@ -// Copyright (c) 2000 +// Copyright (c) 1997-2021 // Utrecht University (The Netherlands), // ETH Zurich (Switzerland), // INRIA Sophia-Antipolis (France), // Max-Planck-Institute Saarbruecken (Germany), -// and Tel-Aviv University (Israel). All rights reserved. +// and Tel-Aviv University (Israel). +// GeometryFactory (France) +// All rights reserved. // // This file is part of CGAL (www.cgal.org) // @@ -14,8 +16,6 @@ // // Author(s) : Geert-Jan Giezeman - - #ifndef CGAL_INTERSECTIONS_H #define CGAL_INTERSECTIONS_H From 4a301448fea6f24f0d7203cc79c5d0e4ae3c758d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mael=20Rouxel-Labb=C3=A9?= Date: Wed, 23 Jun 2021 17:37:47 +0200 Subject: [PATCH 03/31] Comment an assertion that requires an exact kernel --- Cartesian_kernel/include/CGAL/Cartesian/Circle_3.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Cartesian_kernel/include/CGAL/Cartesian/Circle_3.h b/Cartesian_kernel/include/CGAL/Cartesian/Circle_3.h index ba583f69e7d..de200ba3e4b 100644 --- a/Cartesian_kernel/include/CGAL/Cartesian/Circle_3.h +++ b/Cartesian_kernel/include/CGAL/Cartesian/Circle_3.h @@ -66,10 +66,10 @@ public: { // the plane contains the center and it is not degenerate CGAL_kernel_assertion(!R().is_degenerate_3_object()(p)); - CGAL_kernel_assertion((p.a() * center.x() + - p.b() * center.y() + - p.c() * center.z() + - p.d()) == 0); +// CGAL_kernel_assertion((p.a() * center.x() + +// p.b() * center.y() + +// p.c() * center.z() + +// p.d()) == 0); CGAL_kernel_assertion(squared_r >= FT(0)); base = Rep(Sphere_3(center,squared_r), p); } From 9ed943e92fa13c4d1ea4afec9bf7c43e8dad83dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mael=20Rouxel-Labb=C3=A9?= Date: Wed, 23 Jun 2021 17:38:22 +0200 Subject: [PATCH 04/31] Fix parameter names for consistency --- Intersections_2/include/CGAL/Intersection_traits.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Intersections_2/include/CGAL/Intersection_traits.h b/Intersections_2/include/CGAL/Intersection_traits.h index cafd0428ef8..137bb500035 100644 --- a/Intersections_2/include/CGAL/Intersection_traits.h +++ b/Intersections_2/include/CGAL/Intersection_traits.h @@ -47,8 +47,8 @@ template \ inline \ decltype(auto) \ - intersection(const B& a, const A& b) { \ - return BOOST_PP_CAT(K().intersect_, BOOST_PP_CAT(DIM, _object()(a, b))); \ + intersection(const B& b, const A& a) { \ + return BOOST_PP_CAT(K().intersect_, BOOST_PP_CAT(DIM, _object()(b, a))); \ } #define CGAL_INTERSECTION_FUNCTION_SELF(A, DIM) \ @@ -67,8 +67,8 @@ } \ template \ inline bool \ - do_intersect(const B& a, const A& b) { \ - return BOOST_PP_CAT(K().do_intersect_, BOOST_PP_CAT(DIM, _object()(a, b))); \ + do_intersect(const B& b, const A& a) { \ + return BOOST_PP_CAT(K().do_intersect_, BOOST_PP_CAT(DIM, _object()(b, a))); \ } #define CGAL_DO_INTERSECT_FUNCTION_SELF(A, DIM) \ From d1b456cd70df097a7d3b0aba7fa7cefb914519ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mael=20Rouxel-Labb=C3=A9?= Date: Wed, 23 Jun 2021 17:39:52 +0200 Subject: [PATCH 05/31] Add a lot more testing to Intersections_3 --- .../test/Intersections_3/call_test.cpp | 500 +++++-- .../test/Intersections_3/issue_5428.cpp | 17 +- .../test/Intersections_3/line_line.cpp | 80 - .../test/Intersections_3/numrep1.h | 101 -- .../test/Intersections_3/numrep2.h | 46 - .../Intersections_3/test_intersections_3.cpp | 1307 ----------------- .../test_intersections_Iso_cuboid_3.cpp | 714 +++++++++ .../test_intersections_Line_3.cpp | 435 ++++++ .../test_intersections_Plane_3.cpp | 446 ++++++ .../test_intersections_Point_3.cpp | 261 ++++ .../test_intersections_Ray_3.cpp | 283 ++++ .../test_intersections_Segment_3.cpp | 215 +++ .../test_intersections_Sphere_3.cpp | 188 +++ .../test_intersections_Tetrahedron_3.cpp | 330 +++++ .../test_point_3_intersections.cpp | 129 -- .../test/Intersections_3/tetrahedron.cpp | 76 - .../triangle_other_intersection_test.cpp | 6 +- 17 files changed, 3229 insertions(+), 1905 deletions(-) delete mode 100644 Intersections_3/test/Intersections_3/line_line.cpp delete mode 100644 Intersections_3/test/Intersections_3/numrep1.h delete mode 100644 Intersections_3/test/Intersections_3/numrep2.h delete mode 100644 Intersections_3/test/Intersections_3/test_intersections_3.cpp create mode 100644 Intersections_3/test/Intersections_3/test_intersections_Iso_cuboid_3.cpp create mode 100644 Intersections_3/test/Intersections_3/test_intersections_Line_3.cpp create mode 100644 Intersections_3/test/Intersections_3/test_intersections_Plane_3.cpp create mode 100644 Intersections_3/test/Intersections_3/test_intersections_Point_3.cpp create mode 100644 Intersections_3/test/Intersections_3/test_intersections_Ray_3.cpp create mode 100644 Intersections_3/test/Intersections_3/test_intersections_Segment_3.cpp create mode 100644 Intersections_3/test/Intersections_3/test_intersections_Sphere_3.cpp create mode 100644 Intersections_3/test/Intersections_3/test_intersections_Tetrahedron_3.cpp delete mode 100644 Intersections_3/test/Intersections_3/test_point_3_intersections.cpp delete mode 100644 Intersections_3/test/Intersections_3/tetrahedron.cpp diff --git a/Intersections_3/test/Intersections_3/call_test.cpp b/Intersections_3/test/Intersections_3/call_test.cpp index 90f595bcbb6..c9a89275445 100644 --- a/Intersections_3/test/Intersections_3/call_test.cpp +++ b/Intersections_3/test/Intersections_3/call_test.cpp @@ -1,30 +1,16 @@ #include + #include #include #include +#include + // This just tests if every call we promise is actually available -typedef CGAL::Exact_predicates_exact_constructions_kernel Epic; - -typedef CGAL::Cartesian Cartesian; -typedef Epic K; -typedef CGAL::Point_3< K > P; -typedef CGAL::Segment_3< K > S; -typedef CGAL::Line_3< K > L; -typedef CGAL::Plane_3< K > Pl; -typedef CGAL::Triangle_3< K > Tr; -typedef CGAL::Ray_3< K > R; -typedef CGAL::Iso_cuboid_3< K > Cub; - -typedef CGAL::Sphere_3< K > Sph; -typedef CGAL::Circle_3< K > C; - -typedef CGAL::Tetrahedron_3< K > T; - -typedef CGAL::Bbox_3 Bbox_3; template -void call_intersection_global(const A& a, const B& b) { +void call_intersection_global(const A& a, const B& b) +{ const auto x = CGAL::intersection(a, b); const auto y = CGAL::intersection(b, a); const auto z = CGAL::intersection(b, a); @@ -34,188 +20,349 @@ void call_intersection_global(const A& a, const B& b) { } template -void call_do_intersect_global(const A& a, const B& b) { - CGAL::do_intersect(a, b); - CGAL::do_intersect(b, a); -} - -template -void call_intersection_with_kernel(const A& a, const B& b, const K&) { - typedef typename K::Intersect_3 Intersect; - const auto x = Intersect()(a, b); - const auto y = Intersect()(b, a); -} - -template -void call_do_intersect_with_kernel(const A& a, const B& b, const K&) { - typedef typename K::Do_intersect_3 Do_inter; - Do_inter()(a, b); - Do_inter()(b, a); -} - - -int main(int argc, char**) +void call_do_intersect_global(const A& a, const B& b) { - CGAL::Interval_nt_advanced::Protector p; - CGAL_USE(p); - //we only want to check compilation - if(argc > 666 ) - { - call_intersection_global(S(), S()); - call_intersection_global(S(), L()); - call_intersection_global(S(), Pl()); - call_intersection_global(S(), Tr()); - call_intersection_global(S(), R()); - call_intersection_global(S(), Cub()); + const auto x = CGAL::do_intersect(a, b); + const auto y = CGAL::do_intersect(b, a); + CGAL_USE(x); + CGAL_USE(y); +} - call_intersection_global(L(), S()); +template +void call_intersection_with_kernel(const A& a, const B& b, const K& k) +{ + typename K::Intersect_3 intersect = k.intersect_3_object(); + const auto x = intersect(a, b); + const auto y = intersect(b, a); + CGAL_USE(x); + CGAL_USE(y); +} + +template +void call_do_intersect_with_kernel(const A& a, const B& b, const K& k) +{ + typename K::Do_intersect_3 do_intersect = k.do_intersect_3_object(); + const bool x = do_intersect(a, b); + const bool y = do_intersect(b, a); + CGAL_USE(x); + CGAL_USE(y); +} + +template +void test(const int argc) +{ + typedef CGAL::Iso_cuboid_3< K > Cub; + typedef CGAL::Line_3< K > L; + typedef CGAL::Plane_3< K > Pl; + typedef CGAL::Point_3< K > P; + typedef CGAL::Ray_3< K > R; + typedef CGAL::Segment_3< K > S; + typedef CGAL::Sphere_3< K > Sph; + typedef CGAL::Triangle_3< K > Tr; + typedef CGAL::Tetrahedron_3< K > T; + + typedef CGAL::Bbox_3 Bbox_3; + + //we only want to check compilation + if(argc > 0) + { + // --------------------------------------------------------------------------------------------- + // INTERSECTION + // --------------------------------------------------------------------------------------------- + + call_intersection_global(Cub(), Bbox_3()); + call_intersection_global(Cub(), Cub()); + call_intersection_global(Cub(), L()); + call_intersection_global(Cub(), Pl()); + call_intersection_global(Cub(), P()); + call_intersection_global(Cub(), R()); + call_intersection_global(Cub(), S()); + call_intersection_global(Cub(), Tr()); + + call_intersection_global(L(), Bbox_3()); + call_intersection_global(L(), Cub()); call_intersection_global(L(), L()); call_intersection_global(L(), Pl()); - call_intersection_global(L(), Tr()); + call_intersection_global(L(), P()); call_intersection_global(L(), R()); - call_intersection_global(L(), Cub()); + call_intersection_global(L(), S()); + call_intersection_global(L(), T()); + call_intersection_global(L(), Tr()); - call_intersection_global(Pl(), S()); + call_intersection_global(Pl(), Bbox_3()); + call_intersection_global(Pl(), Cub()); call_intersection_global(Pl(), L()); call_intersection_global(Pl(), Pl()); - call_intersection_global(Pl(), Tr()); + call_intersection_global(Pl(), P()); call_intersection_global(Pl(), R()); - // call_intersection_global(Pl(), Cub()); + call_intersection_global(Pl(), S()); + call_intersection_global(Pl(), Sph()); + call_intersection_global(Pl(), Tr()); + call_intersection_global(Pl(), T()); - // special - const auto plplpl = CGAL::intersection(Pl(), Pl(), Pl()); + auto plplpl = CGAL::intersection(Pl(), Pl(), Pl()); + CGAL_USE(plplpl); - call_intersection_global(Tr(), S()); - call_intersection_global(Tr(), L()); - call_intersection_global(Tr(), Pl()); - call_intersection_global(Tr(), Tr()); - call_intersection_global(Tr(), R()); - // call_intersection_global(Tr(), Cub()); + call_intersection_global(P(), Bbox_3()); + call_intersection_global(P(), Cub()); + call_intersection_global(P(), L()); + call_intersection_global(P(), Pl()); + call_intersection_global(P(), P()); + call_intersection_global(P(), R()); + call_intersection_global(P(), S()); + call_intersection_global(P(), Sph()); + call_intersection_global(P(), Tr()); + call_intersection_global(P(), T()); - call_intersection_global(R(), S()); + call_intersection_global(R(), Bbox_3()); + call_intersection_global(R(), Cub()); call_intersection_global(R(), L()); call_intersection_global(R(), Pl()); - call_intersection_global(R(), Tr()); + call_intersection_global(R(), P()); call_intersection_global(R(), R()); - call_intersection_global(R(), Cub()); + call_intersection_global(R(), S()); + call_intersection_global(R(), Tr()); + call_intersection_global(R(), T()); - call_intersection_global(Cub(), S()); - call_intersection_global(Cub(), L()); - // call_intersection_global(Cub(), Pl()); - // call_intersection_global(Cub(), Tr()); - call_intersection_global(Cub(), R()); - call_intersection_global(Cub(), Cub()); -// call_intersection_global(Cub(), Bbox_3()); + call_intersection_global(S(), Bbox_3()); + call_intersection_global(S(), Cub()); + call_intersection_global(S(), L()); + call_intersection_global(S(), Pl()); + call_intersection_global(S(), P()); + call_intersection_global(S(), R()); + call_intersection_global(S(), S()); + call_intersection_global(S(), T()); + call_intersection_global(S(), Tr()); + + call_intersection_global(Sph(), Pl()); + call_intersection_global(Sph(), P()); + call_intersection_global(Sph(), Sph()); + + call_intersection_global(Tr(), Bbox_3()); + call_intersection_global(Tr(), Cub()); + call_intersection_global(Tr(), L()); + call_intersection_global(Tr(), Pl()); + call_intersection_global(Tr(), P()); + call_intersection_global(Tr(), R()); + call_intersection_global(Tr(), S()); + call_intersection_global(Tr(), Tr()); + call_intersection_global(Tr(), T()); + + call_intersection_global(T(), L()); + call_intersection_global(T(), Pl()); + call_intersection_global(T(), P()); + call_intersection_global(T(), R()); + call_intersection_global(T(), S()); + call_intersection_global(T(), Tr()); + + const auto bbbb = CGAL::intersection(Bbox_3(), Bbox_3()); + CGAL_USE(bbbb); - call_intersection_global(Bbox_3(), L()); - call_intersection_global(Bbox_3(), S()); - call_intersection_global(Bbox_3(), R()); call_intersection_global(Bbox_3(), Cub()); - CGAL::intersection(Bbox_3(), Bbox_3()); + call_intersection_global(Bbox_3(), L()); + call_intersection_global(Bbox_3(), Pl()); + call_intersection_global(Bbox_3(), P()); + call_intersection_global(Bbox_3(), R()); + call_intersection_global(Bbox_3(), S()); + call_intersection_global(Bbox_3(), Tr()); call_intersection_global(T(), L()); - // with kernel + call_intersection_with_kernel(Cub(), Bbox_3(), K()); + call_intersection_with_kernel(Cub(), Cub(), K()); + call_intersection_with_kernel(Cub(), L(), K()); + call_intersection_with_kernel(Cub(), Pl(), K()); + call_intersection_with_kernel(Cub(), P(), K()); + call_intersection_with_kernel(Cub(), R(), K()); + call_intersection_with_kernel(Cub(), S(), K()); + call_intersection_with_kernel(Cub(), Tr(), K()); - call_intersection_with_kernel(S(), S(), K()); - call_intersection_with_kernel(S(), L(), K()); - call_intersection_with_kernel(S(), Pl(), K()); - call_intersection_with_kernel(S(), Tr(), K()); - call_intersection_with_kernel(S(), R(), K()); - call_intersection_with_kernel(S(), Cub(), K()); - - call_intersection_with_kernel(L(), S(), K()); + call_intersection_with_kernel(L(), Bbox_3(), K()); + call_intersection_with_kernel(L(), Cub(), K()); call_intersection_with_kernel(L(), L(), K()); call_intersection_with_kernel(L(), Pl(), K()); - call_intersection_with_kernel(L(), Tr(), K()); + call_intersection_with_kernel(L(), P(), K()); call_intersection_with_kernel(L(), R(), K()); - call_intersection_with_kernel(L(), Cub(), K()); + call_intersection_with_kernel(L(), S(), K()); + call_intersection_with_kernel(L(), Tr(), K()); + call_intersection_with_kernel(L(), T(), K()); - call_intersection_with_kernel(Pl(), S(), K()); + call_intersection_with_kernel(Pl(), Bbox_3(), K()); + call_intersection_with_kernel(Pl(), Cub(), K()); call_intersection_with_kernel(Pl(), L(), K()); call_intersection_with_kernel(Pl(), Pl(), K()); - call_intersection_with_kernel(Pl(), Tr(), K()); + call_intersection_with_kernel(Pl(), P(), K()); call_intersection_with_kernel(Pl(), R(), K()); - // call_intersection_with_kernel(Pl(), Cub(), K()); + call_intersection_with_kernel(Pl(), S(), K()); + call_intersection_with_kernel(Pl(), Tr(), K()); + call_intersection_with_kernel(Pl(), T(), K()); //special - K::Intersect_3()(Pl(), Pl(), Pl()); + plplpl = K().intersect_3_object()(Pl(), Pl(), Pl()); + CGAL_USE(plplpl); - call_intersection_with_kernel(Tr(), S(), K()); - call_intersection_with_kernel(Tr(), L(), K()); - call_intersection_with_kernel(Tr(), Pl(), K()); - call_intersection_with_kernel(Tr(), Tr(), K()); - call_intersection_with_kernel(Tr(), R(), K()); - // call_intersection_with_kernel(Tr(), Cub(), K()); + call_intersection_with_kernel(P(), Bbox_3(), K()); + call_intersection_with_kernel(P(), Cub(), K()); + call_intersection_with_kernel(P(), L(), K()); + call_intersection_with_kernel(P(), Pl(), K()); + call_intersection_with_kernel(P(), P(), K()); + call_intersection_with_kernel(P(), R(), K()); + call_intersection_with_kernel(P(), S(), K()); + call_intersection_with_kernel(P(), Sph(), K()); + call_intersection_with_kernel(P(), Tr(), K()); + call_intersection_with_kernel(P(), T(), K()); - call_intersection_with_kernel(R(), S(), K()); + call_intersection_with_kernel(R(), Bbox_3(), K()); + call_intersection_with_kernel(R(), Cub(), K()); call_intersection_with_kernel(R(), L(), K()); call_intersection_with_kernel(R(), Pl(), K()); - call_intersection_with_kernel(R(), Tr(), K()); + call_intersection_with_kernel(R(), P(), K()); call_intersection_with_kernel(R(), R(), K()); - call_intersection_with_kernel(R(), Cub(), K()); + call_intersection_with_kernel(R(), S(), K()); + call_intersection_with_kernel(R(), Tr(), K()); + call_intersection_with_kernel(R(), T(), K()); - call_intersection_with_kernel(Cub(), S(), K()); - call_intersection_with_kernel(Cub(), L(), K()); - // call_intersection_with_kernel(Cub(), Pl(), K()); - // call_intersection_with_kernel(Cub(), Tr(), K()); - call_intersection_with_kernel(Cub(), R(), K()); - call_intersection_with_kernel(Cub(), Cub(), K()); + call_intersection_with_kernel(S(), Bbox_3(), K()); + call_intersection_with_kernel(S(), Cub(), K()); + call_intersection_with_kernel(S(), L(), K()); + call_intersection_with_kernel(S(), Pl(), K()); + call_intersection_with_kernel(S(), P(), K()); + call_intersection_with_kernel(S(), R(), K()); + call_intersection_with_kernel(S(), S(), K()); + call_intersection_with_kernel(S(), Tr(), K()); + call_intersection_with_kernel(S(), T(), K()); + call_intersection_with_kernel(Sph(), Pl(), K()); + call_intersection_with_kernel(Sph(), P(), K()); + call_intersection_with_kernel(Sph(), Sph(), K()); + + call_intersection_with_kernel(Tr(), Bbox_3(), K()); + call_intersection_with_kernel(Tr(), Cub(), K()); + call_intersection_with_kernel(Tr(), L(), K()); + call_intersection_with_kernel(Tr(), Pl(), K()); + call_intersection_with_kernel(Tr(), P(), K()); + call_intersection_with_kernel(Tr(), R(), K()); + call_intersection_with_kernel(Tr(), S(), K()); + call_intersection_with_kernel(Tr(), Tr(), K()); + call_intersection_with_kernel(Tr(), T(), K()); + + call_intersection_with_kernel(T(), L(), K()); + call_intersection_with_kernel(T(), Pl(), K()); + call_intersection_with_kernel(T(), P(), K()); + call_intersection_with_kernel(T(), R(), K()); + call_intersection_with_kernel(T(), S(), K()); + call_intersection_with_kernel(T(), Tr(), K()); + + call_intersection_with_kernel(Bbox_3(), Cub(), K()); call_intersection_with_kernel(Bbox_3(), L(), K()); - call_intersection_with_kernel(Bbox_3(), S(), K()); + call_intersection_with_kernel(Bbox_3(), Pl(), K()); + call_intersection_with_kernel(Bbox_3(), P(), K()); call_intersection_with_kernel(Bbox_3(), R(), K()); + call_intersection_with_kernel(Bbox_3(), S(), K()); + call_intersection_with_kernel(Bbox_3(), Tr(), K()); - // The doc defines calls to do_intersect for these objects + // --------------------------------------------------------------------------------------------- + // DO INTERSECT + // --------------------------------------------------------------------------------------------- - // Plane_3 - // Line_3 - // Ray_3 - // Segment_3 - // Triangle_3. - // Bbox_3. - call_do_intersect_global(Pl(), Pl()); - call_do_intersect_global(Pl(), L()); - call_do_intersect_global(Pl(), R()); - call_do_intersect_global(Pl(), S()); - call_do_intersect_global(Pl(), Tr()); - call_do_intersect_global(Pl(), Bbox_3()); - - call_do_intersect_global(L(), Pl()); + call_do_intersect_global(L(), Cub()); + call_do_intersect_global(L(), Bbox_3()); call_do_intersect_global(L(), L()); + call_do_intersect_global(L(), Pl()); + call_do_intersect_global(L(), P()); call_do_intersect_global(L(), R()); call_do_intersect_global(L(), S()); + call_do_intersect_global(L(), Sph()); call_do_intersect_global(L(), Tr()); - call_do_intersect_global(L(), Bbox_3()); + call_do_intersect_global(L(), T()); - call_do_intersect_global(R(), Pl()); + call_do_intersect_global(Pl(), Bbox_3()); + call_do_intersect_global(Pl(), Cub()); + call_do_intersect_global(Pl(), L()); + call_do_intersect_global(Pl(), Pl()); + call_do_intersect_global(Pl(), P()); + call_do_intersect_global(Pl(), R()); + call_do_intersect_global(Pl(), S()); + call_do_intersect_global(Pl(), Sph()); + call_do_intersect_global(Pl(), Tr()); + call_do_intersect_global(Pl(), T()); + + call_do_intersect_global(P(), Bbox_3()); + call_do_intersect_global(P(), Cub()); + call_do_intersect_global(P(), L()); + call_do_intersect_global(P(), Pl()); + call_do_intersect_global(P(), P()); + call_do_intersect_global(P(), R()); + call_do_intersect_global(P(), S()); + call_do_intersect_global(P(), Sph()); + call_do_intersect_global(P(), Tr()); + call_do_intersect_global(P(), T()); + + call_do_intersect_global(R(), Bbox_3()); + call_do_intersect_global(R(), Cub()); call_do_intersect_global(R(), L()); + call_do_intersect_global(R(), Pl()); + call_do_intersect_global(R(), P()); call_do_intersect_global(R(), R()); call_do_intersect_global(R(), S()); call_do_intersect_global(R(), Tr()); - call_do_intersect_global(R(), Bbox_3()); + call_do_intersect_global(R(), T()); + call_do_intersect_global(S(), Bbox_3()); + call_do_intersect_global(S(), Cub()); call_do_intersect_global(S(), Pl()); + call_do_intersect_global(S(), P()); call_do_intersect_global(S(), L()); call_do_intersect_global(S(), R()); call_do_intersect_global(S(), S()); + call_do_intersect_global(S(), Sph()); call_do_intersect_global(S(), Tr()); - call_do_intersect_global(S(), Bbox_3()); + call_do_intersect_global(S(), T()); - call_do_intersect_global(Tr(), Pl()); + call_do_intersect_global(Sph(), Bbox_3()); + call_do_intersect_global(Sph(), Cub()); + call_do_intersect_global(Sph(), Pl()); + call_do_intersect_global(Sph(), P()); + call_do_intersect_global(Sph(), L()); + call_do_intersect_global(Sph(), R()); + call_do_intersect_global(Sph(), S()); + call_do_intersect_global(Sph(), Sph()); + call_do_intersect_global(Sph(), Tr()); + call_do_intersect_global(Sph(), T()); + + call_do_intersect_global(Tr(), Bbox_3()); + call_do_intersect_global(Tr(), Cub()); call_do_intersect_global(Tr(), L()); + call_do_intersect_global(Tr(), Pl()); + call_do_intersect_global(Tr(), P()); call_do_intersect_global(Tr(), R()); call_do_intersect_global(Tr(), S()); + call_do_intersect_global(Tr(), Sph()); call_do_intersect_global(Tr(), Tr()); - call_do_intersect_global(Tr(), Bbox_3()); + call_do_intersect_global(Tr(), T()); - call_do_intersect_global(Tr(), Pl()); + call_do_intersect_global(Tr(), Bbox_3()); + call_do_intersect_global(Tr(), Cub()); call_do_intersect_global(Tr(), L()); + call_do_intersect_global(Tr(), Pl()); + call_do_intersect_global(Tr(), P()); call_do_intersect_global(Tr(), R()); call_do_intersect_global(Tr(), S()); + call_do_intersect_global(Tr(), Sph()); call_do_intersect_global(Tr(), Tr()); - call_do_intersect_global(Tr(), Bbox_3()); + call_do_intersect_global(Tr(), T()); + + call_do_intersect_global(T(), Bbox_3()); + call_do_intersect_global(T(), Cub()); + call_do_intersect_global(T(), L()); + call_do_intersect_global(T(), Pl()); + call_do_intersect_global(T(), P()); + call_do_intersect_global(T(), R()); + call_do_intersect_global(T(), S()); + call_do_intersect_global(T(), Sph()); + call_do_intersect_global(T(), Tr()); + call_do_intersect_global(T(), T()); call_do_intersect_global(Bbox_3(), Pl()); call_do_intersect_global(Bbox_3(), L()); @@ -226,54 +373,97 @@ int main(int argc, char**) call_do_intersect_global(Bbox_3(), Bbox_3()); // with_kernel - call_do_intersect_with_kernel(Pl(), Pl(), K()); - call_do_intersect_with_kernel(Pl(), L(), K()); - call_do_intersect_with_kernel(Pl(), R(), K()); - call_do_intersect_with_kernel(Pl(), S(), K()); - call_do_intersect_with_kernel(Pl(), Tr(), K()); - call_do_intersect_with_kernel(Pl(), Bbox_3(), K()); - - call_do_intersect_with_kernel(L(), Pl(), K()); + call_do_intersect_with_kernel(L(), Bbox_3(), K()); + call_do_intersect_with_kernel(L(), Cub(), K()); call_do_intersect_with_kernel(L(), L(), K()); + call_do_intersect_with_kernel(L(), Pl(), K()); + call_do_intersect_with_kernel(L(), P(), K()); call_do_intersect_with_kernel(L(), R(), K()); call_do_intersect_with_kernel(L(), S(), K()); + call_do_intersect_with_kernel(L(), Sph(), K()); call_do_intersect_with_kernel(L(), Tr(), K()); - call_do_intersect_with_kernel(L(), Bbox_3(), K()); + call_do_intersect_with_kernel(L(), T(), K()); - call_do_intersect_with_kernel(R(), Pl(), K()); + call_do_intersect_with_kernel(Pl(), Bbox_3(), K()); + call_do_intersect_with_kernel(Pl(), Cub(), K()); + call_do_intersect_with_kernel(Pl(), L(), K()); + call_do_intersect_with_kernel(Pl(), Pl(), K()); + call_do_intersect_with_kernel(Pl(), P(), K()); + call_do_intersect_with_kernel(Pl(), R(), K()); + call_do_intersect_with_kernel(Pl(), S(), K()); + call_do_intersect_with_kernel(Pl(), Sph(), K()); + call_do_intersect_with_kernel(Pl(), Tr(), K()); + call_do_intersect_with_kernel(Pl(), T(), K()); + + call_do_intersect_with_kernel(P(), Bbox_3(), K()); + call_do_intersect_with_kernel(P(), Cub(), K()); + call_do_intersect_with_kernel(P(), L(), K()); + call_do_intersect_with_kernel(P(), Pl(), K()); + call_do_intersect_with_kernel(P(), P(), K()); + call_do_intersect_with_kernel(P(), R(), K()); + call_do_intersect_with_kernel(P(), S(), K()); + call_do_intersect_with_kernel(P(), Sph(), K()); + call_do_intersect_with_kernel(P(), Tr(), K()); + call_do_intersect_with_kernel(P(), T(), K()); + + call_do_intersect_with_kernel(R(), Bbox_3(), K()); + call_do_intersect_with_kernel(R(), Cub(), K()); call_do_intersect_with_kernel(R(), L(), K()); + call_do_intersect_with_kernel(R(), Pl(), K()); + call_do_intersect_with_kernel(R(), P(), K()); call_do_intersect_with_kernel(R(), R(), K()); call_do_intersect_with_kernel(R(), S(), K()); + call_do_intersect_with_kernel(R(), Sph(), K()); call_do_intersect_with_kernel(R(), Tr(), K()); - call_do_intersect_with_kernel(R(), Bbox_3(), K()); + call_do_intersect_with_kernel(R(), T(), K()); - call_do_intersect_with_kernel(S(), Pl(), K()); + call_do_intersect_with_kernel(S(), Bbox_3(), K()); + call_do_intersect_with_kernel(S(), Cub(), K()); + call_do_intersect_with_kernel(S(), R(), K()); call_do_intersect_with_kernel(S(), L(), K()); + call_do_intersect_with_kernel(S(), P(), K()); call_do_intersect_with_kernel(S(), R(), K()); call_do_intersect_with_kernel(S(), S(), K()); + call_do_intersect_with_kernel(S(), Sph(), K()); call_do_intersect_with_kernel(S(), Tr(), K()); - call_do_intersect_with_kernel(S(), Bbox_3(), K()); + call_do_intersect_with_kernel(S(), T(), K()); - call_do_intersect_with_kernel(Tr(), Pl(), K()); + call_do_intersect_with_kernel(Tr(), Bbox_3(), K()); + call_do_intersect_with_kernel(Tr(), Cub(), K()); + call_do_intersect_with_kernel(Tr(), R(), K()); call_do_intersect_with_kernel(Tr(), L(), K()); + call_do_intersect_with_kernel(Tr(), P(), K()); call_do_intersect_with_kernel(Tr(), R(), K()); call_do_intersect_with_kernel(Tr(), S(), K()); call_do_intersect_with_kernel(Tr(), Tr(), K()); - call_do_intersect_with_kernel(Tr(), Bbox_3(), K()); + call_do_intersect_with_kernel(Tr(), T(), K()); - call_do_intersect_with_kernel(Tr(), Pl(), K()); - call_do_intersect_with_kernel(Tr(), L(), K()); - call_do_intersect_with_kernel(Tr(), R(), K()); - call_do_intersect_with_kernel(Tr(), S(), K()); - call_do_intersect_with_kernel(Tr(), Tr(), K()); - call_do_intersect_with_kernel(Tr(), Bbox_3(), K()); + call_do_intersect_with_kernel(T(), Bbox_3(), K()); + call_do_intersect_with_kernel(T(), Cub(), K()); + call_do_intersect_with_kernel(T(), R(), K()); + call_do_intersect_with_kernel(T(), L(), K()); + call_do_intersect_with_kernel(T(), P(), K()); + call_do_intersect_with_kernel(T(), R(), K()); + call_do_intersect_with_kernel(T(), S(), K()); + call_do_intersect_with_kernel(T(), Tr(), K()); + call_do_intersect_with_kernel(T(), T(), K()); - call_do_intersect_with_kernel(Bbox_3(), Pl(), K()); + call_do_intersect_with_kernel(Bbox_3(), Cub(), K()); call_do_intersect_with_kernel(Bbox_3(), L(), K()); + call_do_intersect_with_kernel(Bbox_3(), Pl(), K()); + call_do_intersect_with_kernel(Bbox_3(), P(), K()); call_do_intersect_with_kernel(Bbox_3(), R(), K()); call_do_intersect_with_kernel(Bbox_3(), S(), K()); call_do_intersect_with_kernel(Bbox_3(), Sph(), K()); call_do_intersect_with_kernel(Bbox_3(), Tr(), K()); } +} + +int main(int argc, char**) +{ + test >(argc); + test(argc); + test(argc); + return EXIT_SUCCESS; } diff --git a/Intersections_3/test/Intersections_3/issue_5428.cpp b/Intersections_3/test/Intersections_3/issue_5428.cpp index ea6dc18cd0f..ba39e1bd109 100644 --- a/Intersections_3/test/Intersections_3/issue_5428.cpp +++ b/Intersections_3/test/Intersections_3/issue_5428.cpp @@ -4,21 +4,22 @@ typedef CGAL::Exact_predicates_inexact_constructions_kernel EPICK; typedef EPICK::Point_3 Point; -int main() +int main(int, char**) { - EPICK::Plane_3 pl(Point(0, 0, 0), Point(1, 0, 0), Point(0, 1, 0)); - std::vector pts; - pts.push_back(Point(-10,-10,-10)); - pts.push_back(Point(10,10,10)); + pts.emplace_back(-10,-10,-10); + pts.emplace_back(10,10,10); + + EPICK::Plane_3 pl(Point(0, 0, 0), Point(1, 0, 0), Point(0, 1, 0)); CGAL::Bbox_3 cub = CGAL::bbox_3(pts.begin(), pts.end()); - auto result = intersection(cub,pl); + auto result = intersection(cub, pl); const std::vector* res = boost::get >(&*result); - for (Point p : *res) { + for(const Point& p : *res) std::cout << p << std::endl; - } + + assert(res->size() == 4); return 0; } diff --git a/Intersections_3/test/Intersections_3/line_line.cpp b/Intersections_3/test/Intersections_3/line_line.cpp deleted file mode 100644 index 225d6403d49..00000000000 --- a/Intersections_3/test/Intersections_3/line_line.cpp +++ /dev/null @@ -1,80 +0,0 @@ -#include -#include -#include -#include - -typedef CGAL::Quotient< CGAL::MP_Float > FT; -typedef CGAL::Cartesian K; - -// The construction test has to be working -// The equal test has to be working - -template -void _test_intersection_construct(K k) -{ - typedef typename K::FT FT; - typedef typename K::Point_3 Point_3; - typedef typename K::Line_3 Line_3; - typedef typename K::Intersect_3 Intersect_3; - typedef typename K::Construct_line_3 Construct_line_3; - - Intersect_3 theIntersect_3 = k.intersect_3_object(); - Construct_line_3 theConstruct_line_3 = k.construct_line_3_object(); - - std::cout << "Testing intersection(Line, Line)..." << std::endl; - // Testing the case where it overlaps, or do not intersect - for(int vx=0;vx<4;vx++) { - for(int vy=1;vy<4;vy++) { - for(int vz=0;vz<4;vz++) { - if(vx == 0 && vy == 0 && vz == 0) continue; - const FT a = FT(vx); - const FT b = FT(vy); - const FT c = FT(vz); - Line_3 l = theConstruct_line_3(Point_3(0,0,0), Point_3(a,b,c)); - Line_3 l_1 = theConstruct_line_3(Point_3(0,0,0), Point_3(-a,-b,-c)); - Line_3 l_2 = theConstruct_line_3(Point_3(0,0,0), Point_3(-a,-b,7)); - Line_3 l_3 = theConstruct_line_3(Point_3(1,0,0), Point_3(a,b,c)); - Line_3 l_4 = theConstruct_line_3(Point_3(1,0,0), Point_3(a+1,b,c)); - CGAL::Object obj1 = theIntersect_3(l, l_1); - CGAL::Object obj2 = theIntersect_3(l, l_2); - CGAL::Object obj3 = theIntersect_3(l, l_3); - CGAL::Object obj4 = theIntersect_3(l, l_4); - CGAL::Object obj1l = CGAL::intersection(l, l_1); - CGAL::Object obj2l = CGAL::intersection(l, l_2); - CGAL::Object obj3l = CGAL::intersection(l, l_3); - CGAL::Object obj4l = CGAL::intersection(l, l_4); - - assert(CGAL::do_intersect(l, l_1)); - assert(CGAL::do_intersect(l, l_2)); - assert(CGAL::do_intersect(l, l_3)); - assert(!CGAL::do_intersect(l, l_4)); - - Point_3 interp2, interp3; - Line_3 interl1; - assert(assign(interl1, obj1)); - assert(assign(interp2, obj2)); - assert(assign(interp3, obj3)); - assert(obj4.is_empty()); - assert(interp2 == Point_3(0,0,0)); - assert(interp3 == Point_3(a,b,c)); - Point_3 interp5, interp6; - Line_3 interl2; - assert(assign(interl2, obj1l)); - assert(assign(interp5, obj2l)); - assert(assign(interp6, obj3l)); - assert(obj4l.is_empty()); - assert(interp5 == Point_3(0,0,0)); - assert(interp6 == Point_3(a,b,c)); - } - } - } - - std::cout << "OK!" << std::endl; -} - -int main() -{ - K k; - _test_intersection_construct(k); - return 0; -} diff --git a/Intersections_3/test/Intersections_3/numrep1.h b/Intersections_3/test/Intersections_3/numrep1.h deleted file mode 100644 index d752c26aa0c..00000000000 --- a/Intersections_3/test/Intersections_3/numrep1.h +++ /dev/null @@ -1,101 +0,0 @@ -#if TESTR == 1 - -#include - -inline double to_nt(int d) -{ - return (double) d; -} - -#endif - -#if TESTR == 2 - -# include - -inline long to_nt(int d) -{ - return d; -} - -#endif - -#if TESTR == 3 - -#include -#include - - -inline CGAL::TestfieldC to_nt(int d) -{ - unsigned char dummy1 = 'a'; - signed char dummy2 = 'a'; - return CGAL::TestfieldC(dummy1, dummy2, (double)d); -} - -#endif - -#if TESTR == 4 - -#include -#include - - -inline CGAL::TestrepH to_nt(int d) -{ - unsigned char dummy1 = 'a'; - signed char dummy2 = 'a'; - return CGAL::TestrepH(dummy1, dummy2, d); -} - -#endif - -#if TESTR == 5 - -# include - -inline double to_nt(int d) -{ - return d; -} - -#endif - -#if TESTR == 6 - -# include -# include - -inline CGAL::Checked_long to_nt(int d) -{ - return CGAL::Checked_long(long(d)); -} - -#endif - - -struct randomint { - randomint() ; - int get() const { return sequence[cur]; } - int next() { cur = (cur+1)%11; return get();} -private: - int sequence[11]; - int cur; -}; - -inline randomint::randomint() -{ - cur = 0; - sequence[0] = 19; - sequence[1] = 5; - sequence[2] = 17; - sequence[3] = 13; - sequence[4] = 29; - sequence[5] = 2; - sequence[6] = 23; - sequence[7] = 31; - sequence[8] = 3; - sequence[9] = 37; - sequence[10] = 11; -} - diff --git a/Intersections_3/test/Intersections_3/numrep2.h b/Intersections_3/test/Intersections_3/numrep2.h deleted file mode 100644 index 4f682fa249a..00000000000 --- a/Intersections_3/test/Intersections_3/numrep2.h +++ /dev/null @@ -1,46 +0,0 @@ -#if TESTR == 1 - -typedef double testnt; -typedef CGAL::Cartesian TestR; - -#endif - -#if TESTR == 2 - -typedef long testnt; -typedef CGAL::Homogeneous TestR; - -#endif - - -#if TESTR == 3 - -typedef CGAL::TestfieldC testnt; -typedef CGAL::Cartesian TestR; - -#endif - - -#if TESTR == 4 - -typedef CGAL::TestrepH testnt; -typedef CGAL::Homogeneous TestR; - - -#endif - -#if TESTR == 5 - -#include -//typedef double testnt; // some tests trigger a degenerate case -typedef CGAL::MP_Float testnt; -typedef CGAL::Homogeneous TestR; - -#endif - -#if TESTR == 6 - -typedef CGAL::Checked_long testnt; -typedef CGAL::Homogeneous TestR; - -#endif diff --git a/Intersections_3/test/Intersections_3/test_intersections_3.cpp b/Intersections_3/test/Intersections_3/test_intersections_3.cpp deleted file mode 100644 index d407f6c313d..00000000000 --- a/Intersections_3/test/Intersections_3/test_intersections_3.cpp +++ /dev/null @@ -1,1307 +0,0 @@ -// 3D intersection tests. - -// We want to check that no division is performed for interface macro Do_intersect_3_RT -#define CGAL_NO_MPZF_DIVISION_OPERATOR - -#include -#include -#include -#include - -#include -#include -#include -#include -#include - -#include -#include - -#include "create_bbox_mesh.h" - -const double epsilon = 0.001; - -struct randomint { - randomint() ; - int get() const { return sequence[cur]; } - int next() { cur = (cur+1)%11; return get();} -private: - int sequence[11]; - int cur; -}; - -inline randomint::randomint() -{ - cur = 0; - sequence[0] = 19; - sequence[1] = 5; - sequence[2] = 17; - sequence[3] = 13; - sequence[4] = 29; - sequence[5] = 2; - sequence[6] = 23; - sequence[7] = 31; - sequence[8] = 3; - sequence[9] = 37; - sequence[10] = 11; -} - -randomint ri; - -inline double to_nt(int d) -{ - return double(d); -} - -template < typename K > -struct Test { - - typedef CGAL::Point_3< K > P; - typedef CGAL::Segment_3< K > S; - typedef CGAL::Line_3< K > L; - typedef CGAL::Plane_3< K > Pl; - typedef CGAL::Triangle_3< K > Tr; - typedef CGAL::Ray_3< K > R; - typedef CGAL::Iso_cuboid_3< K > Cub; - typedef CGAL::Sphere_3< K > Sph; - typedef CGAL::Tetrahedron_3< K > Tet; - typedef CGAL::Bbox_3 Bbox; - typedef std::vector

Pol; - - - template < typename Type > - bool approx_equal_nt(const Type &t1, const Type &t2) - { - if (t1 == t2) - return true; - if (CGAL::abs(t1 - t2) / (CGAL::max)(CGAL::abs(t1), CGAL::abs(t2)) < epsilon) - return true; - std::cout << " Approximate comparison failed between : " << t1 << " and " << t2 << "\n"; - return false; - } - - template < typename Type > - bool approx_equal(const Type&t1, const Type&t2) - { - return t1 == t2; - // we need approx equal to check approx kernels, but maybe we should only test with exact kernels - // (approx kernels were useful before, when the text output was checked by diff ?) - // idea : test containment with intervals ? or use some "epsilon double"? - // I need to convert the text output to exact rationals in the source... - // Well, for now the current scheme works. - } - - bool approx_equal(const P & p, const P & q) - { - return approx_equal_nt(p.x(), q.x()) && - approx_equal_nt(p.y(), q.y()) && - approx_equal_nt(p.z(), q.z()); - } - - bool approx_equal(const S & p, const S & q) - { - return approx_equal(p.source(), q.source()) && approx_equal(p.target(), q.target()); - } - - bool approx_equal(const Pol & p, const Pol & q) - { - if(p.size() != q.size()) - return false; - - for(typename Pol::const_iterator itp = p.begin(), itq = q.begin(); itp != p.end(); ++itp, ++itq) - if(!approx_equal(*itp, *itq)) - return false; - - return true; - } - - template < typename O1, typename O2> - void check_no_intersection(const O1& o1, const O2& o2) - { - assert(!CGAL::do_intersect(o1, o2)); - assert(!CGAL::do_intersect(o2, o1)); - } - - template < typename Res, typename O1, typename O2 > - void check_intersection(const O1& o1, const O2& o2) - { - Res tmp; - assert(CGAL::do_intersect(o1, o2)); - assert(CGAL::assign(tmp, CGAL::intersection(o1, o2))); - assert(CGAL::do_intersect(o2, o1)); - assert(CGAL::assign(tmp, CGAL::intersection(o2, o1))); - } - - template < typename Res, typename O1, typename O2 > - void check_intersection(const O1& o1, const O2& o2, const Res& result, bool do_opposite = true) - { - Res tmp; - assert(CGAL::do_intersect(o1, o2)); - assert(CGAL::assign(tmp, CGAL::intersection(o1, o2))); - assert(approx_equal(tmp, result)); - if (do_opposite) { - assert(CGAL::do_intersect(o2, o1)); - assert(CGAL::assign(tmp, CGAL::intersection(o2, o1))); - assert(approx_equal(tmp, result)); - } - } - - - P p(int x, int y, int z) - { - int w = ri.next(); - return P(to_nt(x*w), to_nt(y*w), to_nt(z*w), to_nt(w)); - } - - Pl pl(int a, int b, int c, int d) - { - int w = ri.next(); - return Pl(to_nt(a*w), to_nt(b*w), to_nt(c*w), to_nt(d*w)); - } - - void P_do_intersect() - { - P p(0,0,0), q(1,0,0), r(2,0,0), s(10,10,10), s2(10,10,0), s3(10,-10,-1), t(3,0,0); - Sph sph(p,1); - Cub cub(p,r); - assert(do_intersect(q,sph)); - assert(do_intersect(sph,q)); - assert(! do_intersect(s,cub)); - assert(! do_intersect(cub,s)); - - assert(do_intersect(sph, Tr(p,q,s))); - assert(do_intersect(sph, Tr(r,q,s))); - assert(! do_intersect(sph, Tr(r,s,t))); - - assert(! do_intersect(sph, Tr(s,s2,s3))); - - assert(do_intersect(sph, S(p,r))); - assert(do_intersect(sph, S(q,r))); - assert(do_intersect(sph, S(s,q))); - assert(! do_intersect(sph, S(s,r))); - - assert(do_intersect(sph, L(p,r))); - assert(do_intersect(sph, L(q,r))); - assert(do_intersect(sph, L(s,q))); - assert(! do_intersect(sph, L(s,r))); - - assert(do_intersect(sph, R(p,r))); - assert(do_intersect(sph, R(q,r))); - assert(do_intersect(sph, R(s,q))); - assert(! do_intersect(sph, R(s,r))); - - } - - - void Cub_Cub() - { - std::cout << "Iso_cuboid - Iso_cuboid\n"; - check_intersection (Cub(p(-7, 6, 1), p(7092, 71, 58)), Cub(p(-758, -98725, 43), p(17, 9025473, 47)), - Cub(p(-7, 6, 43), p(17, 71, 47))); - check_no_intersection (Cub(p(-7, 6, 1), p(7092, 71, 58)), Cub(p(-758, 98725, 43), p(17, 9025473, 47))); - check_no_intersection (Cub(p(-73, 6, 1), p(-70, 71, 58)), Cub(p(8, -98725, 43), p(17, 9025473, 47))); - check_no_intersection (Cub(p(-7, 6, 1), p(7092, 71, 58)), Cub(p(-758, -98725, -47), p(17, 9025473, -43))); - } - - void L_Cub() - { - std::cout << "Line - Iso_cuboid\n"; - check_intersection (L(p(-3, 1,-5), p( -2, -5, -7)), Cub(p( -7, -8, -9), p(-1, 2, -4)), - S(P(-3.16667, 2, -4.66667), P(-1.5, -8, -8))); - check_intersection (L(p( 0, 0, 3), p( 1, 2, 3)), Cub(p( 1, 1, 1), p( 3, 5, 8)), - S(P( 1, 2, 3), P( 2.5, 5, 3))); - check_intersection (L(p( 1, 0, 0), p( 1, 2, 3)), Cub(p( 1, 1, 1), p( 3, 5, 8)), - S(P( 1, 1, 1.5), P( 1, 5, 7.5))); - check_intersection (L(p( 0, 2, 0), p( 1, 2, 3)), Cub(p( 2, 1, 1), p( 3, 5, 8)), - S(P( 2, 2, 6), P(2.66667, 2, 8))); - check_no_intersection (L(p( 0, 0, 0), p( 1, 0, 3)), Cub(p( 2, 1, 1), p( 3, 5, 8))); - check_no_intersection (L(p( 4, 0, 0), p( 4, 1, 3)), Cub(p( 2, 1, 1), p( 3, 5, 8))); - check_intersection (L(p( 0, 0, 0), p( 1, 2, 3)), Cub(p( 1, 1, 1), p( 3, 5, 8)), - S(P( 1, 2, 3), P(2.5, 5, 7.5))); - } - - void Pl_L() - { - std::cout << "Plane - Line\n"; - check_intersection (pl(1, 1, 1, 0), L(p( 1, 1, 1), p( 2, 3, 4)), - P(0.5, 0, -0.5)); - check_intersection (pl(0, 0, 1,-1), L(p( 1, 1, 1), p( 2, 3, 1))); - check_no_intersection (pl(0, 0, 1,-2), L(p( 1, 1, 1), p( 2, 3, 1))); - check_intersection (pl(1, 0, 1, 3), L(p( 1, 1, 1), p( 2, 3, -1)), - P( 6, 11, -9)); - check_intersection (pl(1, 2, 4, 7), L(p( 1, 1, 1), p( 2, 3, 4)), - P( 0.176471, -0.647059, -1.47059)); - } - - void Pl_Pl() - { - std::cout << "Plane - Plane\n"; - check_intersection (pl(0, 0, 1, 0), pl(0, 1, 0, 0), L(P(0, 0, 0), P(-85, 0, 0)), false); - check_intersection (pl(0, 1, 0, 0), pl(0, 0, 1, 0), L(P(-85, 0, 0), P(0, 0, 0)), false); - check_intersection (pl(0, 0, 1, 1), pl(0, 0, 3, 3)); - check_no_intersection (pl(2, 1, 3, 4), pl(6, 3, 9, 3)); - check_intersection (pl(2, 1, 3, 4), pl(6, 3, 9, 12)); - check_intersection (pl(2, 3, 7, 5), pl(9, 7, 1, 3), L(P(2,-3, 0), P(-3908, 5182, -1105)), false); - check_intersection (pl(9, 7, 1, 3), pl(2, 3, 7, 5), L(P(-3908, 5182, -1105), P(2,-3, 0)), false); - } - - void Pl_Pl_Pl() - { - std::cout << "Plane - Plane - Plane\n"; - Pl pl1(1,0,0,0); - Pl pl2(0,1,0,0); - Pl pl3(0,0,1,0); - - // Generic intersection. - assert(CGAL::do_intersect(pl1, pl2, pl3)); - CGAL::Object o = CGAL::intersection(pl1, pl2, pl3); - P p; - assert(assign(p, o)); - assert(p == P(0,0,0)); - - // Empty intersection. - Pl pl4(1,0,0,1); // pl4 is // to pl1. - - assert(!CGAL::do_intersect(pl1, pl2, pl4)); - CGAL::Object o2 = CGAL::intersection(pl1, pl2, pl4); - assert(o2.is_empty()); - - assert(!CGAL::do_intersect(pl1, pl4, pl2)); - CGAL::Object o3 = CGAL::intersection(pl1, pl4, pl2); - assert(o3.is_empty()); - - // Intersection in a line. - Pl pl5(1,1,0,0); // pl1, pl2, pl5 intersect in the line l. - L l; - - assert(CGAL::do_intersect(pl1, pl2, pl5)); - CGAL::Object o4 = CGAL::intersection(pl1, pl2, pl5); - assert(assign(l, o4)); - - assert(l == L(P(0,0,0), P(0,0,1))); - - // Intersection in a plane. - assert(CGAL::do_intersect(pl1, pl1, pl1)); - CGAL::Object o5 = CGAL::intersection(pl1, pl1, pl1); - Pl pl; - assert(assign(pl, o5)); - assert(pl == pl1); - } - - void Pl_R() - { - std::cout << "Plane - Ray\n"; - check_no_intersection (pl( 1, 1, 1, 0), R(p(1, 1, 1), p(2, 3, 4))); - check_intersection (pl(-3, 7, 5, -2), R(p(12, -3, 7), p(-1, 5, -3)), P(5.06667, 1.26667, 1.66667)); - check_intersection (pl( 0, 0, 1, -1), R(p( 1, 1, 1), p( 2, 3, 1))); - check_no_intersection (pl( 0, 0, 1, -2), R(p( 1, 1, 1), p( 2, 3, 1))); - check_intersection (pl( 1, 0, 1, 3), R(p( 1, 1, 1), p( 2, 3, -1)), P(6, 11, -9)); - check_no_intersection (pl( 1, 2, 4, 7), R(p( 1, 1, 1), p( 2, 3, 4))); - check_intersection (pl( 0, 0, 1, 0), R(p( 1, 1,-1), p( 2, 3, 4)), P(1.2, 1.4, 0)); - check_intersection (pl( 0, 0, 1, 0), R(p( 2, 3, 4), p( 1, 1, -1)), P(1.2, 1.4, 0)); - check_intersection (pl( 0, 0, 1, 0), R(p( 7, 1, 0), p(83, 1, -4)), P( 7, 1, 0)); - check_intersection (pl( 0, 0, 1, 0), R(p(12, 6,-4), p( 7,25, 0)), P( 7, 25, 0)); - } - - void Pl_S() - { - std::cout << "Plane - Segment\n"; - check_no_intersection (pl( 1, 1, 1, 0), S(p(1, 1, 1), p(2, 3, 4))); - check_intersection (pl(-3, 7, 5, -2), S(p(12, -3, 7), p(-1, 5, -3)), P(5.06667, 1.26667, 1.66667)); - check_intersection (pl( 0, 0, 1, -1), S(p( 1, 1, 1), p( 2, 3, 1))); - check_no_intersection (pl( 0, 0, 1, -2), S(p( 1, 1, 1), p( 2, 3, 1))); - check_no_intersection (pl( 1, 0, 1, 3), S(p( 1, 1, 1), p( 2, 3, -1))); - check_no_intersection (pl( 1, 2, 4, 7), S(p( 1, 1, 1), p( 2, 3, 4))); - check_intersection (pl( 0, 0, 1, 0), S(p( 1, 1,-1), p( 2, 3, 4)), P(1.2, 1.4, 0)); - check_intersection (pl( 0, 0, 1, 0), S(p( 2, 3, 4), p( 1, 1, -1)), P(1.2, 1.4, 0)); - check_intersection (pl( 0, 0, 1, 0), S(p( 7, 1, 0), p(83, 1, -4)), P( 7, 1, 0)); - check_intersection (pl( 0, 0, 1, 0), S(p(12, 6,-4), p( 7,25, 0)), P( 7, 25, 0)); - } - - void R_Cub() - { - std::cout << "Ray - Iso_cuboid\n"; - check_intersection (R(p( -3, 1, -5), p( -2, -5, -7)), Cub(p( -7, -8, -9), p( -1, 2, -4)), - S(P(-3, 1, -5), P(-1.5, -8, -8))); - check_intersection (R(p( 0, 0, 3), p( 1, 2, 3)), Cub(p( 1, 1, 1), p( 3, 5, 8)), - S(P( 1, 2, 3), P( 2.5, 5, 3))); - check_intersection (R(p( 1, 0, 0), p( 1, 2, 3)), Cub(p( 1, 1, 1), p( 3, 5, 8)), - S(P( 1, 1,1.5), P( 1, 5,7.5))); - check_intersection (R(p( 0, 2, 0), p( 1, 2, 3)), Cub(p( 2, 1, 1), p( 3, 5, 8)), - S(P( 2, 2, 6), P(2.66667,2, 8))); - check_no_intersection (R(p( 0, 0, 0), p( 1, 0, 3)), Cub(p( 2, 1, 1), p( 3, 5, 8))); - check_no_intersection (R(p( 4, 0, 0), p( 4, 1, 3)), Cub(p( 2, 1, 1), p( 3, 5, 8))); - check_intersection (R(p( 0, 0, 0), p( 1, 2, 3)), Cub(p( 1, 1, 1), p( 3, 5, 8)), - S(P( 1, 2, 3), P(2.5, 5, 7.5))); - } - - void S_Cub() - { - std::cout << "Segment - Iso_cuboid\n"; - check_intersection (S(p( -3, 1, -5), p( -2, -5, -7)), Cub(p( -7, -8, -9), p( -1, 2, -4)), - S(P(-3, 1, -5), P( -2, -5, -7))); - check_intersection (S(p( 0, 0, 3), p( 1, 2, 3)), Cub(p( 1, 1, 1), p( 3, 5, 8)), - P( 1, 2, 3)); - check_intersection (S(p( 1, 0, 0), p( 1, 2, 3)), Cub(p( 1, 1, 1), p( 3, 5, 8)), - S(P( 1, 1, 1.5), P( 1, 2, 3))); - check_no_intersection (S(p( 0, 2, 0), p( 1, 2, 3)), Cub(p( 2, 1, 1), p( 3, 5, 8))); - check_no_intersection (S(p( 0, 0, 0), p( 1, 0, 3)), Cub(p( 2, 1, 1), p( 3, 5, 8))); - check_no_intersection (S(p( 4, 0, 0), p( 4, 1, 3)), Cub(p( 2, 1, 1), p( 3, 5, 8))); - check_intersection (S(p( 0, 0, 0), p( 1, 2, 3)), Cub(p( 1, 1, 1), p( 3, 5, 8)), - P( 1, 2, 3)); - } - - void Pl_Tr() - { - std::cout << "Plane - Triangle\n"; - check_intersection ( Pl(P(0,0,0),P(12,0,0),P(0,11,0)),Tr(P(0,0,0),P(1,0,0),P(0,1,0)),Tr(P(0,0,0),P(1,0,0),P(0,1,0)),true); - check_intersection ( Pl(P(0,0,0),P(12,0,0),P(0,11,0)),Tr(P(0,0,0),P(1,0,1),P(0,1,1)),P(0,0,0),true); - check_intersection ( Pl(P(0,0,0),P(12,0,0),P(0,11,0)),Tr(P(0,0,0),P(1,0,0),P(0,1,1)),S(P(0,0,0),P(1,0,0)),true); - check_intersection ( Pl(P(0,0,0),P(12,0,0),P(0,11,0)),Tr(P(1,0,-1),P(-1,0,-1),P(0,0,1)),S(P(0.5,0,0),P(-0.5,0,0)),true); - } - - void S_L() - { - std::cout << "Segment - Line\n"; - check_intersection ( S(P(0,0,0),P(12,0,0)),L(P(0,0,0),P(1,0,0)),S(P(0,0,0),P(12,0,0)),true); - check_intersection ( S(P(0,0,0),P(12,0,0)),L(P(0,1,0),P(0,-1,0)),P(0,0,0),true); - check_intersection ( S(P(-12,0,0),P(12,0,0)),L(P(0,1,0),P(0,-1,0)),P(0,0,0),true); - } - - void R_L() - { - std::cout << "Ray - Line\n"; - check_intersection (L(P(0,0,0),P(1,0,0)),R(P(3,0,0),P(6,0,0)),R(P(3,0,0),P(6,0,0))); - check_no_intersection (L(P(0,0,0),P(1,0,0)),R(P(3,0,1),P(6,0,1))); - check_intersection (L(P(0,0,0),P(1,0,0)),R(P(3,0,0),P(6,4,0)),P(3,0,0)); - check_intersection (L(P(0,0,0),P(1,0,0)),R(P(0,-2,0),P(0,-1,0)),P(0,0,0)); - check_no_intersection (L(P(0,0,0),P(1,0,0)),R(P(0, 2,0),P(0,4,0))); - check_intersection (L(P(0,0,0),P(1,0,0)),R(P(5,-2,0),P(5,-1,0)),P(5,0,0)); - check_no_intersection (L(P(0,0,0),P(1,0,0)),R(P(6, 2,0),P(5,4,0))); - } - - void R_S() - { - std::cout << "Ray - Segment\n"; - check_intersection (S(P(-3,0,0),P(3,0,0)),R(P(0,-2,0),P(0,-1,0)),P(0,0,0)); - check_intersection (S(P(-3,0,0),P(3,0,0)),R(P(-3,-2,0),P(-3,-1,0)),P(-3,0,0)); - check_intersection (S(P(-3,0,0),P(3,0,0)),R(P(3,-2,0),P(3,-1,0)),P(3,0,0)); - check_intersection (S(P(-3,0,0),P(3,0,0)),R(P(0,0,0),P(0,-1,0)),P(0,0,0)); - check_intersection (S(P(-3,0,0),P(3,0,0)),R(P(-3,0,0),P(-3,-1,0)),P(-3,0,0)); - check_intersection (S(P(-3,0,0),P(3,0,0)),R(P(3,0,0),P(3,-1,0)),P(3,0,0)); - check_intersection (S(P(-3,0,0),P(3,0,0)),R(P(0,-2,0),P(0,0,0)),P(0,0,0)); - check_intersection (S(P(-3,0,0),P(3,0,0)),R(P(-3,-2,0),P(-3,0,0)),P(-3,0,0)); - check_intersection (S(P(-3,0,0),P(3,0,0)),R(P(3,-2,0),P(3,0,0)),P(3,0,0)); - check_no_intersection (S(P(-3,0,0),P(3,0,0)),R(P(0,-1,0),P(0,-2,0))); - check_no_intersection (S(P(-3,0,0),P(3,0,0)),R(P(-3,-1,0),P(-3,-2,0))); - check_no_intersection (S(P(-3,0,0),P(3,0,0)),R(P(3,-1,0),P(3,-2,0))); - check_intersection (S(P(-3,0,0),P(3,0,0)),R(P(-4,0,0),P(-2,0,0)),S(P(-3,0,0),P(3,0,0))); - check_intersection (S(P(-3,0,0),P(3,0,0)),R(P(-4,0,0),P(7,0,0)),S(P(-3,0,0),P(3,0,0))); - check_intersection (S(P(-3,0,0),P(3,0,0)),R(P(-3,0,0),P(-2,0,0)),S(P(-3,0,0),P(3,0,0))); - check_intersection (S(P(-3,0,0),P(3,0,0)),R(P(-3,0,0),P(7,0,0)),S(P(-3,0,0),P(3,0,0))); - check_intersection (S(P(-3,0,0),P(3,0,0)),R(P(0,0,0),P(-2,0,0)),S(P(0,0,0),P(-3,0,0))); - check_intersection (S(P(-3,0,0),P(3,0,0)),R(P(0,0,0),P(2,0,0)),S(P(0,0,0),P(3,0,0))); - check_intersection (S(P(-3,0,0),P(3,0,0)),R(P(-3,0,0),P(-4,0,0)),P(-3,0,0)); - check_intersection (S(P(-3,0,0),P(3,0,0)),R(P(3,0,0),P(4,0,0)),P(3,0,0)); - check_no_intersection (S(P(-3,0,0),P(3,0,0)),R(P(4,0,0),P(5,0,0))); - check_no_intersection (S(P(-3,0,0),P(3,0,0)),R(P(-5,0,0),P(-8,0,0))); - } - - void R_R() - { - std::cout << "Ray - Ray\n"; - check_intersection (R(P(0,0,0),P(1,0,0)),R(P(0,0,0),P(-1,0,0)),P(0,0,0)); - check_intersection (R(P(0,0,0),P(1,0,0)),R(P(0,0,0),P(0,1,0)),P(0,0,0)); - check_intersection (R(P(0,0,0),P(1,0,0)),R(P(5,0,0),P(5,1,0)),P(5,0,0)); - check_intersection (R(P(0,0,0),P(1,0,0)),R(P(-1,0,0),P(3,0,0)),R(P(0,0,0),P(1,0,0))); - check_intersection (R(P(0,0,0),P(1,0,0)),R(P(2,0,0),P(3,0,0)),R(P(2,0,0),P(6,0,0))); - check_intersection (R(P(0,0,0),P(1,0,0)),R(P(2,0,0),P(-3,0,0)),S(P(0,0,0),P(2,0,0)),false); - check_intersection (R(P(2,0,0),P(-3,0,0)),R(P(0,0,0),P(1,0,0)),S(P(2,0,0),P(0,0,0)),false); - check_no_intersection (R(P(0,0,0),P(1,0,0)),R(P(-2,0,0),P(-3,0,0))); - check_intersection (R(P(0,0,0),P(1,0,0)),R(P(1,0,0),P(1,1,0)),P(1,0,0)); - check_intersection (R(P(0,0,0),P(1,0,0)),R(P(1,-1,0),P(1,1,0)),P(1,0,0)); - check_intersection (R(P(0,0,0),P(1,0,0)),R(P(1,-2,0),P(1,-1,0)),P(1,0,0)); - check_no_intersection (R(P(0,0,0),P(1,0,0)),R(P(1,-1,0),P(1,-2,0))); - check_no_intersection (R(P(0,0,0),P(1,0,0)),R(P(0,-1,0),P(0,-2,0))); - check_no_intersection (R(P(0,0,0),P(1,0,0)),R(P(0,1,0),P(0,2,0))); - } - - void Bbox_L(){ - std::cout << "Bbox - Line\n"; - Bbox box(-1,-1,-1,1,1,1); - - //not in x,y,z slab - check_no_intersection (box,L(P(2,0,0),P(2,0,0.5))); - check_no_intersection (box,L(P(0,2,0),P(0,2,0.5))); - check_no_intersection (box,L(P(0,0,2),P(0.5,0,2))); - //not in x,y,z slab - check_no_intersection (box,L(P(2,0,0.5),P(2,0,0))); - check_no_intersection (box,L(P(0,2,0.5),P(0,2,0))); - check_no_intersection (box,L(P(0.5,0,2),P(0,0,2))); - //in each slab, time not matching - //xz - check_no_intersection (box,L(P(-8,0,0),P(0,0, 8))); - check_no_intersection (box,L(P( 8,0,0),P(0,0, 8))); - check_no_intersection (box,L(P(-8,0,0),P(0,0,-8))); - check_no_intersection (box,L(P( 8,0,0),P(0,0,-8))); - //yz - check_no_intersection (box,L(P(0,-8,0),P(0,0, 8))); - check_no_intersection (box,L(P(0, 8,0),P(0,0, 8))); - check_no_intersection (box,L(P(0,-8,0),P(0,0,-8))); - check_no_intersection (box,L(P(0, 8,0),P(0,0,-8))); - //xy - check_no_intersection (box,L(P(0,-8,0),P(8,0,0))); - check_no_intersection (box,L(P(0, 8,0),P(8,0,0))); - check_no_intersection (box,L(P(0,-8,0),P(-8,0,0))); - check_no_intersection (box,L(P(0, 8,0),P(-8,0,0))); - //Intersecting - //xz - check_intersection (box,L(P(-0.5,0,0),P(0,0, 0.5))); - check_intersection (box,L(P( 0.5,0,0),P(0,0, 0.5))); - check_intersection (box,L(P(-0.5,0,0),P(0,0,-0.5))); - check_intersection (box,L(P( 0.5,0,0),P(0,0,-0.5))); - //yz - check_intersection (box,L(P(0,-0.5,0),P(0,0, 0.5))); - check_intersection (box,L(P(0, 0.5,0),P(0,0, 0.5))); - check_intersection (box,L(P(0,-0.5,0),P(0,0,-0.5))); - check_intersection (box,L(P(0, 0.5,0),P(0,0,-0.5))); - //xy - check_intersection (box,L(P(0,-0.5,0),P(0.5,0,0))); - check_intersection (box,L(P(0, 0.5,0),P(0.5,0,0))); - check_intersection (box,L(P(0,-0.5,0),P(-0.5,0,0))); - check_intersection (box,L(P(0, 0.5,0),P(-0.5,0,0))); - } - - void Bbox_R(){ - std::cout << "Bbox - Ray\n"; - Bbox box(-1,-1,-1,1,1,1); - - //not in x,y,z slab - check_no_intersection (box,R(P(2,0,0),P(2,0,0.5))); - check_no_intersection (box,R(P(0,2,0),P(0,2,0.5))); - check_no_intersection (box,R(P(0,0,2),P(0.5,0,2))); - //not in x,y,z slab - check_no_intersection (box,R(P(2,0,0.5),P(2,0,0))); - check_no_intersection (box,R(P(0,2,0.5),P(0,2,0))); - check_no_intersection (box,R(P(0.5,0,2),P(0,0,2))); - //in each slab, time not matching - //xz - check_no_intersection (box,R(P(-8,0,0),P(0,0, 8))); - check_no_intersection (box,R(P( 8,0,0),P(0,0, 8))); - check_no_intersection (box,R(P(-8,0,0),P(0,0,-8))); - check_no_intersection (box,R(P( 8,0,0),P(0,0,-8))); - //yz - check_no_intersection (box,R(P(0,-8,0),P(0,0, 8))); - check_no_intersection (box,R(P(0, 8,0),P(0,0, 8))); - check_no_intersection (box,R(P(0,-8,0),P(0,0,-8))); - check_no_intersection (box,R(P(0, 8,0),P(0,0,-8))); - //xy - check_no_intersection (box,R(P(0,-8,0),P(8,0,0))); - check_no_intersection (box,R(P(0, 8,0),P(8,0,0))); - check_no_intersection (box,R(P(0,-8,0),P(-8,0,0))); - check_no_intersection (box,R(P(0, 8,0),P(-8,0,0))); - //Intersecting - //xz - check_intersection (box,R(P(-0.5,0,0),P(0,0, 0.5))); - check_intersection (box,R(P( 0.5,0,0),P(0,0, 0.5))); - check_intersection (box,R(P(-0.5,0,0),P(0,0,-0.5))); - check_intersection (box,R(P( 0.5,0,0),P(0,0,-0.5))); - //yz - check_intersection (box,R(P(0,-0.5,0),P(0,0, 0.5))); - check_intersection (box,R(P(0, 0.5,0),P(0,0, 0.5))); - check_intersection (box,R(P(0,-0.5,0),P(0,0,-0.5))); - check_intersection (box,R(P(0, 0.5,0),P(0,0,-0.5))); - //xy - check_intersection (box,R(P(0,-0.5,0),P(0.5,0,0))); - check_intersection (box,R(P(0, 0.5,0),P(0.5,0,0))); - check_intersection (box,R(P(0,-0.5,0),P(-0.5,0,0))); - check_intersection (box,R(P(0, 0.5,0),P(-0.5,0,0))); - } - - void Bbox_Tr() { - std::cout << "Bbox - Triangle\n"; - - typedef CGAL::Polyhedron_3 Polyhedron; - typedef CGAL::AABB_face_graph_triangle_primitive Primitive; - typedef CGAL::AABB_traits Traits; - typedef CGAL::AABB_tree Tree; - - Bbox unit_bbox(-1., -1., -1. - ,1., 1., 1.); - const Polyhedron unit_bbox_poly = create_bbox_mesh(unit_bbox); - const Tree tree(faces(unit_bbox_poly).first, - faces(unit_bbox_poly).second, - unit_bbox_poly); - - const Tr tr(P(-3. , 0. , 0.), - P(-2. , 0.1, 0.), - P(-0.5, 3. , 0.)); - - const bool b = CGAL::do_intersect(unit_bbox, tr); - assert(b == false); - assert(tree.do_intersect(tr) == b); - - CGAL::Random_points_in_cube_3

r(10.); - - std::size_t bbox_does_intersect_counter = 0; - std::size_t plane_does_intersect_counter = 0; - std::size_t do_intersect_counter = 0; - std::cerr << "Begin random testing...\n" - << " (each 'o' in the following line is 1000 tests)\n "; -#if __OPTIMIZE__ - const std::size_t nb_of_tests = 100000; -#else - const std::size_t nb_of_tests = 10000; -#endif - for(std::size_t i = 0, end = nb_of_tests; i < end; ++i) - { - if(i % 1000 == 0) std::cerr << "o"; - const P p0(*r++); - const P p1(*r++); - const P p2(*r++); - const Tr tr(p0, p1, p2); - - const bool b = do_intersect(unit_bbox, tr); - if(b) ++do_intersect_counter; - const bool b_tree = tree.do_intersect(tr); - if(b != b_tree) { - std::stringstream err_msg; - err_msg.precision(17); - CGAL::IO::set_pretty_mode(err_msg); - err_msg << "do_intersect(\n" - << " " << unit_bbox << "\n,\n" - << " " << tr - << " ) = " << std::boolalpha << b << "\n" - << "but the same test with AABB tree gives: " - << std::boolalpha << b_tree << "\n"; - CGAL_error_msg(err_msg.str().c_str()); - std::exit(EXIT_FAILURE); - } - if(CGAL::do_overlap(unit_bbox, tr.bbox())) { - ++bbox_does_intersect_counter; - if(CGAL::do_intersect(unit_bbox, tr.supporting_plane())) { - ++plane_does_intersect_counter; - } - } - // if(); - } // end for-loop - std::cerr << "\n"; - std::cerr << " Number of tests: " - << nb_of_tests << "\n"; - std::cerr << " Number of bbox-does-intersect: " - << bbox_does_intersect_counter << "\n"; - std::cerr << "Number of bbox-and-plane-do-intersect: " - << plane_does_intersect_counter << "\n"; - std::cerr << " Number of intersections: " - << do_intersect_counter << "\n"; - } // end function Bbox_Tr - - void Tet_L(bool is_exact) - { - std::cout << "Tetrahedron_3 - Line_3\n"; - - Tet tet(P(0,0,0), P(0,1,0), P(1,0,0), P(0,0,1)); - if(is_exact) - { - check_no_intersection (tet, L(P(5,0,0), P(5,1,0))); - //on edge - check_intersection (tet, L(P(0,2,0), P(0,3,0)), S(P(0,0,0), P(0,1,0))); - //through vertex and out from face - check_intersection (tet, L(P(0,1,0), P(0.25,0,0.25)), S(P(0,1,0), P(0.25,0,0.25))); - //through a vertex only - check_intersection (tet, L(P(1,1,0), P(-1,1,0)), P(0,1,0)); - //through 2 faces - check_intersection (tet, L(P(0.25,0.25,0), P(0.25,0,0.25)), S(P(0.25,0,0.25), P(0.25,0.25,0))); - //through one edge - check_intersection (tet, L(P(0.5,-0.5,0.5), P(0.5,0.5,0.5)), P(0.5,0,0.5)); - //in a single face through 2 edges - check_intersection (tet, L(P(0.0,0.5,0.0), P(0.5,0.5,0.0)), S(P(0.0,0.5,0.0), P(0.5, 0.5, 0.0) )); - //in a single face through 1 vertex and 1 edge - check_intersection (tet, L(P(0.0,0.5,0.0), P(1.0,0.0,0.0)), S(P(0.0,0.5,0.0), P(1.0, 0.0, 0.0) )); - } - - } - - void Tet_S(bool is_exact) - { - std::cout << "Tetrahedron_3 - Segment_3\n"; - - Tet tet(P(0,0,0), P(0,1,0), P(1,0,0), P(0,0,1)); - if(is_exact) - { - check_no_intersection (tet, S(P(5,0,0), P(5,1,0))); - check_intersection (tet, S(P(0,2,0), P(0,-2,0)), S(P(0,1,0), P(0,0,0))); - check_intersection (tet, S(P(0,1,0), P(0.25,0,0.25)), S(P(0,1,0), P(0.25,0,0.25))); - check_intersection (tet, S(P(2,1,0), P(-2,1,0)), P(0,1,0)); - - check_intersection (tet, S(P(0.1,0.1,0.1), P(0.2,0.2,0.2)), S(P(0.1,0.1,0.1), P(0.2,0.2,0.2))); - typename K::FT coord = 1.0/3.0; - check_intersection (tet, S(P(0.25,0.25,0.25), P(2,2,2)), S(P(0.25,0.25,0.25), P(coord, coord, coord))); - } - else - { - CGAL::intersection (tet, S(P(0,2,0), P(0,-2,0))); - CGAL::intersection (tet, S(P(0,1,0), P(0.25,0,0.25))); - CGAL::intersection (tet, S(P(2,1,0), P(-2,1,0))); - CGAL::intersection (tet, S(P(0.1,0.1,0.1), P(0.2,0.2,0.2))); - CGAL::intersection (tet, S(P(0.25,0.25,0.25), P(2,2,2))); - } - - } - - void Tet_R(bool is_exact) - { - std::cout << "Tetrahedron_3 - Ray_3\n"; - - Tet tet(P(0,0,0), P(0,1,0), P(1,0,0), P(0,0,1)); - if(is_exact) - { - check_no_intersection (tet, R(P(5,0,0), P(5,1,0))); - - check_intersection (tet, R(P(0,2,0), P(0,-2,0)), S(P(0,1,0), P(0,0,0))); - check_intersection (tet, R(P(0,1,0), P(0.25,0,0.25)), S(P(0,1,0), P(0.25,0,0.25))); - check_intersection (tet, R(P(2,1,0), P(-2,1,0)), P(0,1,0)); - - typename K::FT coord = 1.0/3.0; - check_intersection (tet, R(P(0.1,0.1,0.1), P(0.2,0.2,0.2)), S(P(0.1,0.1,0.1), P(coord, coord, coord))); - check_intersection (tet, R(P(0.25,0.25,0.25), P(2,2,2)), S(P(0.25,0.25,0.25), P(coord, coord, coord))); - } - else - { - CGAL::intersection (tet, R(P(0,2,0), P(0,-2,0))); - CGAL::intersection (tet, R(P(0,1,0), P(0.25,0,0.25))); - CGAL::intersection (tet, R(P(2,1,0), P(-2,1,0))); - CGAL::intersection (tet, R(P(0.1,0.1,0.1), P(0.2,0.2,0.2))); - CGAL::intersection (tet, R(P(0.25,0.25,0.25), P(2,2,2))); - } - } - - void Tet_Pl(bool is_exact) - { - std::cout << "Tetrahedron_3 - Plane_3\n"; - - Tet tet(P(0,0,0), P(0,1,0), P(1,0,0), P(0,0,1)); - if(is_exact) - { - check_no_intersection (tet, Pl(P(2,0,0), - P(2,1,0), - P(2,0,1))); - - check_intersection (tet, Pl(P(0,2,0), P(0,0,0), P(0,0,1)), - Tr(P(0,0,0), P(0,1,0), P(0,0,1))); - - check_intersection (tet, Pl(P(0,1,0), P(1,0,0), P(0.5,0,-0.5)), - S(P(0,1,0), P(1,0,0))); - - check_intersection (tet, Pl(P(-1,1,12), P(0,1,-50), P(0.5,1,-0.5)), - P(0,1,0)); - - check_intersection (tet, Pl(P(0,0.5,0), P(1,0.5,-5), P(0.5,0.5,0.5)), - Tr(P(0, 0.5, 0), P(0.5,0.5,0), P(0,0.5,0.5))); - - Pl pl(P(0,0.9,0), P(0.9,0,0), P(0.9,0.01,0.06)); - - typedef typename CGAL::Intersection_traits::result_type Res; - - - //Don't have the right values to test further. - Res res = CGAL::intersection (tet, pl); - - const std::vector

* poly = boost::get >(&*res); - assert(poly != nullptr); - assert(poly->size() == 4); - } - else - { - CGAL::intersection (tet, Pl(P(0,2,0), P(0,0,0), P(0,0,1))); - CGAL::intersection (tet, Pl(P(0,1,0), P(1,0,0), P(0.5,0,-0.5))); - CGAL::intersection (tet, Pl(P(-1,1,12), P(0,1,-50), P(0.5,1,-0.5))); - CGAL::intersection (tet, Pl(P(0,0.5,0), P(1,0.5,-5), P(0.5,0.5,0.5))); - } - - } - - void Tet_Tr(bool is_exact) - { - std::cout << "Tetrahedron_3 - Triangle_3\n"; - - typedef typename CGAL::Intersection_traits::result_type Res; - - Tet tet(P(0,0,0), P(0,1,0), P(1,0,0), P(0,0,1)); - if(is_exact) - { - check_no_intersection (tet, Tr(P(2,0,0), - P(2,1,0), - P(2,0,1))); - - //tr inside a face - check_intersection (tet, Tr(P(0,0.9,0), P(0,0.1,0), P(0,0,0.9)), - Tr(P(0,0.9,0), P(0,0.1,0), P(0,0,0.9))); - //face inside tr - check_intersection (tet, Tr(P(0,2,0), P(0,-2,0), P(0,0,2)), - Tr(P(0,0,1), P(0,0,0), P(0,1,0))); - - Tr tr(P(-2,2,0), P(2,2,0), P(0.25,0.25,0)); - - Res res = CGAL::intersection(tet, tr); - const std::vector

* poly = boost::get >(&*res); - assert(poly != nullptr); - assert(poly->size() == 4); - for(auto& p : *poly) - { - assert(tet.has_on_boundary(p) && tr.has_on(p)); - } - - //only one edge intersecting - check_intersection (tet, Tr(P(-2, 0.5, 0.5), P(-2,0.75,1), P(1.5, 0.5, 0.5)), - P(0,0.5,0.5)); - - - //edge shared, 3rd point outside - check_intersection (tet, Tr(P(0,1,0), P(1,0,0), P(0.5,0,-100)), - S(P(0,1,0), P(1,0,0))); - - //shared edge, 3rd point inside - check_intersection (tet, Tr(P(0,1,0), P(1,0,0), P(0.25,0.25,0.25)), - Tr(P(0,1,0), P(1,0,0), P(0.25,0.25,0.25))); - - //tr adjacent to a vertex, outside - check_intersection (tet, Tr(P(-1,1,12), P(0,1,-50), P(0.5,1,-0.5)), - P(0,1,0)); - - //tr adjacent to an edge, outside - check_intersection (tet, Tr(P(-0.6, 1, 0.6), - P(0.5, 1.20, -0.5), - P(0, -0.5, 0)), - S(P(0,0,0), P(0,1,0))); - - - //tr share a vertex, inside - check_intersection (tet, Tr(P(0,1,0), P(0.1,0.1,0), P(0.5,0.1,0)), - Tr(P(0,1,0), P(0.1,0.1,0), P(0.5,0.1,0))); - - //tr edge adjacent to a vertex - check_intersection (tet, Tr(P(-1,1,0), P(3,1,0), P(0,3,0)), - P(0,1,0)); - - //tr vertex adjacent to a vertex - check_intersection (tet, Tr(P(0,1,0), P(3,1,0), P(0,3,0)), - P(0,1,0)); - - - //traversing triangles - tr = Tr(P(-2, 0.5, 0.25), - P(-2, 0.75, 0.6), - P(1.5, 0.5, 0.25)); - - res = CGAL::intersection(tet, tr); - - - std::vector

* inter = boost::get >(&*res); - assert(inter != nullptr); - assert(inter->size() == 4); - for(auto& p : *inter) - { - assert(tet.has_on_boundary(p) && tr.has_on(p)); - } - - tr = Tr(P(-2, 0.25, 0), - P(-2, 0.75, 0), - P(1.5, 0.5, 0)); - - res = CGAL::intersection(tet, tr); - - - inter = boost::get >(&*res); - assert(inter != nullptr); - assert(inter->size() == 4); - for(auto& p : *inter) - { - assert(tet.has_on_boundary(p) && tr.has_on(p)); - } - - tr = Tr(P(0.2, 0.15, 0.3), - P(-2, 0.6, 0.15), - P(-2, 0.12, 0.15)); - - res = CGAL::intersection(tet, tr); - Tr* res_tr = boost::get(&*res); - assert(res_tr != nullptr); - - tr = Tr(P(0.2, 0.15, 0.3), - P(-1, 0.15, -2), - P(-1, 0.15, 2)); - - res = CGAL::intersection(tet, tr); - - - inter = boost::get >(&*res); - assert(inter != nullptr); - assert(inter->size() == 4); - - tr = Tr(P(0.45, 0.20, 0.1), - P(0.1, 0.20, 0.5), - P(-0.5, 0.25, -0.5)); - - res = CGAL::intersection(tet, tr); - - - inter = boost::get >(&*res); - assert(inter != nullptr); - assert(inter->size() == 4); - - for(auto& p : *inter) - { - assert( - (tet.has_on_bounded_side(p) || tet.has_on_boundary(p)) - && tr.has_on(p)); - } - - //tr share a vertex, through - tr = Tr(P(0,1,0), P(0.1,0.1,0), P(0.9,0.1,0)); - res = CGAL::intersection(tet, tr); - res_tr = boost::get(&*res); - assert(res_tr != nullptr); - - - tr = Tr(P(0.1, 0.5, 0.1), P(0.3,0.1,0.1), P(4,0.3,0.9)); - res = CGAL::intersection(tet, tr); - inter = boost::get >(&*res); - assert(inter != nullptr); - assert(inter->size() == 4); - } - else - { - //tr inside a face - CGAL::intersection(tet, Tr(P(0,0.9,0), P(0,0.1,0), P(0,0,0.9))); - //face inside tr - CGAL::intersection(tet, Tr(P(0,2,0), P(0,-2,0), P(0,0,2))); - - //only one edge intersecting - CGAL::intersection(tet, Tr(P(-2, 0.5, 0.5), P(-2,0.75,1), P(1.5, 0.5, 0.5))); - - //edge shared, 3rd point outside - CGAL::intersection(tet, Tr(P(0,1,0), P(1,0,0), P(0.5,0,-100))); - - //shared edge, 3rd point inside - CGAL::intersection(tet, Tr(P(0,1,0), P(1,0,0), P(0.25,0.25,0.25))); - - //tr adjacent to a vertex, outside - CGAL::intersection(tet, Tr(P(-1,1,12), P(0,1,-50), P(0.5,1,-0.5))); - - //tr share a vertex, inside - CGAL::intersection(tet, Tr(P(0,1,0), P(0.1,0.1,0), P(0.5,0.1,0))); - - //tr edge adjacent to a vertex - CGAL::intersection(tet, Tr(P(-1,1,0), P(3,1,0), P(0,3,0))); - - //tr vertex adjacent to a vertex - CGAL::intersection(tet, Tr(P(0,1,0), P(3,1,0), P(0,3,0))); - - typedef typename CGAL::Intersection_traits::result_type Res; - //traversing triangles - Tr tr(P(-2, 0.5, 0.25), - P(-2, 0.75, 0.6), - P(1.5, 0.5, 0.25)); - - Res res = CGAL::intersection(tet, tr); - - //tr share a vertex, through - tr = Tr(P(0,1,0), P(0.1,0.1,0), P(0.9,0.1,0)); - res = CGAL::intersection(tet, tr); - } - - } - - void Pl_Cub(bool is_exact) - { - std::cout << "Plane_3 - Cuboid_3\n"; - - Cub cub(P(1,1,1), P(2,2,2)); - - if(is_exact) - { - check_no_intersection (cub, Pl(P(3,0,0), - P(3,1,0), - P(3,0,1))); - - //edge - check_intersection (cub, Pl(P(1,1,1), P(1,2,1), P(1.5,0,0)), - S(P(1,1,1), P(1,2,1))); - - - //face - typedef typename CGAL::Intersection_traits::result_type Res; - Res res = CGAL::intersection(cub, Pl(P(1,1,1), P(1,2,1), P(1,2,2))); - - const std::vector

* poly = boost::get >(&*res); - assert(poly != nullptr); - assert(poly->size() == 4); - for(auto& p : *poly) - { - assert(p.x() == 1); - } - res = CGAL::intersection(cub, Pl(P(1,1,1), P(1,2,1), P(2,2,2))); - - poly = boost::get >(&*res); - assert(poly != nullptr); - assert(poly->size() == 4); - for(auto& p : *poly) - { - assert(cub.has_on_boundary(p)); - } - - //vertex - check_intersection (cub, Pl(0.5, -0.5, -0.5, 0), - P(2,1,1)); - //triangle - - check_intersection (cub, Pl(P(2, 1.66, 2), - P(1.66,2,2), - P(2,2,1.66)), - Tr(P(1.66,2,2), - P(2, 2, 1.66), - P(2,1.66,2))); - - //other edge - Pl pl(P(1,1,1), P(1,2,1), P(1.5, 1, 2)); - res = CGAL::intersection(cub, pl); - poly = boost::get >(&*res); - assert(poly != nullptr); - assert(poly->size() == 4); - for(auto& p : *poly) - { - assert(pl.has_on(p) && cub.has_on_boundary(p)); - } - - //random - pl = Pl(0.265189, 0.902464, 0.33946, -2.47551); - res = CGAL::intersection(cub, pl); - poly = boost::get >(&*res); - assert(poly != nullptr); - assert(poly->size() == 5); - for(auto& p : *poly) - { - assert(pl.has_on(p) && cub.has_on_boundary(p)); - } - } - else - { - CGAL::intersection(cub, Pl(P(1,1,1), P(1,2,1), P(1.5,0,0))); - //face - typedef typename CGAL::Intersection_traits::result_type Res; - Res res = CGAL::intersection(cub, Pl(P(1,1,1), P(1,2,1), P(1,2,2))); - res = CGAL::intersection(cub, Pl(P(1,1,1), P(1,2,1), P(2,2,2))); - CGAL::intersection (cub, Pl(0.5, -0.5, -0.5, 0)); - CGAL::intersection (cub, Pl(P(2, 1.66, 2), - P(1.66,2,2), - P(2,2,1.66))); - Pl pl(0.265189, 0.902464, 0.33946, -2.47551); - res = CGAL::intersection(cub, pl); - } - } - - void Cub_Tr(bool is_exact) - { - typedef typename CGAL::Intersection_traits::result_type Res; - - std::cout << "Triangle_3 - Cuboid_3\n"; - - // tr outside - Cub cub(P(1,1,1), P(2,2,2)); - check_no_intersection(cub, Tr(P(1.1, 2, 0), P(2, 3, 1), P(4, 5, 6))); - - // tr in a face - check_intersection(cub, Tr(P(1, 1.1, 1), P(1, 1.5, 1), P(1, 1, 1.1)), - Tr(P(1, 1.1, 1), P(1, 1.5, 1), P(1, 1, 1.1))); - - //face in a tr - Tr tr(P(-3, -3, 1), P(3, -3, 1), P(1.5, 6, 1)); - Res res = CGAL::intersection(cub, tr); - Pol* poly = boost::get >(&*res); - assert(poly != nullptr); - assert(poly->size() == 4); - if(is_exact) - { - for(auto& p : *poly) - assert(tr.has_on(p) && cub.has_on_boundary(p)); - } - - //tr adj to a cuboid vertex - check_intersection(cub, Tr(P(1, 0.5, 0.5), P(3, 2, 1), P(3, 1, 2)), P(2,1,1)); - - //tr adj to a point on a cuboid edge - check_intersection(cub, Tr(P(1, 0.5, 0.5), P(3, 2, 1), P(3, 1, 2)), P(2,1,1)); - - //tr adj to a point on a cuboid face - check_intersection(cub, Tr(P(1, 1.5, 1.5), P(0, 0, 0), P(-4, 3, 1)), P(1, 1.5, 1.5)); - - //tr adj to an edge - check_intersection(cub, Tr(P(2, 1.5, 2), P(5, 6, 7), P(4, 7, 6)), P(2, 1.5, 2)); - - //tr sharing an edge - check_intersection(cub, Tr(P(2, 1.5, 2), P(2, 2.5, 2), P(4, 7, 6)), - S(P(2, 1.5, 2), P(2, 2, 2))); - - //tr sharing part of an edge - check_intersection(cub, Tr(P(2, 1.5, 2), P(5, 6, 7), P(4, 7, 6)), P(2, 1.5, 2)); - - //tr inside - check_intersection(cub, Tr(P(1.1,1.1,1.1), P(1.8,1.8,1.8), P(1.5,1.8,1.1)), - Tr(P(1.1,1.1,1.1), P(1.8,1.8,1.8), P(1.5,1.8,1.1))); - - //tr through - tr = Tr(P(2, 4, 2), P(1, 3.5, -0.5), P(1, -1, 1)); - res = CGAL::intersection(cub, tr); - poly = boost::get >(&*res); - assert(poly != nullptr); - assert(poly->size() == 4); - if(is_exact) - { - for(const P& p : *poly) - assert(tr.has_on(p) && cub.has_on_boundary(p)); - } - - //cutting in half along diagonal (intersection == triangle) - check_intersection(cub, Tr(P(1, 1, 1), P(2, 2, 2), P(2, 2, 1)), - Tr(P(1, 1, 1), P(2, 2, 2), P(2, 2, 1))); - - //cutting in half along diagonal (intersection included in triangle) - tr = Tr(P(1, 1, 10), P(10, 10, 1), P(1, 1, 1)); - res = CGAL::intersection(cub, tr); - poly = boost::get >(&*res); - assert(poly != nullptr); - assert(poly->size() == 4); - if(is_exact) - { - for(const P& p : *poly) - assert(tr.has_on(p) && cub.has_on_boundary(p)); - } - - //6 points intersection - tr = Tr(P(18.66, -5.4, -11.33), P(-2.41, -7.33, 19.75), P(-10.29, 20.15, -10.33)); - res = CGAL::intersection(cub, tr); - poly = boost::get >(&*res); - assert(poly != nullptr); - assert(poly->size() == 6); - if(is_exact) - { - for(const P& p : *poly) - assert(tr.has_on(p) && cub.has_on_boundary(p)); - } - - //triangle clipping a cuboid corner - tr = Tr(P(1.02, 1.33, 0.62), P(1.95, 2.54, 0.95), P(0.79, 2.36, 1.92)); - res = CGAL::intersection(cub, tr); - Tr* tr_res = boost::get(&*res); - assert(tr_res != nullptr); - if(is_exact) - { - assert(cub.has_on_boundary((*tr_res)[0])); - assert(cub.has_on_boundary((*tr_res)[1])); - assert(cub.has_on_boundary((*tr_res)[2])); - } - } - - void Pl_Box(bool is_exact) - { - std::cout << "Plane_3 - Bbox_3\n"; - - Bbox cub(1,1,1,2,2,2); - - if(is_exact) - { - check_no_intersection (cub, Pl(P(3,0,0), - P(3,1,0), - P(3,0,1))); - - //edge - check_intersection (cub, Pl(P(1,1,1), P(1,2,1), P(1.5,0,0)), - S(P(1,1,1), P(1,2,1))); - //face - typedef typename CGAL::Intersection_traits::result_type Res; - Res res = CGAL::intersection(cub, Pl(P(1,1,1), P(1,2,1), P(1,2,2))); - - const std::vector

* poly = boost::get >(&*res); - assert(poly != nullptr); - assert(poly->size() == 4); - for(auto& p : *poly) - { - assert(p.x() == 1); - } - res = CGAL::intersection(cub, Pl(P(1,1,1), P(1,2,1), P(2,2,2))); - poly = boost::get >(&*res); - assert(poly != nullptr); - assert(poly->size() == 4); - //vertex - check_intersection (cub, Pl(0.5, -0.5, -0.5, 0), - P(2,1,1)); - //triangle - - check_intersection (cub, Pl(P(2, 1.66, 2), - P(1.66,2,2), - P(2,2,1.66)), - Tr(P(1.66,2,2), - P(2, 2, 1.66), - P(2,1.66,2))); - - //random - Pl pl(0.265189, 0.902464, 0.33946, -2.47551); - res = CGAL::intersection(cub, pl); - poly = boost::get >(&*res); - assert(poly != nullptr); - assert(poly->size() == 5); - for(auto& p : *poly) - { - assert(pl.has_on(p)); - } - } - else - { - CGAL::intersection(cub, Pl(P(1,1,1), P(1,2,1), P(1.5,0,0))); - //face - typedef typename CGAL::Intersection_traits::result_type Res; - Res res = CGAL::intersection(cub, Pl(P(1,1,1), P(1,2,1), P(1,2,2))); - res = CGAL::intersection(cub, Pl(P(1,1,1), P(1,2,1), P(2,2,2))); - CGAL::intersection (cub, Pl(0.5, -0.5, -0.5, 0)); - CGAL::intersection (cub, Pl(P(2, 1.66, 2), - P(1.66,2,2), - P(2,2,1.66))); - Pl pl(0.265189, 0.902464, 0.33946, -2.47551); - res = CGAL::intersection(cub, pl); - } - } - - void Box_Tr(bool is_exact) - { - std::cout << "Triangle_3 - Cuboid_3\n"; - - Cub cub(P(1,1,1), P(2,2,2)); - - check_no_intersection(cub, Tr(P(1.1, 2,0), - P(2, 3, 1), - P(4, 5, 6))); - - //tr in a face - check_intersection(cub, Tr(P(1,1.1,1), - P(1,1.5,1), - P(1,1,1.1)), - Tr(P(1,1.1,1), - P(1,1.5,1), - P(1,1,1.1)) - ); - //face in a tr - - typedef typename CGAL::Intersection_traits::result_type Res; - Tr tr(P(-3, -3, 1), P(3,-3,1), P(1.5,6,1)); - Res res = CGAL::intersection(cub, tr); - if(is_exact) - { - std::vector

* poly = boost::get >(&*res); - assert(poly != nullptr); - assert(poly->size() == 4); - for(auto& p : *poly) - { - assert(tr.has_on(p) && cub.has_on_boundary(p)); - } - } - - //tr adj to a point - - check_intersection (cub, Tr(P(1, 0.5, 0.5), - P(3, 2, 1), - P(3, 1, 2)), - P(2,1,1)); - //tr adj to an edge - check_intersection (cub, Tr(P(1,0,4), P(2,1,0), P(4,3,0)), - S(P(2,1,2), P(2,1,1))); - //tr inside - check_intersection (cub, Tr(P(1.1,1.1,1.1), P(1.8,1.8,1.8), P(1.5,1.8,1.1)), - Tr(P(1.1,1.1,1.1), P(1.8,1.8,1.8), P(1.5,1.8,1.1))); - //tr through - tr = Tr(P(2, 4, 2), - P(1, 3.5, -0.5), - P(1, -1, 1)); - res = CGAL::intersection(cub, tr); - if(is_exact) - { - std::vector

* poly = boost::get >(&*res); - assert(poly != nullptr); - assert(poly->size() == 4); - for(auto& p : *poly) - { - assert(tr.has_on(p) && cub.has_on_boundary(p)); - } - } - } - - void run(bool is_exact = false) - { - std::cout << "3D Intersection tests\n"; - P_do_intersect(); - Cub_Cub(); - Cub_Tr(is_exact); - L_Cub(); - Pl_L(); - Pl_Pl(); - Pl_Pl_Pl(); - Pl_R(); - Pl_S(); - R_Cub(); - S_Cub(); - Pl_Tr(); - S_L(); - R_L(); - R_S(); - R_R(); - - //If not exact, only check that it doesn't crash - //@{ - Tet_L(is_exact); - Tet_S(is_exact); - Tet_R(is_exact); - Tet_Pl(is_exact); - Tet_Tr(is_exact); - Pl_Cub(is_exact); - Cub_Tr(is_exact); - Pl_Box(is_exact); - Box_Tr(is_exact); - //@} - - Bbox_L(); - Bbox_R(); - Bbox_Tr(); - - } -}; - -int main() -{ - std::cout << " |||||||| Test Simple_cartesian ||||||||" << std::endl; - Test< CGAL::Simple_cartesian >().run(); - - std::cout << " |||||||| Test CGAL::Homogeneous ||||||||" << std::endl; - Test< CGAL::Homogeneous >().run(); - - std::cout << " |||||||| Test EPECK ||||||||" << std::endl; - Test< CGAL::Epeck >().run(true); - - std::cout << " |||||||| Test CGAL::Homogeneous ||||||||" << std::endl; - Test< CGAL::Homogeneous >().run(true); -} diff --git a/Intersections_3/test/Intersections_3/test_intersections_Iso_cuboid_3.cpp b/Intersections_3/test/Intersections_3/test_intersections_Iso_cuboid_3.cpp new file mode 100644 index 00000000000..e0b984070f1 --- /dev/null +++ b/Intersections_3/test/Intersections_3/test_intersections_Iso_cuboid_3.cpp @@ -0,0 +1,714 @@ +// 3D intersection tests. + +// We want to check that no division is performed for interface macro Do_intersect_3_RT +#define CGAL_NO_MPZF_DIVISION_OPERATOR + +// Iso_cuboid_3_X with X < Iso_cuboid (lexicographically) are tested in other files + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include + +#include "intersection_test_helper.h" + +#include +#include +#include +#include +#include + +#include + +#include +#include + +template +struct Iso_cuboid_3_intersection_tester + : public Intersection_3_tester +{ + typedef Intersection_3_tester Base; + + typedef typename K::FT FT; + + typedef CGAL::Iso_cuboid_3 Cub; + typedef CGAL::Line_3 L; + typedef CGAL::Point_3 P; + typedef CGAL::Plane_3 Pl; + typedef CGAL::Ray_3 R; + typedef CGAL::Segment_3 S; + typedef CGAL::Sphere_3 Sph; + typedef CGAL::Tetrahedron_3 Tet; + typedef CGAL::Triangle_3 Tr; + + typedef CGAL::Vector_3 V; + + typedef std::vector

Pol; + + using Base::p; + using Base::pl; + using Base::random_point; + + using Base::check_do_intersect; + using Base::check_do_not_intersect; + using Base::check_intersection; + using Base::check_no_intersection; + +private: + int N = 1000; + +public: + Iso_cuboid_3_intersection_tester(CGAL::Random& r, + const bool has_exact_p = false, + const bool has_exact_c = false) + : Base(r, has_exact_p, has_exact_c) + { } + +public: + void Cub_Cub() + { + std::cout << "Iso_cuboid - Iso_cuboid\n"; + + // No intersection + check_no_intersection(Cub(p(0,1,2), p(0,1,2)), Cub(p(4,8,6), p(5,9,7))); // degenerate cuboids + check_no_intersection(Cub(p(4,8,6), p(5,9,7)), Cub(p(0,4,1), p(0,4,1))); + check_no_intersection(Cub(p(4,8,6), p(4,8,6)), Cub(p(0,4,1), p(0,4,1))); + + check_no_intersection(Cub(p(-7, 6, 1), p(7092, 71, 58)), Cub(p(-758, 98725, 43), p(17, 9025473, 47))); + check_no_intersection(Cub(p(-73, 6, 1), p(-70, 71, 58)), Cub(p(8, -98725, 43), p(17, 9025473, 47))); + check_no_intersection(Cub(p(-7, 6, 1), p(7092, 71, 58)), Cub(p(-758, -98725, -47), p(17, 9025473, -43))); + + // Sharing a point + check_intersection (Cub(p(0,1,2), p(7,6,4)), Cub(p(7,1,4), p(7,1,4)), // degenerate cuboids + Cub(p(7,1,4), p(7,1,4))); + check_intersection (Cub(p(0,1,2), p(7,8,9)), Cub(p(5,1,2), p(5,1,2)), // degenerate cuboids + Cub(p(5,1,2), p(5,1,2))); + check_intersection (Cub(p(0,1,2), p(0,1,2)), Cub(p(0,1,2), p(0,1,2)), // degenerate cuboids + Cub(p(0,1,2), p(0,1,2))); + + check_intersection (Cub(p(1,3,2), p(4,8,6)), Cub(p(4,8,6), p(5,9,7)), + Cub(p(4,8,6), p(4,8,6))); + check_intersection (Cub(p(1,3,2), p(4,8,6)), Cub(p(-3,-6,-4), p(1,3,2)), + Cub(p(1,3,2), p(1,3,2))); + check_intersection (Cub(p(1,3,2), p(4,8,6)), Cub(p(4,0,0), p(6,3,2)), + Cub(p(4,3,2), p(4,3,2))); + check_intersection (Cub(p(1,3,2), p(4,8,5)), Cub(p(4,8,1), p(9,10,2)), + Cub(p(4,8,2), p(4,8,2))); + + // Sharing an edge + check_intersection (Cub(p(1,3,2), p(4,8,5)), Cub(p(4,3,0), p(7,8,2)), + Cub(p(4,3,2), p(4,8,2))); + check_intersection (Cub(p(1,3,2), p(4,8,5)), Cub(p(4,4,0), p(7,6,2)), + Cub(p(4,4,2), p(4,6,2))); + + // Sharing a face + check_intersection (Cub(p(1,3,2), p(4,8,5)), Cub(p(2,4,0), p(3,6,2)), // face within a face + Cub(p(2,4,2), p(3,6,2))); + check_intersection (Cub(p(1,3,2), p(4,8,5)), Cub(p(2,4,0), p(4,8,2)), // face within a face + Cub(p(2,4,2), p(4,8,2))); + check_intersection (Cub(p(1,3,2), p(4,8,5)), Cub(p(1,8,2), p(4,8,5)), // full face + Cub(p(1,8,2), p(4,8,5))); + check_intersection (Cub(p(1,3,2), p(4,8,5)), Cub(p(1,8,2), p(10,12,8)), // full face + Cub(p(1,8,2), p(4,8,5))); + + // Proper intersection + check_intersection (Cub(p(-7, 6, 1), p(7092, 71, 58)), Cub(p(758, 50, 43), p(758, 50, 43)), // degenerate cuboids + Cub(p(758, 50, 43), p(758, 50, 43))); + check_intersection (Cub(p(-7, 6, 1), p(7092, 71, 58)), Cub(p(-758, -98725, 43), p(17, 9025473, 47)), + Cub(p(-7, 6, 43), p(17, 71, 47))); + } + + void Cub_L() + { + std::cout << "Iso_cuboid - Line\n"; + + // No intersection + check_no_intersection(L(p(0, 0, 0), p(1, 0, 3)), Cub(p(2, 1, 1), p(3, 5, 8))); + check_no_intersection(L(p(4, 0, 0), p(4, 1, 3)), Cub(p(2, 1, 1), p(3, 5, 8))); + + // through vertex + check_intersection (Cub(p(-7, -8, -9), p(-1, 2, -4)), L(p(-8,1,-9), p(-6, 3, -9)), + p(-7,2,-9)); + + // Segment + check_intersection (Cub(p(1, 1, 1), p(3, 5, 8)), L(p(0, 0, 3), p(1, 2, 3)), + S(P(1, 2, 3), P(2.5, 5, 3))); + check_intersection (Cub(p(1, 1, 1), p(3, 5, 8)), L(p(1, 0, 0), p(1, 2, 3)), + S(P(1, 1, 1.5), P(1, 5, 7.5))); + check_intersection (Cub(p(1, 1, 1), p(3, 5, 8)), L(p(0, 0, 0), p(1, 2, 3)), + S(P(1, 2, 3), P(2.5, 5, 7.5))); + + for(int i=0; ir.get_int(this->m, this->M); + int my = this->r.get_int(this->m, this->M); + int mz = this->r.get_int(this->m, this->M); + int Mx = this->r.get_int(this->m, this->M); + int My = this->r.get_int(this->m, this->M); + int Mz = this->r.get_int(this->m, this->M); + + if(mx == Mx) ++Mx; + if(my == My) ++My; + if(mz == Mz) ++Mz; + if(mx > Mx) std::swap(mx, Mx); + if(my > My) std::swap(my, My); + if(mz > Mz) std::swap(mz, Mz); + + P mp = p(mx, my, mz), Mp = p(Mx, My, Mz); + Cub cub(mp, Mp); + + P q1 = p(this->r.get_int(mx - this->M, mx), this->r.get_int(my, My), this->r.get_int(mz, Mz)), + q2 = p(this->r.get_int(Mx, Mx + this->M), this->r.get_int(my, My), this->r.get_int(mz, Mz)); + assert(!cub.has_on_bounded_side(q1) && !cub.has_on_bounded_side(q2)); + + L l(q1, q2); + Base::template check_intersection(cub, l); + Base::template check_intersection(cub, l, S(q1, q2), cub); + + q1 = p(this->r.get_int(mx, Mx), this->r.get_int(my - this->M, my), this->r.get_int(mz, Mz)), + q2 = p(this->r.get_int(mx, Mx), this->r.get_int(my + (My - my) / 2, My), this->r.get_int(mz, Mz)); + assert(!cub.has_on_bounded_side(q1) && !cub.has_on_unbounded_side(q2)); + + l = L(q1, q2); + Base::template check_intersection(cub, l); + } + } + + void Cub_Pl() + { + std::cout << "Iso_cuboid - Plane\n"; + + Cub cub(p(1,1,1), p(2,2,2)); + + // no intersection + check_no_intersection(cub, Pl(p(3,0,0), p(3,1,0), p(3,0,1))); + check_no_intersection(Cub(p(1,1,1), p(1,1,1)), Pl(p(3,0,0), p(3,1,0), p(3,0,1))); + + // vertex + check_intersection(cub, Pl(0.5, -0.5, -0.5, 0), + p(2,1,1)); + check_intersection(Cub(p(1, 2, 3), p(5,9,5)), Pl(p(4,-2,3), p(1,2,3), p(3,5,-8)), + p(1,2,3)); + + // edge + check_intersection(cub, Pl(p(1,1,1), p(1,2,1), P(1.5,0,0)), + S(p(1,1,1), p(1,2,1))); + + if(this->has_exact_c) + { + // face + auto res = CGAL::intersection(cub, Pl(p(1,1,1), p(1,2,1), p(1,2,2))); + + const std::vector

* poly = boost::get >(&*res); + assert(poly != nullptr); + assert(poly->size() == 4); + for(const P& pt : *poly) + { + assert(pt.x() == 1); + } + res = CGAL::intersection(cub, Pl(p(1,1,1), p(1,2,1), p(2,2,2))); + + poly = boost::get >(&*res); + assert(poly != nullptr); + assert(poly->size() == 4); + for(const P& pt : *poly) { + assert(cub.has_on_boundary(pt)); + } + + // other edge + Pl pln(p(1,1,1), p(1,2,1), P(1.5, 1, 2)); + res = CGAL::intersection(cub, pln); + poly = boost::get >(&*res); + assert(poly != nullptr); + assert(poly->size() == 4); + for(const P& pt : *poly) { + assert(pln.has_on(pt) && cub.has_on_boundary(pt)); + } + + // triangle + check_intersection(cub, Pl(P(2, 1.66, 2), + P(1.66,2,2), + P(2,2,1.66)), + Tr(P(1.66,2,2), + P(2, 2, 1.66), + P(2,1.66,2))); + + // random + pln = Pl(0.265189, 0.902464, 0.33946, -2.47551); + res = CGAL::intersection(cub, pln); + poly = boost::get >(&*res); + assert(poly != nullptr); + assert(poly->size() == 5); + for(const P& pt : *poly) { + assert(pln.has_on(pt) && cub.has_on_boundary(pt)); + } + } + else + { + // face + auto res = CGAL::intersection(cub, Pl(p(1,1,1), p(1,2,1), p(1,2,2))); + CGAL_USE(res); + + res = CGAL::intersection(cub, Pl(p(1,1,1), p(1,2,1), p(2,2,2))); + CGAL_USE(res); + + CGAL::intersection(cub, Pl(0.5, -0.5, -0.5, 0)); + CGAL::intersection(cub, Pl(P(2, 1.66, 2), + P(1.66,2,2), + P(2,2,1.66))); + + Pl pln(0.265189, 0.902464, 0.33946, -2.47551); + res = CGAL::intersection(cub, pln); + CGAL_USE(res); + } + } + + void Cub_P() + { + std::cout << "Iso_cuboid - Point\n"; + + // Outside + check_no_intersection(Cub(p(0,1,2), p(0,1,2)), p(4,8,6)); // degenerate + check_no_intersection(Cub(p(0,1,2), p(3,7,5)), p(4,8,6)); + + // On vertex + check_intersection(Cub(p(0,4,2), p(0,4,2)), p(0,4,2), p(0,4,2)); // degenerate + check_intersection(Cub(p(0,1,2), p(8,7,2)), p(8,7,2), p(8,7,2)); + check_intersection(Cub(p(0,1,2), p(8,4,8)), p(8,1,8), p(8,1,8)); + check_intersection(Cub(p(0,1,2), p(0,4,2)), p(0,4,2), p(0,4,2)); + + // On edge + check_intersection(Cub(p(6,3,-2), p(6,3,2)), p(6,3,2), p(6,3,2)); // degenerate + check_intersection(Cub(p(6,3,-2), p(6,3,2)), p(6,3,0), p(6,3,0)); // degenerate + check_intersection(Cub(p(0,1,2), p(0,4,5)), p(0,3,2), p(0,3,2)); + check_intersection(Cub(p(0,1,2), p(0,4,5)), p(0,1,3), p(0,1,3)); + + // On face + check_intersection(Cub(p(0,1,2), p(0,4,5)), p(0,3,3), p(0,3,3)); // degenerate + check_intersection(Cub(p(0,1,2), p(3,4,5)), p(2,4,4), p(2,4,4)); + + // Within + check_intersection(Cub(p(0,1,2), p(10,11,12)), p(4,8,6), p(4,8,6)); + } + + void Cub_R() + { + std::cout << "Iso_cuboid - Ray\n"; + + check_no_intersection (Cub(p(2,1,1), p(3,5,8)), R(p(0,0,0), p(1,0,3))); + check_no_intersection (Cub(p(2,1,1), p(3,5,8)), R(p(4,0,0), p(4,1,3))); + + // point + check_intersection (Cub(p(-7, -8, -9), p(-1, 2, -4)), R(p(-7, 2, -4), p(-9, -3, 0)), + p(-7,2,-4)); + + // segment + check_intersection (Cub(p(1, 4, 8), p(2, 9, 10)), R(p(-1, -6, 4), p(0, -1, 6)), + S(p(1, 4, 8), P(2,9,10))); + + check_intersection (Cub(p(-7, -8, -9), p(-1, 2, -4)), R(p(-3, 1, -5), p(-2, -5, -7)), + S(p(-3, 1, -5), P(-1.5, -8, -8))); + check_intersection (Cub(p(1, 1, 1), p(3, 5, 8)), R(p(0, 0, 3), p(1, 2, 3)), + S(p(1, 2, 3), P(2.5, 5, 3))); + check_intersection (Cub(p(1, 1, 1), p(3, 5, 8)), R(p(1, 0, 0), p(1, 2, 3)), + S(P(1, 1,1.5), P(1, 5,7.5))); + check_intersection (Cub(p(1, 1, 1), p(3, 5, 8)), R(p(0, 0, 0), p(1, 2, 3)), + S(p(1, 2, 3), P(2.5, 5, 7.5))); + + Base::template check_intersection(Cub(p(2, 1, 1), p(3, 5, 8)), R(p(0, 2, 0), p(1, 2, 3))); + } + + void Cub_S() + { + std::cout << "Segment - Iso_cuboid\n"; + + // no intersection + check_no_intersection (Cub(p(2, 1, 1), p(3, 5, 8)), S(p(0, 2, 0), p(1, 2, 3))); + check_no_intersection (Cub(p(2, 1, 1), p(3, 5, 8)), S(p(0, 0, 0), p(1, 0, 3))); + check_no_intersection (Cub(p(2, 1, 1), p(3, 5, 8)), S(p(4, 0, 0), p(4, 1, 3))); + + // point + check_intersection (Cub(p(1, 1, 1), p(3, 5, 8)), S(p(0, 0, 3), p(1, 2, 3)), + p(1, 2, 3)); + check_intersection (Cub(p(1, 1, 1), p(3, 5, 8)), S(p(0, 0, 0), p(1, 2, 3)), + p(1, 2, 3)); + + // segment + check_intersection (Cub(p(-7, -8, -9), p(-1, 2, -4)), S(p(-3, 1, -5), p(-2, -5, -7)), + S(p(-3, 1, -5), p(-2, -5, -7))); + check_intersection (Cub(p(1, 1, 1), p(3, 5, 8)), S(p(1, 0, 0), p(1, 2, 3)), + S(P(1, 1, 1.5), p(1, 2, 3))); + + for(int i=0; ir.get_int(this->m, this->M); + int my = this->r.get_int(this->m, this->M); + int mz = this->r.get_int(this->m, this->M); + int Mx = this->r.get_int(this->m, this->M); + int My = this->r.get_int(this->m, this->M); + int Mz = this->r.get_int(this->m, this->M); + + if(mx == Mx) ++Mx; + if(my == My) ++My; + if(mz == Mz) ++Mz; + if(mx > Mx) std::swap(mx, Mx); + if(my > My) std::swap(my, My); + if(mz > Mz) std::swap(mz, Mz); + + P mp = p(mx, my, mz), Mp = p(Mx, My, Mz); + Cub cub(mp, Mp); + + P s0 = p(this->r.get_int(mx, Mx), this->r.get_int(my - this->M, my), this->r.get_int(mz, Mz)), + s1 = p(this->r.get_int(mx, Mx), this->r.get_int(My, My + this->M), this->r.get_int(mz, Mz)); + assert(!cub.has_on_bounded_side(s0) && !cub.has_on_bounded_side(s1)); + + if(CGAL::do_intersect(cub, S(s0, s1))) + { + std::cout << "yo" << std::endl; + std::cin.get(); + check_intersection(cub, S(s0, s1), L(s0, s1), cub); + check_intersection(cub, S(s0, s1), R(s0, s1), cub); + } + + s1 = p(this->r.get_int(mx, Mx), this->r.get_int(my, My), this->r.get_int(mz, Mz)); + assert(!cub.has_on_unbounded_side(s1)); + + check_do_intersect(cub, S(s0, s1)); + check_intersection(cub, S(s1, s0), R(s1, s0), cub); + } + } + + void Cub_Sph() + { + std::cout << "Iso_cuboid - Sphere\n"; + + // no intersection + check_do_not_intersect(Cub(p(0,0,0), p(0,0,0)), Sph(p(1,0,0), 0)); + + // degenerate + check_do_intersect(Cub(p(0,0,0), p(0,0,0)), Sph(p(0,0,0), 0)); + check_do_intersect(Cub(p(0,0,0), p(0,0,0)), Sph(p(0,0,0), 1)); + check_do_intersect(Cub(p(0,0,0), p(1,1,1)), Sph(p(0,0,0), 0)); + + // tangent + check_do_intersect(Cub(p(0,0,0), p(0,0,0)), Sph(p(1,0,0), 1)); // at vertex + check_do_intersect(Cub(p(0,0,0), p(2,2,2)), Sph(p(1,-1,0), 1)); // at edge + check_do_intersect(Cub(p(0,0,0), p(2,2,2)), Sph(p(1,1,-1), 1)); // at face + + for(int i=0; ir.get_int(this->m, this->M); + int my = this->r.get_int(this->m, this->M); + int mz = this->r.get_int(this->m, this->M); + int Mx = this->r.get_int(this->m, this->M); + int My = this->r.get_int(this->m, this->M); + int Mz = this->r.get_int(this->m, this->M); + + if(mx == Mx) ++Mx; + if(my == My) ++My; + if(mz == Mz) ++Mz; + if(mx > Mx) std::swap(mx, Mx); + if(my > My) std::swap(my, My); + if(mz > Mz) std::swap(mz, Mz); + + P mp = p(mx, my, mz), Mp = p(Mx, My, Mz); + Cub cub(mp, Mp); + + P c = p(this->r.get_int(this->m, this->M), this->r.get_int(this->m, this->M), this->r.get_int(this->m, this->M)); + + // smallest distance to the iso cuboid, manually... + FT sq_r = CGAL::squared_distance(c, Tr(p(mx, my, mz), p(Mx, my, mz), p(mx, my, Mz))); + sq_r = (std::min)(sq_r, CGAL::squared_distance(c, Tr(p(Mx, my, mz), p(Mx, my, Mz), p(mx, my, Mz)))); + sq_r = (std::min)(sq_r, CGAL::squared_distance(c, Tr(p(Mx, my, mz), p(Mx, my, Mz), p(Mx, My, Mz)))); + sq_r = (std::min)(sq_r, CGAL::squared_distance(c, Tr(p(Mx, my, mz), p(Mx, My, mz), p(Mx, My, Mz)))); + sq_r = (std::min)(sq_r, CGAL::squared_distance(c, Tr(p(mx, my, mz), p(Mx, my, mz), p(Mx, My, mz)))); + sq_r = (std::min)(sq_r, CGAL::squared_distance(c, Tr(p(mx, my, mz), p(Mx, My, mz), p(mx, My, mz)))); + sq_r = (std::min)(sq_r, CGAL::squared_distance(c, Tr(p(mx, my, mz), p(mx, My, mz), p(mx, My, Mz)))); + sq_r = (std::min)(sq_r, CGAL::squared_distance(c, Tr(p(mx, my, mz), p(mx, my, Mz), p(mx, My, Mz)))); + sq_r = (std::min)(sq_r, CGAL::squared_distance(c, Tr(p(mx, my, Mz), p(Mx, my, Mz), p(mx, My, Mz)))); + sq_r = (std::min)(sq_r, CGAL::squared_distance(c, Tr(p(mx, My, Mz), p(Mx, My, Mz), p(Mx, my, Mz)))); + sq_r = (std::min)(sq_r, CGAL::squared_distance(c, Tr(p(mx, My, mz), p(mx, My, Mz), p(Mx, My, Mz)))); + sq_r = (std::min)(sq_r, CGAL::squared_distance(c, Tr(p(mx, My, mz), p(Mx, My, mz), p(Mx, My, Mz)))); + + check_do_intersect(cub, Sph(c, sq_r)); + } + + // generic inside + for(int i=0; ir.get_int(this->m, this->M); + int my = this->r.get_int(this->m, this->M); + int mz = this->r.get_int(this->m, this->M); + int Mx = this->r.get_int(this->m, this->M); + int My = this->r.get_int(this->m, this->M); + int Mz = this->r.get_int(this->m, this->M); + + if(mx == Mx) ++Mx; + if(my == My) ++My; + if(mz == Mz) ++Mz; + if(mx > Mx) std::swap(mx, Mx); + if(my > My) std::swap(my, My); + if(mz > Mz) std::swap(mz, Mz); + + P mp = p(mx, my, mz), Mp = p(Mx, My, Mz); + Cub cub(mp, Mp); + + P c = p(this->r.get_int(mx, Mx), this->r.get_int(my, My), this->r.get_int(mz, Mz)); + int ms = (std::min)((std::min)(Mx - mx, My - my), Mz - mz) + 1; + + check_do_intersect(cub, Sph(c, CGAL::square(ms))); + } + } + + void Cub_Tet() + { + std::cout << "Iso_cuboid - Sphere\n"; + + // no intersection + check_do_not_intersect(Cub(p(0,0,0), p(1,1,1)), Tet(p(2,4,1), p(1, 2, 0), p(2,3,1), p(4,5,6))); + + // point + check_do_intersect(Cub(p(0,0,0), p(1,1,1)), Tet(p(2,4,1), p(1,1,0), p(2,3,1), p(4,5,6)) + /*p(1,1,1)*/); // shared vertex + check_do_intersect(Cub(p(0,0,0), p(2,1,1)), Tet(p(2,4,1), p(1,1,0), p(2,3,1), p(4,5,6)) + /*p(1,1,1)*/); // on edge + check_do_intersect(Cub(p(0,0,0), p(2,2,2)), Tet(p(2,4,1), p(1,2,1), p(2,3,1), p(4,5,6)) + /*p(1,1,2)*/); // on face + + // edge + check_do_intersect(Cub(p(0,0,0), p(1,1,1)), Tet(p(0,1,0), p(1,1,0), p(2,3,1), p(4,5,6)) + /*S(p(0,1,0), p(1,1,0))*/); + check_do_intersect(Cub(p(0,0,0), p(2,2,2)), Tet(p(0,2,0), p(1,2,0), p(2,3,1), p(4,5,6)) + /*S(p(0,1,0), p(1,1,0))*/); + check_do_intersect(Cub(p(0,0,0), p(2,2,2)), Tet(p(0,2,0), p(2,2,2), p(2,3,1), p(4,5,6)) + /*S(p(0,2,0), p(2,2,0))*/); + check_do_intersect(Cub(p(0,0,0), p(2,2,2)), Tet(p(-1,2,-1), p(3,2,3), p(2,3,1), p(4,5,6)) + /*S(p(0,2,0), p(2,2,0))*/); + + // face + check_do_intersect(Cub(p(0,0,0), p(1,1,1)), Tet(p(0,1,0), p(1,1,0), p(1,1,1), p(4,5,6)) + /*Tr(p(0,1,0), p(1,1,0), p(1,1,1))*/); + check_do_intersect(Cub(p(0,0,0), p(1,1,1)), Tet(p(0,1,0), p(1,1,0), p(4,5,6), p(1,1,1)) + /*Tr(p(0,1,0), p(1,1,0), p(1,1,1))*/); + + // generic inside + for(int i=0; ir.get_int(this->m, this->M); + int my = this->r.get_int(this->m, this->M); + int mz = this->r.get_int(this->m, this->M); + int Mx = this->r.get_int(this->m, this->M); + int My = this->r.get_int(this->m, this->M); + int Mz = this->r.get_int(this->m, this->M); + + if(mx == Mx) ++Mx; + if(my == My) ++My; + if(mz == Mz) ++Mz; + if(mx > Mx) std::swap(mx, Mx); + if(my > My) std::swap(my, My); + if(mz > Mz) std::swap(mz, Mz); + + P mp = p(mx, my, mz), Mp = p(Mx, My, Mz); + Cub cub(mp, Mp); + + P c = p(this->r.get_int(mx, Mx), this->r.get_int(my, My), this->r.get_int(mz, Mz)); + P q1 = p(this->r.get_int(this->m, this->M), this->r.get_int(this->m, this->M), this->r.get_int(this->m, this->M)), + q2 = p(this->r.get_int(this->m, this->M), this->r.get_int(this->m, this->M), this->r.get_int(this->m, this->M)), + q3 = p(this->r.get_int(this->m, this->M), this->r.get_int(this->m, this->M), this->r.get_int(this->m, this->M)); + + Tet tet(c, q1, q2, q3); + if(!tet.is_degenerate()) + check_do_intersect(cub, tet); + + int id = this->r.get_int(0, 8); + Tet teti(q1, cub[id], q2, q3); + if(!teti.is_degenerate()) + check_do_intersect(cub, teti); + + int jd = this->r.get_int(0, 8); + Tet tetj(q1, q2, cub[id], cub[jd]); + if(!tetj.is_degenerate()) + check_do_intersect(cub, tetj); + } + } + + void Cub_Tr() + { + typedef typename CGAL::Intersection_traits::result_type Res; + + std::cout << "Iso_cuboid - Triangle\n"; + + // no intersection + Cub cub(p(1,1,1), p(2,2,2)); + check_no_intersection(cub, Tr(P(1.1,2,0), p(2,3,1), p(4,5,6))); + + // tr adj to a cuboid vertex + check_intersection(cub, Tr(P(1, 0.5, 0.5), p(3, 2, 1), p(3, 1, 2)), p(2,1,1)); + + // tr adj to a point on a cuboid edge + check_intersection(cub, Tr(P(1, 0.5, 0.5), p(3, 2, 1), p(3, 1, 2)), p(2,1,1)); + + // tr adj to a point on a cuboid face + check_intersection(cub, Tr(P(1, 1.5, 1.5), p(0, 0, 0), p(-4, 3, 1)), P(1, 1.5, 1.5)); + + // tr adj to an edge + check_intersection(cub, Tr(P(2, 1.5, 2), p(5, 6, 7), p(4, 7, 6)), P(2, 1.5, 2)); + + // tr sharing an edge + check_intersection(cub, Tr(P(2, 1.5, 2), P(2, 2.5, 2), p(4, 7, 6)), + S(P(2, 1.5, 2), p(2, 2, 2))); + + // tr sharing part of an edge + check_intersection(cub, Tr(P(2, 1.5, 2), p(5, 6, 7), p(4, 7, 6)), P(2, 1.5, 2)); + + // tr in a face + check_intersection(cub, Tr(P(1, 1.1, 1), P(1, 1.5, 1), P(1, 1, 1.1)), + Tr(P(1, 1.1, 1), P(1, 1.5, 1), P(1, 1, 1.1))); + + // face in a tr + Tr tr(p(-3, -3, 1), p(3, -3, 1), P(1.5, 6, 1)); + Res res = CGAL::intersection(cub, tr); + Pol* poly = boost::get >(&*res); + assert(poly != nullptr); + assert(poly->size() == 4); + if(this->has_exact_c) + { + for(const P& pt : *poly) + assert(tr.has_on(pt) && cub.has_on_boundary(pt)); + } + + // tr inside + check_intersection(cub, Tr(P(1.1,1.1,1.1), P(1.8,1.8,1.8), P(1.5,1.8,1.1)), + Tr(P(1.1,1.1,1.1), P(1.8,1.8,1.8), P(1.5,1.8,1.1))); + + for(int i=0; ir.get_int(this->m, this->M); + int my = this->r.get_int(this->m, this->M); + int mz = this->r.get_int(this->m, this->M); + int Mx = this->r.get_int(this->m, this->M); + int My = this->r.get_int(this->m, this->M); + int Mz = this->r.get_int(this->m, this->M); + + if(mx == Mx) ++Mx; + if(my == My) ++My; + if(mz == Mz) ++Mz; + if(mx > Mx) std::swap(mx, Mx); + if(my > My) std::swap(my, My); + if(mz > Mz) std::swap(mz, Mz); + + P mp = p(mx, my, mz), Mp = p(Mx, My, Mz); + Cub rcub(mp, Mp); + + P q1 = p(this->r.get_int(mx, Mx), this->r.get_int(my, My), this->r.get_int(mz, Mz)), + q2 = p(this->r.get_int(mx, Mx), this->r.get_int(my, My), this->r.get_int(mz, Mz)), + q3 = p(this->r.get_int(mx, Mx), this->r.get_int(my, My), this->r.get_int(mz, Mz)); + Tr rtr(q1, q2, q3); + + check_intersection(rcub, rtr, rtr); + } + + // tr through + tr = Tr(p(2, 4, 2), P(1, 3.5, -0.5), p(1, -1, 1)); + res = CGAL::intersection(cub, tr); + poly = boost::get >(&*res); + assert(poly != nullptr); + assert(poly->size() == 4); + if(this->has_exact_c) + { + for(const P& pt : *poly) { + assert(tr.has_on(pt) && cub.has_on_boundary(pt)); + } + } + + // cutting in half along diagonal (intersection == triangle) + check_intersection(cub, Tr(p(1, 1, 1), p(2, 2, 2), p(2, 2, 1)), + Tr(p(1, 1, 1), p(2, 2, 2), p(2, 2, 1))); + + // cutting in half along diagonal (intersection included in triangle) + tr = Tr(p(1, 1, 10), p(10, 10, 1), p(1, 1, 1)); + res = CGAL::intersection(cub, tr); + poly = boost::get >(&*res); + assert(poly != nullptr); + assert(poly->size() == 4); + if(this->has_exact_c) + { + for(const P& pt : *poly) + assert(tr.has_on(pt) && cub.has_on_boundary(pt)); + } + + // 6 points intersection + tr = Tr(P(18.66, -5.4, -11.33), P(-2.41, -7.33, 19.75), P(-10.29, 20.15, -10.33)); + res = CGAL::intersection(cub, tr); + poly = boost::get >(&*res); + assert(poly != nullptr); + assert(poly->size() == 6); + if(this->has_exact_c) + { + for(const P& pt : *poly) + assert(tr.has_on(pt) && cub.has_on_boundary(pt)); + } + + // triangle clipping a cuboid corner + tr = Tr(P(1.02, 1.33, 0.62), P(1.95, 2.54, 0.95), P(0.79, 2.36, 1.92)); + res = CGAL::intersection(cub, tr); + Tr* tr_res = boost::get(&*res); + assert(tr_res != nullptr); + if(this->has_exact_c) + { + assert(cub.has_on_boundary((*tr_res)[0])); + assert(cub.has_on_boundary((*tr_res)[1])); + assert(cub.has_on_boundary((*tr_res)[2])); + } + } + + void run() + { + std::cout << "3D Line Intersection tests\n"; + + Cub_Cub(); +// Cub_L(); // @fixme bugged in random cases + Cub_Pl(); + Cub_P(); + Cub_R(); +// Cub_S(); // @fixme bugged in random cases + Cub_Sph(); + Cub_Tet(); + Cub_Tr(); + } +}; + +int main(int, char**) +{ + std::cout.precision(17); + std::cerr.precision(17); + + CGAL::Random r; + std::cout << "random seed = " << r.get_seed() << std::endl; + + std::cout << " |||||||| Test Simple_cartesian ||||||||" << std::endl; + Iso_cuboid_3_intersection_tester< CGAL::Simple_cartesian >(r).run(); + + std::cout << " |||||||| Test CGAL::Homogeneous ||||||||" << std::endl; + Iso_cuboid_3_intersection_tester< CGAL::Homogeneous >(r).run(); + + std::cout << " |||||||| Test EPICK ||||||||" << std::endl; + Iso_cuboid_3_intersection_tester< CGAL::Epick >(r, true /*exact predicates*/).run(); + + std::cout << " |||||||| Test EPECK ||||||||" << std::endl; + Iso_cuboid_3_intersection_tester< CGAL::Epeck >(r, true /*exact predicates*/, true /*exact constructions*/).run(); + + std::cout << " |||||||| Test CGAL::Homogeneous ||||||||" << std::endl; + Iso_cuboid_3_intersection_tester< CGAL::Homogeneous >(r, true /*exact predicates*/, true /*exact constructions*/).run(); + + std::cout << "OK!" << std::endl; +} diff --git a/Intersections_3/test/Intersections_3/test_intersections_Line_3.cpp b/Intersections_3/test/Intersections_3/test_intersections_Line_3.cpp new file mode 100644 index 00000000000..44bc02f7b17 --- /dev/null +++ b/Intersections_3/test/Intersections_3/test_intersections_Line_3.cpp @@ -0,0 +1,435 @@ +// 3D intersection tests. + +// We want to check that no division is performed for interface macro Do_intersect_3_RT +#define CGAL_NO_MPZF_DIVISION_OPERATOR + +// Line_3_X with X < Line (lexicographically) are tested in other files + +#include +#include +#include +#include +#include +#include +#include +#include + +// just to cross verify +#include +#include +#include +#include +#include + +#include + +#include "intersection_test_helper.h" + +#include +#include +#include +#include +#include + +#include +#include + +template +struct Line_3_intersection_tester + : public Intersection_3_tester +{ + typedef Intersection_3_tester Base; + + typedef typename K::FT FT; + + typedef CGAL::Iso_cuboid_3 Cub; + typedef CGAL::Line_3 L; + typedef CGAL::Point_3 P; + typedef CGAL::Plane_3 Pl; + typedef CGAL::Ray_3 R; + typedef CGAL::Segment_3 S; + typedef CGAL::Sphere_3 Sph; + typedef CGAL::Tetrahedron_3 Tet; + typedef CGAL::Triangle_3 Tr; + + typedef CGAL::Vector_3 V; + + using Base::p; + using Base::pl; + using Base::random_point; + + using Base::check_do_intersect; + using Base::check_do_not_intersect; + using Base::check_intersection; + using Base::check_no_intersection; + +private: + int N = 1000; + +public: + Line_3_intersection_tester(CGAL::Random& r, + const bool has_exact_p = false, + const bool has_exact_c = false) + : Base(r, has_exact_p, has_exact_c) + { } + +public: + void L_L() + { + std::cout << "Line - Line\n"; + + for(int vx=0; vx<4; ++vx) + { + for(int vy=1; vy<4; ++vy) + { + for(int vz=0; vz<4; ++vz) + { + if(vx == 0 && vy == 0 && vz == 0) + continue; + + const int a = vx; + const int b = vy; + const int c = vz; + + const L l = L(p(0,0,0), p( a, b, c)); + const L l_1 = L(p(0,0,0), p(-a, -b,-c)); + const L l_2 = L(p(0,0,0), p(-a, -b, 7)); + const L l_3 = L(p(1,0,0), p( a, b, c)); + const L l_4 = L(p(1,0,0), p( a+1,b, c)); + + const CGAL::Object obj1 = CGAL::intersection(l, l_1); + const CGAL::Object obj2 = CGAL::intersection(l, l_2); + const CGAL::Object obj3 = CGAL::intersection(l, l_3); + const CGAL::Object obj4 = CGAL::intersection(l, l_4); + + check_do_intersect(l, l_1); + check_do_intersect(l, l_2); + check_do_intersect(l, l_3); + check_do_not_intersect(l, l_4); + + Base::template check_intersection(l, l_1); + L interl1; + assert(assign(interl1, obj1)); + + check_intersection(l, l_2, P(0,0,0)); + P interp2; + assert(assign(interp2, obj2)); + assert(interp2 == P(0,0,0)); + + check_intersection(l, l_3, P(a,b,c)); + P interp3; + assert(assign(interp3, obj3)); + assert(interp3 == P(a,b,c)); + + check_no_intersection(l, l_4); + assert(obj4.is_empty()); + } + } + } + } + + void L_Pl() + { + std::cout << "Line - Plane\n"; + + // No intersection + check_no_intersection (pl(0, 0, 1,-2), L(p(1,1,1), p(2,3,1))); + + // Point intersection + check_intersection (L(p(1,1,1), p(2,3,4)), pl(1, 1, 1, 0), + P(0.5, 0, -0.5)); + check_intersection (L(p(1,1,1), p(2,3,-1)), pl(1, 0, 1, 3), + P(6,11,-9)); + Base::template check_intersection

(L(p(1,1,1), p(2,3,4)), pl(1, 2, 4, 7)); + Base::template check_intersection

(L(p(-1,-1,-1), p(2,3,4)), pl(1, 2, 4, 7), + pl(1, 2, 4, 7), S(p(-1,-1,-1), p(2,3,4))); + Base::template check_intersection

(L(p(2,3,4), p(-1,-1,-1)), pl(1, 2, 4, 7), + pl(1, 2, 4, 7), S(p(-1,-1,-1), p(2,3,4))); + + if(this->has_exact_c) // because Plane and Line inner coeffs are actually constructions... + { + for(int i=0; ir.get_double()) * V(pl1 - pl0) + FT(this->r.get_double()) * V(pl1 - pl0); + if(pl.has_on(l1)) + Base::template check_intersection(L(pl3, l1), pl, L(pl3, l1)); // both points on the plane + else + Base::template check_intersection(L(pl3, l1), pl, pl3); // single point on the plane + + if(pl.oriented_side(l0) != pl.oriented_side(l1)) // l0 xor l1 on pl is fine + { + Base::template check_intersection

(L(l0, l1), pl, pl, S(l0, l1)); + Base::template check_intersection

(L(l0, l1), pl, pl, R(l0, l1)); + } + } + } + + // Line intersection + Base::template check_intersection(L(p(1,1,1), p(2,3,1)), pl(0, 0, 1,-1)); + + if(this->has_exact_c) + { + for(int i=0; ihas_exact_c) + { + for(int i=0; i({{tet0, tet1, tet2, tet3}}).size() != 4) + continue; + + P l0 = tet0 + CGAL::cross_product(V(tet0, tet1), V(tet0, tet2)); + P l1 = tet2 + CGAL::cross_product(V(tet2, tet1), V(tet2, tet0)); + + Tet tet(tet0, tet1, tet2, tet3); + assert(tet.has_on_unbounded_side(l0) && tet.has_on_unbounded_side(l1)); + + if(CGAL::do_intersect(S(l0, l1), tet)) + check_intersection(L(l0, l1), tet, tet, S(l0, l1)); + } + } + + void L_Tr() + { + std::cout << "Line - Triangle\n"; + + // No intersection + Tr tr(p(0,0,0), p(1,0,1), p(1,1,0)); + check_no_intersection(L(p(5,0,0), p(5,1,0)), tr); + + // on edge + check_intersection(L(p(-1,0,-1), p(3,0,3)), tr, + S(p(0,0,0), p(1,0,1))); + + // through a vertex only + check_intersection(L(p(-2,-1,0), p(4,2,0)), tr, + P(0,0,0)); + + // through vertex and out from face + Base::template check_intersection(L(p(-3,-3,0), p(-4,-4,0)), Tr(p(0,0,0), p(1,0,0), p(0,1,0))); + + // through one edge + Base::template check_intersection

(L(p(0,1,0), p(1,0,0)), tr); + + // within the face + Base::template check_intersection(L(P(0.25,0.25,0), P(0.3,0.5,0)), Tr(p(0,0,0), p(1,0,0), p(0,1,0))); + + for(int i=0; i ||||||||" << std::endl; + Line_3_intersection_tester< CGAL::Simple_cartesian >(r).run(); + + std::cout << " |||||||| Test CGAL::Homogeneous ||||||||" << std::endl; + Line_3_intersection_tester< CGAL::Homogeneous >(r).run(); + + std::cout << " |||||||| Test EPICK ||||||||" << std::endl; + Line_3_intersection_tester< CGAL::Epick >(r, true /*exact predicates*/).run(); + + std::cout << " |||||||| Test EPECK ||||||||" << std::endl; + Line_3_intersection_tester< CGAL::Epeck >(r, true /*exact predicates*/, true /*exact constructions*/).run(); + + std::cout << " |||||||| Test CGAL::Homogeneous ||||||||" << std::endl; + Line_3_intersection_tester< CGAL::Homogeneous >(r, true /*exact predicates*/, true /*exact constructions*/).run(); + + std::cout << "OK!" << std::endl; +} diff --git a/Intersections_3/test/Intersections_3/test_intersections_Plane_3.cpp b/Intersections_3/test/Intersections_3/test_intersections_Plane_3.cpp new file mode 100644 index 00000000000..02f99f9f78a --- /dev/null +++ b/Intersections_3/test/Intersections_3/test_intersections_Plane_3.cpp @@ -0,0 +1,446 @@ +// 3D intersection tests. + +// We want to check that no division is performed for interface macro Do_intersect_3_RT +#define CGAL_NO_MPZF_DIVISION_OPERATOR + +// Plane_3_X with X < Plane (lexicographically) are tested in other files + +#include +#include +#include +#include +#include +#include +#include + +#include + +#include "intersection_test_helper.h" + +#include +#include +#include +#include +#include + +#include +#include + +template +struct Plane_3_intersection_tester + : public Intersection_3_tester +{ + typedef Intersection_3_tester Base; + + typedef typename K::FT FT; + + typedef CGAL::Circle_3 C; + typedef CGAL::Iso_cuboid_3 Cub; + typedef CGAL::Line_3 L; + typedef CGAL::Point_3 P; + typedef CGAL::Plane_3 Pl; + typedef CGAL::Ray_3 R; + typedef CGAL::Segment_3 S; + typedef CGAL::Sphere_3 Sph; + typedef CGAL::Tetrahedron_3 Tet; + typedef CGAL::Triangle_3 Tr; + + typedef CGAL::Vector_3 V; + + using Base::p; + using Base::pl; + using Base::random_point; + + using Base::check_do_intersect; + using Base::check_do_not_intersect; + using Base::check_intersection; + using Base::check_no_intersection; + +private: + int N = 1000; + +public: + Plane_3_intersection_tester(CGAL::Random& r, + const bool has_exact_p = false, + const bool has_exact_c = false) + : Base(r, has_exact_p, has_exact_c) + { } + +public: + void Pl_Pl() + { + std::cout << "Plane - Plane\n"; + + // No intersection + check_no_intersection(pl(2,1,3,4), pl(6,3,9,3)); + + // Self + check_intersection(pl(2,1,3,4), pl(2,1,3,4), pl(2,1,3,4)); + Base::template check_intersection(Pl(p(0,1,8), p(4,3,7), p(2,9,1)), Pl(p(4,3,7), p(0,1,8), p(2,9,1))); + + // Line (directed...) + check_intersection(pl(0,0,1,0), pl(0,1,0,0), L(P(0,0,0), P(-1,0,0)), false /*do_opposite*/); + check_intersection(pl(0,1,0,0), pl(0,0,1,0), L(P(-85,0,0), P(0,0,0)), false /*do_opposite*/); + check_intersection(pl(2,3,7,5), pl(9,7,1,3), L(P(2,-3,0), P(-3908,5182,-1105)), false /*do_opposite*/); + check_intersection(pl(9,7,1,3), pl(2,3,7,5), L(P(-3908,5182,-1105), P(2,-3,0)), false /*do_opposite*/); + + // generic + for(int i=0; ihas_exact_c) + { + assert(l.has_on(pl1)); + assert(l.has_on(pl2)); + } + } + } + + // Plane + Base::template check_intersection(pl(0,0,1,1), pl(0,0,3,3)); + Base::template check_intersection(pl(2,1,3,4), pl(6,3,9,12)); + } + + void Pl_P() + { + std::cout << "Plane - Point\n"; + + // no intersection + check_no_intersection(Pl(p(5,3,2), p(1,1,1), p(0,0,0)), P(99,98,99)); + + check_intersection(Pl(p(5,3,2), p(1,1,1), p(0,0,0)), P(99,99,99), + P(99,99,99)); + + if(this->has_exact_c) + { + for(int i=0; i (pl(0,0,1,-1), R(p(1,1,1), p(2,3,1))); + check_intersection(pl(0,0,1,-1), R(p(1,1,1), p(2,3,1)), R(p(1,1,1), p(2,3,1))); + } + + void Pl_S() + { + std::cout << "Plane - Segment\n"; + + // No intersection + check_no_intersection (pl(1,1,1,0), S(p(1,1,1), p(2,3,4))); + check_no_intersection (pl(0,0,1,-2), S(p(1,1,1), p(2,3,1))); + check_no_intersection (pl(1,0,1,3), S(p(1,1,1), p(2,3,-1))); + check_no_intersection (pl(1,2,4,7), S(p(1,1,1), p(2,3,4))); + + // Point + check_intersection (pl(0,0,1,0), S(p(1,1,-1), p(-1,-1,1)), + P(0,0,0)); + check_intersection (pl(0,0,1,0), S(p(7,1,0), p(83,1,-4)), + p(7,1,0)); + check_intersection (pl(0,0,1,0), S(p(12,6,-4), p(7,25,0)), + p(7,25,0)); + + // Segment + Base::template check_intersection(pl(0,0,1,-1), S(p(1,1,1), p(2,3,1))); + } + + // see also circle_other.cpp + void Pl_Sph() + { + std::cout << "Plane - Sphere\n"; + + // No intersection + check_no_intersection(pl(1,1,1,0), Sph(p(4,3,1), 1)); + + // Point + check_intersection (pl(0,10,0,0), Sph(p(4,-2,1), 4), p(4,0,1)); + check_intersection (pl(1,1,0,0), Sph(p(4,4,-10), 32), p(0,0,-10)); + + // generic + check_intersection (pl(0,0,1,-1), Sph(p(0,0,2), 4), C(pl(0,0,1,-1), Sph(p(0,0,2), 4))); + + if(this->has_exact_c) + { + for(int i=0; ihas_exact_c) + { + check_intersection(tet, Pl(P(0,0.5,0), P(1,0.5,-5), P(0.5,0.5,0.5)), + Tr(P(0,0.5,0), P(0.5,0.5,0), P(0,0.5,0.5))); + + Pl pln(P(0,0.9,0), P(0.9,0,0), P(0.9,0.01,0.06)); + + // Don't have the right values to test further. + auto res = CGAL::intersection(tet, pln); + const std::vector

* poly = boost::get >(&*res); + assert(poly != nullptr); + assert(poly->size() == 4); + } + + for(int i=0; i os; + os.insert(pln.oriented_side(tet0)); + os.insert(pln.oriented_side(tet1)); + os.insert(pln.oriented_side(tet2)); + os.insert(pln.oriented_side(tet3)); + if(os.size() == 1 && (*os.begin() != CGAL::ZERO)) + check_no_intersection(pln, t); + else + check_do_intersect(pln, t); + } + } + + void Pl_Tr() + { + std::cout << "Plane - Triangle\n"; + + // No intersection + + // Point + check_intersection(Pl(p(0,0,0), p(12,0,0), p(0,11,0)), Tr(p(0,0,0), p(1,0,1), p(0,1,1)), + p(0,0,0)); + + // Segment + check_intersection(Pl(p(0,0,0), p(12,0,0), p(0,11,0)), Tr(p(0,0,0), p(1,0,0), p(0,1,1)), + S(p(0,0,0), p(1,0,0))); + check_intersection(Pl(p(0,0,0), p(12,0,0), p(0,11,0)), Tr(p(1,0,-1), p(-1,0,-1), p(0,0,1)), + S(P(0.5,0,0), P(-0.5,0,0))); + + // Triangle + check_intersection(Pl(p(0,0,0), p(12,0,0), p(0,11,0)), Tr(p(0,0,0), p(1,0,0), p(0,1,0)), + Tr(p(0,0,0), p(1,0,0), p(0,1,0))); + + for(int i=0; i(pln, Tr(pl0, pl3, pl4)); + } + } + } + + void Pl_Pl_Pl() + { + std::cout << "Plane - Plane - Plane\n"; + + Pl pl1(1,0,0,0); + Pl pl2(0,1,0,0); + Pl pl3(0,0,1,0); + Pl pl4(1,0,0,1); // pl4 is parallel to pl1. + + // No intersection + check_no_intersection(pl1, pl2, pl4); + check_no_intersection(pl1, pl4, pl2); + check_no_intersection(pl4, pl2, pl1); + + check_no_intersection(Pl(p(0,0,0),p(1,1,1),p(1,1,0)), + Pl(p(0,0,0),p(1,-1,1),p(1,-1,-2)), + Pl(1,0,0,-5)); + + // Intersection in a line. + Pl pl5(1,1,0,0); // pl1, pl2, pl5 intersect in the line l. + L l; + assert(CGAL::do_intersect(pl1, pl2, pl5)); + CGAL::Object o4 = CGAL::intersection(pl1, pl2, pl5); + assert(assign(l, o4)); + assert(l == L(P(0,0,0), P(0,0,1))); + + // Intersection in a plane. + assert(CGAL::do_intersect(pl1, pl1, pl1)); + CGAL::Object o5 = CGAL::intersection(pl1, pl1, pl1); + Pl pln; + assert(assign(pln, o5)); + assert(pln == pl1); + + // Generic intersection. + assert(CGAL::do_intersect(pl1, pl2, pl3)); + CGAL::Object o = CGAL::intersection(pl1, pl2, pl3); + P pt; + assert(assign(pt, o)); + assert(pt == P(0,0,0)); + } + + void run() + { + std::cout << "3D Plane Intersection tests\n"; + + Pl_Pl(); + Pl_P(); + Pl_R(); + Pl_S(); + Pl_Sph(); + Pl_Tet(); + Pl_Tr(); + + Pl_Pl_Pl(); + } +}; + +int main(int, char**) +{ + std::cout.precision(17); + std::cerr.precision(17); + + CGAL::Random r; + std::cout << "random seed = " << r.get_seed() << std::endl; + + std::cout << " |||||||| Test Simple_cartesian ||||||||" << std::endl; + Plane_3_intersection_tester< CGAL::Simple_cartesian >(r).run(); + + // Homogenous is broken for projection and Pln-Sphere +// std::cout << " |||||||| Test CGAL::Homogeneous ||||||||" << std::endl; +// Plane_3_intersection_tester< CGAL::Homogeneous >(r).run(); + + std::cout << " |||||||| Test EPICK ||||||||" << std::endl; + Plane_3_intersection_tester< CGAL::Epick >(r, true /*exact predicates*/).run(); + + std::cout << " |||||||| Test EPECK ||||||||" << std::endl; + Plane_3_intersection_tester< CGAL::Epeck >(r, true /*exact predicates*/, true /*exact constructions*/).run(); + + // FIXME BROKEN PROJECTION, BROKEN PLN-SPHERE +// std::cout << " |||||||| Test CGAL::Homogeneous ||||||||" << std::endl; +// Plane_3_intersection_tester< CGAL::Homogeneous >(r, true /*exact predicates*/, true /*exact constructions*/).run(); + + std::cout << "OK!" << std::endl; +} diff --git a/Intersections_3/test/Intersections_3/test_intersections_Point_3.cpp b/Intersections_3/test/Intersections_3/test_intersections_Point_3.cpp new file mode 100644 index 00000000000..3f30a775dbd --- /dev/null +++ b/Intersections_3/test/Intersections_3/test_intersections_Point_3.cpp @@ -0,0 +1,261 @@ +// 3D intersection tests. + +// We want to check that no division is performed for interface macro Do_intersect_3_RT +#define CGAL_NO_MPZF_DIVISION_OPERATOR + +// Point_3_X with X < Point (lexicographically) are tested in other files + +#include +#include +#include +#include +#include +#include + +#include + +#include "intersection_test_helper.h" + +#include +#include +#include +#include +#include + +#include +#include + + +template +struct Point_3_intersection_tester + : public Intersection_3_tester +{ + typedef Intersection_3_tester Base; + + typedef typename K::FT FT; + + typedef CGAL::Iso_cuboid_3 Cub; + typedef CGAL::Line_3 L; + typedef CGAL::Point_3 P; + typedef CGAL::Plane_3 Pl; + typedef CGAL::Ray_3 R; + typedef CGAL::Segment_3 S; + typedef CGAL::Sphere_3 Sph; + typedef CGAL::Tetrahedron_3 Tet; + typedef CGAL::Triangle_3 Tr; + + typedef CGAL::Vector_3 V; + + using Base::p; + using Base::pl; + using Base::random_point; + + using Base::check_do_intersect; + using Base::check_do_not_intersect; + using Base::check_intersection; + using Base::check_no_intersection; + +private: + int N = 1000; + +public: + Point_3_intersection_tester(CGAL::Random& r, + const bool has_exact_p = false, + const bool has_exact_c = false) + : Base(r, has_exact_p, has_exact_c) + { } + +public: + void P_P() + { + std::cout << "Point - Point\n"; + + P p(0.99,0.99,0.99); + check_intersection(p,p,p); + + P q = random_point(); + check_no_intersection(p,q); + } + + void P_R() + { + std::cout << "Point - Ray\n"; + + P pt(1,1,1); + R ray(p(-1,-1,-1), p(3,3,3)); + check_intersection(ray, pt, pt); + + if(this->has_exact_c) + { + for(int i=0; ihas_exact_c) + { + for(int i=0; ihas_exact_c) + { + for(int i=0; i ||||||||" << std::endl; + Point_3_intersection_tester< CGAL::Simple_cartesian >(r).run(); + + std::cout << " |||||||| Test CGAL::Homogeneous ||||||||" << std::endl; + Point_3_intersection_tester< CGAL::Homogeneous >(r).run(); + + std::cout << " |||||||| Test EPICK ||||||||" << std::endl; + Point_3_intersection_tester< CGAL::Epick >(r, true /*exact predicates*/).run(); + + std::cout << " |||||||| Test EPECK ||||||||" << std::endl; + Point_3_intersection_tester< CGAL::Epeck >(r, true /*exact predicates*/, true /*exact constructions*/).run(); + + std::cout << " |||||||| Test CGAL::Homogeneous ||||||||" << std::endl; + Point_3_intersection_tester< CGAL::Homogeneous >(r, true /*exact predicates*/, true /*exact constructions*/).run(); + + std::cout << "OK!" << std::endl; +} diff --git a/Intersections_3/test/Intersections_3/test_intersections_Ray_3.cpp b/Intersections_3/test/Intersections_3/test_intersections_Ray_3.cpp new file mode 100644 index 00000000000..e67bd82de7f --- /dev/null +++ b/Intersections_3/test/Intersections_3/test_intersections_Ray_3.cpp @@ -0,0 +1,283 @@ +// 3D intersection tests. + +// We want to check that no division is performed for interface macro Do_intersect_3_RT +#define CGAL_NO_MPZF_DIVISION_OPERATOR + +// Sphere_3_X with X < Sphere (lexicographically) are tested in other files + +#include +#include +#include +#include +#include +#include + +#include "intersection_test_helper.h" + +#include +#include +#include +#include +#include + +#include +#include + +template +struct Ray_3_intersection_tester + : public Intersection_3_tester +{ + typedef Intersection_3_tester Base; + + typedef typename K::FT FT; + + typedef CGAL::Iso_cuboid_3 Cub; + typedef CGAL::Line_3 L; + typedef CGAL::Point_3 P; + typedef CGAL::Plane_3 Pl; + typedef CGAL::Ray_3 R; + typedef CGAL::Segment_3 S; + typedef CGAL::Sphere_3 Sph; + typedef CGAL::Tetrahedron_3 Tet; + typedef CGAL::Triangle_3 Tr; + + typedef CGAL::Vector_3 V; + + using Base::p; + using Base::pl; + using Base::random_point; + + using Base::check_do_intersect; + using Base::check_do_not_intersect; + using Base::check_intersection; + using Base::check_no_intersection; + +private: + int N = 1000; + +public: + Ray_3_intersection_tester(CGAL::Random& r, + const bool has_exact_p = false, + const bool has_exact_c = false) + : Base(r, has_exact_p, has_exact_c) + { } + +public: + void R_R() + { + std::cout << "Ray - Ray\n"; + + // No intersection + check_no_intersection (R(p(0,0,0), p(1,0,0)), R(p(-2,0,0), p(-3,0,0))); + check_no_intersection (R(p(0,0,0), p(1,0,0)), R(p(1,-1,0), p(1,-2,0))); + check_no_intersection (R(p(0,0,0), p(1,0,0)), R(p(0,-1,0), p(0,-2,0))); + check_no_intersection (R(p(0,0,0), p(1,0,0)), R(p(0,1,0), p(0,2,0))); + + // Point + check_intersection (R(p(0,0,0), p(1,0,0)), R(p(0,0,0), p(-1,0,0)), + p(0,0,0)); + check_intersection (R(p(0,0,0), p(1,0,0)), R(p(0,0,0), p(0,1,0)), + p(0,0,0)); + check_intersection (R(p(0,0,0), p(1,0,0)), R(p(5,0,0), p(5,1,0)), + p(5,0,0)); + check_intersection (R(p(0,0,0), p(1,0,0)), R(p(1,0,0), p(1,1,0)), + p(1,0,0)); + check_intersection (R(p(0,0,0), p(1,0,0)), R(p(1,-1,0), p(1,1,0)), + p(1,0,0)); + check_intersection (R(p(0,0,0), p(1,0,0)), R(p(1,-2,0), p(1,-1,0)), + p(1,0,0)); + + // Segment + // @fixme +// check_intersection (R(p(0,0,0), p(1,0,0)), R(p(2,0,0), p(-3,0,0)), +// S(p(0,0,0), p(2,0,0))); +// check_intersection (R(p(2,0,0), p(-3,0,0)), R(p(0,0,0), p(1,0,0)), +// S(p(2,0,0), p(0,0,0))); + + // Ray + check_intersection (R(p(0,0,0), p(1,0,0)), R(p(-1,0,0), p(3,0,0)), + R(p(0,0,0), p(1,0,0))); + check_intersection (R(p(0,0,0), p(1,0,0)), R(p(2,0,0), p(3,0,0)), + R(p(2,0,0), p(6,0,0))); + } + + void R_S() + { + std::cout << "Ray - Segment\n"; + + // No intersection + check_no_intersection (S(p(-3,0,0), p(3,0,0)), R(p(0,-1,0), p(0,-2,0))); + check_no_intersection (S(p(-3,0,0), p(3,0,0)), R(p(-3,-1,0), p(-3,-2,0))); + check_no_intersection (S(p(-3,0,0), p(3,0,0)), R(p(3,-1,0), p(3,-2,0))); + check_no_intersection (S(p(-3,0,0), p(3,0,0)), R(p(4,0,0), p(5,0,0))); + check_no_intersection (S(p(-3,0,0), p(3,0,0)), R(p(-5,0,0), p(-8,0,0))); + + // Point + check_intersection (S(p(-3,0,0), p(3,0,0)), R(p(0,-2,0), p(0,-1,0)), + p(0,0,0)); + check_intersection (S(p(-3,0,0), p(3,0,0)), R(p(-3,-2,0), p(-3,-1,0)), + p(-3,0,0)); + check_intersection (S(p(-3,0,0), p(3,0,0)), R(p(3,-2,0), p(3,-1,0)), + p(3,0,0)); + check_intersection (S(p(-3,0,0), p(3,0,0)), R(p(0,0,0), p(0,-1,0)), + p(0,0,0)); + check_intersection (S(p(-3,0,0), p(3,0,0)), R(p(-3,0,0), p(-3,-1,0)), + p(-3,0,0)); + check_intersection (S(p(-3,0,0), p(3,0,0)), R(p(3,0,0), p(3,-1,0)), + p(3,0,0)); + check_intersection (S(p(-3,0,0), p(3,0,0)), R(p(0,-2,0), p(0,0,0)), + p(0,0,0)); + check_intersection (S(p(-3,0,0), p(3,0,0)), R(p(-3,-2,0), p(-3,0,0)), + p(-3,0,0)); + check_intersection (S(p(-3,0,0), p(3,0,0)), R(p(3,-2,0), p(3,0,0)), + p(3,0,0)); + check_intersection (S(p(-3,0,0), p(3,0,0)), R(p(-3,0,0), p(-4,0,0)), + p(-3,0,0)); + check_intersection (S(p(-3,0,0), p(3,0,0)), R(p(3,0,0), p(4,0,0)), + p(3,0,0)); + + // Segment + check_intersection (S(p(-3,0,0), p(3,0,0)), R(p(-4,0,0), p(-2,0,0)), + S(p(-3,0,0), p(3,0,0))); + check_intersection (S(p(-3,0,0), p(3,0,0)), R(p(-4,0,0), p(7,0,0)), + S(p(-3,0,0), p(3,0,0))); + check_intersection (S(p(-3,0,0), p(3,0,0)), R(p(-3,0,0), p(-2,0,0)), + S(p(-3,0,0), p(3,0,0))); + check_intersection (S(p(-3,0,0), p(3,0,0)), R(p(-3,0,0), p(7,0,0)), + S(p(-3,0,0), p(3,0,0))); + check_intersection (S(p(-3,0,0), p(3,0,0)), R(p(0,0,0), p(-2,0,0)), + S(p(0,0,0), p(-3,0,0))); + check_intersection (S(p(-3,0,0), p(3,0,0)), R(p(0,0,0), p(2,0,0)), + S(p(0,0,0), p(3,0,0))); + } + + void R_Sph() + { + std::cout << "Ray - Sphere\n"; + + // No intersection + check_do_not_intersect(R(p(0,1,7), p(1,2,1)), Sph(p(0,8,4), 4)); + + for(int i=0; ihas_exact_c) + { + Pl pln(q, V(c, q)); // plane tangent to the sphere at q + V v1 = pln.base1(); + check_do_intersect(R(q, q + v1), sph); + } + + // maybe two points + P r = random_point(); + if(q == r) + continue; + + check_do_intersect(R(q, r), sph); + } + } + + void R_Tet() + { + std::cout << "Ray - Tetrahedron\n"; + + Tet tet(p(0,0,0), p(0,1,0), p(1,0,0), p(0,0,1)); + + check_no_intersection (R(p(5,0,0), p(5,1,0)), tet); + + check_intersection (R(p(0,2,0), p(0,-2,0)), tet, + S(p(0,1,0), p(0,0,0))); + check_intersection (R(p(0,1,0), P(0.25,0,0.25)), tet, + S(p(0,1,0), P(0.25,0,0.25))); + check_intersection (R(p(2,1,0), p(-2,1,0)), tet, + p(0,1,0)); + + typename K::FT third = FT(1)/FT(3); + typename K::FT fifth = FT(1)/FT(5); + typename K::FT tenth = FT(1)/FT(10); + + if(this->has_exact_c) + { + check_intersection (tet, R(P(tenth,tenth,tenth), P(fifth,fifth,fifth)), + S(P(tenth,tenth,tenth), P(third, third, third))); + check_intersection (tet, R(P(0.25,0.25,0.25), p(2,2,2)), + S(P(0.25,0.25,0.25), P(third, third, third))); + } + else + { + CGAL::intersection(tet, R(p(0,2,0), p(0,-2,0))); + CGAL::intersection(tet, R(p(0,1,0), P(0.25,0,0.25))); + CGAL::intersection(tet, R(p(2,1,0), p(-2,1,0))); + CGAL::intersection(tet, R(P(tenth,tenth,tenth), P(fifth,fifth,fifth))); + CGAL::intersection(tet, R(P(0.25,0.25,0.25), p(2,2,2))); + } + } + + void R_Tr() + { + std::cout << "Ray - Triangle\n"; + + check_no_intersection(R(p(0,0,0), p(1,1,1)), Tr(p(-4, 2, 2), p(3, 7, -1), p(0, 9, -4))); + check_no_intersection(R(p(0,0,0), p(1,1,1)), Tr(p(-1, -1, -1), p(3, 7, -1), p(0, 9, -4))); + + // Point + check_intersection(R(p(0,0,0), p(1,1,1)), Tr(p(0, 0, 0), p(3, 7, -1), p(0, 9, -4)), + p(0, 0, 0)); + check_intersection(R(p(0,0,0), p(1,1,1)), Tr(p(2, 2, 2), p(3, 7, -1), p(0, 9, -4)), + p(2, 2, 2)); + check_intersection(R(p(0,0,0), p(4,-2,6)), Tr(p(2, -1, 3), p(3, 7, -1), p(0, 9, -4)), + p(2, -1, 3)); + check_intersection(R(p(0,0,0), p(2,-1,3)), Tr(p(4, -2, 6), p(3, 7, -2), p(0, 8, -4)), + p(4, -2, 6)); + + Base::template check_intersection

(R(p(0,0,0), p(1,1,1)), Tr(p(2, 4, 2), p(5, -7, -1), p(0, -9, 4))); + + // Segment + check_intersection(R(p(0,0,1), p(1,1,1)), Tr(p(3, 3, 1), p(7, 7, 1), p(0, -9, -4)), + S(p(3, 3, 1), p(7,7,1))); + check_intersection(R(p(0,0,1), p(1,1,1)), Tr(p(7, 7, 1), p(3, 3, 1), p(0, -9, -4)), + S(p(3, 3, 1), p(7,7,1))); + check_intersection(R(p(3,3,1), p(7,7,1)), Tr(p(4, 4, 1), p(2, 2, 1), p(0, -9, -4)), + S(p(3, 3, 1), p(4,4,1))); + } + + void run() + { + std::cout << "3D Ray Intersection tests\n"; + + R_R(); + R_S(); + R_Sph(); + R_Tet(); + R_Tr(); + } +}; + +int main(int, char**) +{ + std::cout.precision(17); + std::cerr.precision(17); + + CGAL::Random r; + std::cout << "random seed = " << r.get_seed() << std::endl; + + std::cout << " |||||||| Test Simple_cartesian ||||||||" << std::endl; + Ray_3_intersection_tester< CGAL::Simple_cartesian >(r).run(); + + std::cout << " |||||||| Test CGAL::Homogeneous ||||||||" << std::endl; + Ray_3_intersection_tester< CGAL::Homogeneous >(r).run(); + + std::cout << " |||||||| Test EPICK ||||||||" << std::endl; + Ray_3_intersection_tester< CGAL::Epick >(r, true /*exact predicates*/).run(); + + std::cout << " |||||||| Test EPECK ||||||||" << std::endl; + Ray_3_intersection_tester< CGAL::Epeck >(r, true /*exact predicates*/, true /*exact constructions*/).run(); + + std::cout << " |||||||| Test CGAL::Homogeneous ||||||||" << std::endl; + Ray_3_intersection_tester< CGAL::Homogeneous >(r, true /*exact predicates*/, true /*exact constructions*/).run(); + + std::cout << "OK!" << std::endl; +} diff --git a/Intersections_3/test/Intersections_3/test_intersections_Segment_3.cpp b/Intersections_3/test/Intersections_3/test_intersections_Segment_3.cpp new file mode 100644 index 00000000000..7e56289423e --- /dev/null +++ b/Intersections_3/test/Intersections_3/test_intersections_Segment_3.cpp @@ -0,0 +1,215 @@ +// 3D intersection tests. + +// We want to check that no division is performed for interface macro Do_intersect_3_RT +#define CGAL_NO_MPZF_DIVISION_OPERATOR + +// Sphere_3_X with X < Sphere (lexicographically) are tested in other files + +#include +#include +#include +#include + +#include + +#include "intersection_test_helper.h" + +#include +#include +#include +#include +#include + +#include +#include + +template +struct Segment_3_intersection_tester + : public Intersection_3_tester +{ + typedef Intersection_3_tester Base; + + typedef typename K::FT FT; + + typedef CGAL::Iso_cuboid_3 Cub; + typedef CGAL::Line_3 L; + typedef CGAL::Point_3 P; + typedef CGAL::Plane_3 Pl; + typedef CGAL::Ray_3 R; + typedef CGAL::Segment_3 S; + typedef CGAL::Sphere_3 Sph; + typedef CGAL::Tetrahedron_3 Tet; + typedef CGAL::Triangle_3 Tr; + + typedef CGAL::Vector_3 V; + + using Base::p; + using Base::pl; + using Base::random_point; + + using Base::check_do_intersect; + using Base::check_do_not_intersect; + using Base::check_intersection; + using Base::check_no_intersection; + +private: + int N = 1000; + +public: + Segment_3_intersection_tester(CGAL::Random& r, + const bool has_exact_p = false, + const bool has_exact_c = false) + : Base(r, has_exact_p, has_exact_c) + { } + +public: + void S_S() + { + // see segment_segment.cpp + } + + // @fixme EPICK + void S_Sph() + { + std::cout << "Segment - Sphere\n"; + + // No intersection + check_do_not_intersect(S(p(4,1,9), p(4,6,-1)), Sph(p(9,2,4), 1)); + check_do_not_intersect(S(p(-2,3,4), p(1,2,-1)), Sph(p(9,2,4), 10000)); + + check_do_intersect(S(p(-2,3,4), p(1,2,-1)), Sph(p(9,2,4), 100)); + + for(int i=0; ir.get_int(this->m + 1, this->M); + Sph sph(c, sqr); + if(sph.oriented_side(s0) != sph.oriented_side(s1)) + check_do_intersect(sph, S(s0, s1)); + else + check_do_not_intersect(sph, S(s0, s1)); + } + } + + void S_Tet() + { + std::cout << "Segment - Tetrahedron\n"; + + Tet tet(p(0,0,0), p(0,1,0), p(1,0,0), p(0,0,1)); + + // No intersection + check_no_intersection(S(p(5,0,0), p(5,1,0)), tet); + + // Point + check_intersection(S(p(0,1,7), p(-7,-1,0)), Tet(p(0,1,7), p(9,4,-2), p(3,-7,2), p(7,-8,1)), + p(0,1,7)); + check_intersection(S(p(4,3,2), p(-7,-1,0)), Tet(p(0,1,6), p(8,5,-2), p(3,-7,2), p(7,-8,1)), + p(4,3,2)); + check_intersection(S(p(3,2,2), p(-7,-1,3)), Tet(p(4,1,6), p(2,-1,-2), p(3,6,2), p(7,-8,1)), + p(3,2,2)); + + // Segment + check_intersection(S(p(0,1,7), p(-7,-1,0)), Tet(p(0,1,7), p(-7,-1,0), p(3,-7,2), p(7,-8,1)), + S(p(0,1,7), p(-7,-1,0))); + check_intersection(S(p(0,1,7), p(-8,-1,1)), Tet(p(0,1,7), p(-4,0,4), p(3,-7,2), p(7,-8,1)), + S(p(0,1,7), p(-4,0,4))); + check_intersection(S(p(0,1,7), p(3,-7,2)), Tet(p(0,1,7), p(-4,0,4), p(3,-7,2), p(7,-8,1)), + S(p(0,1,7), p(3,-7,2))); + + FT fourth = FT(1)/FT(4); + FT fifth = FT(1)/FT(5); + FT tenth = FT(1)/FT(10); + + if(this->has_exact_c) + { + check_intersection(tet, S(p(0,2,0), p(0,-2,0)), + S(p(0,1,0), p(0,0,0))); + check_intersection(tet, S(p(0,1,0), P(fourth,0,fourth)), + S(p(0,1,0), P(fourth,0,fourth))); + check_intersection(tet, S(p(2,1,0), p(-2,1,0)), p(0,1,0)); + + check_intersection(tet, S(P(tenth,tenth,tenth), P(fifth,fifth,fifth)), + S(P(tenth,tenth,tenth), P(fifth,fifth,fifth))); + typename K::FT third = FT(1)/FT(3); + check_intersection(tet, S(P(fourth,fourth,fourth), p(2,2,2)), + S(P(fourth,fourth,fourth), P(third, third, third))); + } + else + { + CGAL::intersection(tet, S(p(0,2,0), p(0,-2,0))); + CGAL::intersection(tet, S(p(0,1,0), P(fourth,0,fourth))); + CGAL::intersection(tet, S(p(2,1,0), p(-2,1,0))); + CGAL::intersection(tet, S(P(tenth,tenth,tenth), P(fifth,fifth,fifth))); + CGAL::intersection(tet, S(P(fourth,fourth,fourth), p(2,2,2))); + } + } + + void S_Tr() + { + std::cout << "Segment - Triangle\n"; + + // No intersection + check_no_intersection(S(p(1,4,7), p(2,3,9)), Tr(p(-1,9,8), p(-5,3,4), p(-0,8,9))); + + // Point + check_intersection(S(p(4,2,7), p(1,3,7)), Tr(p(1,3,7), p(3,9,-1), p(-7,6,3)), + p(1,3,7)); + check_intersection(S(p(1,3,9), p(5,1,7)), Tr(p(3,2,8), p(-1,9,7), p(-2,2,8)), + p(3,2,8)); + + // Segment + check_intersection(S(p(3,2,7), p(1,-2,-9)), Tr(p(3,2,7), p(1,-2,-9), p(4,3,9)), + S(p(3,2,7), p(1,-2,-9))); + check_intersection(S(p(3,2,7), p(1,-2,-9)), Tr(p(5,6,23), p(1,-2,-9), p(4,3,9)), + S(p(3,2,7), p(1,-2,-9))); + check_intersection(S(p(3,2,7), p(1,-2,-9)), Tr(p(5,6,23), p(-1,-6,-25), p(4,3,9)), + S(p(3,2,7), p(1,-2,-9))); + check_intersection(S(p(1,3,9), p(5,1,7)), Tr(p(4,0,6), p(2,4,10), p(-2,2,8)), + S(p(1,3,9), p(3,2,8))); + + Base::template check_intersection(S(p(1,3,7), p(5,1,7)), Tr(p(4,0,7), p(2,4,7), p(-2,2,7))); + Base::template check_intersection(S(p(1,3,7), p(5,1,7)), Tr(p(4,0,7), p(2,4,7), p(1,2,7))); + } + + void run() + { + std::cout << "3D Segment Intersection tests\n"; + + S_S(); +// S_Sph(); // @fixme + S_Tet(); + S_Tr(); + } +}; + +int main(int, char**) +{ + std::cout.precision(17); + std::cerr.precision(17); + + CGAL::Random r; + std::cout << "random seed = " << r.get_seed() << std::endl; + + std::cout << " |||||||| Test Simple_cartesian ||||||||" << std::endl; + Segment_3_intersection_tester< CGAL::Simple_cartesian >(r).run(); + + std::cout << " |||||||| Test CGAL::Homogeneous ||||||||" << std::endl; + Segment_3_intersection_tester< CGAL::Homogeneous >(r).run(); + + std::cout << " |||||||| Test EPICK ||||||||" << std::endl; + Segment_3_intersection_tester< CGAL::Epick >(r, true /*exact predicates*/).run(); + + std::cout << " |||||||| Test EPECK ||||||||" << std::endl; + Segment_3_intersection_tester< CGAL::Epeck >(r, true /*exact predicates*/, true /*exact constructions*/).run(); + + std::cout << " |||||||| Test CGAL::Homogeneous ||||||||" << std::endl; + Segment_3_intersection_tester< CGAL::Homogeneous >(r, true /*exact predicates*/, true /*exact constructions*/).run(); + + std::cout << "OK!" << std::endl; +} diff --git a/Intersections_3/test/Intersections_3/test_intersections_Sphere_3.cpp b/Intersections_3/test/Intersections_3/test_intersections_Sphere_3.cpp new file mode 100644 index 00000000000..a4a2e255d86 --- /dev/null +++ b/Intersections_3/test/Intersections_3/test_intersections_Sphere_3.cpp @@ -0,0 +1,188 @@ +// 3D intersection tests. + +// We want to check that no division is performed for interface macro Do_intersect_3_RT +#define CGAL_NO_MPZF_DIVISION_OPERATOR + +// Sphere_3_X with X < Sphere (lexicographically) are tested in other files + +#include +#include +#include + +#include + +#include "intersection_test_helper.h" + +#include +#include +#include +#include +#include + +#include +#include + +template +struct Sphere_3_intersection_tester + : public Intersection_3_tester +{ + typedef Intersection_3_tester Base; + + typedef typename K::FT FT; + + typedef CGAL::Line_3 L; + typedef CGAL::Point_3 P; + typedef CGAL::Plane_3 Pl; + typedef CGAL::Ray_3 R; + typedef CGAL::Segment_3 S; + typedef CGAL::Sphere_3 Sph; + typedef CGAL::Tetrahedron_3 Tet; + typedef CGAL::Triangle_3 Tr; + + typedef CGAL::Vector_3 V; + + using Base::p; + using Base::pl; + using Base::random_point; + + using Base::check_do_intersect; + using Base::check_do_not_intersect; + using Base::check_intersection; + using Base::check_no_intersection; + +private: + int N = 1000; + +public: + Sphere_3_intersection_tester(CGAL::Random& r, + const bool has_exact_p = false, + const bool has_exact_c = false) + : Base(r, has_exact_p, has_exact_c) + { } + +public: + void Sph_Sph() + { + std::cout << "Sphere - Sphere\n"; + + // No intersection + check_no_intersection(Sph(p(0,0,0), 4), Sph(p(6,3,8), 9)); + + for(int i=0; ir.get_int(this->m + 1, this->M), r1 = this->r.get_int(this->m + 1, this->M); + if(r0 == r1) + check_intersection(Sph(c0, r0), Sph(c0, r1), Sph(c0, r0)); + else + check_no_intersection(Sph(c0, r0), Sph(c0, r1)); + + const FT sqd = CGAL::squared_distance(c0, c1); + if(sqd <= 8) + continue; + + const int r = int(CGAL::to_double((sqd / 4)) - 1); + check_no_intersection(Sph(c0, r), Sph(c1, r)); + } + } + + void Sph_Tet() + { + std::cout << "Sphere - Tetrahedron\n"; + + // No intersection + check_do_not_intersect(Sph(p(0,0,0), 3), Tet(p(6,3,8), p(7,2,8), p(1,9,7), p(2,3,4))); + check_do_not_intersect(Sph(p(0,0,0), 10000), Tet(p(6,3,8), p(7,2,8), p(1,9,7), p(2,3,4))); + + // Point + check_do_intersect(Sph(p(0,0,0), 4), Tet(p(2,0,0), p(9,3,7), p(4,9,7), p(8,-3,4))); // vertex + check_do_intersect(Sph(p(0,0,0), 4), Tet(p(2,2,0), p(2,-2,0), p(4,9,7), p(8,-3,4))); // edge + check_do_intersect(Sph(p(0,0,0), 4), Tet(p(2,2,3), p(2,-2,-3), p(4,2,-3), p(8,-3,4))); // face + + for(int i=0; ir.get_int(this->m + 1, this->M); + Sph sph(c, r); + + if(sph.oriented_side(tr0) != sph.oriented_side(tr1) || + sph.oriented_side(tr0) != sph.oriented_side(tr2) || + sph.oriented_side(tr2) != sph.oriented_side(tr1)) + check_do_intersect(sph, tr); + else + check_do_not_intersect(sph, tr); + } + } + + void run() + { + std::cout << "3D Sphere Intersection tests\n"; + + Sph_Sph(); + Sph_Tet(); + Sph_Tr(); + } +}; + +int main(int, char**) +{ + std::cout.precision(17); + std::cerr.precision(17); + + CGAL::Random r; + std::cout << "random seed = " << r.get_seed() << std::endl; + + std::cout << " |||||||| Test Simple_cartesian ||||||||" << std::endl; + Sphere_3_intersection_tester< CGAL::Simple_cartesian >(r).run(); + + // @fixme illegal Plane_3 constructor in Cartesian_kernel::Construct_radical_plane_3 +// std::cout << " |||||||| Test CGAL::Homogeneous ||||||||" << std::endl; +// Sphere_3_intersection_tester< CGAL::Homogeneous >(r).run(); + + std::cout << " |||||||| Test EPICK ||||||||" << std::endl; + Sphere_3_intersection_tester< CGAL::Epick >(r, true /*exact predicates*/).run(); + + std::cout << " |||||||| Test EPECK ||||||||" << std::endl; + Sphere_3_intersection_tester< CGAL::Epeck >(r, true /*exact predicates*/, true /*exact constructions*/).run(); + +// std::cout << " |||||||| Test CGAL::Homogeneous ||||||||" << std::endl; +// Sphere_3_intersection_tester< CGAL::Homogeneous >(r, true /*exact predicates*/, true /*exact constructions*/).run(); + + std::cout << "OK!" << std::endl; +} diff --git a/Intersections_3/test/Intersections_3/test_intersections_Tetrahedron_3.cpp b/Intersections_3/test/Intersections_3/test_intersections_Tetrahedron_3.cpp new file mode 100644 index 00000000000..5d025cc0df4 --- /dev/null +++ b/Intersections_3/test/Intersections_3/test_intersections_Tetrahedron_3.cpp @@ -0,0 +1,330 @@ +// 3D intersection tests. + +// We want to check that no division is performed for interface macro Do_intersect_3_RT +#define CGAL_NO_MPZF_DIVISION_OPERATOR + +// Tetrahedron_3_X with X < Tetrahedron (lexicographically) are tested in other files + +#include +#include + +#include + +#include "intersection_test_helper.h" + +#include +#include +#include +#include +#include + +#include +#include + +template +struct Tetrahedron_3_intersection_tester + : public Intersection_3_tester +{ + typedef Intersection_3_tester Base; + + typedef typename K::FT FT; + + typedef CGAL::Iso_cuboid_3 Cub; + typedef CGAL::Line_3 L; + typedef CGAL::Point_3 P; + typedef CGAL::Plane_3 Pl; + typedef CGAL::Ray_3 R; + typedef CGAL::Segment_3 S; + typedef CGAL::Sphere_3 Sph; + typedef CGAL::Tetrahedron_3 Tet; + typedef CGAL::Triangle_3 Tr; + + typedef CGAL::Vector_3 V; + + using Base::p; + using Base::pl; + using Base::random_point; + + using Base::check_do_intersect; + using Base::check_do_not_intersect; + using Base::check_intersection; + using Base::check_no_intersection; + +private: + int N = 1000; + +public: + Tetrahedron_3_intersection_tester(CGAL::Random& r, + const bool has_exact_p = false, + const bool has_exact_c = false) + : Base(r, has_exact_p, has_exact_c) + { } + +public: + void Tet_Tet() + { + std::cout << "Tetrahedron - Tetrahedron\n"; + + for(int i=0; i os; + os.insert(tet0.oriented_side(tet10)); + os.insert(tet0.oriented_side(tet11)); + os.insert(tet0.oriented_side(tet12)); + os.insert(tet0.oriented_side(tet13)); + + if(os.size() == 1 && (*os.begin() == CGAL::ON_POSITIVE_SIDE)) + check_do_not_intersect(tet0, tet4); + else + check_do_intersect(tet0, tet4); + } + } + + void Tet_Tr() + { + Tet tet(p(0,0,0), p(0,1,0), p(1,0,0), p(0,0,1)); + +// check_no_intersection(tet, Tr(p(2,0,0), p(2,1,0), p(2,0,1))); + + // tr inside a face + check_intersection(tet, Tr(P(0,0.9,0), P(0,0.1,0), P(0,0,0.9)), + Tr(P(0,0.9,0), P(0,0.1,0), P(0,0,0.9))); + // face inside tr + check_intersection(tet, Tr(p(0,2,0), p(0,-2,0), p(0,0,2)), + Tr(p(0,0,1), p(0,0,0), p(0,1,0))); + + // only one edge intersecting + check_do_intersect(tet, Tr(P(-2, 0.5, 0.5), P(-2,0.75,1), P(1.5, 0.5, 0.5))); + + // edge shared, 3rd point outside + check_do_intersect(tet, Tr(p(0,1,0), p(1,0,0), P(0.5,0,-100))); + + // shared edge, 3rd point inside + check_do_intersect(tet, Tr(p(0,1,0), p(1,0,0), P(0.25,0.25,0.25))); + + // tr adjacent to a vertex, outside + check_do_intersect(tet, Tr(p(-1,1,12), p(0,1,-50), P(0.5,1,-0.5))); + + // tr share a vertex, inside + check_do_intersect(tet, Tr(p(0,1,0), P(0.1,0.1,0), P(0.5,0.1,0))); + + // tr edge adjacent to a vertex + check_do_intersect(tet, Tr(p(-1,1,0), p(3,1,0), p(0,3,0))); + + // tr vertex adjacent to a vertex + check_do_intersect(tet, Tr(p(0,1,0), p(3,1,0), p(0,3,0))); + + // traversing triangles + Tr tr(P(-2, 0.5, 0.25), P(-2, 0.75, 0.6), P(1.5, 0.5, 0.25)); + check_do_intersect(tet, tr); + + // tr share a vertex, through + tr = Tr(p(0,1,0), P(0.1,0.1,0), P(0.9,0.1,0)); + check_do_intersect(tet, tr); + + if(this->has_exact_c) + { + Tr tr(p(-2,2,0), p(2,2,0), P(0.25,0.25,0)); + auto res = CGAL::intersection(tet, tr); + const std::vector

* poly = boost::get >(&*res); + assert(poly != nullptr); + assert(poly->size() == 4); + for(const P& pt : *poly) + { + assert(tet.has_on_boundary(pt) && tr.has_on(pt)); + } + + // only one edge intersecting + check_intersection (tet, Tr(P(-2, 0.5, 0.5), P(-2,0.75,1), P(1.5, 0.5, 0.5)), + P(0,0.5,0.5)); + + // edge shared, 3rd point outside + check_intersection (tet, Tr(p(0,1,0), p(1,0,0), P(0.5,0,-100)), + S(p(0,1,0), p(1,0,0))); + + // shared edge, 3rd point inside + check_intersection (tet, Tr(p(0,1,0), p(1,0,0), P(0.25,0.25,0.25)), + Tr(p(0,1,0), p(1,0,0), P(0.25,0.25,0.25))); + + // tr adjacent to a vertex, outside + check_intersection (tet, Tr(p(-1,1,12), p(0,1,-50), P(0.5,1,-0.5)), + p(0,1,0)); + + // tr adjacent to an edge, outside + check_intersection (tet, Tr(P(-0.6, 1, 0.6), P(0.5, 1.20, -0.5), P(0, -0.5, 0)), + S(p(0,0,0), p(0,1,0))); + + // tr share a vertex, inside + check_intersection (tet, Tr(p(0,1,0), P(0.1,0.1,0), P(0.5,0.1,0)), + Tr(p(0,1,0), P(0.1,0.1,0), P(0.5,0.1,0))); + + // tr edge adjacent to a vertex + check_intersection (tet, Tr(p(-1,1,0), p(3,1,0), p(0,3,0)), + p(0,1,0)); + + // tr vertex adjacent to a vertex + check_intersection (tet, Tr(p(0,1,0), p(3,1,0), p(0,3,0)), + p(0,1,0)); + + // traversing triangles + tr = Tr(P(-2, 0.5, 0.25), P(-2, 0.75, 0.6), P(1.5, 0.5, 0.25)); + res = CGAL::intersection(tet, tr); + std::vector

* inter = boost::get >(&*res); + assert(inter != nullptr); + assert(inter->size() == 4); + for(const P& pt : *inter) { + assert(tet.has_on_boundary(pt) && tr.has_on(pt)); + } + + tr = Tr(P(-2, 0.25, 0), P(-2, 0.75, 0), P(1.5, 0.5, 0)); + res = CGAL::intersection(tet, tr); + inter = boost::get >(&*res); + assert(inter != nullptr); + assert(inter->size() == 4); + for(const P& pt : *inter) { + assert(tet.has_on_boundary(pt) && tr.has_on(pt)); + } + + tr = Tr(P(0.2, 0.15, 0.3), P(-2, 0.6, 0.15), P(-2, 0.12, 0.15)); + res = CGAL::intersection(tet, tr); + Tr* res_tr = boost::get(&*res); + assert(res_tr != nullptr); + + tr = Tr(P(0.2, 0.15, 0.3), P(-1, 0.15, -2), P(-1, 0.15, 2)); + res = CGAL::intersection(tet, tr); + inter = boost::get >(&*res); + assert(inter != nullptr); + assert(inter->size() == 4); + + tr = Tr(P(0.45, 0.20, 0.1), P(0.1, 0.20, 0.5), P(-0.5, 0.25, -0.5)); + res = CGAL::intersection(tet, tr); + inter = boost::get >(&*res); + assert(inter != nullptr); + assert(inter->size() == 4); + for(const P& pt : *inter) { + assert((tet.has_on_bounded_side(pt) || tet.has_on_boundary(pt)) && tr.has_on(pt)); + } + + // tr share a vertex, through + tr = Tr(p(0,1,0), P(0.1,0.1,0), P(0.9,0.1,0)); + res = CGAL::intersection(tet, tr); + res_tr = boost::get(&*res); + assert(res_tr != nullptr); + + tr = Tr(P(0.1, 0.5, 0.1), P(0.3,0.1,0.1), P(4,0.3,0.9)); + res = CGAL::intersection(tet, tr); + inter = boost::get >(&*res); + assert(inter != nullptr); + assert(inter->size() == 4); + } + + for(int i=0; i os; + os.insert(tet.oriented_side(tr0)); + os.insert(tet.oriented_side(tr1)); + os.insert(tet.oriented_side(tr2)); + + std::cout << "Tet: " << tet << std::endl; + std::cout << "Tr: " << tr << std::endl; + + if(os.size() == 1 && (*os.begin() == CGAL::ON_POSITIVE_SIDE)) + check_do_not_intersect(tet, tr); + else + check_do_intersect(tet, tr); + } + } + + void run() + { + std::cout << "3D Tetrahedron Intersection tests\n"; + + Tet_Tet(); + Tet_Tr(); + } +}; + +int main(int, char**) +{ + std::cout.precision(17); + std::cerr.precision(17); + + CGAL::Random r; + std::cout << "random seed = " << r.get_seed() << std::endl; + + std::cout << " |||||||| Test Simple_cartesian ||||||||" << std::endl; + Tetrahedron_3_intersection_tester< CGAL::Simple_cartesian >(r).run(); + + std::cout << " |||||||| Test CGAL::Homogeneous ||||||||" << std::endl; + Tetrahedron_3_intersection_tester< CGAL::Homogeneous >(r).run(); + + std::cout << " |||||||| Test EPICK ||||||||" << std::endl; + Tetrahedron_3_intersection_tester< CGAL::Epick >(r, true /*exact predicates*/).run(); + + std::cout << " |||||||| Test EPECK ||||||||" << std::endl; + Tetrahedron_3_intersection_tester< CGAL::Epeck >(r, true /*exact predicates*/, true /*exact constructions*/).run(); + + std::cout << " |||||||| Test CGAL::Homogeneous ||||||||" << std::endl; + Tetrahedron_3_intersection_tester< CGAL::Homogeneous >(r, true /*exact predicates*/, true /*exact constructions*/).run(); + + std::cout << "OK!" << std::endl; +} diff --git a/Intersections_3/test/Intersections_3/test_point_3_intersections.cpp b/Intersections_3/test/Intersections_3/test_point_3_intersections.cpp deleted file mode 100644 index d5b90fec323..00000000000 --- a/Intersections_3/test/Intersections_3/test_point_3_intersections.cpp +++ /dev/null @@ -1,129 +0,0 @@ -#include -#include - - -typedef CGAL::Exact_predicates_exact_constructions_kernel Epeck; -typedef CGAL::Exact_predicates_inexact_constructions_kernel Epick; - -template -void test_P_Cub() -{ - typedef CGAL::Point_3 P; - typedef CGAL::Iso_cuboid_3 Cub; - P p(0.0,1.0,0.5); - Cub cub(P(-1.0,-1.0,-1.0), P(1.0,1.0,1.0)); - assert(CGAL::do_intersect(p, cub)); - CGAL::Object o = CGAL::intersection(p,cub); - P res; - assert(assign(res, o)); - assert(res == p); -} -template -void test_P_L() -{ - typedef CGAL::Point_3 P; - typedef CGAL::Line_3 Line; - P p(0.99,0.99,0.99); - Line line(P(-1.0,-1.0,-1.0), P(1.0,1.0,1.0)); - assert(CGAL::do_intersect(p, line)); - CGAL::Object o = CGAL::intersection(p,line); - P res; - assert(assign(res, o)); - assert(res == p); -} -template -void test_P_R() -{ - typedef CGAL::Point_3 P; - typedef CGAL::Ray_3 Ray; - P p(0.99,0.99,0.99); - Ray ray(P(-1.0,-1.0,-1.0), P(1.0,1.0,1.0)); - assert(CGAL::do_intersect(p, ray)); - CGAL::Object o = CGAL::intersection(p,ray); - P res; - assert(assign(res, o)); - assert(res == p); -} -template -void test_P_S() -{ - typedef CGAL::Point_3 P; - typedef CGAL::Segment_3 S; - P p(0.99,0.99,0.99); - S s(P(-1.0,-1.0,-1.0), P(1.0,1.0,1.0)); - assert(CGAL::do_intersect(p, s)); - CGAL::Object o = CGAL::intersection(p,s); - P res; - assert(assign(res, o)); - assert(res == p); -} -template -void test_P_P() -{ - typedef CGAL::Point_3 P; - P p(0.99,0.99,0.99); - assert(CGAL::do_intersect(p, p)); - CGAL::Object o = CGAL::intersection(p,p); - P res; - assert(assign(res, o)); - assert(res == p); -} -template -void test_P_Pl() -{ - typedef CGAL::Point_3 P; - typedef CGAL::Plane_3 Pl; - P p(0.99,0.99,0.99); - Pl pl(P(-1.0,-1.0,-1.0), P(1.0,1.0,1.0), P(0.0,0.0,0.0)); - assert(CGAL::do_intersect(p, pl)); - CGAL::Object o = CGAL::intersection(p,pl); - P res; - assert(assign(res, o)); - assert(res == p); -} - -template -void test_P_Tet() -{ - typedef CGAL::Point_3 P; - typedef CGAL::Tetrahedron_3 T; - P p(0,0,0), q(1,0,0), r(1,1,0), s(0,0,1); - T t(p,q,r,s); - P q0(0.1, 0.1, 0.1), q1(10,10,10); - - assert(CGAL::do_intersect(p,t)); - assert(CGAL::do_intersect(t,p)); - - assert(CGAL::do_intersect(q0,t)); - assert(CGAL::do_intersect(t,q0)); - - assert(! CGAL::do_intersect(q1,t)); - assert(! CGAL::do_intersect(t,q1)); -} - -int main() -{ - test_P_Cub(); - test_P_Cub(); - - test_P_L(); - test_P_L(); - - test_P_R(); - test_P_R(); - test_P_S(); - test_P_S(); - - test_P_P(); - test_P_P(); - - test_P_Pl(); - test_P_Pl(); - - test_P_Tet(); - test_P_Tet(); -} -#include - - - diff --git a/Intersections_3/test/Intersections_3/tetrahedron.cpp b/Intersections_3/test/Intersections_3/tetrahedron.cpp deleted file mode 100644 index 2696eeef178..00000000000 --- a/Intersections_3/test/Intersections_3/tetrahedron.cpp +++ /dev/null @@ -1,76 +0,0 @@ -#include - -#include - -typedef CGAL::Cartesian K; - -typedef K::Point_3 Point; -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() -{ - Point p(0,0,0), q(10,0,0), r(10,10,0), s(0, 10,10); - Point p2(1,1,1), q2(20,20,20), r2(0,0,20); - Tetrahedron tet(p,q,r,s), - tet2(p, Point(9,0,0), Point(15, 15, 0), Point(0, 15, 10)), - v_v(p,Point(-10,0,0),Point(-10,-10,0), Point(0,-10,-10)), - v_e(Point(-10,0,0), Point(0,0,10), Point(0,0,-10), Point(-10,10,0)), - v_f(Point(-10,0,0), Point(0,-10,-10), Point(0,-10,10), Point(0,10,0)), - e_e(Point(-10,0,0), Point(-15,0,0), Point(0,5,10), Point(0,10,5)), - e_f(Point(0,15,15), Point(-15,0,0), Point(0,-11,10), Point(0,10,-11)), - f_f(Point(10,10,10), q, r, s), - tet3(Point(-1,0,0), Point(-10,0,0), Point(-10,-10,0), Point(0,-10,-10)); - - Sphere sp(p2,1.0); - - CGAL::do_intersect(tet,Triangle(p2,q2,r2)); - CGAL::do_intersect(tet,Segment(p2,q2)); - CGAL::do_intersect(tet,Iso_cuboid(p2,q2)); - CGAL::do_intersect(tet,sp); - CGAL::do_intersect(tet,Plane(p2,q2,r2)); - CGAL::do_intersect(tet,Line(p2,q2)); - CGAL::do_intersect(tet,Ray(p2,q2)); - CGAL::do_intersect(tet,tet); - CGAL::do_intersect(tet,sp.bbox()); - CGAL::do_intersect(sp, Line(p2,q2)); - CGAL::do_intersect(sp, Ray(p2,q2)); - CGAL::do_intersect(sp, Segment(p2,q2)); - - - CGAL::do_intersect(Triangle(p2,q2,r2), tet); - CGAL::do_intersect(Segment(p2,q2), tet); - CGAL::do_intersect(Iso_cuboid(p2,q2), tet); - CGAL::do_intersect(sp, tet); - CGAL::do_intersect(Plane(p2,q2,r2), tet); - CGAL::do_intersect(Line(p2,q2), tet); - CGAL::do_intersect(Ray(p2,q2), tet); - CGAL::do_intersect(sp.bbox(), tet); - - CGAL::do_intersect(Line(p2,q2), sp); - CGAL::do_intersect(Ray(p2,q2), sp); - CGAL::do_intersect(Segment(p2,q2), sp); - - CGAL_assertion(CGAL::do_intersect(tet, v_e)); - CGAL_assertion(CGAL::do_intersect(tet, v_f)); - CGAL_assertion(CGAL::do_intersect(tet, v_v)); - CGAL_assertion(CGAL::do_intersect(tet, tet2)); - CGAL_assertion(CGAL::do_intersect(tet, e_e)); - CGAL_assertion(CGAL::do_intersect(tet, e_f)); - CGAL_assertion(CGAL::do_intersect(tet, f_f)); - - CGAL_assertion(!CGAL::do_intersect(tet, tet3)); - - - return 0; -} diff --git a/Intersections_3/test/Intersections_3/triangle_other_intersection_test.cpp b/Intersections_3/test/Intersections_3/triangle_other_intersection_test.cpp index f93aabdf95a..ae3064c7e91 100644 --- a/Intersections_3/test/Intersections_3/triangle_other_intersection_test.cpp +++ b/Intersections_3/test/Intersections_3/triangle_other_intersection_test.cpp @@ -633,13 +633,13 @@ int main() random_test(); std::cout << "\tTesting with Simple_cartesian..." << std::endl ; - random_test(); + random_test(); std::cout << "\tTesting with Cartesian..." << std::endl ; - random_test(); + random_test(); std::cout << "\tTesting with Cartesian..." << std::endl ; - random_test(); + random_test(); std::cout << "\tTesting with Exact_predicates_inexact_constructions_kernel..." << std::endl ; random_test(); From 8de38803d4828d6f2e49bd7bdcd6e99d60c555c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mael=20Rouxel-Labb=C3=A9?= Date: Wed, 23 Jun 2021 17:40:15 +0200 Subject: [PATCH 06/31] Fix indentation --- Kernel_23/include/CGAL/Circle_3.h | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/Kernel_23/include/CGAL/Circle_3.h b/Kernel_23/include/CGAL/Circle_3.h index 0b42941a064..fdcf34c377a 100644 --- a/Kernel_23/include/CGAL/Circle_3.h +++ b/Kernel_23/include/CGAL/Circle_3.h @@ -120,27 +120,27 @@ public: return typename R::Construct_bbox_3()(*this); } - FT area_divided_by_pi() const - { - return typename R::Compute_area_divided_by_pi_3()(*this); + FT area_divided_by_pi() const + { + return typename R::Compute_area_divided_by_pi_3()(*this); } double approximate_area() const { - return typename R::Compute_approximate_area_3()(*this); - } + return typename R::Compute_approximate_area_3()(*this); + } - FT squared_length_divided_by_pi_square() const - { - return typename R::Compute_squared_length_divided_by_pi_square_3()(*this); + FT squared_length_divided_by_pi_square() const + { + return typename R::Compute_squared_length_divided_by_pi_square_3()(*this); } double approximate_squared_length() const { - return typename R::Compute_approximate_squared_length_3()(*this); - } + return typename R::Compute_approximate_squared_length_3()(*this); + } - typename R::Boolean + typename R::Boolean has_on(const Point_3 &p) const { return typename R::Has_on_3()(*this, p); From 0d28171726282eddca199209e91e1e81f4510e2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mael=20Rouxel-Labb=C3=A9?= Date: Wed, 23 Jun 2021 17:40:25 +0200 Subject: [PATCH 07/31] Fix include --- Skin_surface_3/include/CGAL/Skin_surface_refinement_policy_3.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Skin_surface_3/include/CGAL/Skin_surface_refinement_policy_3.h b/Skin_surface_3/include/CGAL/Skin_surface_refinement_policy_3.h index 9e09c52ad29..ac7e7bd24c1 100644 --- a/Skin_surface_3/include/CGAL/Skin_surface_refinement_policy_3.h +++ b/Skin_surface_3/include/CGAL/Skin_surface_refinement_policy_3.h @@ -17,11 +17,11 @@ #include #include +#include #include #include -#include namespace CGAL { template From 22f5d89270488eed77a64d26c4e5583a1ff54430 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mael=20Rouxel-Labb=C3=A9?= Date: Fri, 25 Jun 2021 20:15:56 +0200 Subject: [PATCH 08/31] Fix Iso_cuboidH3::has_on_unbounded_side --- Homogeneous_kernel/include/CGAL/Homogeneous/Iso_cuboidH3.h | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/Homogeneous_kernel/include/CGAL/Homogeneous/Iso_cuboidH3.h b/Homogeneous_kernel/include/CGAL/Homogeneous/Iso_cuboidH3.h index 112ae818a8c..0119260a3c1 100644 --- a/Homogeneous_kernel/include/CGAL/Homogeneous/Iso_cuboidH3.h +++ b/Homogeneous_kernel/include/CGAL/Homogeneous/Iso_cuboidH3.h @@ -360,10 +360,7 @@ CGAL_KERNEL_INLINE bool Iso_cuboidH3:: has_on_unbounded_side(const typename Iso_cuboidH3::Point_3& p) const -{ - return ( ( lexicographically_xyz_smaller(p,(this->min)() )) - ||( lexicographically_xyz_smaller((this->max)(),p )) ); -} +{ return ( bounded_side(p) == ON_UNBOUNDED_SIDE ); } template < class R > CGAL_KERNEL_INLINE From e70a62ac62542ec12e1df93be4213fbffc3ba68a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mael=20Rouxel-Labb=C3=A9?= Date: Fri, 25 Jun 2021 20:16:29 +0200 Subject: [PATCH 09/31] Fix Iso_cuboid_3 / Line_3 Do_intersect() --- .../internal/Bbox_3_Line_3_do_intersect.h | 13 ++++- .../internal/Bbox_3_Segment_3_do_intersect.h | 25 ++++---- .../Iso_cuboid_3_Line_3_do_intersect.h | 57 +++---------------- 3 files changed, 31 insertions(+), 64 deletions(-) diff --git a/Intersections_3/include/CGAL/Intersections_3/internal/Bbox_3_Line_3_do_intersect.h b/Intersections_3/include/CGAL/Intersections_3/internal/Bbox_3_Line_3_do_intersect.h index f0054560f00..ce5e156530d 100644 --- a/Intersections_3/include/CGAL/Intersections_3/internal/Bbox_3_Line_3_do_intersect.h +++ b/Intersections_3/include/CGAL/Intersections_3/internal/Bbox_3_Line_3_do_intersect.h @@ -22,14 +22,21 @@ namespace CGAL { namespace Intersections { namespace internal { -template +template inline bool bbox_line_do_intersect_aux(const FT& px, const FT& py, const FT& pz, const FT& vx, const FT& vy, const FT& vz, - const FT& bxmin, const FT& bymin, const FT& bzmin, - const FT& bxmax, const FT& bymax, const FT& bzmax) + const BFT& bxmin, const BFT& bymin, const BFT& bzmin, + const BFT& bxmax, const BFT& bymax, const BFT& bzmax) { + if((px >= bxmin) && (px <= bxmax) && + (py >= bymin) && (py <= bymax) && + (pz >= bzmin) && (pz <= bzmax)) + { + return true; + } + // ----------------------------------- // treat x coord // ----------------------------------- diff --git a/Intersections_3/include/CGAL/Intersections_3/internal/Bbox_3_Segment_3_do_intersect.h b/Intersections_3/include/CGAL/Intersections_3/internal/Bbox_3_Segment_3_do_intersect.h index 4b6d802250c..1c27d3c530b 100644 --- a/Intersections_3/include/CGAL/Intersections_3/internal/Bbox_3_Segment_3_do_intersect.h +++ b/Intersections_3/include/CGAL/Intersections_3/internal/Bbox_3_Segment_3_do_intersect.h @@ -140,11 +140,11 @@ do_intersect_bbox_segment_aux(const FT& px, const FT& py, const FT& pz, const BFT& bxmax, const BFT& bymax, const BFT& bzmax) { if(((px >= bxmin) && (px <= bxmax) && - (py >= bymin) && (py <= bymax) && - (pz >= bzmin) && (pz <= bzmax)) || - ((qx >= bxmin) && (qx <= bxmax) && - (qy >= bymin) && (qy <= bymax) && - (qz >= bzmin) && (qz <= bzmax))) + (py >= bymin) && (py <= bymax) && + (pz >= bzmin) && (pz <= bzmax)) || + ((qx >= bxmin) && (qx <= bxmax) && + (qy >= bymin) && (qy <= bymax) && + (qz >= bzmin) && (qz <= bzmax))) { return true; } @@ -208,7 +208,7 @@ do_intersect_bbox_segment_aux(const FT& px, const FT& py, const FT& pz, // If the query is vertical for x, then check its x-coordinate is in // the x-slab. if((px == qx) && // <=> (dmin == 0) - (! (bounded_0 && bounded_1))) // do not check for a segment + (!(bounded_0 && bounded_1))) // do not check for a segment { if(px > bxmax || px < bxmin) return false; @@ -396,25 +396,23 @@ do_intersect_bbox_segment_aux(const FT& px, const FT& py, const FT& pz, } Is_greater_value b = Is_greater_value(); + // If tymin/dymin > t1, set t1 = tymin/dymin. if((px == qx) || // <=> (dmin == 0) ((py != qy) && // <=> (dymin > 0) - certainly(b = is_greater( dmin*tymin, dymin* tmin)))) + certainly(b = is_greater(dmin*tymin, dymin*tmin)))) { tmin = tymin; dmin = dymin; } if(is_indeterminate(b)) - return b; // Note that the default-constructed - - // Is_greater_value cannot be - // indeterminate. + return b; // Note that the default-constructed Is_greater_value cannot be indeterminate. // If tymax/dymax < t2, set t2 = tymax/dymax. if((px == qx) || // <=> (dmax > 0) ((py != qy) && // <=> dymax > 0 - certainly(b = is_greater(dymax* tmax, dmax*tymax)))) + certainly(b = is_greater(dymax*tmax, dmax*tymax)))) { tmax = tymax; dmax = dymax; @@ -437,7 +435,7 @@ do_intersect_bbox_segment_aux(const FT& px, const FT& py, const FT& pz, if(is_greater.bound_overflow() || is_greater.value_might_underflow()) return Is_greater::uncertain(); - const Is_greater_value b1 = is_greater(dzmax* tmin, dmin*tzmax); + const Is_greater_value b1 = is_greater(dzmax*tmin, dmin*tzmax); if(possibly(b1)) return !b1; // if(is_greater) return false; // or uncertain @@ -445,6 +443,7 @@ do_intersect_bbox_segment_aux(const FT& px, const FT& py, const FT& pz, if(possibly(b2)) return !b2; // if(is_greater) return false; // or uncertain } + return true; } diff --git a/Intersections_3/include/CGAL/Intersections_3/internal/Iso_cuboid_3_Line_3_do_intersect.h b/Intersections_3/include/CGAL/Intersections_3/internal/Iso_cuboid_3_Line_3_do_intersect.h index a9095b41d31..0b3c26bf131 100644 --- a/Intersections_3/include/CGAL/Intersections_3/internal/Iso_cuboid_3_Line_3_do_intersect.h +++ b/Intersections_3/include/CGAL/Intersections_3/internal/Iso_cuboid_3_Line_3_do_intersect.h @@ -13,6 +13,8 @@ #ifndef CGAL_INTERNAL_INTERSECTIONS_3_ISO_CUBOID_3_LINE_3_DO_INTERSECT_H #define CGAL_INTERNAL_INTERSECTIONS_3_ISO_CUBOID_3_LINE_3_DO_INTERSECT_H +#include + #include #include @@ -23,60 +25,19 @@ namespace internal { template inline bool do_intersect(const typename K::Line_3& line, - const typename K::Iso_cuboid_3& box, + const typename K::Iso_cuboid_3& ic, const K&) { typedef typename K::Point_3 Point_3; typedef typename K::Vector_3 Vector_3; - typedef typename K::FT FT; - bool all_values = true; - FT _min = 0, _max = 0; // initialization to stop compiler warning - FT _denum; - const Point_3& _ref_point = line.point(); - const Vector_3& _dir = line.direction().vector(); - const Point_3& _iso_min = (box.min)(); - const Point_3& _iso_max = (box.max)(); + const Point_3& point = line.point(); + const Vector_3& v = line.to_vector(); - for(int i=0; i< _ref_point.dimension(); ++i) { - if(_dir.homogeneous(i) == 0) { - if(_ref_point.cartesian(i) < _iso_min.cartesian(i)) - return false; - - if(_ref_point.cartesian(i) > _iso_max.cartesian(i)) - return false; - } else { - FT newmin, newmax; - FT newdenum = _dir.cartesian(i); - if(_dir.homogeneous(i) > 0) { - newmin = (_iso_min.cartesian(i) - _ref_point.cartesian(i)); - newmax = (_iso_max.cartesian(i) - _ref_point.cartesian(i)); - } else { - newmin = (_iso_max.cartesian(i) - _ref_point.cartesian(i)); - newmax = (_iso_min.cartesian(i) - _ref_point.cartesian(i)); - } - - if(all_values) { - _min = newmin; - _max = newmax; - _denum = newdenum; - } else { - if(compare_quotients(newmin, newdenum, _min, _denum) == LARGER) - _min = newmin; - if(compare_quotients(newmax, newdenum, _max, _denum) == LARGER) - _max = newmax; - if(compare_quotients(_max, _denum, _min, _denum) == SMALLER) - return false; - - _denum = newdenum; - - } - all_values = false; - } - } - - CGAL_kernel_assertion(!all_values); - return true; + return bbox_line_do_intersect_aux(point.x(), point.y(), point.z(), + v.x(), v.y(), v.z(), + (ic.min)().x(), (ic.min)().y(), (ic.min)().z(), + (ic.max)().x(), (ic.max)().y(), (ic.max)().z()); } template From 65b7d11acd9bcca8406e41e8b5b024ab39c33faa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mael=20Rouxel-Labb=C3=A9?= Date: Fri, 25 Jun 2021 21:28:54 +0200 Subject: [PATCH 10/31] Test improvements --- .../test_intersections_Iso_cuboid_3.cpp | 20 +++++++++---------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/Intersections_3/test/Intersections_3/test_intersections_Iso_cuboid_3.cpp b/Intersections_3/test/Intersections_3/test_intersections_Iso_cuboid_3.cpp index e0b984070f1..91e91913a48 100644 --- a/Intersections_3/test/Intersections_3/test_intersections_Iso_cuboid_3.cpp +++ b/Intersections_3/test/Intersections_3/test_intersections_Iso_cuboid_3.cpp @@ -156,9 +156,9 @@ public: int My = this->r.get_int(this->m, this->M); int Mz = this->r.get_int(this->m, this->M); - if(mx == Mx) ++Mx; - if(my == My) ++My; - if(mz == Mz) ++Mz; + if(abs(mx - Mx) < 2) Mx = mx + 2; + if(abs(my - My) < 2) My = my + 2; + if(abs(mz - Mz) < 2) Mz = mz + 2; if(mx > Mx) std::swap(mx, Mx); if(my > My) std::swap(my, My); if(mz > Mz) std::swap(mz, Mz); @@ -166,8 +166,8 @@ public: P mp = p(mx, my, mz), Mp = p(Mx, My, Mz); Cub cub(mp, Mp); - P q1 = p(this->r.get_int(mx - this->M, mx), this->r.get_int(my, My), this->r.get_int(mz, Mz)), - q2 = p(this->r.get_int(Mx, Mx + this->M), this->r.get_int(my, My), this->r.get_int(mz, Mz)); + P q1 = p(this->r.get_int(mx - this->M, mx - 1), this->r.get_int(my, My), this->r.get_int(mz, Mz)), + q2 = p(this->r.get_int(Mx + 1, Mx + this->M), this->r.get_int(my, My), this->r.get_int(mz, Mz)); assert(!cub.has_on_bounded_side(q1) && !cub.has_on_bounded_side(q2)); L l(q1, q2); @@ -175,8 +175,8 @@ public: Base::template check_intersection(cub, l, S(q1, q2), cub); q1 = p(this->r.get_int(mx, Mx), this->r.get_int(my - this->M, my), this->r.get_int(mz, Mz)), - q2 = p(this->r.get_int(mx, Mx), this->r.get_int(my + (My - my) / 2, My), this->r.get_int(mz, Mz)); - assert(!cub.has_on_bounded_side(q1) && !cub.has_on_unbounded_side(q2)); + q2 = p(this->r.get_int(mx+1, Mx), this->r.get_int(my+1, My), this->r.get_int(mz+1, Mz)); + assert(cub.has_on_unbounded_side(q1) && cub.has_on_bounded_side(q2)); l = L(q1, q2); Base::template check_intersection(cub, l); @@ -373,8 +373,6 @@ public: if(CGAL::do_intersect(cub, S(s0, s1))) { - std::cout << "yo" << std::endl; - std::cin.get(); check_intersection(cub, S(s0, s1), L(s0, s1), cub); check_intersection(cub, S(s0, s1), R(s0, s1), cub); } @@ -676,11 +674,11 @@ public: std::cout << "3D Line Intersection tests\n"; Cub_Cub(); -// Cub_L(); // @fixme bugged in random cases + Cub_L(); Cub_Pl(); Cub_P(); Cub_R(); -// Cub_S(); // @fixme bugged in random cases + Cub_S(); Cub_Sph(); Cub_Tet(); Cub_Tr(); From 6b6ab287a8bfedc36b98e15dffdc6711777bc9d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mael=20Rouxel-Labb=C3=A9?= Date: Mon, 28 Jun 2021 13:26:28 +0200 Subject: [PATCH 11/31] Fix Segment_3-Sphere_3 do intersect: detect fully contained segments --- .../Segment_3_Sphere_3_do_intersect.h | 29 ++++++++++++++++--- .../test_intersections_Segment_3.cpp | 9 +++--- 2 files changed, 29 insertions(+), 9 deletions(-) diff --git a/Intersections_3/include/CGAL/Intersections_3/internal/Segment_3_Sphere_3_do_intersect.h b/Intersections_3/include/CGAL/Intersections_3/internal/Segment_3_Sphere_3_do_intersect.h index ff1a7ffb4eb..e4d3818043c 100644 --- a/Intersections_3/include/CGAL/Intersections_3/internal/Segment_3_Sphere_3_do_intersect.h +++ b/Intersections_3/include/CGAL/Intersections_3/internal/Segment_3_Sphere_3_do_intersect.h @@ -28,12 +28,33 @@ do_intersect(const typename K::Sphere_3& sp, const K& k) { typedef typename K::RT RT; - RT num, den; + typedef typename K::Bounded_side Bounded_side; + + typename K::Bounded_side_3 bounded_side = k.bounded_side_3_object(); + typename K::Compute_squared_radius_3 sq_radius = k.compute_squared_radius_3_object(); + typename K::Construct_center_3 center = k.construct_center_3_object(); + typename K::Construct_source_3 source = k.construct_source_3_object(); + typename K::Construct_target_3 target = k.construct_target_3_object(); + + const Bounded_side source_side = bounded_side(sp, source(seg)); + const Bounded_side target_side = bounded_side(sp, target(seg)); + + if(source_side != target_side) + return true; + else if(source_side == ON_BOUNDED_SIDE) // else if ==> both extremities are on the same side + return false; + else if(source_side == ON_BOUNDARY) + return true; + + CGAL_kernel_assertion(source_side == ON_UNBOUNDED_SIDE && target_side == ON_UNBOUNDED_SIDE); + + // Both out can still be intersecting the sphere + RT num, den; + CGAL::internal::squared_distance_RT(center(sp), seg, num, den, k); - CGAL::internal::squared_distance_RT(sp.center(), seg, num, den, k); return !(compare_quotients(num, den, - Rational_traits().numerator(sp.squared_radius()), - Rational_traits().denominator(sp.squared_radius())) == LARGER); + Rational_traits().numerator(sq_radius(sp)), + Rational_traits().denominator(sq_radius(sp))) == LARGER); } template diff --git a/Intersections_3/test/Intersections_3/test_intersections_Segment_3.cpp b/Intersections_3/test/Intersections_3/test_intersections_Segment_3.cpp index 7e56289423e..e8dd7a23868 100644 --- a/Intersections_3/test/Intersections_3/test_intersections_Segment_3.cpp +++ b/Intersections_3/test/Intersections_3/test_intersections_Segment_3.cpp @@ -68,16 +68,17 @@ public: // see segment_segment.cpp } - // @fixme EPICK void S_Sph() { std::cout << "Segment - Sphere\n"; // No intersection check_do_not_intersect(S(p(4,1,9), p(4,6,-1)), Sph(p(9,2,4), 1)); - check_do_not_intersect(S(p(-2,3,4), p(1,2,-1)), Sph(p(9,2,4), 10000)); + check_do_not_intersect(S(p(-2,3,4), p(1,2,-1)), Sph(p(9,2,4), 10000)); + check_do_intersect(S(p(0,1,0), p(2,1,0)), Sph(p(1,0,0), 1)); check_do_intersect(S(p(-2,3,4), p(1,2,-1)), Sph(p(9,2,4), 100)); + check_do_intersect(S(p(-2,3,4), p(3,2,-5)), Sph(p(9,2,4), 100)); for(int i=0; i Date: Tue, 29 Jun 2021 09:24:53 +0200 Subject: [PATCH 12/31] Fix Construct_radical_plane_3 for Homogeneous_kernel --- .../include/CGAL/Cartesian/function_objects.h | 18 +++---- .../CGAL/Homogeneous/function_objects.h | 52 ++++++++++++++++--- 2 files changed, 53 insertions(+), 17 deletions(-) diff --git a/Cartesian_kernel/include/CGAL/Cartesian/function_objects.h b/Cartesian_kernel/include/CGAL/Cartesian/function_objects.h index 7bc920bd961..77ca7528782 100644 --- a/Cartesian_kernel/include/CGAL/Cartesian/function_objects.h +++ b/Cartesian_kernel/include/CGAL/Cartesian/function_objects.h @@ -3260,15 +3260,15 @@ namespace CartesianKernelFunctors { result_type operator() (const Circle_2 & c1, const Circle_2 & c2) const - { + { // Concentric Circles don't have radical line CGAL_kernel_precondition (c1.center() != c2.center()); const FT a = 2*(c2.center().x() - c1.center().x()); const FT b = 2*(c2.center().y() - c1.center().y()); const FT c = CGAL::square(c1.center().x()) + - CGAL::square(c1.center().y()) - c1.squared_radius() - - CGAL::square(c2.center().x()) - - CGAL::square(c2.center().y()) + c2.squared_radius(); + CGAL::square(c1.center().y()) - c1.squared_radius() - + CGAL::square(c2.center().x()) - + CGAL::square(c2.center().y()) + c2.squared_radius(); return Line_2(a, b, c); } }; @@ -3293,11 +3293,11 @@ namespace CartesianKernelFunctors { const FT b = 2*(s2.center().y() - s1.center().y()); const FT c = 2*(s2.center().z() - s1.center().z()); const FT d = CGAL::square(s1.center().x()) + - CGAL::square(s1.center().y()) + - CGAL::square(s1.center().z()) - s1.squared_radius() - - CGAL::square(s2.center().x()) - - CGAL::square(s2.center().y()) - - CGAL::square(s2.center().z()) + s2.squared_radius(); + CGAL::square(s1.center().y()) + + CGAL::square(s1.center().z()) - s1.squared_radius() - + CGAL::square(s2.center().x()) - + CGAL::square(s2.center().y()) - + CGAL::square(s2.center().z()) + s2.squared_radius(); return Plane_3(a, b, c, d); } }; diff --git a/Homogeneous_kernel/include/CGAL/Homogeneous/function_objects.h b/Homogeneous_kernel/include/CGAL/Homogeneous/function_objects.h index 2868dd8f7d2..93e0204231b 100644 --- a/Homogeneous_kernel/include/CGAL/Homogeneous/function_objects.h +++ b/Homogeneous_kernel/include/CGAL/Homogeneous/function_objects.h @@ -45,7 +45,6 @@ namespace HomogeneousKernelFunctors { using CartesianKernelFunctors::Compute_approximate_squared_length_3; using CartesianKernelFunctors::Compute_area_divided_by_pi_3; using CartesianKernelFunctors::Compute_squared_length_divided_by_pi_square_3; - using CartesianKernelFunctors::Construct_radical_plane_3; template class Angle_2 @@ -3418,22 +3417,59 @@ namespace HomogeneousKernelFunctors { result_type operator() (const Circle_2 & c1, const Circle_2 & c2) const - { + { // Concentric Circles don't have radical line CGAL_kernel_precondition (c1.center() != c2.center()); const FT a = 2*(c2.center().x() - c1.center().x()); const FT b = 2*(c2.center().y() - c1.center().y()); const FT c = CGAL::square(c1.center().x()) + - CGAL::square(c1.center().y()) - c1.squared_radius() - - CGAL::square(c2.center().x()) - - CGAL::square(c2.center().y()) + c2.squared_radius(); - const RT aa = a.numerator() * b.denominator() * c.denominator(); - const RT bb = a.denominator() * b.numerator() * c.denominator(); - const RT cc = a.denominator() * b.denominator() * c.numerator(); + CGAL::square(c1.center().y()) - c1.squared_radius() - + CGAL::square(c2.center().x()) - + CGAL::square(c2.center().y()) + c2.squared_radius(); + + const RT aa = a.numerator() * b.denominator() * c.denominator(); + const RT bb = a.denominator() * b.numerator() * c.denominator(); + const RT cc = a.denominator() * b.denominator() * c.numerator(); + return Line_2(aa, bb, cc); } }; + template + class Construct_radical_plane_3 + { + typedef typename K::Plane_3 Plane_3; + typedef typename K::Sphere_3 Sphere_3; + typedef typename K::RT RT; + typedef typename K::FT FT; + + public: + + typedef Plane_3 result_type; + + result_type + operator() (const Sphere_3 & s1, const Sphere_3 & s2) const + { + // Concentric Spheres don't have radical plane + CGAL_kernel_precondition (s1.center() != s2.center()); + const FT a = 2*(s2.center().x() - s1.center().x()); + const FT b = 2*(s2.center().y() - s1.center().y()); + const FT c = 2*(s2.center().z() - s1.center().z()); + const FT d = CGAL::square(s1.center().x()) + + CGAL::square(s1.center().y()) + + CGAL::square(s1.center().z()) - s1.squared_radius() - + CGAL::square(s2.center().x()) - + CGAL::square(s2.center().y()) - + CGAL::square(s2.center().z()) + s2.squared_radius(); + + const RT aa = a.numerator() * b.denominator() * c.denominator() * d.denominator(); + const RT bb = a.denominator() * b.numerator() * c.denominator() * d.denominator(); + const RT cc = a.denominator() * b.denominator() * c.numerator() * d.denominator(); + const RT dd = a.denominator() * b.denominator() * c.denominator() * d.numerator(); + + return Plane_3(aa, bb, cc, dd); + } + }; template class Construct_scaled_vector_2 From 3afa3b546babdfc69c4a42a5fa233bfb6c72d404 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mael=20Rouxel-Labb=C3=A9?= Date: Tue, 29 Jun 2021 09:25:40 +0200 Subject: [PATCH 13/31] Re-enable tests + enhancements --- .../internal/Ray_3_Ray_3_do_intersect.h | 6 +++--- .../test/Intersections_3/test_intersections_Ray_3.cpp | 10 +++++----- .../Intersections_3/test_intersections_Sphere_3.cpp | 9 ++++----- 3 files changed, 12 insertions(+), 13 deletions(-) diff --git a/Intersections_3/include/CGAL/Intersections_3/internal/Ray_3_Ray_3_do_intersect.h b/Intersections_3/include/CGAL/Intersections_3/internal/Ray_3_Ray_3_do_intersect.h index 45a2f9dd9fb..cf334475335 100644 --- a/Intersections_3/include/CGAL/Intersections_3/internal/Ray_3_Ray_3_do_intersect.h +++ b/Intersections_3/include/CGAL/Intersections_3/internal/Ray_3_Ray_3_do_intersect.h @@ -36,8 +36,8 @@ do_intersect(const typename K::Ray_3& r1, typename K::Coplanar_orientation_3 pred = k.coplanar_orientation_3_object(); - CGAL::Orientation p0p1s = pred(r1.point(0), r1.point(1), r2.source()); - CGAL::Orientation stp0 = pred(r2.source(), r2.second_point(), r1.point(0)); + CGAL::Orientation p0p1s = pred(r1.source(), r1.second_point(), r2.source()); + CGAL::Orientation stp0 = pred(r2.source(), r2.second_point(), r1.source()); if(p0p1s == COLLINEAR) { @@ -49,7 +49,7 @@ do_intersect(const typename K::Ray_3& r1, } if(stp0 == COLLINEAR) - return Ray_3_has_on_collinear_Point_3(r2, r1.point(0), k); + return Ray_3_has_on_collinear_Point_3(r2, r1.source(), k); return (p0p1s != stp0); } diff --git a/Intersections_3/test/Intersections_3/test_intersections_Ray_3.cpp b/Intersections_3/test/Intersections_3/test_intersections_Ray_3.cpp index e67bd82de7f..e1d603d4a5e 100644 --- a/Intersections_3/test/Intersections_3/test_intersections_Ray_3.cpp +++ b/Intersections_3/test/Intersections_3/test_intersections_Ray_3.cpp @@ -72,6 +72,7 @@ public: check_no_intersection (R(p(0,0,0), p(1,0,0)), R(p(1,-1,0), p(1,-2,0))); check_no_intersection (R(p(0,0,0), p(1,0,0)), R(p(0,-1,0), p(0,-2,0))); check_no_intersection (R(p(0,0,0), p(1,0,0)), R(p(0,1,0), p(0,2,0))); + check_no_intersection (R(p(0,0,0), p(1,0,0)), R(p(-1,0,0), p(-1,-1,0))); // Point check_intersection (R(p(0,0,0), p(1,0,0)), R(p(0,0,0), p(-1,0,0)), @@ -88,11 +89,10 @@ public: p(1,0,0)); // Segment - // @fixme -// check_intersection (R(p(0,0,0), p(1,0,0)), R(p(2,0,0), p(-3,0,0)), -// S(p(0,0,0), p(2,0,0))); -// check_intersection (R(p(2,0,0), p(-3,0,0)), R(p(0,0,0), p(1,0,0)), -// S(p(2,0,0), p(0,0,0))); + check_intersection (R(p(0,0,0), p(1,0,0)), R(p(2,0,0), p(-3,0,0)), + S(p(0,0,0), p(2,0,0)), false); + check_intersection (R(p(2,0,0), p(-3,0,0)), R(p(0,0,0), p(1,0,0)), + S(p(2,0,0), p(0,0,0)), false); // Ray check_intersection (R(p(0,0,0), p(1,0,0)), R(p(-1,0,0), p(3,0,0)), diff --git a/Intersections_3/test/Intersections_3/test_intersections_Sphere_3.cpp b/Intersections_3/test/Intersections_3/test_intersections_Sphere_3.cpp index a4a2e255d86..62ecc427419 100644 --- a/Intersections_3/test/Intersections_3/test_intersections_Sphere_3.cpp +++ b/Intersections_3/test/Intersections_3/test_intersections_Sphere_3.cpp @@ -171,9 +171,8 @@ int main(int, char**) std::cout << " |||||||| Test Simple_cartesian ||||||||" << std::endl; Sphere_3_intersection_tester< CGAL::Simple_cartesian >(r).run(); - // @fixme illegal Plane_3 constructor in Cartesian_kernel::Construct_radical_plane_3 -// std::cout << " |||||||| Test CGAL::Homogeneous ||||||||" << std::endl; -// Sphere_3_intersection_tester< CGAL::Homogeneous >(r).run(); + std::cout << " |||||||| Test CGAL::Homogeneous ||||||||" << std::endl; + Sphere_3_intersection_tester< CGAL::Homogeneous >(r).run(); std::cout << " |||||||| Test EPICK ||||||||" << std::endl; Sphere_3_intersection_tester< CGAL::Epick >(r, true /*exact predicates*/).run(); @@ -181,8 +180,8 @@ int main(int, char**) std::cout << " |||||||| Test EPECK ||||||||" << std::endl; Sphere_3_intersection_tester< CGAL::Epeck >(r, true /*exact predicates*/, true /*exact constructions*/).run(); -// std::cout << " |||||||| Test CGAL::Homogeneous ||||||||" << std::endl; -// Sphere_3_intersection_tester< CGAL::Homogeneous >(r, true /*exact predicates*/, true /*exact constructions*/).run(); + std::cout << " |||||||| Test CGAL::Homogeneous ||||||||" << std::endl; + Sphere_3_intersection_tester< CGAL::Homogeneous >(r, true /*exact predicates*/, true /*exact constructions*/).run(); std::cout << "OK!" << std::endl; } From 2b41096f69a656b530f4c7b4e11817d2f3a26c1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mael=20Rouxel-Labb=C3=A9?= Date: Wed, 30 Jun 2021 11:26:13 +0200 Subject: [PATCH 14/31] Fix Sphere_3 Triangle_3/Tetrahedron_3 do_intersect --- .../Segment_3_Sphere_3_do_intersect.h | 2 +- .../Sphere_3_Triangle_3_do_intersect.h | 27 ++++++++++++++++--- .../test_intersections_Sphere_3.cpp | 20 +++++++++----- 3 files changed, 38 insertions(+), 11 deletions(-) diff --git a/Intersections_3/include/CGAL/Intersections_3/internal/Segment_3_Sphere_3_do_intersect.h b/Intersections_3/include/CGAL/Intersections_3/internal/Segment_3_Sphere_3_do_intersect.h index e4d3818043c..3be7f782408 100644 --- a/Intersections_3/include/CGAL/Intersections_3/internal/Segment_3_Sphere_3_do_intersect.h +++ b/Intersections_3/include/CGAL/Intersections_3/internal/Segment_3_Sphere_3_do_intersect.h @@ -48,7 +48,7 @@ do_intersect(const typename K::Sphere_3& sp, CGAL_kernel_assertion(source_side == ON_UNBOUNDED_SIDE && target_side == ON_UNBOUNDED_SIDE); - // Both out can still be intersecting the sphere + // Both extremities are out, but the segment can still be intersecting the sphere RT num, den; CGAL::internal::squared_distance_RT(center(sp), seg, num, den, k); diff --git a/Intersections_3/include/CGAL/Intersections_3/internal/Sphere_3_Triangle_3_do_intersect.h b/Intersections_3/include/CGAL/Intersections_3/internal/Sphere_3_Triangle_3_do_intersect.h index 7357899bcdf..f5d0e65c7a5 100644 --- a/Intersections_3/include/CGAL/Intersections_3/internal/Sphere_3_Triangle_3_do_intersect.h +++ b/Intersections_3/include/CGAL/Intersections_3/internal/Sphere_3_Triangle_3_do_intersect.h @@ -28,12 +28,31 @@ do_intersect(const typename K::Sphere_3& sp, const K& k) { typedef typename K::RT RT; - RT num, den; + typedef typename K::Bounded_side Bounded_side; + + typename K::Bounded_side_3 bounded_side = k.bounded_side_3_object(); + typename K::Compute_squared_radius_3 sq_radius = k.compute_squared_radius_3_object(); + typename K::Construct_center_3 center = k.construct_center_3_object(); + typename K::Construct_vertex_3 vertex = k.construct_vertex_3_object(); + + const Bounded_side v0_side = bounded_side(sp, vertex(tr, 0)); + const Bounded_side v1_side = bounded_side(sp, vertex(tr, 1)); + const Bounded_side v2_side = bounded_side(sp, vertex(tr, 2)); + + if(v0_side != v1_side || v0_side != v2_side || v1_side != v2_side) + return true; + else if(v0_side == ON_BOUNDED_SIDE) // 'else if' ==> all vertices are on the same side + return false; + else if(v0_side == ON_BOUNDARY) + return true; + + // All vertices are out, but the triangle can still be intersecting the sphere + RT num, den; + CGAL::internal::squared_distance_RT(center(sp), tr, num, den, k); - CGAL::internal::squared_distance_RT(sp.center(), tr, num, den, k); return !(compare_quotients(num, den, - Rational_traits().numerator(sp.squared_radius()), - Rational_traits().denominator(sp.squared_radius())) == LARGER); + Rational_traits().numerator(sq_radius(sp)), + Rational_traits().denominator(sq_radius(sp))) == LARGER); } template diff --git a/Intersections_3/test/Intersections_3/test_intersections_Sphere_3.cpp b/Intersections_3/test/Intersections_3/test_intersections_Sphere_3.cpp index 62ecc427419..9ba7c91f09d 100644 --- a/Intersections_3/test/Intersections_3/test_intersections_Sphere_3.cpp +++ b/Intersections_3/test/Intersections_3/test_intersections_Sphere_3.cpp @@ -129,24 +129,32 @@ public: check_do_not_intersect(Sph(p(0,0,0), 3), Tr(p(6,3,8), p(7,2,8), p(1,9,7))); check_do_not_intersect(Sph(p(0,0,0), 10000), Tr(p(6,3,8), p(7,2,8), p(1,9,7))); + check_do_intersect(Sph(p(1, 2, 3), 100), Tr(p(-15, -18, 3), p(-15, 13, 1), p(15, 0, 2))); + check_do_intersect(Sph(p(1, 2, 3), 100), Tr(p(-150, -180, 3), p(-150, 130, 1), p(150, 0, 2))); + // Generic for(int i=0; ir.get_int(this->m + 1, this->M); + const P c = random_point(); + + if(this->has_exact_c) + check_do_intersect(Sph(c, CGAL::squared_distance(c, tr)), tr); + + const FT r = this->r.get_int(this->m + 1, this->M); Sph sph(c, r); + if(c != tr1 && c != tr2) + check_do_intersect(sph, Tr(c, tr1, tr2)); + if(sph.oriented_side(tr0) != sph.oriented_side(tr1) || sph.oriented_side(tr0) != sph.oriented_side(tr2) || sph.oriented_side(tr2) != sph.oriented_side(tr1)) check_do_intersect(sph, tr); - else - check_do_not_intersect(sph, tr); } } From e118e28e72563a336f26d9a58d7d83c37d800a93 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mael=20Rouxel-Labb=C3=A9?= Date: Mon, 5 Jul 2021 22:02:11 +0200 Subject: [PATCH 15/31] Rewrite CGAL::intersection(Tetrahedron_3, Triangle_3) --- .../Plane_3_Tetrahedron_3_intersection.h | 4 +- .../Tetrahedron_3_Triangle_3_intersection.h | 571 ++++++++++++++---- .../tetrahedron_intersection_helpers.h | 274 --------- 3 files changed, 451 insertions(+), 398 deletions(-) delete mode 100644 Intersections_3/include/CGAL/Intersections_3/internal/tetrahedron_intersection_helpers.h diff --git a/Intersections_3/include/CGAL/Intersections_3/internal/Plane_3_Tetrahedron_3_intersection.h b/Intersections_3/include/CGAL/Intersections_3/internal/Plane_3_Tetrahedron_3_intersection.h index d8e8fa27fc7..bd7b49193f3 100644 --- a/Intersections_3/include/CGAL/Intersections_3/internal/Plane_3_Tetrahedron_3_intersection.h +++ b/Intersections_3/include/CGAL/Intersections_3/internal/Plane_3_Tetrahedron_3_intersection.h @@ -18,7 +18,6 @@ #include #include #include -#include #include @@ -119,8 +118,7 @@ intersection(const typename K::Tetrahedron_3& tet, // check for intersection of the edge if (orientations[next_id] == ON_POSITIVE_SIDE) { - ids.push_back( - inter_pt_index(current_id, next_id, edge_id)); + ids.push_back(inter_pt_index(current_id, next_id, edge_id)); } break; } diff --git a/Intersections_3/include/CGAL/Intersections_3/internal/Tetrahedron_3_Triangle_3_intersection.h b/Intersections_3/include/CGAL/Intersections_3/internal/Tetrahedron_3_Triangle_3_intersection.h index b0117ed27a7..4ede09428a6 100644 --- a/Intersections_3/include/CGAL/Intersections_3/internal/Tetrahedron_3_Triangle_3_intersection.h +++ b/Intersections_3/include/CGAL/Intersections_3/internal/Tetrahedron_3_Triangle_3_intersection.h @@ -9,18 +9,19 @@ // // // Author(s) : Maxime Gimeno +// Mael Rouxel-Labbé // - #ifndef CGAL_INTERNAL_INTERSECTIONS_3_TETRAHEDRON_3_TRIANGLE_3_INTERSECTIONS_H #define CGAL_INTERNAL_INTERSECTIONS_3_TETRAHEDRON_3_TRIANGLE_3_INTERSECTIONS_H #include -#include #include #include +#include +#include #include #include #include @@ -29,6 +30,256 @@ namespace CGAL { namespace Intersections { namespace internal { +template +void filter_segments(std::list& segments) +{ + auto are_equal = [](const Segment& l, const Segment& r) -> bool + { + return (l == r || l == r.opposite()); + }; + + segments.sort(are_equal); + segments.erase(std::unique(segments.begin(), segments.end(), are_equal), segments.end()); +} + +// plane going through the ref segment's source, a point above (given by the normal of the input +// triangle) and two points (ref_other / query) that need to be ordered +template +bool first_comes_first_pt(const typename K::Point_3& ref_source, + const typename K::Point_3& ref_z, + const typename K::Point_3& ref_other, + const typename K::Point_3& query, + const K& k) +{ + typename K::Orientation_3 orientation = k.orientation_3_object(); + + // points have filtered to remove segments' extremities + CGAL_precondition(ref_other != query); + + const Orientation o = orientation(ref_source, ref_z, ref_other, query); + CGAL_assertion(o != COPLANAR); + + // ref_other comes first <==> query is on the positive side of the plane + return (o == POSITIVE); +} + +template +bool first_comes_first(const typename K::Point_3& ref_source, + const typename K::Point_3& ref_z, + const typename K::Point_3& ref_other, + const SegPtVariant& seg_or_pt, + const K& k) +{ + typedef typename K::Point_3 Point_3; + typedef typename K::Segment_3 Segment_3; + + typedef typename std::list::iterator SCI; + typedef typename std::vector::iterator PCI; + + if(seg_or_pt.which() == 0) + { + const Segment_3& s = *(boost::get(seg_or_pt)); + return first_comes_first_pt(ref_source, ref_z, ref_other, s.source(), k); + } + else + { + CGAL_assertion(seg_or_pt.which() == 1); + + const Point_3& p = *(boost::get(seg_or_pt)); + return first_comes_first_pt(ref_source, ref_z, ref_other, p, k); + } +} + +template +typename Intersection_traits::result_type +build_intersection(const typename K::Tetrahedron_3& input_tetrahedron, + const typename K::Triangle_3& input_triangle, + PointContainer& points, + SegmentContainer& segments, + const K& k) +{ + typedef typename Intersection_traits::result_type result_type; + + typedef typename K::Point_3 Point_3; + typedef typename K::Segment_3 Segment_3; + typedef typename K::Vector_3 Vector_3; + typedef typename K::Triangle_3 Triangle_3; + typedef std::vector Poly; + + typedef typename SegmentContainer::iterator SCI; + typedef typename PointContainer::iterator PCI; + + // @todo? Could do the 1 segment case with this code too... + CGAL_precondition(segments.size() >= 2 && segments.size() <= 4); + CGAL_precondition(points.size() <= 2); + + // Constructions @fixme avoidable? + const Vector_3 input_triangle_normal = input_triangle.supporting_plane().orthogonal_vector(); + + // remove points that are just segments extremities + auto is_extremity = [&segments](const Point_3& p) -> bool + { + for(const Segment_3& s : segments) + if(p == s.source() || p == s.target()) + return true; + return false; + }; + std::remove_if(points.begin(), points.end(), is_extremity); + + // Take the first segment as reference, and order the rest to form a convex polygon + // + // All segments and points involved in the intersection are on the input triangle + // and thus everything is coplanar, at least theoretically (the kernel might not provide + // exact constructions...) + // + // Given an arbitrary segment, the code below sorts the other segments and the points + // in a ccw order. Using a vector because the number of segments and points is bounded + // (max 4 segments and max 2 points) so the linear insertion is a little ugly, + // but it's not a big cost. + // + // Example: + /* + x p0 + + / + / + s1 / \ s2 + / \ + -------------- + s0 + */ + // + // s0 is chosen as the reference segment + // output will be 's0 s2 p0 s1' + + Segment_3& ref_s = segments.front(); + const Point_3& ref_sp = ref_s.source(); + const Point_3& ref_tp = ref_s.target(); + Point_3 ref_z = ref_sp + input_triangle_normal; + + // The reference segment should be such that all other intersection parts are + // on the positive side of the plane described by the normal of the triangle and ref_s + bool swapped = false; + for(SCI slit = std::next(segments.begin()); slit != segments.end(); ++slit) + { + const Segment_3& other = *slit; + + if(k.orientation_3_object()(ref_sp, ref_z, ref_tp, other.source()) == CGAL::NEGATIVE || + k.orientation_3_object()(ref_sp, ref_z, ref_tp, other.target()) == CGAL::NEGATIVE) + { + ref_s = ref_s.opposite(); + ref_z = ref_sp + input_triangle_normal; + swapped = true; + break; + } + } + + if(!swapped) + { + for(PCI plit = points.begin(); plit != points.end(); ++plit) + { + const Point_3& other = *plit; + if(k.orientation_3_object()(ref_sp, ref_z, ref_tp, other) == CGAL::NEGATIVE) + { + swapped = true; + ref_s = ref_s.opposite(); + ref_z = ref_sp + input_triangle_normal; + break; + } + } + } + + // Now, order the other parts of the intersection + std::list > res_elements; // iterators to the points/segments + res_elements.emplace_back(segments.begin()); + + for(SCI slit = std::next(segments.begin()); slit != segments.end(); ++slit) + { + // first, check if the segment is well oriented, meaning its source comes before its target (ccwly) + Segment_3& curr_s = *slit; + const Point_3& sp = curr_s.source(); + const Point_3& tp = curr_s.target(); + + if(sp == ref_sp || tp == ref_tp) // consecutive segments must have consistent orientation + { + curr_s = curr_s.opposite(); + } + else if(sp == ref_tp || tp == ref_sp) + { + // nothing to do here as we know that sp&tp are on the positive side of (normal, ref_s) + } + else if(first_comes_first_pt(ref_sp, ref_z, tp, sp, k)) + { + curr_s = curr_s.opposite(); + } + + // Find where the current segment fit in the final polygon intersection + for(auto rit = std::next(res_elements.begin()); ; ++rit) + { + // always pick the current segment's source to ensure ref_source != ref_other + if(rit == res_elements.end() || first_comes_first(ref_sp, ref_z, sp, *rit, k)) + { + res_elements.insert(rit, slit); + break; + } + } + } + + for(PCI plit = points.begin(); plit != points.end(); ++plit) + { + // first, check if the segment is well oriented, meaning its source comes before its target (ccwly) + const Point_3& curr_p = *plit; + + // Find where the current point fit in the boundary of the polygon intersection + for(auto rit = std::next(res_elements.begin()); ; ++rit) + { + if(rit == res_elements.end() || first_comes_first(ref_sp, ref_z, curr_p, *rit, k)) + { + res_elements.insert(rit, plit); + break; + } + } + } + + CGAL_postcondition(res_elements.size() == points.size() + segments.size()); + + // Concatenate points to create the polygonal output + Poly res; + for(const boost::variant& e : res_elements) + { + if(const SCI* sci = boost::get(&e)) + { + const Segment_3& s = **sci; + + if(res.empty() || s.source() != res.back()) // common extremity for consecutive segments + res.push_back(s.source()); + if(res.empty() || s.target() != res.front()) + res.push_back(s.target()); + } + else if(const PCI* pci = boost::get(&e)) + { + res.push_back(**pci); + } + else + { + CGAL_assertion(false); + } + } + + CGAL_assertion(std::set(res.begin(), res.end()).size() == res.size()); + CGAL_assertion(res.size() >= 3); + + if(res.size() == 3) + { + Triangle_3 tr { res[0], res[1], res[2] }; + return result_type(std::forward(tr)); + } + else + { + return result_type(std::forward(res)); + } +} + template typename Intersection_traits::result_type intersection(const typename K::Tetrahedron_3& tet, @@ -38,42 +289,62 @@ intersection(const typename K::Tetrahedron_3& tet, typedef typename Intersection_traits::result_type result_type; typedef typename Intersection_traits::result_type Inter_type; + CGAL_precondition(!tet.is_degenerate()); + CGAL_precondition(!tr.is_degenerate()); + typedef typename K::Point_3 Point_3; typedef typename K::Segment_3 Segment_3; typedef typename K::Triangle_3 Triangle_3; - typedef std::vector Poly; - std::vector inside_points; - for(int i = 0; i< 3; ++i) - if(tet.has_on_bounded_side(tr.vertex(i)) || tet.has_on_boundary(tr.vertex(i))) - inside_points.push_back(tr.vertex(i)); + typename K::Bounded_side_3 bounded_side = k.bounded_side_3_object(); + typename K::Construct_vertex_3 vertex = k.construct_vertex_3_object(); + typename K::Construct_triangle_3 triangle = k.construct_triangle_3_object(); - switch(inside_points.size()) + std::vector vertex_sides(3); + + std::vector points; + int inside_points = 0; + int strictly_inside_points = 0; + + for(int i=0; i<3; ++i) + { + vertex_sides[i] = bounded_side(tet, vertex(tr, i)); + + if(vertex_sides[i] != ON_UNBOUNDED_SIDE) + ++inside_points; + + if(vertex_sides[i] == ON_BOUNDED_SIDE) + { + ++strictly_inside_points; + points.push_back(vertex(tr, i)); + } + } + + switch(inside_points) { case 0: { Inter_type intersections[4]; - std::vector segments; + std::list segments; std::vector seg_ids; - std::vector points; for(std::size_t i = 0; i < 4; ++i) { - const Triangle_3 triangle = k.construct_triangle_3_object()(tet.vertex((i+1)%4), - tet.vertex((i+2)%4), - tet.vertex((i+3)%4)); - intersections[i] = intersection(tr, triangle, k); + const Triangle_3 face = triangle(vertex(tet, (i+1)%4), + vertex(tet, (i+2)%4), + vertex(tet, (i+3)%4)); + intersections[i] = intersection(tr, face, k); if(intersections[i]) { - //a face is inside the input tr + // a face is inside the input tr if(const Triangle_3* t = boost::get(&*intersections[i])) { Triangle_3 res = *t; return result_type(std::forward(res)); } - //get segs and pts to construct poly else if(const Segment_3* s = boost::get(&*intersections[i])) { + // get segs and pts to construct poly segments.push_back(*s); seg_ids.push_back(i); } @@ -81,9 +352,9 @@ intersection(const typename K::Tetrahedron_3& tet, { points.push_back(*p); } - //if poly : then the input is in a supporting plane of a face, return the poly. else if(const Poly* p = boost::get(&*intersections[i])) { + // the input triangle is in the supporting plane of a tet face, return the poly. Poly res = *p; return result_type(std::forward(res)); } @@ -91,58 +362,46 @@ intersection(const typename K::Tetrahedron_3& tet, } if(segments.size() > 1) - { - std::vector filtered; - filter_segments(segments, filtered); - segments = filtered; - } + filter_segments(segments); - //if there are several segments, then we need to compute the polygone. - if(segments.size() > 1) + // no segments and no inside points, there can still be an intersecting (tet vertex on + // an edge|face of the triangle) + if(segments.empty()) { - std::list tmp; - fill_segments_infos(segments, tmp, tr); - Poly res; - res.reserve(4); - for(const Point_3& p : tmp) - res.push_back(p); - return result_type(std::forward(res)); + if(points.empty()) + return result_type(); + + return result_type(std::forward(points.front())); } - //else it must be adjacent to an vertex, so we return the point else if(segments.size() == 1) { - //adjacency to an edge, return resulting segment. - return result_type(std::forward(segments.front())); + // adjacency to an edge, return resulting segment. + return result_type(segments.front()); } - else + else if(segments.size() > 1) { - CGAL_assertion(!points.empty()); - - //no segment = adjacency to an vertex or an edge : return result point - return result_type(std::forward(points.front())); + return build_intersection(tet, tr, points, segments, k); } } break; case 1: - case 2: + case 2: // 1 or 2 inside points { - //tricky cases Inter_type intersections[4]; - std::vector points; - std::vector segments; + std::list segments; for(std::size_t i = 0; i < 4; ++i) { - const Triangle_3 triangle = k.construct_triangle_3_object()(tet.vertex((i+1)%4), - tet.vertex((i+2)%4), - tet.vertex((i+3)%4)); - intersections[i] = intersection(tr, triangle, k); - if(intersections[i]){ + const Triangle_3 face = triangle(vertex(tet, (i+1)%4), + vertex(tet, (i+2)%4), + vertex(tet, (i+3)%4)); + intersections[i] = intersection(tr, face, k); + if(intersections[i]) + { if(const Triangle_3* t = boost::get(&*intersections[i])) { Triangle_3 res = *t; return result_type(std::forward(res)); } - //get segs and pts to construct poly else if(const Segment_3* s = boost::get(&*intersections[i])) { segments.push_back(*s); @@ -151,110 +410,179 @@ intersection(const typename K::Tetrahedron_3& tet, { points.push_back(*p); } - //if poly : then the input is in a supporting plane of a face, return the poly. else if(const Poly* p = boost::get(&*intersections[i])) { + // the input is in a supporting plane of a face Poly res = *p; return result_type(std::forward(res)); } } } - if(segments.empty()) // only one point of contact - return result_type(std::forward(points.front())); - if(segments.size() > 1) - { - std::vector filtered; - filter_segments(segments, filtered); - segments = filtered; - } + filter_segments(segments); switch(segments.size()) { - case 1: + case 0: { - bool return_solo_seg = true; - //only one intersection, a triangle edge is one of the tet edges, and - //the 3rd point is outside. This is the only intersection. - for(const Point_3& p : inside_points) - { - if(!tet.has_on_boundary(p)) - { - return_solo_seg = false; - break; - } - } + // there can only be one point of contact, otherwise by convexity + // there would be a full segment on a face (interior segment isn't possible either + // because there are at most 2 inside points and an interior segment would also + // yield at least a segment on the boundary) + return result_type(std::forward(points.front())); + } + case 1: // 1 segment + { + const Segment_3& s = segments.front(); - if(return_solo_seg) - return result_type(std::forward(segments.front())); + if(strictly_inside_points == 1) + { + // Doesn't matter whether there is another (non-strictly) inside point: if there is, + // it is an extremity of the segment - if(inside_points.size() == 1) - { - Triangle_3 res = k.construct_triangle_3_object()(inside_points.front(), - segments.front().source(), - segments.front().target()); - return result_type(std::forward(res)); + const std::size_t str_inside_pt_pos = + (std::find(vertex_sides.begin(), vertex_sides.end(), ON_BOUNDED_SIDE) - vertex_sides.begin()); + CGAL_assertion(str_inside_pt_pos >= 0 && str_inside_pt_pos < 3); + + Triangle_3 res_tr = triangle(vertex(tr, str_inside_pt_pos), s.source(), s.target()); + return result_type(std::forward(res_tr)); } - else //size 2 + else if(strictly_inside_points == 2) { + CGAL_assertion(inside_points == 2); // can't be 3 since we're in the 1&2 switch + Poly res(4); - res[0] = inside_points.front(); - res[1] = inside_points.back(); - if((inside_points.front() - inside_points.back()) * - (segments.front().source() - segments.front().target()) > 0) + + // Grab the 2 strictly inside points + int id = 0; + for(int i=0; i<3; ++i) + if(vertex_sides[i] == ON_BOUNDED_SIDE) + res[id++] = vertex(tr, i); + + CGAL_assertion(id == 2); + + if((res[0] - res[1]) * (s.source() - s.target()) > 0) { - res[2] = segments.front().target(); - res[3] = segments.front().source(); + res[2] = s.target(); + res[3] = s.source(); } else { - res[3] = segments.front().target(); - res[2] = segments.front().source(); + res[3] = s.target(); + res[2] = s.source(); } return result_type(std::forward(res)); } + else if(inside_points == 1) // 1 point on the boundary + { + CGAL_assertion(strictly_inside_points == 0); + + // Grab the inside point + const std::size_t boundary_pt_pos = + (std::find(vertex_sides.begin(), vertex_sides.end(), ON_BOUNDARY) - vertex_sides.begin()); + CGAL_assertion(boundary_pt_pos >= 0 && boundary_pt_pos < 3); + + const Point_3& boundary_pt = vertex(tr, boundary_pt_pos); + if(boundary_pt == s.source() || boundary_pt == s.target()) + { + return result_type(s); + } + else + { + Triangle_3 res_tr = triangle(boundary_pt, s.source(), s.target()); + return result_type(std::forward(res_tr)); + } + } + else // 2 points on the boundary + { + CGAL_assertion(inside_points == 2 && strictly_inside_points == 0); + + // 2 boundary points and 1 segment, have to distinguish between cases + // depending on if the extremities of the segment are triangle extremities + + std::array boundary_pts; + std::array is_boundary_point_an_extremity; + + // Grab the inside points + std::size_t id = 0; + for(int i=0; i<3; ++i) + { + if(vertex_sides[i] == ON_BOUNDARY) + { + boundary_pts[id] = i; + + if(vertex(tr, i) == s.source()) + is_boundary_point_an_extremity[id] = true; + else if(vertex(tr, i) == s.target()) + is_boundary_point_an_extremity[id] = true; + else + is_boundary_point_an_extremity[id] = false; + + ++id; + } + } + + CGAL_assertion(id == 2); + + if(is_boundary_point_an_extremity[0]) + { + if(is_boundary_point_an_extremity[1]) + { + // the segment is composed of the two boundary points + return result_type(s); + } + else // only boundary_pts[0] is an extremity + { + Triangle_3 res_tr = triangle(s.source(), s.target(), vertex(tr, boundary_pts[1])); + return result_type(std::forward(res_tr)); + } + } + else // boundary_pts[0] is not an extremity + { + if(is_boundary_point_an_extremity[1]) // only boundary_pts[1] is an extremity + { + Triangle_3 res_tr = triangle(s.source(), s.target(), vertex(tr, boundary_pts[0])); + return result_type(std::forward(res_tr)); + } + else // neither boundary points are extremities + { + Poly res(4); + res[0] = vertex(tr, boundary_pts[0]); + res[1] = vertex(tr, boundary_pts[1]); + + if((res[0] - res[1]) * (s.source() - s.target()) > 0) + { + res[2] = s.target(); + res[3] = s.source(); + } + else + { + res[3] = s.target(); + res[2] = s.source(); + } + + return result_type(std::forward(res)); + } + } + } + + CGAL_assertion(false); } break; + // 2 or 3 segments (and 1 or 2 inside points) case 2: case 3: + case 4: { - std::list segs(segments.begin(), segments.end()); - std::list tmp; - fill_points_list(segs, tmp); - if(inside_points.size() == 1) - { - Poly res; - res.reserve(4); - res.push_back(inside_points.front()); - for(const Point_3& p : tmp) - res.push_back(p); - - return result_type(std::forward(res)); - } - else //size 2 - { - typename K::Compute_scalar_product_3 scalar = k.compute_scalar_product_3_object(); - typename K::Construct_vector_3 construct_vector = k.construct_vector_3_object(); - - Poly res; - res.reserve(5); - if(scalar(construct_vector(inside_points.front(), inside_points.back()), - construct_vector(tmp.front(), tmp.back())) > 0) - { - res.push_back(inside_points.front()); - } - res.push_back(inside_points.back()); - for(const Point_3& p : tmp) - res.push_back(p); - - return result_type(std::forward(res)); - } + // @todo do that for a single segment too? + return build_intersection(tet, tr, points, segments, k); } break; default: - //3 faces max if a point or more are inside tetrahedron + // can't have more than 4 segments (1 per tet face) + CGAL_assertion(false); break; } } @@ -262,14 +590,15 @@ intersection(const typename K::Tetrahedron_3& tet, case 3: { - //triangle entirely inside tetra : return input triangle + // the input triangle is entirely contained within the tetrahedron return result_type(tr); } break; default: - //never happens (only 3 pts in a tr) + CGAL_assertion(false); // never happens (only 3 pts in a tr) break; } + return result_type(); } diff --git a/Intersections_3/include/CGAL/Intersections_3/internal/tetrahedron_intersection_helpers.h b/Intersections_3/include/CGAL/Intersections_3/internal/tetrahedron_intersection_helpers.h deleted file mode 100644 index ddcf2618003..00000000000 --- a/Intersections_3/include/CGAL/Intersections_3/internal/tetrahedron_intersection_helpers.h +++ /dev/null @@ -1,274 +0,0 @@ -// Copyright (c) 2019 GeometryFactory(France). -// All rights reserved. -// -// This file is part of CGAL (www.cgal.org) -// -// $URL$ -// $Id$ -// SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-Commercial -// -// -// Author(s) : Maxime Gimeno -// - -#ifndef CGAL_INTERNAL_TETRAHEDRON_INTERSECTION_HELPERS_H -#define CGAL_INTERNAL_TETRAHEDRON_INTERSECTION_HELPERS_H - -#include - -#include -#include -#include - -namespace CGAL { -namespace Intersections { -namespace internal { - -template -void filter_segments(const std::vector& input, - std::vector& output) -{ - std::list tmp(input.begin(), input.end()); - - do - { - Segment s = tmp.back(); - tmp.pop_back(); - for(auto s_it = tmp.begin(); s_it != tmp.end();) - { - if(s == *s_it || s == s_it->opposite()) - { - s_it = tmp.erase(s_it); - } - else - { - ++s_it; - } - } - output.push_back(s); - } while (!tmp.empty()); -} - -template -void fill_segments_infos(std::vector& segments, - std::list& points, - const Triangle& input_tr) -{ - struct Wrapped_segment - { - Segment segment; - bool s_dangling; - bool t_dangling; - std::size_t s_neighbor; - std::size_t t_neighbor; - - Wrapped_segment(const Segment& s) - : segment(s), s_dangling(true), - t_dangling(true), s_neighbor(0), - t_neighbor(0) - { } - }; - - std::vector wrapped_segments; - for(const Segment& s : segments) - wrapped_segments.emplace_back(s); - - std::vector bis = segments; - while(!bis.empty()) - { - Segment s = bis.back(); - bis.pop_back(); - - Wrapped_segment& w_s = wrapped_segments.back(); - if(!w_s.s_dangling && ! w_s.t_dangling) - continue; - - for(std::size_t i = 0; i< bis.size(); ++i) - { - const Segment& s2 = bis[i]; - if(s2.target() == s.source()) - { - w_s.s_dangling = false; - w_s.s_neighbor = i; - //same i because we empty from the bottom - wrapped_segments[i].t_dangling = false; - wrapped_segments[i].t_neighbor = bis.size(); - } - else if(s2.target() == s.target()) - { - w_s.t_dangling = false; - w_s.t_neighbor = i; - wrapped_segments[i].s_dangling = false; - wrapped_segments[i].s_neighbor = bis.size(); - wrapped_segments[i].segment = wrapped_segments[i].segment.opposite(); //also orient the structure - } - else if(s2.source() == s.source()) - { - w_s.s_dangling = false; - w_s.s_neighbor = i; - wrapped_segments[i].t_dangling = false; - wrapped_segments[i].t_neighbor = bis.size(); - wrapped_segments[i].segment = wrapped_segments[i].segment.opposite(); - } - else if(s2.source() == s.target()) - { - w_s.t_dangling = false; - w_s.t_neighbor = i; - wrapped_segments[i].s_dangling = false; - wrapped_segments[i].s_neighbor = bis.size(); - } - } - - //fill dangling extremities using triangle edges - if(w_s.s_dangling) - { - for(int e_id = 0; e_id < 3; ++e_id) - { - Segment edge(input_tr.vertex(e_id), input_tr.vertex(e_id+1)); - if(!edge.has_on(s.source())) - continue; - - for(std::size_t i = 0; i< bis.size(); ++i) - { - if(edge.has_on(bis[i].source())) - { - w_s.s_dangling = false; - w_s.s_neighbor = i; - //same i because we empty from the bottom - wrapped_segments[i].t_dangling = false; - wrapped_segments[i].t_neighbor = bis.size(); - wrapped_segments[i].segment = wrapped_segments[i].segment.opposite(); - } - else if(edge.has_on(bis[i].target())) - { - w_s.s_dangling = false; - w_s.s_neighbor = i; - //same i because we empty from the bottom - wrapped_segments[i].t_dangling = false; - wrapped_segments[i].t_neighbor = bis.size(); - } - } - } - } - - if(w_s.t_dangling) - { - for(int e_id = 0; e_id < 3; ++e_id) - { - Segment edge(input_tr.vertex(e_id), input_tr.vertex(e_id+1)); - if(!edge.has_on(s.target())) - continue; - - for(std::size_t i = 0; i< bis.size(); ++i) - { - if(edge.has_on(bis[i].source())) - { - w_s.t_dangling = false; - w_s.t_neighbor = i; - //same i because we empty from the bottom - wrapped_segments[i].s_dangling = false; - wrapped_segments[i].s_neighbor = bis.size(); - } - else if(edge.has_on(bis[i].target())) - { - w_s.t_dangling = false; - w_s.t_neighbor = i; - //same i because we empty from the bottom - wrapped_segments[i].s_dangling = false; - wrapped_segments[i].s_neighbor = bis.size(); - wrapped_segments[i].segment = wrapped_segments[i].segment.opposite(); - } - } - } - } - - if(w_s.s_dangling || w_s.t_dangling) - { - std::cerr << "Error. Kernel must have exact constructions to compute this intersection." << std::endl; - return; - } - } - - // finally fill points - std::size_t n = 0; - do - { - Wrapped_segment& ws = wrapped_segments[n]; - points.push_back(ws.segment.source()); - - if(wrapped_segments[ws.t_neighbor].segment.source() != ws.segment.target()) - points.push_back(ws.segment.target()); - - n = ws.t_neighbor; - } - while(n!=0); -} - - -template -void fill_points_list(std::list& segments, std::list& points) -{ - CGAL_assertion(segments.size() > 1); - - Segment seg = segments.front(); - segments.pop_front(); - - points.push_back(seg.source()); - points.push_back(seg.target()); - - //find first seg with a point in common with seg.front = s2. - do - { - auto seg_it = segments.begin(); - bool found = false; - for(;seg_it != segments.end(); ++seg_it) - { - if(seg_it->source() == points.front()) - { - points.push_front(seg_it->target()); - found = true; - } - else if(seg_it->source() == points.back()) - { - points.push_back(seg_it->target()); - found = true; - } - else if(seg_it->target() == points.front()) - { - points.push_front(seg_it->source()); - found = true; - } - else if(seg_it->target() == points.back()) - { - points.push_back(seg_it->source()); - found = true; - } - - if(found) - break; - } - - if(!found) - { - std::cerr<<"Error. Kernel must have exact constructions to compute this intersection."< Date: Mon, 5 Jul 2021 22:02:40 +0200 Subject: [PATCH 16/31] More tests for the intersection Tet_3/Tr_3 --- .../test_intersections_Tetrahedron_3.cpp | 238 +++++++++--------- 1 file changed, 114 insertions(+), 124 deletions(-) diff --git a/Intersections_3/test/Intersections_3/test_intersections_Tetrahedron_3.cpp b/Intersections_3/test/Intersections_3/test_intersections_Tetrahedron_3.cpp index 5d025cc0df4..e3d2cfe4a03 100644 --- a/Intersections_3/test/Intersections_3/test_intersections_Tetrahedron_3.cpp +++ b/Intersections_3/test/Intersections_3/test_intersections_Tetrahedron_3.cpp @@ -41,6 +41,8 @@ struct Tetrahedron_3_intersection_tester typedef CGAL::Vector_3 V; + typedef std::vector

Poly; + using Base::p; using Base::pl; using Base::random_point; @@ -100,15 +102,13 @@ public: if(tet4.is_degenerate()) continue; - std::set os; - os.insert(tet0.oriented_side(tet10)); - os.insert(tet0.oriented_side(tet11)); - os.insert(tet0.oriented_side(tet12)); - os.insert(tet0.oriented_side(tet13)); + std::set os; + os.insert(tet0.bounded_side(tet10)); + os.insert(tet0.bounded_side(tet11)); + os.insert(tet0.bounded_side(tet12)); + os.insert(tet0.bounded_side(tet13)); - if(os.size() == 1 && (*os.begin() == CGAL::ON_POSITIVE_SIDE)) - check_do_not_intersect(tet0, tet4); - else + if(os.size() != 1 || (*os.begin() != CGAL::ON_UNBOUNDED_SIDE)) check_do_intersect(tet0, tet4); } } @@ -117,138 +117,120 @@ public: { Tet tet(p(0,0,0), p(0,1,0), p(1,0,0), p(0,0,1)); -// check_no_intersection(tet, Tr(p(2,0,0), p(2,1,0), p(2,0,1))); + // no intersection + check_no_intersection(tet, Tr(p(2,0,0), p(2,1,0), p(2,0,1))); - // tr inside a face - check_intersection(tet, Tr(P(0,0.9,0), P(0,0.1,0), P(0,0,0.9)), - Tr(P(0,0.9,0), P(0,0.1,0), P(0,0,0.9))); - // face inside tr - check_intersection(tet, Tr(p(0,2,0), p(0,-2,0), p(0,0,2)), - Tr(p(0,0,1), p(0,0,0), p(0,1,0))); + // tr share a vertex, triangle on face + check_intersection(tet, Tr(p(0,1,0), P(0.1,0.1,0), P(0.5,0.1,0)), + Tr(p(0,1,0), P(0.1,0.1,0), P(0.5,0.1,0))); - // only one edge intersecting - check_do_intersect(tet, Tr(P(-2, 0.5, 0.5), P(-2,0.75,1), P(1.5, 0.5, 0.5))); + // tr vertex adjacent to a vertex + check_intersection(tet, Tr(p(0,1,0), p(3,1,0), p(0,3,0)), + p(0,1,0)); - // edge shared, 3rd point outside - check_do_intersect(tet, Tr(p(0,1,0), p(1,0,0), P(0.5,0,-100))); + // tr edge adjacent to a vertex + check_intersection(tet, Tr(p(-1,1,0), p(3,1,0), p(0,3,0)), + p(0,1,0)); - // shared edge, 3rd point inside - check_do_intersect(tet, Tr(p(0,1,0), p(1,0,0), P(0.25,0.25,0.25))); + // tr adjacent to a vertex, outside + check_intersection(tet, Tr(p(-1,1,12), p(0,1,-50), P(0.5,1,-0.5)), + p(0,1,0)); - // tr adjacent to a vertex, outside - check_do_intersect(tet, Tr(p(-1,1,12), p(0,1,-50), P(0.5,1,-0.5))); + // only one edge intersecting + check_intersection(tet, Tr(P(-2, 0.5, 0.5), P(-2,0.75,1), P(1.5, 0.5, 0.5)), + P(0,0.5,0.5)); - // tr share a vertex, inside - check_do_intersect(tet, Tr(p(0,1,0), P(0.1,0.1,0), P(0.5,0.1,0))); + // edge shared, 3rd point outside + check_intersection(tet, Tr(p(0,1,0), p(1,0,0), P(0.5,0,-100)), + S(p(0,1,0), p(1,0,0))); - // tr edge adjacent to a vertex - check_do_intersect(tet, Tr(p(-1,1,0), p(3,1,0), p(0,3,0))); + // shared edge, 3rd point inside + check_intersection(tet, Tr(p(0,1,0), p(1,0,0), P(0.25,0.25,0.25)), + Tr(p(0,1,0), p(1,0,0), P(0.25,0.25,0.25))); - // tr vertex adjacent to a vertex - check_do_intersect(tet, Tr(p(0,1,0), p(3,1,0), p(0,3,0))); + // tr edge containing a tetrahedron edge + check_intersection(tet, Tr(p(0,-1,0), p(0,3,0), p(1,1,-1)), S(p(0,0,0), p(0,1,0))); - // traversing triangles - Tr tr(P(-2, 0.5, 0.25), P(-2, 0.75, 0.6), P(1.5, 0.5, 0.25)); - check_do_intersect(tet, tr); + // tr edge intersecting a tet face + check_intersection(tet, Tr(P(-0.5,0,0.5), P(2,0,0.5), P(0.5,-2,0)), + S(P(0,0,0.5), P(0.5,0,0.5))); - // tr share a vertex, through - tr = Tr(p(0,1,0), P(0.1,0.1,0), P(0.9,0.1,0)); - check_do_intersect(tet, tr); + // tr face containing a tetrahedron edge + check_intersection(Tet(p(0,1,0), p(0,0,1), p(0,1,1), p(1, 0, 1)), + Tr(p(-2,0,-2), P(0,0,5), p(10,0,0)), + S(p(0,0,1), p(1,0,1))); + + // sharing a point on edge + check_intersection(tet, Tr(P(-2, 1, 0.5), P(-2, 0.75, 1.6), P(2, 0, 0.5)), + P(0, 0.5, 0.5)); + + // tr inside a face + check_intersection(tet, Tr(P(0,0.9,0), P(0,0.1,0), P(0,0,0.9)), + Tr(P(0,0.9,0), P(0,0.1,0), P(0,0,0.9))); + + // face inside tr + check_intersection(tet, Tr(p(0,2,0), p(0,-2,0), p(0,0,2)), + Tr(p(0,0,1), p(0,0,0), p(0,1,0))); + + // on the same plane, polygonal intersection + Base::template check_intersection(tet, Tr(p(0,-2,0), p(1,1,0), p(1,2,0))); + + // traversing triangles + Base::template check_intersection(tet, Tr(P(-2, 0.5, 0.25), P(-2, 0.75, 0.6), P(1.5, 0.5, 0.25))); + + // tr share an edge, third point on face + Base::template check_intersection(tet, Tr(p(0,1,0), P(0.1,0.1,0), P(0.9,0.1,0))); + + // sharing a vertex + edge/face intersection + Base::template check_intersection(tet, Tr(p(0,0,0), P(0.5,-1,0), P(0.5,1,0))); + + // vertex on edge & triangle inside, triangle intersection + Base::template check_intersection(tet, Tr(P(0.5,0,0), P(0.5,0.25,0.25), P(0.5,-0.5,0))); + + // vertex on edge & triangle inside, double segment + Base::template check_intersection(tet, Tr(P(0,0,0.5), P(-1,1.5,0.25), P(1.5,-1,0.25))); + + // vertex on edge & triangle inside, double segment non-incident + Base::template check_intersection(tet, Tr(P(0.25,0,0.25), P(-1,0.5,0.25), P(1.5,0.5,0.25))); + + // vertex on face, triangle outside & segment intersection + Base::check_intersection(tet, Tr(P(0.5,0,-0.25), P(0.5,0,0.25), P(0.5,-0.5,0)), + S(P(0.5, 0, 0.25), P(0.5, 0, 0))); + + // vertex on face & inside, triangle intersection + Base::template check_intersection(tet, Tr(P(0.5,0,0), P(0.5,0.25,0.25), P(0.5,-0.5,0))); + + // vertex on face, triangle intersection + Base::template check_intersection(tet, Tr(P(0, 0.25, 0.25), P(0.5, -0.25, 0.25), P(0.5, -0.25, 0.5))); + + // vertex inside, segment-triangle intersection + Base::template check_intersection(tet, Tr(P(0.2, 0.15, 0.3), P(-2, 0.6, 0.15), P(-2, 0.12, 0.15))); + + // vertex inside, double segment intersection + Base::template check_intersection(tet, Tr(P(0.2, 0.15, 0.3), P(-1, 0.15, -2), P(-1, 0.15, 2))); + + // two vertices inside + Base::template check_intersection(tet, Tr(P(0.1, 0.5, 0.1), P(0.3,0.1,0.1), P(4,0.3,0.9))); if(this->has_exact_c) { Tr tr(p(-2,2,0), p(2,2,0), P(0.25,0.25,0)); auto res = CGAL::intersection(tet, tr); - const std::vector

* poly = boost::get >(&*res); + const Poly* poly = boost::get(&*res); assert(poly != nullptr); assert(poly->size() == 4); - for(const P& pt : *poly) - { + for(const P& pt : *poly) { assert(tet.has_on_boundary(pt) && tr.has_on(pt)); } - // only one edge intersecting - check_intersection (tet, Tr(P(-2, 0.5, 0.5), P(-2,0.75,1), P(1.5, 0.5, 0.5)), - P(0,0.5,0.5)); - - // edge shared, 3rd point outside - check_intersection (tet, Tr(p(0,1,0), p(1,0,0), P(0.5,0,-100)), - S(p(0,1,0), p(1,0,0))); - - // shared edge, 3rd point inside - check_intersection (tet, Tr(p(0,1,0), p(1,0,0), P(0.25,0.25,0.25)), - Tr(p(0,1,0), p(1,0,0), P(0.25,0.25,0.25))); - - // tr adjacent to a vertex, outside - check_intersection (tet, Tr(p(-1,1,12), p(0,1,-50), P(0.5,1,-0.5)), - p(0,1,0)); - - // tr adjacent to an edge, outside - check_intersection (tet, Tr(P(-0.6, 1, 0.6), P(0.5, 1.20, -0.5), P(0, -0.5, 0)), - S(p(0,0,0), p(0,1,0))); - - // tr share a vertex, inside - check_intersection (tet, Tr(p(0,1,0), P(0.1,0.1,0), P(0.5,0.1,0)), - Tr(p(0,1,0), P(0.1,0.1,0), P(0.5,0.1,0))); - - // tr edge adjacent to a vertex - check_intersection (tet, Tr(p(-1,1,0), p(3,1,0), p(0,3,0)), - p(0,1,0)); - - // tr vertex adjacent to a vertex - check_intersection (tet, Tr(p(0,1,0), p(3,1,0), p(0,3,0)), - p(0,1,0)); - - // traversing triangles - tr = Tr(P(-2, 0.5, 0.25), P(-2, 0.75, 0.6), P(1.5, 0.5, 0.25)); - res = CGAL::intersection(tet, tr); - std::vector

* inter = boost::get >(&*res); - assert(inter != nullptr); - assert(inter->size() == 4); - for(const P& pt : *inter) { - assert(tet.has_on_boundary(pt) && tr.has_on(pt)); - } - - tr = Tr(P(-2, 0.25, 0), P(-2, 0.75, 0), P(1.5, 0.5, 0)); - res = CGAL::intersection(tet, tr); - inter = boost::get >(&*res); - assert(inter != nullptr); - assert(inter->size() == 4); - for(const P& pt : *inter) { - assert(tet.has_on_boundary(pt) && tr.has_on(pt)); - } - - tr = Tr(P(0.2, 0.15, 0.3), P(-2, 0.6, 0.15), P(-2, 0.12, 0.15)); - res = CGAL::intersection(tet, tr); - Tr* res_tr = boost::get(&*res); - assert(res_tr != nullptr); - - tr = Tr(P(0.2, 0.15, 0.3), P(-1, 0.15, -2), P(-1, 0.15, 2)); - res = CGAL::intersection(tet, tr); - inter = boost::get >(&*res); - assert(inter != nullptr); - assert(inter->size() == 4); - tr = Tr(P(0.45, 0.20, 0.1), P(0.1, 0.20, 0.5), P(-0.5, 0.25, -0.5)); res = CGAL::intersection(tet, tr); - inter = boost::get >(&*res); + const Poly* inter = boost::get(&*res); assert(inter != nullptr); - assert(inter->size() == 4); + assert(inter->size() == 5); for(const P& pt : *inter) { assert((tet.has_on_bounded_side(pt) || tet.has_on_boundary(pt)) && tr.has_on(pt)); } - - // tr share a vertex, through - tr = Tr(p(0,1,0), P(0.1,0.1,0), P(0.9,0.1,0)); - res = CGAL::intersection(tet, tr); - res_tr = boost::get(&*res); - assert(res_tr != nullptr); - - tr = Tr(P(0.1, 0.5, 0.1), P(0.3,0.1,0.1), P(4,0.3,0.9)); - res = CGAL::intersection(tet, tr); - inter = boost::get >(&*res); - assert(inter != nullptr); - assert(inter->size() == 4); } for(int i=0; i os; - os.insert(tet.oriented_side(tr0)); - os.insert(tet.oriented_side(tr1)); - os.insert(tet.oriented_side(tr2)); + std::set os; + os.insert(tet.bounded_side(tr0)); + os.insert(tet.bounded_side(tr1)); + os.insert(tet.bounded_side(tr2)); - std::cout << "Tet: " << tet << std::endl; - std::cout << "Tr: " << tr << std::endl; - - if(os.size() == 1 && (*os.begin() == CGAL::ON_POSITIVE_SIDE)) - check_do_not_intersect(tet, tr); - else + if(os.size() != 1 || (*os.begin() != CGAL::ON_UNBOUNDED_SIDE)) + { check_do_intersect(tet, tr); + + auto res = CGAL::intersection(tet, tr); + if(const Poly* poly = boost::get(&*res)) + { + for(const P& pt : *poly) { + assert((tet.has_on_bounded_side(pt) || tet.has_on_boundary(pt)) && tr.has_on(pt)); + } + +// assert(CGAL::is_simple_2(poly->begin(), poly->end(), +// CGAL::Projection_traits_3(tr.supporting_plane().orthogonal_vector()))); + } + } } } From 98b7235aea5ecd6f3a594364e8a274aace14a114 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mael=20Rouxel-Labb=C3=A9?= Date: Thu, 29 Jul 2021 13:43:40 +0200 Subject: [PATCH 17/31] Add missing helper file --- .../intersection_test_helper.h | 445 ++++++++++++++++++ 1 file changed, 445 insertions(+) create mode 100644 Intersections_3/test/Intersections_3/intersection_test_helper.h diff --git a/Intersections_3/test/Intersections_3/intersection_test_helper.h b/Intersections_3/test/Intersections_3/intersection_test_helper.h new file mode 100644 index 00000000000..857a82313e2 --- /dev/null +++ b/Intersections_3/test/Intersections_3/intersection_test_helper.h @@ -0,0 +1,445 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include "create_bbox_mesh.h" + +#include +#include +#include + +const double epsilon = 0.001; + +struct randomint +{ + randomint() ; + int get() const { return sequence[cur]; } + int next() { cur = (cur+1)%11; return get();} + +private: + int sequence[11]; + int cur; +}; + +inline randomint::randomint() +{ + cur = 0; + sequence[0] = 19; + sequence[1] = 5; + sequence[2] = 17; + sequence[3] = 13; + sequence[4] = 29; + sequence[5] = 2; + sequence[6] = 23; + sequence[7] = 31; + sequence[8] = 3; + sequence[9] = 37; + sequence[10] = 11; +} + +randomint ri; + +inline double to_nt(int d) +{ + return double(d); +} + +template +struct Intersection_3_tester +{ + typedef CGAL::Bbox_3 Bbox; + + typedef CGAL::Iso_cuboid_3 Cub; + typedef CGAL::Line_3 L; + typedef CGAL::Point_3 P; + typedef CGAL::Plane_3 Pl; + typedef CGAL::Ray_3 R; + typedef CGAL::Segment_3 S; + typedef CGAL::Sphere_3 Sph; + typedef CGAL::Tetrahedron_3 Tet; + typedef CGAL::Triangle_3 Tr; + + typedef std::vector

Pol; + +protected: + CGAL::Random& r; + + bool has_exact_p; + bool has_exact_c; + + double m = 0, M = 100; + + bool verbose = true; + +public: + Intersection_3_tester(CGAL::Random& r, + const bool has_exact_p = false, + const bool has_exact_c = false) + : r(r), has_exact_p(has_exact_p), has_exact_c(has_exact_c) + { } + +public: + Pl pl(int a, int b, int c, int d) + { + int w = ri.next(); + return Pl(to_nt(a*w), to_nt(b*w), to_nt(c*w), to_nt(d*w)); + } + + P p(int x, int y, int z) + { + int w = ri.next(); + return P(to_nt(x*w), to_nt(y*w), to_nt(z*w), to_nt(w)); + } + + P random_point() + { + return p(r.get_int(m, M), r.get_int(m, M), r.get_int(m, M)); + } + +public: + template + bool approx_equal_nt(const Type &t1, const Type &t2) + { + if(t1 == t2) + return true; + + if(has_exact_c) + { + std::cerr << " Comparison failed between : " << t1 << " and " << t2 << "\n"; + return false; + } + + if(CGAL::abs(t1 - t2) / (CGAL::max)(CGAL::abs(t1), CGAL::abs(t2)) < epsilon) + return true; + + std::cerr << " Approximate comparison failed between : " << t1 << " and " << t2 << "\n"; + + return false; + } + + // we need approx equal to check approx kernels, but maybe we should only test with exact kernels + // (approx kernels were useful before, when the text output was checked by diff ?) + // idea : test containment with intervals ? or use some "epsilon double"? + // I need to convert the text output to exact rationals in the source... + // Well, for now the current scheme works. + template + bool approx_equal(const Type& t1, const Type& t2) + { + if(t1 != t2) + { + if(verbose) + std::cerr << "Failed comparison of " << typeid(Type).name() << ": " << t1 << " is NOT " << t2 << std::endl; + + return false; + } + + return true; + } + +// bool approx_equal(const P& p, const P& q) +// { +// return approx_equal_nt(p.x(), q.x()) && +// approx_equal_nt(p.y(), q.y()) && +// approx_equal_nt(p.z(), q.z()); +// } + + bool approx_equal(const S& p, const S& q) + { + std::cout << "compare segments " << p << " & " << q << std::endl; + + // allow opposite orientation + return (approx_equal(p.source(), q.source()) && approx_equal(p.target(), q.target())) || + (approx_equal(p.source(), q.target()) && approx_equal(p.target(), q.source())); + } + + bool approx_equal(const Pol& p, const Pol& q) + { + if(p.size() != q.size()) + return false; + + for(typename Pol::const_iterator itp = p.begin(), itq = q.begin(); itp != p.end(); ++itp, ++itq) + if(!approx_equal(*itp, *itq)) + return false; + + return true; + } + +public: + template + void check_do_intersect(const O1& o1, const O2& o2) + { + if(verbose) + { + std::cout << "\nExpecting intersection between " << typeid(O1).name() << " = " << o1 + << "\nand " << typeid(O2).name() << " = " << o2 << std::endl; + } + + const bool res12 = CGAL::do_intersect(o1, o2); + const bool res21 = CGAL::do_intersect(o2, o1); + + if(has_exact_p) + { + assert(res12); + assert(res21); + } + else + { + CGAL_warning(res12); + CGAL_warning(res21); + } + } + + template + void check_intersection(const O1& o1, const O2& o2) + { + check_do_intersect(o1, o2); + + std::cout << "1 --------------" << std::endl; + const auto res12 = CGAL::intersection(o1, o2); + std::cout << "2 --------------" << std::endl; + const auto res21 = CGAL::intersection(o2, o1); + + Res tmp; + if(has_exact_p) + { + assert(CGAL::assign(tmp, res12)); + assert(CGAL::assign(tmp, res21)); + } + else + { + CGAL_warning(CGAL::assign(tmp, res12)); + CGAL_warning(CGAL::assign(tmp, res21)); + } + } + + template + void check_intersection(const O1& o1, const O2& o2, + const Res& result, + bool do_opposite = true) + { + if(verbose) + { + std::cout << "\nCheck intersection between " << typeid(O1).name() << " = " << o1 + << "\nand " << typeid(O2).name() << " = " << o2 << std::endl; + std::cout << "Expecting result " << typeid(Res).name() << " = " << result << std::endl; + } + + const bool res12 = CGAL::do_intersect(o1, o2); + if(has_exact_p) + assert(res12); + else + CGAL_warning(res12); + + const auto ires12 = CGAL::intersection(o1, o2); + + Res tmp; + if(has_exact_p) + { + assert(CGAL::assign(tmp, ires12)); + assert(approx_equal(tmp, result)); + } + else + { + if(CGAL::assign(tmp, ires12)) + assert(approx_equal(tmp, result)); + else + CGAL_warning_msg(false, "Expected an intersection, but it was not found!"); + } + + if(do_opposite) + check_intersection(o2, o1, result, false); + } + + template + void check_intersection(const O1& o1, const O2& o2, + const O3& o3, const O4& o4) + { + if(verbose) + { + std::cout << "\nCheck intersection between " << typeid(O1).name() << " = " << o1 + << "\nand " << typeid(O2).name() << " = " << o2 << std::endl; + std::cout << "Expecting result to be the same as intersection between " << typeid(O3).name() << " = " << o3 + << "\nand " << typeid(O4).name() << " = " << o4 << std::endl; + } + + const bool res12 = CGAL::do_intersect(o1, o2); + const bool res34 = CGAL::do_intersect(o3, o4); + + if(has_exact_p) + assert(res12 == res34); + else + CGAL_warning(res12 == res34); + + if(res12 && res34) + { + const auto ires12 = CGAL::intersection(o1, o2); + const auto ires34 = CGAL::intersection(o3, o4); + + Res tmp12, tmp34; + if(has_exact_c) + { + assert(CGAL::assign(tmp12, ires12)); + assert(CGAL::assign(tmp34, ires34)); + assert(tmp12 == tmp34); + } + else + { + if(CGAL::assign(tmp12, ires12) && CGAL::assign(tmp34, ires34)) + { + CGAL_warning(tmp12 == tmp34); + } + } + } + } + + template + struct Variant_visitor + { + Variant_visitor(const OV& other_variant) + : ov(other_variant), equal(false) + { + assert(ov); + } + + template + bool compare_to_other_variant(const T& t) const + { + if(ov->type() == typeid(T)) + { + auto* r = boost::get(&*ov); // ov is an optional + assert(r); + return (t == *r); + } + + return false; + } + + template + void operator()(const T& value) const + { + if(equal) + return; + + if(compare_to_other_variant(value)) + equal = true; + } + + const OV& ov; + mutable bool equal; + }; + + template + void check_intersection(const O1& o1, const O2& o2, + const O3& o3, const O4& o4) + { + if(verbose) + { + std::cout << "\nCheck intersection between " << typeid(O1).name() << " = " << o1 + << "\nand " << typeid(O2).name() << " = " << o2 << std::endl; + std::cout << "Expecting result to be the same as intersection between " << typeid(O3).name() << " = " << o3 + << "\nand " << typeid(O4).name() << " = " << o4 << std::endl; + } + + const bool res12 = CGAL::do_intersect(o1, o2); + const bool res34 = CGAL::do_intersect(o3, o4); + + if(has_exact_p) + assert(res12 == res34); + else + CGAL_warning(res12 == res34); + + if(res12 && res34) + { + const auto ires12 = CGAL::intersection(o1, o2); + const auto ires34 = CGAL::intersection(o3, o4); + + if(has_exact_c) + { + assert(ires12 && ires34); + + Variant_visitor vis(ires12); + boost::apply_visitor(vis, *ires34); + assert(vis.equal); + } + } + } + +public: + template + void check_do_not_intersect(const O1& o1, const O2& o2) + { + const bool res12 = CGAL::do_intersect(o1, o2); + const bool res21 = CGAL::do_intersect(o2, o1); + + if(has_exact_p) + { + assert(!res12); + assert(!res21); + } + else + { + CGAL_warning(!res12); + CGAL_warning(!res21); + } + } + + template + void check_do_not_intersect(const O1& o1, const O2& o2, const O3& o3) + { + auto res123 = CGAL::do_intersect(o1, o2, o3); + auto res132 = CGAL::do_intersect(o1, o3, o2); + auto res213 = CGAL::do_intersect(o2, o1, o3); + auto res231 = CGAL::do_intersect(o2, o3, o1); + auto res312 = CGAL::do_intersect(o3, o1, o2); + auto res321 = CGAL::do_intersect(o3, o2, o1); + if(has_exact_p) + assert(!res123 && !res132 && !res213 && !res231 && !res312 && !res321); + else + CGAL_warning(!res123 && !res132 && !res213 && !res231 && !res312 && !res321); + } + + template + void check_no_intersection(const O1& o1, const O2& o2) + { + check_do_not_intersect(o1, o2); + + auto res12 = CGAL::intersection(o1, o2); + auto res21 = CGAL::intersection(o2, o1); + if(has_exact_p) + { + assert(!res12); + assert(!res21); + } + else + { + CGAL_warning(!res12); + CGAL_warning(!res21); + } + } + + template + void check_no_intersection(const O1& o1, const O2& o2, const O3& o3) + { + check_do_not_intersect(o1, o2, o3); + + auto res123 = CGAL::intersection(o1, o2, o3); + auto res132 = CGAL::intersection(o1, o3, o2); + auto res213 = CGAL::intersection(o2, o1, o3); + auto res231 = CGAL::intersection(o2, o3, o1); + auto res312 = CGAL::intersection(o3, o1, o2); + auto res321 = CGAL::intersection(o3, o2, o1); + if(has_exact_p) + assert(!res123 && !res132 && !res213 && !res231 && !res312 && !res321); + else + CGAL_warning(!res123 && !res132 && !res213 && !res231 && !res312 && !res321); + } +}; From 9c6456f94915dea0fea37814c20f0910e1e065ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mael=20Rouxel-Labb=C3=A9?= Date: Thu, 29 Jul 2021 14:23:40 +0200 Subject: [PATCH 18/31] Fix some precision issues for Bbox_3 / kernel object do_intersect tests The previous code relied on the kernel's FT having at least as much precision as double, which isn't always the case. Plenty of code still do this in Intersections_23... --- .../Bbox_3_Iso_cuboid_3_do_intersect.h | 9 ++- .../internal/Bbox_3_Line_3_do_intersect.h | 81 ++++++++++--------- .../internal/Bbox_3_Sphere_3_do_intersect.h | 22 ++--- .../Iso_cuboid_3_Sphere_3_do_intersect.h | 76 ++++++++--------- 4 files changed, 95 insertions(+), 93 deletions(-) diff --git a/Intersections_3/include/CGAL/Intersections_3/internal/Bbox_3_Iso_cuboid_3_do_intersect.h b/Intersections_3/include/CGAL/Intersections_3/internal/Bbox_3_Iso_cuboid_3_do_intersect.h index 853e253fecf..1a2ae1310e5 100644 --- a/Intersections_3/include/CGAL/Intersections_3/internal/Bbox_3_Iso_cuboid_3_do_intersect.h +++ b/Intersections_3/include/CGAL/Intersections_3/internal/Bbox_3_Iso_cuboid_3_do_intersect.h @@ -15,6 +15,8 @@ #define CGAL_INTERNAL_INTERSECTIONS_3_BBOX_3_ISO_CUBOID_3_DO_INTERSECT_H #include +#include +#include namespace CGAL { namespace Intersections { @@ -25,11 +27,12 @@ bool do_intersect(const CGAL::Bbox_3& bb, const typename K::Iso_cuboid_3& ic, const K& /* k */) { - if (bb.xmax() < ic.xmin() || ic.xmax() < bb.xmin()) + // use CGAL::compare to access the Coercion_traits between K::FT and double + if(compare(bb.xmax(), ic.xmin()) == SMALLER || compare(ic.xmax(), bb.xmin()) == SMALLER) return false; - if (bb.ymax() < ic.ymin() || ic.ymax() < bb.ymin()) + if(compare(bb.ymax(), ic.ymin()) == SMALLER || compare(ic.ymax(), bb.ymin()) == SMALLER) return false; - if (bb.zmax() < ic.zmin() || ic.zmax() < bb.zmin()) + if(compare(bb.zmax(), ic.zmin()) == SMALLER || compare(ic.zmax(), bb.zmin()) == SMALLER) return false; return true; } diff --git a/Intersections_3/include/CGAL/Intersections_3/internal/Bbox_3_Line_3_do_intersect.h b/Intersections_3/include/CGAL/Intersections_3/internal/Bbox_3_Line_3_do_intersect.h index ce5e156530d..1caea8e0919 100644 --- a/Intersections_3/include/CGAL/Intersections_3/internal/Bbox_3_Line_3_do_intersect.h +++ b/Intersections_3/include/CGAL/Intersections_3/internal/Bbox_3_Line_3_do_intersect.h @@ -17,41 +17,49 @@ // inspired from http://cag.csail.mit.edu/~amy/papers/box-jgt.pdf #include +#include +#include +#include namespace CGAL { namespace Intersections { namespace internal { -template +template inline bool -bbox_line_do_intersect_aux(const FT& px, const FT& py, const FT& pz, - const FT& vx, const FT& vy, const FT& vz, - const BFT& bxmin, const BFT& bymin, const BFT& bzmin, - const BFT& bxmax, const BFT& bymax, const BFT& bzmax) +bbox_line_do_intersect_aux(const LFT px, const LFT py, const LFT pz, + const LFT vx, const LFT vy, const LFT vz, + const BFT bxmin, const BFT bymin, const BFT bzmin, + const BFT bxmax, const BFT bymax, const BFT bzmax) { - if((px >= bxmin) && (px <= bxmax) && - (py >= bymin) && (py <= bymax) && - (pz >= bzmin) && (pz <= bzmax)) + // use CGAL::compare to access the Coercion_traits between LFT and BFT + + if(compare(px, bxmin) != SMALLER && compare(px, bxmax) != LARGER && // (px >= bxmin) && (px <= bxmax) + compare(py, bymin) != SMALLER && compare(py, bymax) != LARGER && // (py >= bymin) && (py <= bymax) + compare(pz, bzmin) != SMALLER && compare(pz, bzmax) != LARGER) // (pz >= bzmin) && (pz <= bzmax) { return true; } + typedef typename Coercion_traits::Type FT; + typename Coercion_traits::Cast to_FT; + // ----------------------------------- // treat x coord // ----------------------------------- FT dmin, tmin, tmax; - if(vx >= 0) + if(is_negative(vx)) { - tmin = bxmin - px; - tmax = bxmax - px; - dmin = vx; + tmin = to_FT(px) - to_FT(bxmax); + tmax = to_FT(px) - to_FT(bxmin); + dmin = - to_FT(vx); } - else + else // vx >= LFT(0) { - tmin = px - bxmax; - tmax = px - bxmin; - dmin = -vx; + tmin = to_FT(bxmin) - to_FT(px); + tmax = to_FT(bxmax) - to_FT(px); + dmin = to_FT(vx); } //if px is not in the x-slab @@ -64,23 +72,23 @@ bbox_line_do_intersect_aux(const FT& px, const FT& py, const FT& pz, // treat y coord // ----------------------------------- FT d_, tmin_, tmax_; - if(vy >= 0) + if(is_negative(vy)) { - tmin_ = bymin - py; - tmax_ = bymax - py; - d_ = vy; + tmin_ = to_FT(py) - to_FT(bymax); + tmax_ = to_FT(py) - to_FT(bymin); + d_ = - to_FT(vy); } - else + else // vy >= LFT(0) { - tmin_ = py - bymax; - tmax_ = py - bymin; - d_ = -vy; + tmin_ = to_FT(bymin) - to_FT(py); + tmax_ = to_FT(bymax) - to_FT(py); + d_ = to_FT(vy); } - if(d_ == FT(0)) + if(is_zero(d_)) { //if py is not in the y-slab - if((tmin_ > FT(0) || tmax_ < FT(0))) + if((is_positive(tmin_) || is_negative(tmax_))) return false; } else @@ -104,17 +112,17 @@ bbox_line_do_intersect_aux(const FT& px, const FT& py, const FT& pz, // ----------------------------------- // treat z coord // ----------------------------------- - if(vz >= 0) + if(is_negative(vz)) { - tmin_ = bzmin - pz; - tmax_ = bzmax - pz; - d_ = vz; + tmin_ = to_FT(pz) - to_FT(bzmax); + tmax_ = to_FT(pz) - to_FT(bzmin); + d_ = - to_FT(vz); } - else + else // vz >= LFT(0) { - tmin_ = pz - bzmax; - tmax_ = pz - bzmin; - d_ = -vz; + tmin_ = to_FT(bzmin) - to_FT(pz); + tmax_ = to_FT(bzmax) - to_FT(pz); + d_ = to_FT(vz); } // if pz is not in the z-slab @@ -131,7 +139,6 @@ bool do_intersect(const typename K::Line_3& line, const CGAL::Bbox_3& bbox, const K&) { - typedef typename K::FT FT; typedef typename K::Point_3 Point_3; typedef typename K::Vector_3 Vector_3; @@ -140,8 +147,8 @@ bool do_intersect(const typename K::Line_3& line, return bbox_line_do_intersect_aux(point.x(), point.y(), point.z(), v.x(), v.y(), v.z(), - FT(bbox.xmin()), FT(bbox.ymin()), FT(bbox.zmin()), - FT(bbox.xmax()), FT(bbox.ymax()), FT(bbox.zmax())); + bbox.xmin(), bbox.ymin(), bbox.zmin(), + bbox.xmax(), bbox.ymax(), bbox.zmax()); } template diff --git a/Intersections_3/include/CGAL/Intersections_3/internal/Bbox_3_Sphere_3_do_intersect.h b/Intersections_3/include/CGAL/Intersections_3/internal/Bbox_3_Sphere_3_do_intersect.h index c4f9b9cb783..f37ede7b5fa 100644 --- a/Intersections_3/include/CGAL/Intersections_3/internal/Bbox_3_Sphere_3_do_intersect.h +++ b/Intersections_3/include/CGAL/Intersections_3/internal/Bbox_3_Sphere_3_do_intersect.h @@ -22,21 +22,23 @@ namespace CGAL { namespace Intersections { namespace internal { -template -bool do_intersect(const CGAL::Bbox_3& bbox, - const typename K::Sphere_3& sphere, - const K& k) -{ - return do_intersect_sphere_box_3(sphere, bbox, k); -} - - template bool do_intersect(const typename K::Sphere_3& sphere, const CGAL::Bbox_3& bbox, const K& k) { - return do_intersect_sphere_box_3(sphere, bbox, k); + return do_intersect_sphere_box_3(sphere, + bbox.xmin(), bbox.ymin(), bbox.zmin(), + bbox.xmax(), bbox.ymax(), bbox.zmax(), + k); +} + +template +bool do_intersect(const CGAL::Bbox_3& bbox, + const typename K::Sphere_3& sphere, + const K& k) +{ + return do_intersect(sphere, bbox, k); } } // namespace internal diff --git a/Intersections_3/include/CGAL/Intersections_3/internal/Iso_cuboid_3_Sphere_3_do_intersect.h b/Intersections_3/include/CGAL/Intersections_3/internal/Iso_cuboid_3_Sphere_3_do_intersect.h index fc64cbde6d5..dbf67d10b8c 100644 --- a/Intersections_3/include/CGAL/Intersections_3/internal/Iso_cuboid_3_Sphere_3_do_intersect.h +++ b/Intersections_3/include/CGAL/Intersections_3/internal/Iso_cuboid_3_Sphere_3_do_intersect.h @@ -13,6 +13,7 @@ #ifndef CGAL_INTERNAL_INTERSECTIONS_3_ISO_CUBOID_3_SPHERE_3_DO_INTERSECT_H #define CGAL_INTERNAL_INTERSECTIONS_3_ISO_CUBOID_3_SPHERE_3_DO_INTERSECT_H +#include #include #include @@ -20,32 +21,36 @@ namespace CGAL { namespace Intersections { namespace internal { -template // Iso_cuboid_3 or Bbox_3 +template // Iso_cuboid_3 or Bbox_3 bool do_intersect_sphere_box_3(const typename K::Sphere_3& sphere, - const Box3& bbox, + const BFT bxmin, const BFT bymin, const BFT bzmin, + const BFT bxmax, const BFT bymax, const BFT bzmax, const K&) { - typedef typename K::FT FT; + typedef typename K::FT SFT; + typedef typename Coercion_traits::Type FT; typedef typename K::Point_3 Point; + typename Coercion_traits::Cast to_FT; + FT d = FT(0); FT distance = FT(0); FT sr = sphere.squared_radius(); const Point& center = sphere.center(); - if(center.x() < FT{bbox.xmin()}) + if(compare(center.x(), bxmin) == SMALLER) { - d = FT{bbox.xmin()} - center.x(); + d = to_FT(bxmin) - to_FT(center.x()); d = square(d); if(certainly(d > sr)) return false; distance = d; } - else if(center.x() > FT{bbox.xmax()}) + else if(compare(center.x(), bxmax) == LARGER) { - d = center.x() - FT{bbox.xmax()}; + d = to_FT(center.x()) - to_FT(bxmax); d = square(d); if(certainly(d > sr)) return false; @@ -53,18 +58,18 @@ bool do_intersect_sphere_box_3(const typename K::Sphere_3& sphere, distance = d; } - if(center.y() < FT{bbox.ymin()}) + if(compare(center.y(), bymin) == SMALLER) { - d = FT{bbox.ymin()} - center.y(); + d = to_FT(bymin) - to_FT(center.y()); d = square(d); if(certainly(d > sr)) return false; distance += d; } - else if(center.y() > FT{bbox.ymax()}) + else if(compare(center.y(), bymax) == LARGER) { - d = center.y() - FT{bbox.ymax()}; + d = to_FT(center.y()) - to_FT(bymax); d = square(d); if(certainly(d > sr)) return false; @@ -72,46 +77,20 @@ bool do_intersect_sphere_box_3(const typename K::Sphere_3& sphere, distance += d; } - if(center.z() < FT{bbox.zmin()}) + if(compare(center.z(), bzmin) == SMALLER) { - d = FT{bbox.zmin()} - center.z(); + d = to_FT(bzmin) - to_FT(center.z()); d = square(d); distance += d; } - else if(center.z() > FT{bbox.zmax()}) + else if(compare(center.z(), bzmax) == LARGER) { - d = center.z() - FT{bbox.zmax()}; + d = to_FT(center.z()) - to_FT(bzmax); d = square(d); distance += d; } -// For unknown reasons this causes a syntax error on VC2005 -// but compiles fine on Linux and MAC -// -// int i; -// for(i = 0; i < 3; ++i) -// { -// if(center[i] < (FT)bbox.min(i)) -// { -// d = (FT)bbox.min(i) - center[i]; -// distance += d * d; -// } -// else if(center[i] > (FT)bbox.max(i)) -// { -// d = center[i] - (FT)bbox.max(i); -// distance += d * d; -// } -// } - - return distance <= sr; -} - -template -bool do_intersect(const typename K::Iso_cuboid_3& ic, - const typename K::Sphere_3& sphere, - const K& k) -{ - return do_intersect_sphere_box_3(sphere, ic, k); + return (distance <= sr); } template @@ -119,7 +98,18 @@ bool do_intersect(const typename K::Sphere_3& sphere, const typename K::Iso_cuboid_3& ic, const K& k) { - return do_intersect_sphere_box_3(sphere, ic, k); + return do_intersect_sphere_box_3(sphere, + (ic.min)().x(), (ic.min)().y(), (ic.min)().z(), + (ic.max)().x(), (ic.max)().y(), (ic.max)().z(), + k); +} + +template +bool do_intersect(const typename K::Iso_cuboid_3& ic, + const typename K::Sphere_3& sphere, + const K& k) +{ + return do_intersect(sphere, ic, k); } } // namespace internal From bdba6eedfea437a98384957f3dcf984e75d52ba3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mael=20Rouxel-Labb=C3=A9?= Date: Thu, 29 Jul 2021 14:24:54 +0200 Subject: [PATCH 19/31] Fix accidentally calling API-only tests --- Intersections_3/test/Intersections_3/call_test.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Intersections_3/test/Intersections_3/call_test.cpp b/Intersections_3/test/Intersections_3/call_test.cpp index c9a89275445..1ae3209d481 100644 --- a/Intersections_3/test/Intersections_3/call_test.cpp +++ b/Intersections_3/test/Intersections_3/call_test.cpp @@ -63,8 +63,8 @@ void test(const int argc) typedef CGAL::Bbox_3 Bbox_3; - //we only want to check compilation - if(argc > 0) + // only check compilation + if(argc > 1) { // --------------------------------------------------------------------------------------------- // INTERSECTION From 5662b4cd41da670a1c9fd4d5b2bae7dd2f348fb2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mael=20Rouxel-Labb=C3=A9?= Date: Tue, 3 Aug 2021 14:34:05 +0200 Subject: [PATCH 20/31] Fix assuming some member functions actually return const& --- .../Tetrahedron_3_Triangle_3_intersection.h | 34 +++++++++---------- 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/Intersections_3/include/CGAL/Intersections_3/internal/Tetrahedron_3_Triangle_3_intersection.h b/Intersections_3/include/CGAL/Intersections_3/internal/Tetrahedron_3_Triangle_3_intersection.h index 4ede09428a6..4eb861c618c 100644 --- a/Intersections_3/include/CGAL/Intersections_3/internal/Tetrahedron_3_Triangle_3_intersection.h +++ b/Intersections_3/include/CGAL/Intersections_3/internal/Tetrahedron_3_Triangle_3_intersection.h @@ -134,8 +134,8 @@ build_intersection(const typename K::Tetrahedron_3& input_tetrahedron, // // Given an arbitrary segment, the code below sorts the other segments and the points // in a ccw order. Using a vector because the number of segments and points is bounded - // (max 4 segments and max 2 points) so the linear insertion is a little ugly, - // but it's not a big cost. + // (max 4 segments and max 2 points) so even if the linear insertion is a little ugly, + // it is not expensive anyway. // // Example: /* @@ -153,9 +153,7 @@ build_intersection(const typename K::Tetrahedron_3& input_tetrahedron, // output will be 's0 s2 p0 s1' Segment_3& ref_s = segments.front(); - const Point_3& ref_sp = ref_s.source(); - const Point_3& ref_tp = ref_s.target(); - Point_3 ref_z = ref_sp + input_triangle_normal; + Point_3 ref_z = ref_s.source() + input_triangle_normal; // The reference segment should be such that all other intersection parts are // on the positive side of the plane described by the normal of the triangle and ref_s @@ -164,11 +162,11 @@ build_intersection(const typename K::Tetrahedron_3& input_tetrahedron, { const Segment_3& other = *slit; - if(k.orientation_3_object()(ref_sp, ref_z, ref_tp, other.source()) == CGAL::NEGATIVE || - k.orientation_3_object()(ref_sp, ref_z, ref_tp, other.target()) == CGAL::NEGATIVE) + if(k.orientation_3_object()(ref_s.source(), ref_z, ref_s.target(), other.source()) == CGAL::NEGATIVE || + k.orientation_3_object()(ref_s.source(), ref_z, ref_s.target(), other.target()) == CGAL::NEGATIVE) { ref_s = ref_s.opposite(); - ref_z = ref_sp + input_triangle_normal; + ref_z = ref_s.source() + input_triangle_normal; swapped = true; break; } @@ -179,16 +177,19 @@ build_intersection(const typename K::Tetrahedron_3& input_tetrahedron, for(PCI plit = points.begin(); plit != points.end(); ++plit) { const Point_3& other = *plit; - if(k.orientation_3_object()(ref_sp, ref_z, ref_tp, other) == CGAL::NEGATIVE) + if(k.orientation_3_object()(ref_s.source(), ref_z, ref_s.target(), other) == CGAL::NEGATIVE) { swapped = true; ref_s = ref_s.opposite(); - ref_z = ref_sp + input_triangle_normal; + ref_z = ref_s.source() + input_triangle_normal; break; } } } + const Point_3& ref_sp = ref_s.source(); + const Point_3& ref_tp = ref_s.target(); + // Now, order the other parts of the intersection std::list > res_elements; // iterators to the points/segments res_elements.emplace_back(segments.begin()); @@ -197,18 +198,16 @@ build_intersection(const typename K::Tetrahedron_3& input_tetrahedron, { // first, check if the segment is well oriented, meaning its source comes before its target (ccwly) Segment_3& curr_s = *slit; - const Point_3& sp = curr_s.source(); - const Point_3& tp = curr_s.target(); - if(sp == ref_sp || tp == ref_tp) // consecutive segments must have consistent orientation + if(curr_s.source() == ref_sp || curr_s.target() == ref_tp) // consecutive segments must have consistent orientation { curr_s = curr_s.opposite(); } - else if(sp == ref_tp || tp == ref_sp) + else if(curr_s.source() == ref_tp || curr_s.target() == ref_sp) { // nothing to do here as we know that sp&tp are on the positive side of (normal, ref_s) } - else if(first_comes_first_pt(ref_sp, ref_z, tp, sp, k)) + else if(first_comes_first_pt(ref_sp, ref_z, curr_s.target(), curr_s.source(), k)) { curr_s = curr_s.opposite(); } @@ -217,7 +216,7 @@ build_intersection(const typename K::Tetrahedron_3& input_tetrahedron, for(auto rit = std::next(res_elements.begin()); ; ++rit) { // always pick the current segment's source to ensure ref_source != ref_other - if(rit == res_elements.end() || first_comes_first(ref_sp, ref_z, sp, *rit, k)) + if(rit == res_elements.end() || first_comes_first(ref_sp, ref_z, curr_s.source(), *rit, k)) { res_elements.insert(rit, slit); break; @@ -227,10 +226,9 @@ build_intersection(const typename K::Tetrahedron_3& input_tetrahedron, for(PCI plit = points.begin(); plit != points.end(); ++plit) { - // first, check if the segment is well oriented, meaning its source comes before its target (ccwly) const Point_3& curr_p = *plit; - // Find where the current point fit in the boundary of the polygon intersection + // Find where the current point fits in the boundary of the polygon intersection for(auto rit = std::next(res_elements.begin()); ; ++rit) { if(rit == res_elements.end() || first_comes_first(ref_sp, ref_z, curr_p, *rit, k)) From 0002c4ae61a32fcccbc9116bcfdb9b9bfe1c6273 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mael=20Rouxel-Labb=C3=A9?= Date: Tue, 3 Aug 2021 14:34:37 +0200 Subject: [PATCH 21/31] Enhance tests --- .../intersection_test_helper.h | 2 - .../test_intersections_Tetrahedron_3.cpp | 39 +++++++++++++++---- 2 files changed, 31 insertions(+), 10 deletions(-) diff --git a/Intersections_3/test/Intersections_3/intersection_test_helper.h b/Intersections_3/test/Intersections_3/intersection_test_helper.h index 857a82313e2..9ee7caa8040 100644 --- a/Intersections_3/test/Intersections_3/intersection_test_helper.h +++ b/Intersections_3/test/Intersections_3/intersection_test_helper.h @@ -203,9 +203,7 @@ public: { check_do_intersect(o1, o2); - std::cout << "1 --------------" << std::endl; const auto res12 = CGAL::intersection(o1, o2); - std::cout << "2 --------------" << std::endl; const auto res21 = CGAL::intersection(o2, o1); Res tmp; diff --git a/Intersections_3/test/Intersections_3/test_intersections_Tetrahedron_3.cpp b/Intersections_3/test/Intersections_3/test_intersections_Tetrahedron_3.cpp index e3d2cfe4a03..6b83de7d349 100644 --- a/Intersections_3/test/Intersections_3/test_intersections_Tetrahedron_3.cpp +++ b/Intersections_3/test/Intersections_3/test_intersections_Tetrahedron_3.cpp @@ -160,10 +160,6 @@ public: Tr(p(-2,0,-2), P(0,0,5), p(10,0,0)), S(p(0,0,1), p(1,0,1))); - // sharing a point on edge - check_intersection(tet, Tr(P(-2, 1, 0.5), P(-2, 0.75, 1.6), P(2, 0, 0.5)), - P(0, 0.5, 0.5)); - // tr inside a face check_intersection(tet, Tr(P(0,0.9,0), P(0,0.1,0), P(0,0,0.9)), Tr(P(0,0.9,0), P(0,0.1,0), P(0,0,0.9))); @@ -214,6 +210,10 @@ public: if(this->has_exact_c) { + // sharing a point on edge + check_intersection(tet, Tr(P(-2, 1, 0.5), P(-2, 0.75, 1.6), P(2, 0, 0.5)), + P(0, 0.5, 0.5)); + Tr tr(p(-2,2,0), p(2,2,0), P(0.25,0.25,0)); auto res = CGAL::intersection(tet, tr); const Poly* poly = boost::get(&*res); @@ -266,20 +266,43 @@ public: os.insert(tet.bounded_side(tr1)); os.insert(tet.bounded_side(tr2)); + // conservative if(os.size() != 1 || (*os.begin() != CGAL::ON_UNBOUNDED_SIDE)) { check_do_intersect(tet, tr); + if(!this->has_exact_c) + continue; + auto res = CGAL::intersection(tet, tr); - if(const Poly* poly = boost::get(&*res)) + + std::vector

points; + if(const P* pt = boost::get

(&*res)) { - for(const P& pt : *poly) { - assert((tet.has_on_bounded_side(pt) || tet.has_on_boundary(pt)) && tr.has_on(pt)); - } + points.push_back(*pt); + } + else if(const S* s = boost::get(&*res)) + { + points.push_back(s->source()); + points.push_back(s->target()); + } + else if(const Tr* itr = boost::get(&*res)) + { + points.push_back(itr->operator[](0)); + points.push_back(itr->operator[](1)); + points.push_back(itr->operator[](2)); + } + else if(const Poly* poly = boost::get(&*res)) + { + points = *poly; // assert(CGAL::is_simple_2(poly->begin(), poly->end(), // CGAL::Projection_traits_3(tr.supporting_plane().orthogonal_vector()))); } + + for(const P& pt : points) { + assert(!tet.has_on_unbounded_side(pt) && tr.has_on(pt)); + } } } } From db4c3fbc76475ba75572717e58d53532a802df5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mael=20Rouxel-Labb=C3=A9?= Date: Fri, 6 Aug 2021 10:12:37 +0200 Subject: [PATCH 22/31] Fix misc issues within intersection tests themselves --- .../Tetrahedron_3_Triangle_3_intersection.h | 2 +- .../test/Intersections_3/call_test.cpp | 681 +++++++++--------- .../test_intersections_Line_3.cpp | 25 +- .../test_intersections_Plane_3.cpp | 3 +- .../test_intersections_Point_3.cpp | 18 +- 5 files changed, 376 insertions(+), 353 deletions(-) diff --git a/Intersections_3/include/CGAL/Intersections_3/internal/Tetrahedron_3_Triangle_3_intersection.h b/Intersections_3/include/CGAL/Intersections_3/internal/Tetrahedron_3_Triangle_3_intersection.h index 4eb861c618c..f135007aa36 100644 --- a/Intersections_3/include/CGAL/Intersections_3/internal/Tetrahedron_3_Triangle_3_intersection.h +++ b/Intersections_3/include/CGAL/Intersections_3/internal/Tetrahedron_3_Triangle_3_intersection.h @@ -92,7 +92,7 @@ bool first_comes_first(const typename K::Point_3& ref_source, template typename Intersection_traits::result_type -build_intersection(const typename K::Tetrahedron_3& input_tetrahedron, +build_intersection(const typename K::Tetrahedron_3& /*input_tetrahedron*/, const typename K::Triangle_3& input_triangle, PointContainer& points, SegmentContainer& segments, diff --git a/Intersections_3/test/Intersections_3/call_test.cpp b/Intersections_3/test/Intersections_3/call_test.cpp index 1ae3209d481..946b534c3ca 100644 --- a/Intersections_3/test/Intersections_3/call_test.cpp +++ b/Intersections_3/test/Intersections_3/call_test.cpp @@ -70,392 +70,403 @@ void test(const int argc) // INTERSECTION // --------------------------------------------------------------------------------------------- - call_intersection_global(Cub(), Bbox_3()); - call_intersection_global(Cub(), Cub()); - call_intersection_global(Cub(), L()); - call_intersection_global(Cub(), Pl()); - call_intersection_global(Cub(), P()); - call_intersection_global(Cub(), R()); - call_intersection_global(Cub(), S()); - call_intersection_global(Cub(), Tr()); + Bbox_3 bbox { 0, 0, 0, 1, 1, 1 }; + Cub cub { 0, 0, 0, 1, 1, 1 }; + L l { P{0, 0, 0}, P{1, 1, 1} }; + Pl pl { P{0, 0, 0}, P{1, 0, 0}, P{0, 1, 0} }; + P p { 0, 0, 0 }; + R r { P{0, 0, 0}, P{1, 1, 1} }; + S s { P{0, 0, 0}, P{1, 1, 1} }; + Sph sph { P{0, 0, 0}, 1 }; + Tr tr { P{0, 0, 0}, P{1, 0, 0}, P{0, 1, 0} }; + T tet { P{0, 0, 0}, P{1, 0, 0}, P{0, 1, 0}, P{0, 0, 1} }; - call_intersection_global(L(), Bbox_3()); - call_intersection_global(L(), Cub()); - call_intersection_global(L(), L()); - call_intersection_global(L(), Pl()); - call_intersection_global(L(), P()); - call_intersection_global(L(), R()); - call_intersection_global(L(), S()); - call_intersection_global(L(), T()); - call_intersection_global(L(), Tr()); + call_intersection_global(cub, bbox); + call_intersection_global(cub, cub); + call_intersection_global(cub, l); + call_intersection_global(cub, pl); + call_intersection_global(cub, p); + call_intersection_global(cub, r); + call_intersection_global(cub, s); + call_intersection_global(cub, tr); - call_intersection_global(Pl(), Bbox_3()); - call_intersection_global(Pl(), Cub()); - call_intersection_global(Pl(), L()); - call_intersection_global(Pl(), Pl()); - call_intersection_global(Pl(), P()); - call_intersection_global(Pl(), R()); - call_intersection_global(Pl(), S()); - call_intersection_global(Pl(), Sph()); - call_intersection_global(Pl(), Tr()); - call_intersection_global(Pl(), T()); + call_intersection_global(l, bbox); + call_intersection_global(l, cub); + call_intersection_global(l, l); + call_intersection_global(l, pl); + call_intersection_global(l, p); + call_intersection_global(l, r); + call_intersection_global(l, s); + call_intersection_global(l, tet); + call_intersection_global(l, tr); - auto plplpl = CGAL::intersection(Pl(), Pl(), Pl()); + call_intersection_global(pl, bbox); + call_intersection_global(pl, cub); + call_intersection_global(pl, l); + call_intersection_global(pl, pl); + call_intersection_global(pl, p); + call_intersection_global(pl, r); + call_intersection_global(pl, s); + call_intersection_global(pl, sph); + call_intersection_global(pl, tr); + call_intersection_global(pl, tet); + + auto plplpl = CGAL::intersection(pl, pl, pl); CGAL_USE(plplpl); - call_intersection_global(P(), Bbox_3()); - call_intersection_global(P(), Cub()); - call_intersection_global(P(), L()); - call_intersection_global(P(), Pl()); - call_intersection_global(P(), P()); - call_intersection_global(P(), R()); - call_intersection_global(P(), S()); - call_intersection_global(P(), Sph()); - call_intersection_global(P(), Tr()); - call_intersection_global(P(), T()); + call_intersection_global(p, bbox); + call_intersection_global(p, cub); + call_intersection_global(p, l); + call_intersection_global(p, pl); + call_intersection_global(p, p); + call_intersection_global(p, r); + call_intersection_global(p, s); + call_intersection_global(p, sph); + call_intersection_global(p, tr); + call_intersection_global(p, tet); - call_intersection_global(R(), Bbox_3()); - call_intersection_global(R(), Cub()); - call_intersection_global(R(), L()); - call_intersection_global(R(), Pl()); - call_intersection_global(R(), P()); - call_intersection_global(R(), R()); - call_intersection_global(R(), S()); - call_intersection_global(R(), Tr()); - call_intersection_global(R(), T()); + call_intersection_global(r, bbox); + call_intersection_global(r, cub); + call_intersection_global(r, l); + call_intersection_global(r, pl); + call_intersection_global(r, p); + call_intersection_global(r, r); + call_intersection_global(r, s); + call_intersection_global(r, tr); + call_intersection_global(r, tet); - call_intersection_global(S(), Bbox_3()); - call_intersection_global(S(), Cub()); - call_intersection_global(S(), L()); - call_intersection_global(S(), Pl()); - call_intersection_global(S(), P()); - call_intersection_global(S(), R()); - call_intersection_global(S(), S()); - call_intersection_global(S(), T()); - call_intersection_global(S(), Tr()); + call_intersection_global(s, bbox); + call_intersection_global(s, cub); + call_intersection_global(s, l); + call_intersection_global(s, pl); + call_intersection_global(s, p); + call_intersection_global(s, r); + call_intersection_global(s, s); + call_intersection_global(s, tet); + call_intersection_global(s, tr); - call_intersection_global(Sph(), Pl()); - call_intersection_global(Sph(), P()); - call_intersection_global(Sph(), Sph()); + call_intersection_global(sph, pl); + call_intersection_global(sph, p); + call_intersection_global(sph, sph); - call_intersection_global(Tr(), Bbox_3()); - call_intersection_global(Tr(), Cub()); - call_intersection_global(Tr(), L()); - call_intersection_global(Tr(), Pl()); - call_intersection_global(Tr(), P()); - call_intersection_global(Tr(), R()); - call_intersection_global(Tr(), S()); - call_intersection_global(Tr(), Tr()); - call_intersection_global(Tr(), T()); + call_intersection_global(tr, bbox); + call_intersection_global(tr, cub); + call_intersection_global(tr, l); + call_intersection_global(tr, pl); + call_intersection_global(tr, p); + call_intersection_global(tr, r); + call_intersection_global(tr, s); + call_intersection_global(tr, tr); + call_intersection_global(tr, tet); - call_intersection_global(T(), L()); - call_intersection_global(T(), Pl()); - call_intersection_global(T(), P()); - call_intersection_global(T(), R()); - call_intersection_global(T(), S()); - call_intersection_global(T(), Tr()); + call_intersection_global(tet, l); + call_intersection_global(tet, pl); + call_intersection_global(tet, p); + call_intersection_global(tet, r); + call_intersection_global(tet, s); + call_intersection_global(tet, tr); - const auto bbbb = CGAL::intersection(Bbox_3(), Bbox_3()); + const auto bbbb = CGAL::intersection(bbox, bbox); CGAL_USE(bbbb); - call_intersection_global(Bbox_3(), Cub()); - call_intersection_global(Bbox_3(), L()); - call_intersection_global(Bbox_3(), Pl()); - call_intersection_global(Bbox_3(), P()); - call_intersection_global(Bbox_3(), R()); - call_intersection_global(Bbox_3(), S()); - call_intersection_global(Bbox_3(), Tr()); + call_intersection_global(bbox, cub); + call_intersection_global(bbox, l); + call_intersection_global(bbox, pl); + call_intersection_global(bbox, p); + call_intersection_global(bbox, r); + call_intersection_global(bbox, s); + call_intersection_global(bbox, tr); - call_intersection_global(T(), L()); + call_intersection_global(tet, l); // with kernel - call_intersection_with_kernel(Cub(), Bbox_3(), K()); - call_intersection_with_kernel(Cub(), Cub(), K()); - call_intersection_with_kernel(Cub(), L(), K()); - call_intersection_with_kernel(Cub(), Pl(), K()); - call_intersection_with_kernel(Cub(), P(), K()); - call_intersection_with_kernel(Cub(), R(), K()); - call_intersection_with_kernel(Cub(), S(), K()); - call_intersection_with_kernel(Cub(), Tr(), K()); + call_intersection_with_kernel(cub, bbox, K()); + call_intersection_with_kernel(cub, cub, K()); + call_intersection_with_kernel(cub, l, K()); + call_intersection_with_kernel(cub, pl, K()); + call_intersection_with_kernel(cub, p, K()); + call_intersection_with_kernel(cub, r, K()); + call_intersection_with_kernel(cub, s, K()); + call_intersection_with_kernel(cub, tr, K()); - call_intersection_with_kernel(L(), Bbox_3(), K()); - call_intersection_with_kernel(L(), Cub(), K()); - call_intersection_with_kernel(L(), L(), K()); - call_intersection_with_kernel(L(), Pl(), K()); - call_intersection_with_kernel(L(), P(), K()); - call_intersection_with_kernel(L(), R(), K()); - call_intersection_with_kernel(L(), S(), K()); - call_intersection_with_kernel(L(), Tr(), K()); - call_intersection_with_kernel(L(), T(), K()); + call_intersection_with_kernel(l, bbox, K()); + call_intersection_with_kernel(l, cub, K()); + call_intersection_with_kernel(l, l, K()); + call_intersection_with_kernel(l, pl, K()); + call_intersection_with_kernel(l, p, K()); + call_intersection_with_kernel(l, r, K()); + call_intersection_with_kernel(l, s, K()); + call_intersection_with_kernel(l, tr, K()); + call_intersection_with_kernel(l, tet, K()); - call_intersection_with_kernel(Pl(), Bbox_3(), K()); - call_intersection_with_kernel(Pl(), Cub(), K()); - call_intersection_with_kernel(Pl(), L(), K()); - call_intersection_with_kernel(Pl(), Pl(), K()); - call_intersection_with_kernel(Pl(), P(), K()); - call_intersection_with_kernel(Pl(), R(), K()); - call_intersection_with_kernel(Pl(), S(), K()); - call_intersection_with_kernel(Pl(), Tr(), K()); - call_intersection_with_kernel(Pl(), T(), K()); + call_intersection_with_kernel(pl, bbox, K()); + call_intersection_with_kernel(pl, cub, K()); + call_intersection_with_kernel(pl, l, K()); + call_intersection_with_kernel(pl, pl, K()); + call_intersection_with_kernel(pl, p, K()); + call_intersection_with_kernel(pl, r, K()); + call_intersection_with_kernel(pl, s, K()); + call_intersection_with_kernel(pl, tr, K()); + call_intersection_with_kernel(pl, tet, K()); //special - plplpl = K().intersect_3_object()(Pl(), Pl(), Pl()); + plplpl = K().intersect_3_object()(pl, pl, pl); CGAL_USE(plplpl); - call_intersection_with_kernel(P(), Bbox_3(), K()); - call_intersection_with_kernel(P(), Cub(), K()); - call_intersection_with_kernel(P(), L(), K()); - call_intersection_with_kernel(P(), Pl(), K()); - call_intersection_with_kernel(P(), P(), K()); - call_intersection_with_kernel(P(), R(), K()); - call_intersection_with_kernel(P(), S(), K()); - call_intersection_with_kernel(P(), Sph(), K()); - call_intersection_with_kernel(P(), Tr(), K()); - call_intersection_with_kernel(P(), T(), K()); + call_intersection_with_kernel(p, bbox, K()); + call_intersection_with_kernel(p, cub, K()); + call_intersection_with_kernel(p, l, K()); + call_intersection_with_kernel(p, pl, K()); + call_intersection_with_kernel(p, p, K()); + call_intersection_with_kernel(p, r, K()); + call_intersection_with_kernel(p, s, K()); + call_intersection_with_kernel(p, sph, K()); + call_intersection_with_kernel(p, tr, K()); + call_intersection_with_kernel(p, tet, K()); - call_intersection_with_kernel(R(), Bbox_3(), K()); - call_intersection_with_kernel(R(), Cub(), K()); - call_intersection_with_kernel(R(), L(), K()); - call_intersection_with_kernel(R(), Pl(), K()); - call_intersection_with_kernel(R(), P(), K()); - call_intersection_with_kernel(R(), R(), K()); - call_intersection_with_kernel(R(), S(), K()); - call_intersection_with_kernel(R(), Tr(), K()); - call_intersection_with_kernel(R(), T(), K()); + call_intersection_with_kernel(r, bbox, K()); + call_intersection_with_kernel(r, cub, K()); + call_intersection_with_kernel(r, l, K()); + call_intersection_with_kernel(r, pl, K()); + call_intersection_with_kernel(r, p, K()); + call_intersection_with_kernel(r, r, K()); + call_intersection_with_kernel(r, s, K()); + call_intersection_with_kernel(r, tr, K()); + call_intersection_with_kernel(r, tet, K()); - call_intersection_with_kernel(S(), Bbox_3(), K()); - call_intersection_with_kernel(S(), Cub(), K()); - call_intersection_with_kernel(S(), L(), K()); - call_intersection_with_kernel(S(), Pl(), K()); - call_intersection_with_kernel(S(), P(), K()); - call_intersection_with_kernel(S(), R(), K()); - call_intersection_with_kernel(S(), S(), K()); - call_intersection_with_kernel(S(), Tr(), K()); - call_intersection_with_kernel(S(), T(), K()); + call_intersection_with_kernel(s, bbox, K()); + call_intersection_with_kernel(s, cub, K()); + call_intersection_with_kernel(s, l, K()); + call_intersection_with_kernel(s, pl, K()); + call_intersection_with_kernel(s, p, K()); + call_intersection_with_kernel(s, r, K()); + call_intersection_with_kernel(s, s, K()); + call_intersection_with_kernel(s, tr, K()); + call_intersection_with_kernel(s, tet, K()); - call_intersection_with_kernel(Sph(), Pl(), K()); - call_intersection_with_kernel(Sph(), P(), K()); - call_intersection_with_kernel(Sph(), Sph(), K()); + call_intersection_with_kernel(sph, pl, K()); + call_intersection_with_kernel(sph, p, K()); + call_intersection_with_kernel(sph, sph, K()); - call_intersection_with_kernel(Tr(), Bbox_3(), K()); - call_intersection_with_kernel(Tr(), Cub(), K()); - call_intersection_with_kernel(Tr(), L(), K()); - call_intersection_with_kernel(Tr(), Pl(), K()); - call_intersection_with_kernel(Tr(), P(), K()); - call_intersection_with_kernel(Tr(), R(), K()); - call_intersection_with_kernel(Tr(), S(), K()); - call_intersection_with_kernel(Tr(), Tr(), K()); - call_intersection_with_kernel(Tr(), T(), K()); + call_intersection_with_kernel(tr, bbox, K()); + call_intersection_with_kernel(tr, cub, K()); + call_intersection_with_kernel(tr, l, K()); + call_intersection_with_kernel(tr, pl, K()); + call_intersection_with_kernel(tr, p, K()); + call_intersection_with_kernel(tr, r, K()); + call_intersection_with_kernel(tr, s, K()); + call_intersection_with_kernel(tr, tr, K()); + call_intersection_with_kernel(tr, tet, K()); - call_intersection_with_kernel(T(), L(), K()); - call_intersection_with_kernel(T(), Pl(), K()); - call_intersection_with_kernel(T(), P(), K()); - call_intersection_with_kernel(T(), R(), K()); - call_intersection_with_kernel(T(), S(), K()); - call_intersection_with_kernel(T(), Tr(), K()); + call_intersection_with_kernel(tet, l, K()); + call_intersection_with_kernel(tet, pl, K()); + call_intersection_with_kernel(tet, p, K()); + call_intersection_with_kernel(tet, r, K()); + call_intersection_with_kernel(tet, s, K()); + call_intersection_with_kernel(tet, tr, K()); - call_intersection_with_kernel(Bbox_3(), Cub(), K()); - call_intersection_with_kernel(Bbox_3(), L(), K()); - call_intersection_with_kernel(Bbox_3(), Pl(), K()); - call_intersection_with_kernel(Bbox_3(), P(), K()); - call_intersection_with_kernel(Bbox_3(), R(), K()); - call_intersection_with_kernel(Bbox_3(), S(), K()); - call_intersection_with_kernel(Bbox_3(), Tr(), K()); + call_intersection_with_kernel(bbox, cub, K()); + call_intersection_with_kernel(bbox, l, K()); + call_intersection_with_kernel(bbox, pl, K()); + call_intersection_with_kernel(bbox, p, K()); + call_intersection_with_kernel(bbox, r, K()); + call_intersection_with_kernel(bbox, s, K()); + call_intersection_with_kernel(bbox, tr, K()); // --------------------------------------------------------------------------------------------- // DO INTERSECT // --------------------------------------------------------------------------------------------- - call_do_intersect_global(L(), Cub()); - call_do_intersect_global(L(), Bbox_3()); - call_do_intersect_global(L(), L()); - call_do_intersect_global(L(), Pl()); - call_do_intersect_global(L(), P()); - call_do_intersect_global(L(), R()); - call_do_intersect_global(L(), S()); - call_do_intersect_global(L(), Sph()); - call_do_intersect_global(L(), Tr()); - call_do_intersect_global(L(), T()); + call_do_intersect_global(l, cub); + call_do_intersect_global(l, bbox); + call_do_intersect_global(l, l); + call_do_intersect_global(l, pl); + call_do_intersect_global(l, p); + call_do_intersect_global(l, r); + call_do_intersect_global(l, s); + call_do_intersect_global(l, sph); + call_do_intersect_global(l, tr); + call_do_intersect_global(l, tet); - call_do_intersect_global(Pl(), Bbox_3()); - call_do_intersect_global(Pl(), Cub()); - call_do_intersect_global(Pl(), L()); - call_do_intersect_global(Pl(), Pl()); - call_do_intersect_global(Pl(), P()); - call_do_intersect_global(Pl(), R()); - call_do_intersect_global(Pl(), S()); - call_do_intersect_global(Pl(), Sph()); - call_do_intersect_global(Pl(), Tr()); - call_do_intersect_global(Pl(), T()); + call_do_intersect_global(pl, bbox); + call_do_intersect_global(pl, cub); + call_do_intersect_global(pl, l); + call_do_intersect_global(pl, pl); + call_do_intersect_global(pl, p); + call_do_intersect_global(pl, r); + call_do_intersect_global(pl, s); + call_do_intersect_global(pl, sph); + call_do_intersect_global(pl, tr); + call_do_intersect_global(pl, tet); - call_do_intersect_global(P(), Bbox_3()); - call_do_intersect_global(P(), Cub()); - call_do_intersect_global(P(), L()); - call_do_intersect_global(P(), Pl()); - call_do_intersect_global(P(), P()); - call_do_intersect_global(P(), R()); - call_do_intersect_global(P(), S()); - call_do_intersect_global(P(), Sph()); - call_do_intersect_global(P(), Tr()); - call_do_intersect_global(P(), T()); + call_do_intersect_global(p, bbox); + call_do_intersect_global(p, cub); + call_do_intersect_global(p, l); + call_do_intersect_global(p, pl); + call_do_intersect_global(p, p); + call_do_intersect_global(p, r); + call_do_intersect_global(p, s); + call_do_intersect_global(p, sph); + call_do_intersect_global(p, tr); + call_do_intersect_global(p, tet); - call_do_intersect_global(R(), Bbox_3()); - call_do_intersect_global(R(), Cub()); - call_do_intersect_global(R(), L()); - call_do_intersect_global(R(), Pl()); - call_do_intersect_global(R(), P()); - call_do_intersect_global(R(), R()); - call_do_intersect_global(R(), S()); - call_do_intersect_global(R(), Tr()); - call_do_intersect_global(R(), T()); + call_do_intersect_global(r, bbox); + call_do_intersect_global(r, cub); + call_do_intersect_global(r, l); + call_do_intersect_global(r, pl); + call_do_intersect_global(r, p); + call_do_intersect_global(r, r); + call_do_intersect_global(r, s); + call_do_intersect_global(r, tr); + call_do_intersect_global(r, tet); - call_do_intersect_global(S(), Bbox_3()); - call_do_intersect_global(S(), Cub()); - call_do_intersect_global(S(), Pl()); - call_do_intersect_global(S(), P()); - call_do_intersect_global(S(), L()); - call_do_intersect_global(S(), R()); - call_do_intersect_global(S(), S()); - call_do_intersect_global(S(), Sph()); - call_do_intersect_global(S(), Tr()); - call_do_intersect_global(S(), T()); + call_do_intersect_global(s, bbox); + call_do_intersect_global(s, cub); + call_do_intersect_global(s, pl); + call_do_intersect_global(s, p); + call_do_intersect_global(s, l); + call_do_intersect_global(s, r); + call_do_intersect_global(s, s); + call_do_intersect_global(s, sph); + call_do_intersect_global(s, tr); + call_do_intersect_global(s, tet); - call_do_intersect_global(Sph(), Bbox_3()); - call_do_intersect_global(Sph(), Cub()); - call_do_intersect_global(Sph(), Pl()); - call_do_intersect_global(Sph(), P()); - call_do_intersect_global(Sph(), L()); - call_do_intersect_global(Sph(), R()); - call_do_intersect_global(Sph(), S()); - call_do_intersect_global(Sph(), Sph()); - call_do_intersect_global(Sph(), Tr()); - call_do_intersect_global(Sph(), T()); + call_do_intersect_global(sph, bbox); + call_do_intersect_global(sph, cub); + call_do_intersect_global(sph, pl); + call_do_intersect_global(sph, p); + call_do_intersect_global(sph, l); + call_do_intersect_global(sph, r); + call_do_intersect_global(sph, s); + call_do_intersect_global(sph, sph); + call_do_intersect_global(sph, tr); + call_do_intersect_global(sph, tet); - call_do_intersect_global(Tr(), Bbox_3()); - call_do_intersect_global(Tr(), Cub()); - call_do_intersect_global(Tr(), L()); - call_do_intersect_global(Tr(), Pl()); - call_do_intersect_global(Tr(), P()); - call_do_intersect_global(Tr(), R()); - call_do_intersect_global(Tr(), S()); - call_do_intersect_global(Tr(), Sph()); - call_do_intersect_global(Tr(), Tr()); - call_do_intersect_global(Tr(), T()); + call_do_intersect_global(tr, bbox); + call_do_intersect_global(tr, cub); + call_do_intersect_global(tr, l); + call_do_intersect_global(tr, pl); + call_do_intersect_global(tr, p); + call_do_intersect_global(tr, r); + call_do_intersect_global(tr, s); + call_do_intersect_global(tr, sph); + call_do_intersect_global(tr, tr); + call_do_intersect_global(tr, tet); - call_do_intersect_global(Tr(), Bbox_3()); - call_do_intersect_global(Tr(), Cub()); - call_do_intersect_global(Tr(), L()); - call_do_intersect_global(Tr(), Pl()); - call_do_intersect_global(Tr(), P()); - call_do_intersect_global(Tr(), R()); - call_do_intersect_global(Tr(), S()); - call_do_intersect_global(Tr(), Sph()); - call_do_intersect_global(Tr(), Tr()); - call_do_intersect_global(Tr(), T()); + call_do_intersect_global(tr, bbox); + call_do_intersect_global(tr, cub); + call_do_intersect_global(tr, l); + call_do_intersect_global(tr, pl); + call_do_intersect_global(tr, p); + call_do_intersect_global(tr, r); + call_do_intersect_global(tr, s); + call_do_intersect_global(tr, sph); + call_do_intersect_global(tr, tr); + call_do_intersect_global(tr, tet); - call_do_intersect_global(T(), Bbox_3()); - call_do_intersect_global(T(), Cub()); - call_do_intersect_global(T(), L()); - call_do_intersect_global(T(), Pl()); - call_do_intersect_global(T(), P()); - call_do_intersect_global(T(), R()); - call_do_intersect_global(T(), S()); - call_do_intersect_global(T(), Sph()); - call_do_intersect_global(T(), Tr()); - call_do_intersect_global(T(), T()); + call_do_intersect_global(tet, bbox); + call_do_intersect_global(tet, cub); + call_do_intersect_global(tet, l); + call_do_intersect_global(tet, pl); + call_do_intersect_global(tet, p); + call_do_intersect_global(tet, r); + call_do_intersect_global(tet, s); + call_do_intersect_global(tet, sph); + call_do_intersect_global(tet, tr); + call_do_intersect_global(tet, tet); - call_do_intersect_global(Bbox_3(), Pl()); - call_do_intersect_global(Bbox_3(), L()); - call_do_intersect_global(Bbox_3(), R()); - call_do_intersect_global(Bbox_3(), S()); - call_do_intersect_global(Bbox_3(), Tr()); - call_do_intersect_global(Bbox_3(), Sph()); - call_do_intersect_global(Bbox_3(), Bbox_3()); + call_do_intersect_global(bbox, pl); + call_do_intersect_global(bbox, l); + call_do_intersect_global(bbox, r); + call_do_intersect_global(bbox, s); + call_do_intersect_global(bbox, tr); + call_do_intersect_global(bbox, sph); + call_do_intersect_global(bbox, bbox); // with_kernel - call_do_intersect_with_kernel(L(), Bbox_3(), K()); - call_do_intersect_with_kernel(L(), Cub(), K()); - call_do_intersect_with_kernel(L(), L(), K()); - call_do_intersect_with_kernel(L(), Pl(), K()); - call_do_intersect_with_kernel(L(), P(), K()); - call_do_intersect_with_kernel(L(), R(), K()); - call_do_intersect_with_kernel(L(), S(), K()); - call_do_intersect_with_kernel(L(), Sph(), K()); - call_do_intersect_with_kernel(L(), Tr(), K()); - call_do_intersect_with_kernel(L(), T(), K()); + call_do_intersect_with_kernel(l, bbox, K()); + call_do_intersect_with_kernel(l, cub, K()); + call_do_intersect_with_kernel(l, l, K()); + call_do_intersect_with_kernel(l, pl, K()); + call_do_intersect_with_kernel(l, p, K()); + call_do_intersect_with_kernel(l, r, K()); + call_do_intersect_with_kernel(l, s, K()); + call_do_intersect_with_kernel(l, sph, K()); + call_do_intersect_with_kernel(l, tr, K()); + call_do_intersect_with_kernel(l, tet, K()); - call_do_intersect_with_kernel(Pl(), Bbox_3(), K()); - call_do_intersect_with_kernel(Pl(), Cub(), K()); - call_do_intersect_with_kernel(Pl(), L(), K()); - call_do_intersect_with_kernel(Pl(), Pl(), K()); - call_do_intersect_with_kernel(Pl(), P(), K()); - call_do_intersect_with_kernel(Pl(), R(), K()); - call_do_intersect_with_kernel(Pl(), S(), K()); - call_do_intersect_with_kernel(Pl(), Sph(), K()); - call_do_intersect_with_kernel(Pl(), Tr(), K()); - call_do_intersect_with_kernel(Pl(), T(), K()); + call_do_intersect_with_kernel(pl, bbox, K()); + call_do_intersect_with_kernel(pl, cub, K()); + call_do_intersect_with_kernel(pl, l, K()); + call_do_intersect_with_kernel(pl, pl, K()); + call_do_intersect_with_kernel(pl, p, K()); + call_do_intersect_with_kernel(pl, r, K()); + call_do_intersect_with_kernel(pl, s, K()); + call_do_intersect_with_kernel(pl, sph, K()); + call_do_intersect_with_kernel(pl, tr, K()); + call_do_intersect_with_kernel(pl, tet, K()); - call_do_intersect_with_kernel(P(), Bbox_3(), K()); - call_do_intersect_with_kernel(P(), Cub(), K()); - call_do_intersect_with_kernel(P(), L(), K()); - call_do_intersect_with_kernel(P(), Pl(), K()); - call_do_intersect_with_kernel(P(), P(), K()); - call_do_intersect_with_kernel(P(), R(), K()); - call_do_intersect_with_kernel(P(), S(), K()); - call_do_intersect_with_kernel(P(), Sph(), K()); - call_do_intersect_with_kernel(P(), Tr(), K()); - call_do_intersect_with_kernel(P(), T(), K()); + call_do_intersect_with_kernel(p, bbox, K()); + call_do_intersect_with_kernel(p, cub, K()); + call_do_intersect_with_kernel(p, l, K()); + call_do_intersect_with_kernel(p, pl, K()); + call_do_intersect_with_kernel(p, p, K()); + call_do_intersect_with_kernel(p, r, K()); + call_do_intersect_with_kernel(p, s, K()); + call_do_intersect_with_kernel(p, sph, K()); + call_do_intersect_with_kernel(p, tr, K()); + call_do_intersect_with_kernel(p, tet, K()); - call_do_intersect_with_kernel(R(), Bbox_3(), K()); - call_do_intersect_with_kernel(R(), Cub(), K()); - call_do_intersect_with_kernel(R(), L(), K()); - call_do_intersect_with_kernel(R(), Pl(), K()); - call_do_intersect_with_kernel(R(), P(), K()); - call_do_intersect_with_kernel(R(), R(), K()); - call_do_intersect_with_kernel(R(), S(), K()); - call_do_intersect_with_kernel(R(), Sph(), K()); - call_do_intersect_with_kernel(R(), Tr(), K()); - call_do_intersect_with_kernel(R(), T(), K()); + call_do_intersect_with_kernel(r, bbox, K()); + call_do_intersect_with_kernel(r, cub, K()); + call_do_intersect_with_kernel(r, l, K()); + call_do_intersect_with_kernel(r, pl, K()); + call_do_intersect_with_kernel(r, p, K()); + call_do_intersect_with_kernel(r, r, K()); + call_do_intersect_with_kernel(r, s, K()); + call_do_intersect_with_kernel(r, sph, K()); + call_do_intersect_with_kernel(r, tr, K()); + call_do_intersect_with_kernel(r, tet, K()); - call_do_intersect_with_kernel(S(), Bbox_3(), K()); - call_do_intersect_with_kernel(S(), Cub(), K()); - call_do_intersect_with_kernel(S(), R(), K()); - call_do_intersect_with_kernel(S(), L(), K()); - call_do_intersect_with_kernel(S(), P(), K()); - call_do_intersect_with_kernel(S(), R(), K()); - call_do_intersect_with_kernel(S(), S(), K()); - call_do_intersect_with_kernel(S(), Sph(), K()); - call_do_intersect_with_kernel(S(), Tr(), K()); - call_do_intersect_with_kernel(S(), T(), K()); + call_do_intersect_with_kernel(s, bbox, K()); + call_do_intersect_with_kernel(s, cub, K()); + call_do_intersect_with_kernel(s, r, K()); + call_do_intersect_with_kernel(s, l, K()); + call_do_intersect_with_kernel(s, p, K()); + call_do_intersect_with_kernel(s, r, K()); + call_do_intersect_with_kernel(s, s, K()); + call_do_intersect_with_kernel(s, sph, K()); + call_do_intersect_with_kernel(s, tr, K()); + call_do_intersect_with_kernel(s, tet, K()); - call_do_intersect_with_kernel(Tr(), Bbox_3(), K()); - call_do_intersect_with_kernel(Tr(), Cub(), K()); - call_do_intersect_with_kernel(Tr(), R(), K()); - call_do_intersect_with_kernel(Tr(), L(), K()); - call_do_intersect_with_kernel(Tr(), P(), K()); - call_do_intersect_with_kernel(Tr(), R(), K()); - call_do_intersect_with_kernel(Tr(), S(), K()); - call_do_intersect_with_kernel(Tr(), Tr(), K()); - call_do_intersect_with_kernel(Tr(), T(), K()); + call_do_intersect_with_kernel(tr, bbox, K()); + call_do_intersect_with_kernel(tr, cub, K()); + call_do_intersect_with_kernel(tr, r, K()); + call_do_intersect_with_kernel(tr, l, K()); + call_do_intersect_with_kernel(tr, p, K()); + call_do_intersect_with_kernel(tr, r, K()); + call_do_intersect_with_kernel(tr, s, K()); + call_do_intersect_with_kernel(tr, tr, K()); + call_do_intersect_with_kernel(tr, tet, K()); - call_do_intersect_with_kernel(T(), Bbox_3(), K()); - call_do_intersect_with_kernel(T(), Cub(), K()); - call_do_intersect_with_kernel(T(), R(), K()); - call_do_intersect_with_kernel(T(), L(), K()); - call_do_intersect_with_kernel(T(), P(), K()); - call_do_intersect_with_kernel(T(), R(), K()); - call_do_intersect_with_kernel(T(), S(), K()); - call_do_intersect_with_kernel(T(), Tr(), K()); - call_do_intersect_with_kernel(T(), T(), K()); + call_do_intersect_with_kernel(tet, bbox, K()); + call_do_intersect_with_kernel(tet, cub, K()); + call_do_intersect_with_kernel(tet, r, K()); + call_do_intersect_with_kernel(tet, l, K()); + call_do_intersect_with_kernel(tet, p, K()); + call_do_intersect_with_kernel(tet, r, K()); + call_do_intersect_with_kernel(tet, s, K()); + call_do_intersect_with_kernel(tet, tr, K()); + call_do_intersect_with_kernel(tet, tet, K()); - call_do_intersect_with_kernel(Bbox_3(), Cub(), K()); - call_do_intersect_with_kernel(Bbox_3(), L(), K()); - call_do_intersect_with_kernel(Bbox_3(), Pl(), K()); - call_do_intersect_with_kernel(Bbox_3(), P(), K()); - call_do_intersect_with_kernel(Bbox_3(), R(), K()); - call_do_intersect_with_kernel(Bbox_3(), S(), K()); - call_do_intersect_with_kernel(Bbox_3(), Sph(), K()); - call_do_intersect_with_kernel(Bbox_3(), Tr(), K()); + call_do_intersect_with_kernel(bbox, cub, K()); + call_do_intersect_with_kernel(bbox, l, K()); + call_do_intersect_with_kernel(bbox, pl, K()); + call_do_intersect_with_kernel(bbox, p, K()); + call_do_intersect_with_kernel(bbox, r, K()); + call_do_intersect_with_kernel(bbox, s, K()); + call_do_intersect_with_kernel(bbox, sph, K()); + call_do_intersect_with_kernel(bbox, tr, K()); } } diff --git a/Intersections_3/test/Intersections_3/test_intersections_Line_3.cpp b/Intersections_3/test/Intersections_3/test_intersections_Line_3.cpp index 44bc02f7b17..5d59b3c14f3 100644 --- a/Intersections_3/test/Intersections_3/test_intersections_Line_3.cpp +++ b/Intersections_3/test/Intersections_3/test_intersections_Line_3.cpp @@ -339,17 +339,21 @@ public: { P tet0 = random_point(), tet1 = random_point(), tet2 = random_point(), tet3 = random_point(); - if(std::set

({{tet0, tet1, tet2, tet3}}).size() != 4) + const Tet tet(tet0, tet1, tet2, tet3); + if(tet.is_degenerate()) continue; P l0 = tet0 + CGAL::cross_product(V(tet0, tet1), V(tet0, tet2)); P l1 = tet2 + CGAL::cross_product(V(tet2, tet1), V(tet2, tet0)); - Tet tet(tet0, tet1, tet2, tet3); assert(tet.has_on_unbounded_side(l0) && tet.has_on_unbounded_side(l1)); - if(CGAL::do_intersect(S(l0, l1), tet)) - check_intersection(L(l0, l1), tet, tet, S(l0, l1)); + const S s {l0, l1}; + if(s.is_degenerate()) + continue; + + if(CGAL::do_intersect(s, tet)) + check_intersection(L(l0, l1), tet, tet, s); } } @@ -382,14 +386,17 @@ public: { P tr0 = random_point(), tr1 = random_point(), tr2 = random_point(); - if(tr0 == tr1 || tr1 == tr2 || tr0 == tr2) - continue; - P l0 = tr0 + CGAL::cross_product(V(tr0, tr1), V(tr0, tr2)); P l1 = tr2 + CGAL::cross_product(V(tr2, tr1), V(tr2, tr0)); - if(CGAL::do_intersect(S(l0, l1), Tr(tr0, tr1, tr2))) - check_intersection(L(l0, l1), Tr(tr0, tr1, tr2), Tr(tr0, tr1, tr2), S(l0, l1)); + S s{l0, l1}; + Tr tr{tr0, tr1, tr2}; + + if(s.is_degenerate() || tr.is_degenerate()) + continue; + + if(CGAL::do_intersect(s, tr)) + check_intersection(L(l0, l1), tr, tr, s); } } diff --git a/Intersections_3/test/Intersections_3/test_intersections_Plane_3.cpp b/Intersections_3/test/Intersections_3/test_intersections_Plane_3.cpp index 02f99f9f78a..c3b3fb28e54 100644 --- a/Intersections_3/test/Intersections_3/test_intersections_Plane_3.cpp +++ b/Intersections_3/test/Intersections_3/test_intersections_Plane_3.cpp @@ -128,7 +128,8 @@ public: check_intersection(Pl(p(5,3,2), p(1,1,1), p(0,0,0)), P(99,99,99), P(99,99,99)); - if(this->has_exact_c) + // Homogeneous projections are broken + if(this->has_exact_c && std::is_same::value) { for(int i=0; i #include #include +#include #include #include - +#include template struct Point_3_intersection_tester @@ -85,7 +86,7 @@ public: R ray(p(-1,-1,-1), p(3,3,3)); check_intersection(ray, pt, pt); - if(this->has_exact_c) + if(this->has_exact_c && std::is_same::value) { for(int i=0; ihas_exact_c) + // @fixme Homogeneous' projection is broken + if(this->has_exact_c && std::is_same::value) { for(int i=0; ihas_exact_c) + if(this->has_exact_c && std::is_same::value) { for(int i=0; i Date: Fri, 6 Aug 2021 10:13:00 +0200 Subject: [PATCH 23/31] Remove useless sort --- .../internal/Tetrahedron_3_Triangle_3_intersection.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Intersections_3/include/CGAL/Intersections_3/internal/Tetrahedron_3_Triangle_3_intersection.h b/Intersections_3/include/CGAL/Intersections_3/internal/Tetrahedron_3_Triangle_3_intersection.h index f135007aa36..7444307adc7 100644 --- a/Intersections_3/include/CGAL/Intersections_3/internal/Tetrahedron_3_Triangle_3_intersection.h +++ b/Intersections_3/include/CGAL/Intersections_3/internal/Tetrahedron_3_Triangle_3_intersection.h @@ -38,8 +38,8 @@ void filter_segments(std::list& segments) return (l == r || l == r.opposite()); }; - segments.sort(are_equal); - segments.erase(std::unique(segments.begin(), segments.end(), are_equal), segments.end()); + auto it = std::unique(segments.begin(), segments.end(), are_equal); + segments.erase(it, segments.end()); } // plane going through the ref segment's source, a point above (given by the normal of the input From 6dfe06a286f1ccfd56be5b59fd75cd6fff891261 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mael=20Rouxel-Labb=C3=A9?= Date: Mon, 23 Aug 2021 11:49:45 +0200 Subject: [PATCH 24/31] Fix conversion warnings --- .../internal/Tetrahedron_3_Triangle_3_intersection.h | 10 +++++----- .../test/Intersections_3/intersection_test_helper.h | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Intersections_3/include/CGAL/Intersections_3/internal/Tetrahedron_3_Triangle_3_intersection.h b/Intersections_3/include/CGAL/Intersections_3/internal/Tetrahedron_3_Triangle_3_intersection.h index 7444307adc7..c3ff9d6e819 100644 --- a/Intersections_3/include/CGAL/Intersections_3/internal/Tetrahedron_3_Triangle_3_intersection.h +++ b/Intersections_3/include/CGAL/Intersections_3/internal/Tetrahedron_3_Triangle_3_intersection.h @@ -439,8 +439,8 @@ intersection(const typename K::Tetrahedron_3& tet, // Doesn't matter whether there is another (non-strictly) inside point: if there is, // it is an extremity of the segment - const std::size_t str_inside_pt_pos = - (std::find(vertex_sides.begin(), vertex_sides.end(), ON_BOUNDED_SIDE) - vertex_sides.begin()); + const int str_inside_pt_pos = + int(std::find(vertex_sides.begin(), vertex_sides.end(), ON_BOUNDED_SIDE) - vertex_sides.begin()); CGAL_assertion(str_inside_pt_pos >= 0 && str_inside_pt_pos < 3); Triangle_3 res_tr = triangle(vertex(tr, str_inside_pt_pos), s.source(), s.target()); @@ -478,8 +478,8 @@ intersection(const typename K::Tetrahedron_3& tet, CGAL_assertion(strictly_inside_points == 0); // Grab the inside point - const std::size_t boundary_pt_pos = - (std::find(vertex_sides.begin(), vertex_sides.end(), ON_BOUNDARY) - vertex_sides.begin()); + const int boundary_pt_pos = + int(std::find(vertex_sides.begin(), vertex_sides.end(), ON_BOUNDARY) - vertex_sides.begin()); CGAL_assertion(boundary_pt_pos >= 0 && boundary_pt_pos < 3); const Point_3& boundary_pt = vertex(tr, boundary_pt_pos); @@ -500,7 +500,7 @@ intersection(const typename K::Tetrahedron_3& tet, // 2 boundary points and 1 segment, have to distinguish between cases // depending on if the extremities of the segment are triangle extremities - std::array boundary_pts; + std::array boundary_pts; std::array is_boundary_point_an_extremity; // Grab the inside points diff --git a/Intersections_3/test/Intersections_3/intersection_test_helper.h b/Intersections_3/test/Intersections_3/intersection_test_helper.h index 9ee7caa8040..e3f8a9e7dcc 100644 --- a/Intersections_3/test/Intersections_3/intersection_test_helper.h +++ b/Intersections_3/test/Intersections_3/intersection_test_helper.h @@ -76,7 +76,7 @@ protected: bool has_exact_p; bool has_exact_c; - double m = 0, M = 100; + int m = 0, M = 100; bool verbose = true; From e1d6f75579538afe0b0b0bbe890001275eaca841 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mael=20Rouxel-Labb=C3=A9?= Date: Mon, 23 Aug 2021 11:49:54 +0200 Subject: [PATCH 25/31] Fix bad tests --- .../test/Intersections_3/test_intersections_Plane_3.cpp | 7 ++++++- .../test/Intersections_3/test_intersections_Sphere_3.cpp | 3 --- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/Intersections_3/test/Intersections_3/test_intersections_Plane_3.cpp b/Intersections_3/test/Intersections_3/test_intersections_Plane_3.cpp index c3b3fb28e54..565a1e697ad 100644 --- a/Intersections_3/test/Intersections_3/test_intersections_Plane_3.cpp +++ b/Intersections_3/test/Intersections_3/test_intersections_Plane_3.cpp @@ -239,6 +239,11 @@ public: if(pln.has_on(sph6)) continue; + // The sphere constructor will assert on degenerate positions + const Tet tet(pl0, sph6, sph5, sph4); + if(tet.is_degenerate()) + continue; + sph = Sph(pl0, sph6, sph5, sph4); check_intersection(pln, sph, C(pln, sph)); } @@ -439,7 +444,7 @@ int main(int, char**) std::cout << " |||||||| Test EPECK ||||||||" << std::endl; Plane_3_intersection_tester< CGAL::Epeck >(r, true /*exact predicates*/, true /*exact constructions*/).run(); - // FIXME BROKEN PROJECTION, BROKEN PLN-SPHERE + // See above // std::cout << " |||||||| Test CGAL::Homogeneous ||||||||" << std::endl; // Plane_3_intersection_tester< CGAL::Homogeneous >(r, true /*exact predicates*/, true /*exact constructions*/).run(); diff --git a/Intersections_3/test/Intersections_3/test_intersections_Sphere_3.cpp b/Intersections_3/test/Intersections_3/test_intersections_Sphere_3.cpp index 9ba7c91f09d..56b04367bd5 100644 --- a/Intersections_3/test/Intersections_3/test_intersections_Sphere_3.cpp +++ b/Intersections_3/test/Intersections_3/test_intersections_Sphere_3.cpp @@ -148,9 +148,6 @@ public: const FT r = this->r.get_int(this->m + 1, this->M); Sph sph(c, r); - if(c != tr1 && c != tr2) - check_do_intersect(sph, Tr(c, tr1, tr2)); - if(sph.oriented_side(tr0) != sph.oriented_side(tr1) || sph.oriented_side(tr0) != sph.oriented_side(tr2) || sph.oriented_side(tr2) != sph.oriented_side(tr1)) From cc6e76dd850dfd8ded31d469c34ca0f62addf315 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mael=20Rouxel-Labb=C3=A9?= Date: Tue, 24 Aug 2021 11:40:26 +0200 Subject: [PATCH 26/31] Lower verbosity of Intersection_3 tests --- Intersections_3/test/Intersections_3/intersection_test_helper.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Intersections_3/test/Intersections_3/intersection_test_helper.h b/Intersections_3/test/Intersections_3/intersection_test_helper.h index e3f8a9e7dcc..96e1a986270 100644 --- a/Intersections_3/test/Intersections_3/intersection_test_helper.h +++ b/Intersections_3/test/Intersections_3/intersection_test_helper.h @@ -78,7 +78,7 @@ protected: int m = 0, M = 100; - bool verbose = true; + bool verbose = false; public: Intersection_3_tester(CGAL::Random& r, From fe37492692dc9f74b009dbac9dc32d343a7f2c3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mael=20Rouxel-Labb=C3=A9?= Date: Wed, 25 Aug 2021 08:39:25 +0200 Subject: [PATCH 27/31] Remove debug print --- Intersections_3/test/Intersections_3/intersection_test_helper.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/Intersections_3/test/Intersections_3/intersection_test_helper.h b/Intersections_3/test/Intersections_3/intersection_test_helper.h index 96e1a986270..7a57839f3df 100644 --- a/Intersections_3/test/Intersections_3/intersection_test_helper.h +++ b/Intersections_3/test/Intersections_3/intersection_test_helper.h @@ -154,8 +154,6 @@ public: bool approx_equal(const S& p, const S& q) { - std::cout << "compare segments " << p << " & " << q << std::endl; - // allow opposite orientation return (approx_equal(p.source(), q.source()) && approx_equal(p.target(), q.target())) || (approx_equal(p.source(), q.target()) && approx_equal(p.target(), q.source())); From 5b94d2db56117cfd3b9ce89dc5ffc149fb236091 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mael=20Rouxel-Labb=C3=A9?= Date: Wed, 25 Aug 2021 14:52:22 +0200 Subject: [PATCH 28/31] Actually erase duplicate internal points --- .../internal/Tetrahedron_3_Triangle_3_intersection.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Intersections_3/include/CGAL/Intersections_3/internal/Tetrahedron_3_Triangle_3_intersection.h b/Intersections_3/include/CGAL/Intersections_3/internal/Tetrahedron_3_Triangle_3_intersection.h index c3ff9d6e819..272a07da6c0 100644 --- a/Intersections_3/include/CGAL/Intersections_3/internal/Tetrahedron_3_Triangle_3_intersection.h +++ b/Intersections_3/include/CGAL/Intersections_3/internal/Tetrahedron_3_Triangle_3_intersection.h @@ -124,7 +124,8 @@ build_intersection(const typename K::Tetrahedron_3& /*input_tetrahedron*/, return true; return false; }; - std::remove_if(points.begin(), points.end(), is_extremity); + points.erase(std::remove_if(points.begin(), points.end(), is_extremity), + points.end()); // Take the first segment as reference, and order the rest to form a convex polygon // From f0b00551f6f456253d658a90fcf2ef247b8736cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mael=20Rouxel-Labb=C3=A9?= Date: Sun, 29 Aug 2021 13:53:33 +0200 Subject: [PATCH 29/31] Fix constructing degenerate spheres in Plane_3 intersection tests --- .../test/Intersections_3/test_intersections_Plane_3.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Intersections_3/test/Intersections_3/test_intersections_Plane_3.cpp b/Intersections_3/test/Intersections_3/test_intersections_Plane_3.cpp index 565a1e697ad..9f6151dcba5 100644 --- a/Intersections_3/test/Intersections_3/test_intersections_Plane_3.cpp +++ b/Intersections_3/test/Intersections_3/test_intersections_Plane_3.cpp @@ -232,6 +232,10 @@ public: if(pln.has_on(sph5)) continue; + Tet tet{pl0, pl1, sph5, sph4}; + if(tet.is_degenerate()) + continue; + sph = Sph(pl0, pl1, sph5, sph4); check_intersection(pln, sph, C(pln, sph)); @@ -240,7 +244,7 @@ public: continue; // The sphere constructor will assert on degenerate positions - const Tet tet(pl0, sph6, sph5, sph4); + tet = Tet{pl0, sph6, sph5, sph4}; if(tet.is_degenerate()) continue; @@ -428,6 +432,8 @@ int main(int, char**) std::cout.precision(17); std::cerr.precision(17); + CGAL::Set_ieee_double_precision pfr; + CGAL::Random r; std::cout << "random seed = " << r.get_seed() << std::endl; From 529da2ff68a73cef98f7ab20177726492ac4e192 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mael=20Rouxel-Labb=C3=A9?= Date: Sun, 29 Aug 2021 13:54:01 +0200 Subject: [PATCH 30/31] Explicit the random seed in triangle/other tests --- .../triangle_other_intersection_test.cpp | 39 ++++++++++--------- 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/Intersections_3/test/Intersections_3/triangle_other_intersection_test.cpp b/Intersections_3/test/Intersections_3/triangle_other_intersection_test.cpp index ae3064c7e91..67f5197c695 100644 --- a/Intersections_3/test/Intersections_3/triangle_other_intersection_test.cpp +++ b/Intersections_3/test/Intersections_3/triangle_other_intersection_test.cpp @@ -17,8 +17,7 @@ #include #include - - +#include // ----------------------------------- // Kernels @@ -128,18 +127,19 @@ double random_in(const double a, } template -typename K::Point_3 random_point_in(const CGAL::Bbox_3& bbox) +typename K::Point_3 random_point_in(const CGAL::Bbox_3& bbox, + CGAL::Random& r) { typedef typename K::FT FT; - FT x = (FT)random_in(bbox.xmin(),bbox.xmax()); - FT y = (FT)random_in(bbox.ymin(),bbox.ymax()); - FT z = (FT)random_in(bbox.zmin(),bbox.zmax()); + FT x(r.get_double(bbox.xmin(), bbox.xmax())); + FT y(r.get_double(bbox.ymin(), bbox.ymax())); + FT z(r.get_double(bbox.zmin(), bbox.zmax())); return typename K::Point_3(x,y,z); } // random_test() template -void random_test() +void random_test(CGAL::Random& r) { typedef typename K::Point_3 Point; typedef typename K::Segment_3 Segment; @@ -158,9 +158,9 @@ void random_test() // Use 10 triangles, 100 queries for each triangle for ( int i=0 ; i<10 ; ++i ) { - Triangle t(random_point_in(bbox), - random_point_in(bbox), - random_point_in(bbox)); + Triangle t(random_point_in(bbox, r), + random_point_in(bbox, r), + random_point_in(bbox, r)); if ( is_degenerate(t) ) continue; @@ -169,8 +169,8 @@ void random_test() for ( int j=0 ; j<100 ; ++j ) { - Point a = random_point_in(bbox); - Point b = random_point_in(bbox); + Point a = random_point_in(bbox, r); + Point b = random_point_in(bbox, r); Segment s (a,b); Ray r(a,b); @@ -597,6 +597,9 @@ bool test(bool is_kernel_exact = true) // ----------------------------------- int main() { + CGAL::Random r; + std::cout << "random seed = " << r.get_seed() << std::endl; + // ----------------------------------- // Test intersection results // ----------------------------------- @@ -630,22 +633,22 @@ int main() srand( static_cast(time(nullptr)) ); std::cout << std::endl << "Test random intersections" << std::endl; std::cout << "\tTesting with Simple_cartesian..." << std::endl ; - random_test(); + random_test(r); std::cout << "\tTesting with Simple_cartesian..." << std::endl ; - random_test(); + random_test(r); std::cout << "\tTesting with Cartesian..." << std::endl ; - random_test(); + random_test(r); std::cout << "\tTesting with Cartesian..." << std::endl ; - random_test(); + random_test(r); std::cout << "\tTesting with Exact_predicates_inexact_constructions_kernel..." << std::endl ; - random_test(); + random_test(r); std::cout << "\tTesting with Exact_predicates_exact_constructions_kernel..." << std::endl ; - random_test(); + random_test(r); if ( b ) { return EXIT_SUCCESS; From d61680e324e80ad583588cf830bc95dcd44056d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mael=20Rouxel-Labb=C3=A9?= Date: Tue, 31 Aug 2021 08:45:35 +0200 Subject: [PATCH 31/31] Fix warning --- .../Intersections_3/triangle_other_intersection_test.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Intersections_3/test/Intersections_3/triangle_other_intersection_test.cpp b/Intersections_3/test/Intersections_3/triangle_other_intersection_test.cpp index 67f5197c695..5093b6348db 100644 --- a/Intersections_3/test/Intersections_3/triangle_other_intersection_test.cpp +++ b/Intersections_3/test/Intersections_3/triangle_other_intersection_test.cpp @@ -131,9 +131,9 @@ typename K::Point_3 random_point_in(const CGAL::Bbox_3& bbox, CGAL::Random& r) { typedef typename K::FT FT; - FT x(r.get_double(bbox.xmin(), bbox.xmax())); - FT y(r.get_double(bbox.ymin(), bbox.ymax())); - FT z(r.get_double(bbox.zmin(), bbox.zmax())); + FT x = static_cast(r.get_double(bbox.xmin(), bbox.xmax())); + FT y = static_cast(r.get_double(bbox.ymin(), bbox.ymax())); + FT z = static_cast(r.get_double(bbox.zmin(), bbox.zmax())); return typename K::Point_3(x,y,z); }