Add the remaining missing functions

This commit is contained in:
Andreas Fabri 2018-02-05 15:46:23 +00:00
parent 5d5f4d0a3d
commit 12a5cd9f82
6 changed files with 429 additions and 13 deletions

View File

@ -27,6 +27,7 @@
#define CGAL_TRIANGLE_3_TETRAHEDRON_3_DO_INTERSECT_H
#include <CGAL/Triangle_3_Triangle_3_do_intersect.h>
#include <CGAL/internal/Intersections_3/Iso_cuboid_3_Triangle_3_do_intersect.h>
namespace CGAL {
@ -36,11 +37,12 @@ namespace CGAL {
namespace internal {
// This code is not optimized:
template <class K>
template <class K, class Bounded>
typename K::Boolean
do_intersect(const typename K::Triangle_3 &tr,
const typename K::Tetrahedron_3 &tet,
const K & k)
do_intersect_tetrahedron_bounded(const typename Bounded &tr,
const typename K::Tetrahedron_3 &tet,
const typename K::Point_3 p,
const K & k)
{
typedef typename K::Triangle_3 Triangle;
@ -52,12 +54,7 @@ do_intersect(const typename K::Triangle_3 &tr,
if (do_intersect(tr, Triangle(tet[0], tet[2], tet[3]), k)) return true;
if (do_intersect(tr, Triangle(tet[1], tet[2], tet[3]), k)) return true;
CGAL_kernel_assertion(k.bounded_side_3_object()(tet, tr[0]) ==
k.bounded_side_3_object()(tet, tr[1]));
CGAL_kernel_assertion(k.bounded_side_3_object()(tet, tr[0]) ==
k.bounded_side_3_object()(tet, tr[2]));
return k.has_on_bounded_side_3_object()(tet, tr[0]);
return k.has_on_bounded_side_3_object()(tet, p);
}
@ -68,12 +65,134 @@ do_intersect(const typename K::Tetrahedron_3 &tet,
const typename K::Triangle_3 &tr,
const K & k)
{
return do_intersect(tr, tet, k);
return do_intersect_tetrahedron_bounded(tr, tet, tr[0], k);
}
template <class K>
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 <class K>
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 <class K>
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 <class K>
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 <class K>
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 <class K>
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 <class K>
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 <class K>
inline
typename K::Boolean
do_intersect(const typename K::Tetrahedron_3 &tet,
const typename K::Tetrahedron_3 &sp,
const K & k)
{
return do_intersect_tetrahedron_bounded(sp, tet, tet[0], k);
}
template <class K>
inline
typename K::Boolean
do_intersect(const typename K::Tetrahedron_3 &tet,
const typename Bbox_3 &bb,
const K & k)
{
return do_intersect_tetrahedron_bounded(bb, tet, typename K::Point_3(bb.xmin(), bb.ymin(), bb.zmin()), k);
}
template <class K>
inline
typename K::Boolean
do_intersect(const typename Bbox_3 &bb,
const typename K::Tetrahedron_3 &tet,
const K & k)
{
return do_intersect_tetrahedron_bounded(bb, tet, typename K::Point_3(bb.xmin(), bb.ymin(), bb.zmin()), k);
}
} // namespace internal
CGAL_DO_INTERSECT_FUNCTION(Triangle_3, Tetrahedron_3, 3)
CGAL_DO_INTERSECT_FUNCTION(Segment_3, Tetrahedron_3, 3)
CGAL_DO_INTERSECT_FUNCTION(Iso_cuboid_3, Tetrahedron_3, 3)
CGAL_DO_INTERSECT_FUNCTION(Sphere_3, Tetrahedron_3, 3)
CGAL_DO_INTERSECT_FUNCTION_SELF(Tetrahedron_3, 3)
template<typename K>
bool do_intersect(const CGAL::Tetrahedron_3<K>& a,
const CGAL::Bbox_3& b) {
return K().do_intersect_3_object()(a, b);
}
template<typename K>
bool do_intersect(const CGAL::Bbox_3& b,
const CGAL::Tetrahedron_3<K>& a) {
return K().do_intersect_3_object()(a, b);
}
} //namespace CGAL

View File

@ -0,0 +1,116 @@
// Copyright (c) 2018 GeometryFactory Sarl (France).
// All rights reserved.
//
// This file is part of CGAL (www.cgal.org); you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public License as
// published by the Free Software Foundation; either version 3 of the License,
// or (at your option) any later version.
//
// Licensees holding a valid commercial license may use this file in
// accordance with the commercial license agreement provided with the software.
//
// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
//
// $URL$
// $Id$
// SPDX-License-Identifier: LGPL-3.0+
//
//
// Author(s) : Andreas Fabri
#ifndef CGAL_INTERNAL_INTERSECTIONS_3_TETRAHEDRON_3_DO_INTERSECT_H
#define CGAL_INTERNAL_INTERSECTIONS_3_TETRAHEDRON_3_DO_INTERSECT_H
#include <CGAL/Tetrahedron_3.h>
#include <CGAL/Plane_3.h>
#include <CGAL/Line_3.h>
#include <CGAL/Ray_3.h>
namespace CGAL {
namespace internal {
template<typename K, class Unbounded>
bool do_intersect_tetrahedron_unbounded(const typename K::Tetrahedron_3& tet,
const Unbounded& unb,
const K& k) {
if (do_intersect(unb, Triangle(tet[0], tet[1], tet[2]), k)) return true;
if (do_intersect(unb, Triangle(tet[0], tet[1], tet[3]), k)) return true;
if (do_intersect(unb, Triangle(tet[0], tet[2], tet[3]), k)) return true;
if (do_intersect(unb, Triangle(tet[1], tet[2], tet[3]), k)) return true;
return false;
}
template<typename K>
bool do_intersect(const typename K::Tetrahedron_3& tet,
const typename K::Plane_3& unb,
const K& k) {
return do_intersect_tetrahedron_unbounded(tet, unb, k);
}
template<typename K>
bool do_intersect(const typename K::Tetrahedron_3& tet,
const typename K::Line_3& unb,
const K& k) {
return do_intersect_tetrahedron_unbounded(tet, unb, k);
}
template<typename K>
bool do_intersect(const typename K::Tetrahedron_3& tet,
const typename K::Ray_3& unb,
const K& k) {
return do_intersect_tetrahedron_unbounded(tet, unb, k);
}
} // namespace internal
template<typename K>
bool do_intersect(const CGAL::Tetrahedron_3<K>& a,
const CGAL::Plane_3<K>& b) {
return K().do_intersect_3_object()(a, b);
}
template<typename K>
bool do_intersect(const CGAL::Plane_3<K>& b,
const CGAL::Tetrahedron_3<K>& a) {
return K().do_intersect_3_object()(a, b);
}
template<typename K>
bool do_intersect(const CGAL::Tetrahedron_3<K>& a,
const CGAL::Line_3<K>& b) {
return K().do_intersect_3_object()(a, b);
}
template<typename K>
bool do_intersect(const CGAL::Line_3<K>& b,
const CGAL::Tetrahedron_3<K>& a) {
return K().do_intersect_3_object()(a, b);
}
template<typename K>
bool do_intersect(const CGAL::Tetrahedron_3<K>& a,
const CGAL::Ray_3<K>& b) {
return K().do_intersect_3_object()(a, b);
}
template<typename K>
bool do_intersect(const CGAL::Ray_3<K>& b,
const CGAL::Tetrahedron_3<K>& a) {
return K().do_intersect_3_object()(a, b);
}
} // namespace CGAL
#endif CGAL_INTERNAL_INTERSECTIONS_3_TETRAHEDRON_3_DO_INTERSECT_H

View File

@ -0,0 +1,125 @@
// Copyright (c) 2018 GeometryFactory Sarl
// All rights reserved.
//
// This file is part of CGAL (www.cgal.org); you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public License as
// published by the Free Software Foundation; either version 3 of the License,
// or (at your option) any later version.
//
// Licensees holding a valid commercial license may use this file in
// accordance with the commercial license agreement provided with the software.
//
// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
//
// $URL$
// $Id$
// SPDX-License-Identifier: LGPL-3.0+
//
//
// Author(s) : Andreas Fabri
#ifndef CGAL_TRIANGLE_3_SPHERE_3_DO_INTERSECT_H
#define CGAL_TRIANGLE_3_SPHERE_3_DO_INTERSECT_H
#include <CGAL/squared_distance_3_2.h>
#include <CGAL/Intersection_traits_3.h>
namespace CGAL {
template <class K>
class Triangle_3;
template <class K>
class Sphere_3;
template <class K>
class Line_3;
namespace internal {
template <class K>
inline
typename K::Boolean
do_intersect(const typename K::Sphere_3 &sp,
const typename K::Triangle_3 &tr,
const K & k)
{
return squared_distance(sp.center(), tr) <= sp.squared_radius();
}
template <class K>
inline
typename K::Boolean
do_intersect(const typename K::Sphere_3 &sp,
const typename K::Line_3 &lin,
const K & k)
{
return squared_distance(sp.center(), lin) <= sp.squared_radius();
}
template <class K>
inline
typename K::Boolean
do_intersect(const typename K::Line_3 &lin,
const typename K::Sphere_3 &sp,
const K & k)
{
return squared_distance(sp.center(), lin) <= sp.squared_radius();
}
template <class K>
inline
typename K::Boolean
do_intersect(const typename K::Sphere_3 &sp,
const typename K::Ray_3 &lin,
const K & k)
{
return squared_distance(sp.center(), lin) <= sp.squared_radius();
}
template <class K>
inline
typename K::Boolean
do_intersect(const typename K::Ray_3 &lin,
const typename K::Sphere_3 &sp,
const K & k)
{
return squared_distance(sp.center(), lin) <= sp.squared_radius();
}
template <class K>
inline
typename K::Boolean
do_intersect(const typename K::Sphere_3 &sp,
const typename K::Segment_3 &lin,
const K & k)
{
return squared_distance(sp.center(), lin) <= sp.squared_radius();
}
template <class K>
inline
typename K::Boolean
do_intersect(const typename K::Segment_3 &lin,
const typename K::Sphere_3 &sp,
const K & k)
{
return squared_distance(sp.center(), lin) <= sp.squared_radius();
}
} // namespace internal
CGAL_DO_INTERSECT_FUNCTION(Triangle_3, Sphere_3, 3)
CGAL_DO_INTERSECT_FUNCTION(Line_3, Sphere_3, 3)
CGAL_DO_INTERSECT_FUNCTION(Ray_3, Sphere_3, 3)
CGAL_DO_INTERSECT_FUNCTION(Segment_3, Sphere_3, 3)
} // namespace CGAL
#endif CGAL_TRIANGLE_3_SPHERE_3_DO_INTERSECT_H

View File

@ -64,6 +64,8 @@
#include <CGAL/internal/Intersections_3/Iso_cuboid_3_Ray_3_do_intersect.h>
#include <CGAL/internal/Intersections_3/Iso_cuboid_3_Sphere_3_do_intersect.h>
#include <CGAL/internal/Intersections_3/Iso_cuboid_3_Triangle_3_do_intersect.h>
#include <CGAL/internal/Intersections_3/Tetrahedron_3_do_intersect.h>
#include <CGAL/internal/Intersections_3/Triangle_3_Sphere_3_do_intersect.h>
#include <CGAL/enable_warnings.h>

View File

@ -0,0 +1,56 @@
#include <cassert>
#include <CGAL/Cartesian.h>
#include <CGAL/intersections.h>
typedef CGAL::Cartesian<double> K;
typedef K::Tetrahedron_3 Tetrahedron;
typedef K::Segment_3 Segment;
typedef K::Triangle_3 Triangle;
typedef K::Iso_cuboid_3 Iso_cuboid;
typedef K::Sphere_3 Sphere;
typedef K::Plane_3 Plane;
typedef K::Line_3 Line;
typedef K::Ray_3 Ray;
typedef CGAL::Bbox_3 Bbox;
int main()
{
Tetrahedron tet;
Sphere sp;
CGAL::do_intersect(tet,Triangle());
CGAL::do_intersect(tet,Segment());
CGAL::do_intersect(tet,Iso_cuboid());
CGAL::do_intersect(tet,Sphere());
CGAL::do_intersect(tet,Plane());
CGAL::do_intersect(tet,Line());
CGAL::do_intersect(tet,Ray());
CGAL::do_intersect(tet,tet);
CGAL::do_intersect(tet,Bbox());
CGAL::do_intersect(sp, Line());
CGAL::do_intersect(sp, Ray());
CGAL::do_intersect(sp, Segment());
CGAL::do_intersect(Triangle(), tet);
CGAL::do_intersect(Segment(), tet);
CGAL::do_intersect(Iso_cuboid(), tet);
CGAL::do_intersect(Sphere(), tet);
CGAL::do_intersect(Plane(), tet);
CGAL::do_intersect(Line(), tet);
CGAL::do_intersect(Ray(), tet);
CGAL::do_intersect(Bbox(), tet);
CGAL::do_intersect(Line(), sp);
CGAL::do_intersect(Ray(), sp);
CGAL::do_intersect(Segment(), sp);
return 0;
}

View File

@ -1,7 +1,5 @@
#include <cassert>
#include <CGAL/basic.h>
#include <CGAL/Cartesian.h>
#include <CGAL/Triangle_2_Triangle_2_do_intersect.h>
#include <CGAL/Triangle_3_Line_3_do_intersect.h>