WIP review

This commit is contained in:
Maxime Gimeno 2019-10-04 15:30:52 +02:00
parent 9ede1f3ee7
commit 3c875e8a18
11 changed files with 58 additions and 55 deletions

View File

@ -39,18 +39,17 @@ do_intersect(const CGAL::Bbox_2& c,
return CGAL::do_overlap(c, bbox); return CGAL::do_overlap(c, bbox);
} }
typename boost::optional< typename typename boost::optional< typename boost::variant< Bbox_2> >
boost::variant< Bbox_2> >
inline inline
intersection(const CGAL::Bbox_2& a, intersection(const CGAL::Bbox_2& a,
const CGAL::Bbox_2& b) { const CGAL::Bbox_2& b) {
typedef typename typedef typename
boost::variant< Bbox_2> variant_type; boost::variant< Bbox_2> variant_type;
typedef typename boost::optional< variant_type > Result_type; typedef typename boost::optional< variant_type > result_type;
if(!do_intersect(a,b)) if(!do_intersect(a,b))
{ {
return Result_type(); return result_type();
} }
double xmin, xmax, ymin, ymax; double xmin, xmax, ymin, ymax;
@ -60,7 +59,7 @@ intersection(const CGAL::Bbox_2& a,
ymin = (std::max)(a.ymin(), b.ymin()); ymin = (std::max)(a.ymin(), b.ymin());
ymax = (std::min)(a.ymax(), b.ymax()); ymax = (std::min)(a.ymax(), b.ymax());
return Result_type(std::forward<Bbox_2>(Bbox_2(xmin, ymin, xmax, ymax))); return result_type(std::forward<Bbox_2>(Bbox_2(xmin, ymin, xmax, ymax)));
} }
} }

View File

@ -25,8 +25,6 @@
#include <CGAL/Bbox_2.h> #include <CGAL/Bbox_2.h>
#include <CGAL/Iso_rectangle_2.h> #include <CGAL/Iso_rectangle_2.h>
#include <CGAL/kernel_assertions.h>
#include <CGAL/number_utils.h>
#include <CGAL/Intersections_2/Iso_rectangle_2_Iso_rectangle_2.h> #include <CGAL/Intersections_2/Iso_rectangle_2_Iso_rectangle_2.h>
namespace CGAL { namespace CGAL {
@ -34,35 +32,34 @@ namespace CGAL {
template <class K> template <class K>
inline bool do_intersect( inline bool do_intersect(
const Iso_rectangle_2<K> &line, const Iso_rectangle_2<K> &rect,
const Bbox_2 &box) const Bbox_2 &box)
{ {
typename K::Iso_rectangle_2 rec(box.xmin(), box.ymin(), box.xmax(), box.ymax()); return do_intersect(K::Iso_rectangle_2(box), rect);
return do_intersect(rec, line);
} }
template <class K> template <class K>
inline bool do_intersect( inline bool do_intersect(
const Bbox_2 &box, const Bbox_2 &box,
const Iso_rectangle_2<K> &line) const Iso_rectangle_2<K> &rect)
{ {
return do_intersect(line, box); return do_intersect(rect, box);
} }
template<typename K> template<typename K>
typename Intersection_traits<K, typename K::Iso_rectangle_2, Bbox_2>::result_type typename Intersection_traits<K, typename K::Iso_rectangle_2, Bbox_2>::result_type
intersection(const CGAL::Bbox_2& box, intersection(const Bbox_2& box,
const Iso_rectangle_2<K>& line) { const Iso_rectangle_2<K>& rect) {
typename K::Iso_rectangle_2 rec(box.xmin(), box.ymin(), box.xmax(), box.ymax()); typename K::Iso_rectangle_2 rec(box.xmin(), box.ymin(), box.xmax(), box.ymax());
return intersection(rec, line); return intersection(rec, rect);
} }
template<typename K> template<typename K>
typename Intersection_traits<K, typename K::Iso_rectangle_2, Bbox_2>::result_type typename Intersection_traits<K, typename K::Iso_rectangle_2, Bbox_2>::result_type
intersection(const Iso_rectangle_2<K>& line, intersection(const Iso_rectangle_2<K>& rect,
const CGAL::Bbox_2& box) { const Bbox_2& box) {
return intersection(box, line); return intersection(box, rect);
} }
} }
#endif // BBOX_2_ISO_RECTANGLE_2_H #endif // CGAL_INTERSECTIONS_BBOX_2_ISO_RECTANGLE_2_H

View File

@ -28,7 +28,6 @@
#include <CGAL/Intersections_2/Iso_rectangle_2_Point_2.h> #include <CGAL/Intersections_2/Iso_rectangle_2_Point_2.h>
namespace CGAL { namespace CGAL {
namespace Intersections { namespace Intersections {
namespace internal { namespace internal {

View File

@ -25,8 +25,6 @@
#include <CGAL/Bbox_2.h> #include <CGAL/Bbox_2.h>
#include <CGAL/Segment_2.h> #include <CGAL/Segment_2.h>
#include <CGAL/kernel_assertions.h>
#include <CGAL/number_utils.h>
#include <CGAL/Intersections_2/Iso_rectangle_2_Segment_2.h> #include <CGAL/Intersections_2/Iso_rectangle_2_Segment_2.h>
namespace CGAL { namespace CGAL {
@ -34,35 +32,35 @@ namespace CGAL {
template <class K> template <class K>
inline bool do_intersect( inline bool do_intersect(
const Segment_2<K> &line, const Segment_2<K> &seg,
const Bbox_2 &box) const Bbox_2 &box)
{ {
typename K::Iso_rectangle_2 rec(box.xmin(), box.ymin(), box.xmax(), box.ymax()); typename K::Iso_rectangle_2 rec(box.xmin(), box.ymin(), box.xmax(), box.ymax());
return do_intersect(rec, line); return do_intersect(rec, seg);
} }
template <class K> template <class K>
inline bool do_intersect( inline bool do_intersect(
const Bbox_2 &box, const Bbox_2 &box,
const Segment_2<K> &line) const Segment_2<K> &seg)
{ {
return do_intersect(line, box); return do_intersect(seg, box);
} }
template<typename K> template<typename K>
typename Intersection_traits<K, typename K::Segment_2, Bbox_2>::result_type typename Intersection_traits<K, typename K::Segment_2, Bbox_2>::result_type
intersection(const CGAL::Bbox_2& box, intersection(const CGAL::Bbox_2& box,
const Segment_2<K>& line) { const Segment_2<K>& seg) {
typename K::Iso_rectangle_2 rec(box.xmin(), box.ymin(), box.xmax(), box.ymax()); typename K::Iso_rectangle_2 rec(box.xmin(), box.ymin(), box.xmax(), box.ymax());
return intersection(rec, line); return intersection(rec, seg);
} }
template<typename K> template<typename K>
typename Intersection_traits<K, typename K::Segment_2, Bbox_2>::result_type typename Intersection_traits<K, typename K::Segment_2, Bbox_2>::result_type
intersection(const Segment_2<K>& line, intersection(const Segment_2<K>& seg,
const CGAL::Bbox_2& box) { const CGAL::Bbox_2& box) {
return intersection(box, line); return intersection(box, seg);
} }
} }
#endif // BBOX_2_SEGMENT_2_H #endif // CGAL_INTERSECTIONS_BBOX_2_SEGMENT_2_H

View File

@ -25,8 +25,6 @@
#include <CGAL/Bbox_2.h> #include <CGAL/Bbox_2.h>
#include <CGAL/Triangle_2.h> #include <CGAL/Triangle_2.h>
#include <CGAL/kernel_assertions.h>
#include <CGAL/number_utils.h>
#include <CGAL/Intersections_2/Iso_rectangle_2_Triangle_2.h> #include <CGAL/Intersections_2/Iso_rectangle_2_Triangle_2.h>
namespace CGAL { namespace CGAL {
@ -34,35 +32,35 @@ namespace CGAL {
template <class K> template <class K>
inline bool do_intersect( inline bool do_intersect(
const Triangle_2<K> &line, const Triangle_2<K> &tr,
const Bbox_2 &box) const Bbox_2 &box)
{ {
typename K::Iso_rectangle_2 rec(box.xmin(), box.ymin(), box.xmax(), box.ymax()); typename K::Iso_rectangle_2 rec(box.xmin(), box.ymin(), box.xmax(), box.ymax());
return do_intersect(rec, line); return do_intersect(rec, tr);
} }
template <class K> template <class K>
inline bool do_intersect( inline bool do_intersect(
const Bbox_2 &box, const Bbox_2 &box,
const Triangle_2<K> &line) const Triangle_2<K> &tr)
{ {
return do_intersect(line, box); return do_intersect(tr, box);
} }
template<typename K> template<typename K>
typename Intersection_traits<K, typename K::Triangle_2, Bbox_2>::result_type typename Intersection_traits<K, typename K::Triangle_2, Bbox_2>::result_type
intersection(const CGAL::Bbox_2& box, intersection(const Bbox_2& box,
const Triangle_2<K>& line) { const Triangle_2<K>& tr) {
typename K::Iso_rectangle_2 rec(box.xmin(), box.ymin(), box.xmax(), box.ymax()); typename K::Iso_rectangle_2 rec(box.xmin(), box.ymin(), box.xmax(), box.ymax());
return intersection(rec, line); return intersection(rec, tr);
} }
template<typename K> template<typename K>
typename Intersection_traits<K, typename K::Triangle_2, Bbox_2>::result_type typename Intersection_traits<K, typename K::Triangle_2, Bbox_2>::result_type
intersection(const Triangle_2<K>& line, intersection(const Triangle_2<K>& tr,
const CGAL::Bbox_2& box) { const Bbox_2& box) {
return intersection(box, line); return intersection(box, tr);
} }
} }
#endif // BBOX_2_TRIANGLE_2_H #endif // CGAL_INTERSECTIONS_BBOX_2_TRIANGLE_2_H

View File

@ -30,6 +30,7 @@
namespace CGAL { namespace CGAL {
namespace Intersections { namespace Intersections {
namespace internal { namespace internal {
template <class K> template <class K>
bool bool
do_intersect(const typename K::Circle_2 & c, do_intersect(const typename K::Circle_2 & c,

View File

@ -30,6 +30,7 @@
namespace CGAL { namespace CGAL {
namespace Intersections { namespace Intersections {
namespace internal { namespace internal {
template <class K> template <class K>
bool bool
do_intersect(const typename K::Circle_2 & c, do_intersect(const typename K::Circle_2 & c,

View File

@ -30,6 +30,7 @@
namespace CGAL { namespace CGAL {
namespace Intersections { namespace Intersections {
namespace internal { namespace internal {
template <class K> template <class K>
bool bool
do_intersect(const typename K::Circle_2 & c, do_intersect(const typename K::Circle_2 & c,

View File

@ -329,9 +329,9 @@ Triangle_2_Triangle_2_pair<K>::intersection_point() const
//algorithm taken from here : https://stackoverflow.com/questions/1165647/how-to-determine-if-a-list-of-polygon-points-are-in-clockwise-order //algorithm taken from here : https://stackoverflow.com/questions/1165647/how-to-determine-if-a-list-of-polygon-points-are-in-clockwise-order
template <typename K, typename ArrayOfPoints, typename Exact> template <typename K, typename Exact>
struct Is_cw{ struct Is_cw{
bool operator()(const ArrayOfPoints& ps) bool operator()(const std::vector<typename K::Point_2>& ps)
{ {
typename K::FT res(0); typename K::FT res(0);
std::size_t length = ps.size(); std::size_t length = ps.size();
@ -343,9 +343,9 @@ bool operator()(const ArrayOfPoints& ps)
} }
}; };
template <typename K, typename ArrayOfPoints> template <typename K>
struct Is_cw<K, ArrayOfPoints,Tag_true>{ struct Is_cw<K,Tag_true>{
bool operator()(const ArrayOfPoints& ps) bool operator()(const std::vector<typename K::Point_2>& ps)
{ {
return !CGAL::left_turn(ps[0], ps[1], ps[2]); return !CGAL::left_turn(ps[0], ps[1], ps[2]);
} }
@ -378,7 +378,7 @@ intersection(const typename K::Triangle_2 &tr1,
for (int i =0; i < ispair.vertex_count(); i++) { for (int i =0; i < ispair.vertex_count(); i++) {
points[i] = ispair.vertex(i); points[i] = ispair.vertex(i);
} }
if(Is_cw<K, Container, typename Algebraic_structure_traits<typename K::FT>::Is_exact>()(points)) if(Is_cw<K, typename Algebraic_structure_traits<typename K::FT>::Is_exact>()(points))
{ {
std::size_t length = points.size(); std::size_t length = points.size();

View File

@ -98,7 +98,7 @@ struct Test
{ {
if (p.size() != q.size()) if (p.size() != q.size())
return false; return false;
if (CGAL::Intersections::internal::Is_cw<K, Pol, if (CGAL::Intersections::internal::Is_cw<K,
typename CGAL::Algebraic_structure_traits<typename K::FT>::Is_exact>()(p)) typename CGAL::Algebraic_structure_traits<typename K::FT>::Is_exact>()(p))
return false; return false;
for(typename Pol::const_iterator itp = p.begin(), itq = q.begin(); itp != p.end(); ++itp, ++itq) for(typename Pol::const_iterator itp = p.begin(), itq = q.begin(); itp != p.end(); ++itp, ++itq)
@ -110,9 +110,12 @@ struct Test
bool approx_equal(const T & p, const T & q) bool approx_equal(const T & p, const T & q)
{ {
std::vector<P> vec(3); if(p.size() != q.size())
for(int i=0; i<3; ++i){vec[i]=p[i];} return false;
if (CGAL::Intersections::internal::Is_cw<K, std::vector<P>,
std::vector<P> vec { p[0], p[1], p[2] };
if (CGAL::Intersections::internal::Is_cw<K,
typename CGAL::Algebraic_structure_traits<typename K::FT>::Is_exact>(vec)) typename CGAL::Algebraic_structure_traits<typename K::FT>::Is_exact>(vec))
return false; return false;
return p == q; return p == q;
@ -336,11 +339,15 @@ struct Test
check_no_do_intersect (C(p( 2, 8), 6), S(p(-3, -2), p( 2, -4))); check_no_do_intersect (C(p( 2, 8), 6), S(p(-3, -2), p( 2, -4)));
check_no_do_intersect (C(p( 2, 8), 6), S(p(-3, 22), p( 2, 34))); check_no_do_intersect (C(p( 2, 8), 6), S(p(-3, 22), p( 2, 34)));
check_no_do_intersect (C(p( 2, 8), 9), S(p(2.5, 3.5), p(3, 4)));
check_do_intersect (C(p( 3, 4), 0), S(p(-3, 8), p( 6, 2))); check_do_intersect (C(p( 3, 4), 0), S(p(-3, 8), p( 6, 2)));
check_do_intersect (C(p( 4, 3), 4), S(p( 6, -7), p( 5, 2))); check_do_intersect (C(p( 4, 3), 4), S(p( 6, -7), p( 5, 2)));
check_do_intersect (C(p(-3, 1), 7), S(p(-1, -3), p(-6, 7))); check_do_intersect (C(p(-3, 1), 7), S(p(-1, -3), p(-6, 7)));
check_do_intersect (C(p(1, 1), 4), S(p(-1, 1), p(-6, -8)));
check_do_intersect (C(p(1, 1), 4), S(p(-1, 4), p(-1, -4)));
} }
void C_R() void C_R()
@ -360,6 +367,7 @@ struct Test
{ {
std::cout << "Circle - Triangle" << std::endl; std::cout << "Circle - Triangle" << std::endl;
check_no_do_intersect (C(p( 2, 8), 6), T(p(6,0), p( 8, 0), p(8,2))); check_no_do_intersect (C(p( 2, 8), 6), T(p(6,0), p( 8, 0), p(8,2)));
check_no_do_intersect (C(p( 0, 0), 9), T(p(1,1), p( 1, -1), p(0.1,0.1)));
check_do_intersect (C(p( 3, 4), 0), T(p(-3, 8), p( 6, 2), p(4,6))); check_do_intersect (C(p( 3, 4), 0), T(p(-3, 8), p( 6, 2), p(4,6)));
check_do_intersect (C(p( 4, 3), 4), T(p( 6, -7), p( 5, 2), p(2,-3))); check_do_intersect (C(p( 4, 3), 4), T(p( 6, -7), p( 5, 2), p(2,-3)));

View File

@ -39,9 +39,10 @@ CGAL_INTERSECTION_TRAITS_2(Line_3, Segment_3, Point_3, Segment_3)
CGAL_INTERSECTION_TRAITS_2(Segment_3, Line_3, Point_3, Segment_3) CGAL_INTERSECTION_TRAITS_2(Segment_3, Line_3, Point_3, Segment_3)
CGAL_INTERSECTION_TRAITS_2(Line_3, Triangle_3, Point_3, Segment_3) CGAL_INTERSECTION_TRAITS_2(Line_3, Triangle_3, Point_3, Segment_3)
CGAL_INTERSECTION_TRAITS_2(Line_3, Tetrahedron_3, Point_3, Segment_3)
CGAL_INTERSECTION_TRAITS_2(Triangle_3, Line_3, Point_3, Segment_3) CGAL_INTERSECTION_TRAITS_2(Triangle_3, Line_3, Point_3, Segment_3)
CGAL_INTERSECTION_TRAITS_2(Line_3, Tetrahedron_3, Point_3, Segment_3)
CGAL_INTERSECTION_TRAITS_2(Plane_3, Plane_3, Line_3, Plane_3) CGAL_INTERSECTION_TRAITS_2(Plane_3, Plane_3, Line_3, Plane_3)
CGAL_INTERSECTION_TRAITS_2(Plane_3, Ray_3, Point_3, Ray_3) CGAL_INTERSECTION_TRAITS_2(Plane_3, Ray_3, Point_3, Ray_3)