From 3c875e8a188c00d6142aae7ae3977e58cecfbe0f Mon Sep 17 00:00:00 2001 From: Maxime Gimeno Date: Fri, 4 Oct 2019 15:30:52 +0200 Subject: [PATCH] WIP review --- .../CGAL/Intersections_2/Bbox_2_Bbox_2.h | 9 +++---- .../Intersections_2/Bbox_2_Iso_rectangle_2.h | 25 ++++++++----------- .../CGAL/Intersections_2/Bbox_2_Point_2.h | 1 - .../CGAL/Intersections_2/Bbox_2_Segment_2.h | 20 +++++++-------- .../CGAL/Intersections_2/Bbox_2_Triangle_2.h | 24 ++++++++---------- .../CGAL/Intersections_2/Circle_2_Ray_2.h | 1 + .../CGAL/Intersections_2/Circle_2_Segment_2.h | 1 + .../Intersections_2/Circle_2_Triangle_2.h | 1 + .../Triangle_2_Triangle_2_intersection_impl.h | 12 ++++----- .../Intersections_2/test_intersections_2.cpp | 16 +++++++++--- .../include/CGAL/Intersection_traits_3.h | 3 ++- 11 files changed, 58 insertions(+), 55 deletions(-) diff --git a/Intersections_2/include/CGAL/Intersections_2/Bbox_2_Bbox_2.h b/Intersections_2/include/CGAL/Intersections_2/Bbox_2_Bbox_2.h index 90fdc2495e4..3ccbcad3c61 100644 --- a/Intersections_2/include/CGAL/Intersections_2/Bbox_2_Bbox_2.h +++ b/Intersections_2/include/CGAL/Intersections_2/Bbox_2_Bbox_2.h @@ -39,18 +39,17 @@ do_intersect(const CGAL::Bbox_2& c, return CGAL::do_overlap(c, bbox); } -typename boost::optional< typename -boost::variant< Bbox_2> > +typename boost::optional< typename boost::variant< Bbox_2> > inline intersection(const CGAL::Bbox_2& a, const CGAL::Bbox_2& b) { typedef typename 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)) { - return Result_type(); + return result_type(); } double xmin, xmax, ymin, ymax; @@ -60,7 +59,7 @@ intersection(const CGAL::Bbox_2& a, ymin = (std::max)(a.ymin(), b.ymin()); ymax = (std::min)(a.ymax(), b.ymax()); - return Result_type(std::forward(Bbox_2(xmin, ymin, xmax, ymax))); + return result_type(std::forward(Bbox_2(xmin, ymin, xmax, ymax))); } } diff --git a/Intersections_2/include/CGAL/Intersections_2/Bbox_2_Iso_rectangle_2.h b/Intersections_2/include/CGAL/Intersections_2/Bbox_2_Iso_rectangle_2.h index 907ae0bc05b..decd0a11a61 100644 --- a/Intersections_2/include/CGAL/Intersections_2/Bbox_2_Iso_rectangle_2.h +++ b/Intersections_2/include/CGAL/Intersections_2/Bbox_2_Iso_rectangle_2.h @@ -25,8 +25,6 @@ #include #include -#include -#include #include namespace CGAL { @@ -34,35 +32,34 @@ namespace CGAL { template inline bool do_intersect( - const Iso_rectangle_2 &line, + const Iso_rectangle_2 &rect, const Bbox_2 &box) { - typename K::Iso_rectangle_2 rec(box.xmin(), box.ymin(), box.xmax(), box.ymax()); - return do_intersect(rec, line); + return do_intersect(K::Iso_rectangle_2(box), rect); } template inline bool do_intersect( const Bbox_2 &box, -const Iso_rectangle_2 &line) +const Iso_rectangle_2 &rect) { - return do_intersect(line, box); + return do_intersect(rect, box); } template typename Intersection_traits::result_type -intersection(const CGAL::Bbox_2& box, - const Iso_rectangle_2& line) { +intersection(const Bbox_2& box, + const Iso_rectangle_2& rect) { typename K::Iso_rectangle_2 rec(box.xmin(), box.ymin(), box.xmax(), box.ymax()); - return intersection(rec, line); + return intersection(rec, rect); } template typename Intersection_traits::result_type -intersection(const Iso_rectangle_2& line, - const CGAL::Bbox_2& box) { - return intersection(box, line); +intersection(const Iso_rectangle_2& rect, + const Bbox_2& box) { + return intersection(box, rect); } } -#endif // BBOX_2_ISO_RECTANGLE_2_H +#endif // CGAL_INTERSECTIONS_BBOX_2_ISO_RECTANGLE_2_H diff --git a/Intersections_2/include/CGAL/Intersections_2/Bbox_2_Point_2.h b/Intersections_2/include/CGAL/Intersections_2/Bbox_2_Point_2.h index 196c756fe5b..c047a36474c 100644 --- a/Intersections_2/include/CGAL/Intersections_2/Bbox_2_Point_2.h +++ b/Intersections_2/include/CGAL/Intersections_2/Bbox_2_Point_2.h @@ -28,7 +28,6 @@ #include - namespace CGAL { namespace Intersections { namespace internal { diff --git a/Intersections_2/include/CGAL/Intersections_2/Bbox_2_Segment_2.h b/Intersections_2/include/CGAL/Intersections_2/Bbox_2_Segment_2.h index 92f9881e87c..67b4aa7cc0c 100644 --- a/Intersections_2/include/CGAL/Intersections_2/Bbox_2_Segment_2.h +++ b/Intersections_2/include/CGAL/Intersections_2/Bbox_2_Segment_2.h @@ -25,8 +25,6 @@ #include #include -#include -#include #include namespace CGAL { @@ -34,35 +32,35 @@ namespace CGAL { template inline bool do_intersect( - const Segment_2 &line, + const Segment_2 &seg, const Bbox_2 &box) { 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 inline bool do_intersect( const Bbox_2 &box, -const Segment_2 &line) +const Segment_2 &seg) { - return do_intersect(line, box); + return do_intersect(seg, box); } template typename Intersection_traits::result_type intersection(const CGAL::Bbox_2& box, - const Segment_2& line) { + const Segment_2& seg) { typename K::Iso_rectangle_2 rec(box.xmin(), box.ymin(), box.xmax(), box.ymax()); - return intersection(rec, line); + return intersection(rec, seg); } template typename Intersection_traits::result_type -intersection(const Segment_2& line, +intersection(const Segment_2& seg, 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 diff --git a/Intersections_2/include/CGAL/Intersections_2/Bbox_2_Triangle_2.h b/Intersections_2/include/CGAL/Intersections_2/Bbox_2_Triangle_2.h index a21a55908b1..6a712e160b6 100644 --- a/Intersections_2/include/CGAL/Intersections_2/Bbox_2_Triangle_2.h +++ b/Intersections_2/include/CGAL/Intersections_2/Bbox_2_Triangle_2.h @@ -25,8 +25,6 @@ #include #include -#include -#include #include namespace CGAL { @@ -34,35 +32,35 @@ namespace CGAL { template inline bool do_intersect( - const Triangle_2 &line, + const Triangle_2 &tr, const Bbox_2 &box) { 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 inline bool do_intersect( const Bbox_2 &box, -const Triangle_2 &line) +const Triangle_2 &tr) { - return do_intersect(line, box); + return do_intersect(tr, box); } template typename Intersection_traits::result_type -intersection(const CGAL::Bbox_2& box, - const Triangle_2& line) { +intersection(const Bbox_2& box, + const Triangle_2& tr) { typename K::Iso_rectangle_2 rec(box.xmin(), box.ymin(), box.xmax(), box.ymax()); - return intersection(rec, line); + return intersection(rec, tr); } template typename Intersection_traits::result_type -intersection(const Triangle_2& line, - const CGAL::Bbox_2& box) { - return intersection(box, line); +intersection(const Triangle_2& tr, + const Bbox_2& box) { + return intersection(box, tr); } } -#endif // BBOX_2_TRIANGLE_2_H +#endif // CGAL_INTERSECTIONS_BBOX_2_TRIANGLE_2_H diff --git a/Intersections_2/include/CGAL/Intersections_2/Circle_2_Ray_2.h b/Intersections_2/include/CGAL/Intersections_2/Circle_2_Ray_2.h index 63f7ace0629..1882357d31b 100644 --- a/Intersections_2/include/CGAL/Intersections_2/Circle_2_Ray_2.h +++ b/Intersections_2/include/CGAL/Intersections_2/Circle_2_Ray_2.h @@ -30,6 +30,7 @@ namespace CGAL { namespace Intersections { namespace internal { + template bool do_intersect(const typename K::Circle_2 & c, diff --git a/Intersections_2/include/CGAL/Intersections_2/Circle_2_Segment_2.h b/Intersections_2/include/CGAL/Intersections_2/Circle_2_Segment_2.h index de9128f56e2..2188499ee83 100644 --- a/Intersections_2/include/CGAL/Intersections_2/Circle_2_Segment_2.h +++ b/Intersections_2/include/CGAL/Intersections_2/Circle_2_Segment_2.h @@ -30,6 +30,7 @@ namespace CGAL { namespace Intersections { namespace internal { + template bool do_intersect(const typename K::Circle_2 & c, diff --git a/Intersections_2/include/CGAL/Intersections_2/Circle_2_Triangle_2.h b/Intersections_2/include/CGAL/Intersections_2/Circle_2_Triangle_2.h index 354b2253fcf..c9151401e3f 100644 --- a/Intersections_2/include/CGAL/Intersections_2/Circle_2_Triangle_2.h +++ b/Intersections_2/include/CGAL/Intersections_2/Circle_2_Triangle_2.h @@ -30,6 +30,7 @@ namespace CGAL { namespace Intersections { namespace internal { + template bool do_intersect(const typename K::Circle_2 & c, diff --git a/Intersections_2/include/CGAL/Intersections_2/internal/Triangle_2_Triangle_2_intersection_impl.h b/Intersections_2/include/CGAL/Intersections_2/internal/Triangle_2_Triangle_2_intersection_impl.h index 7d6b32f3239..f326ac10779 100644 --- a/Intersections_2/include/CGAL/Intersections_2/internal/Triangle_2_Triangle_2_intersection_impl.h +++ b/Intersections_2/include/CGAL/Intersections_2/internal/Triangle_2_Triangle_2_intersection_impl.h @@ -329,9 +329,9 @@ Triangle_2_Triangle_2_pair::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 -template +template struct Is_cw{ -bool operator()(const ArrayOfPoints& ps) +bool operator()(const std::vector& ps) { typename K::FT res(0); std::size_t length = ps.size(); @@ -343,9 +343,9 @@ bool operator()(const ArrayOfPoints& ps) } }; -template -struct Is_cw{ -bool operator()(const ArrayOfPoints& ps) +template +struct Is_cw{ +bool operator()(const std::vector& ps) { 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++) { points[i] = ispair.vertex(i); } - if(Is_cw::Is_exact>()(points)) + if(Is_cw::Is_exact>()(points)) { std::size_t length = points.size(); diff --git a/Intersections_2/test/Intersections_2/test_intersections_2.cpp b/Intersections_2/test/Intersections_2/test_intersections_2.cpp index bc1ea6bd322..53004b4cf62 100644 --- a/Intersections_2/test/Intersections_2/test_intersections_2.cpp +++ b/Intersections_2/test/Intersections_2/test_intersections_2.cpp @@ -98,7 +98,7 @@ struct Test { if (p.size() != q.size()) return false; - if (CGAL::Intersections::internal::Is_cw::Is_exact>()(p)) return false; 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) { - std::vector

vec(3); - for(int i=0; i<3; ++i){vec[i]=p[i];} - if (CGAL::Intersections::internal::Is_cw, + if(p.size() != q.size()) + return false; + + std::vector

vec { p[0], p[1], p[2] }; + + if (CGAL::Intersections::internal::Is_cw::Is_exact>(vec)) return false; 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, 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( 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(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() @@ -360,6 +367,7 @@ struct Test { 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( 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( 4, 3), 4), T(p( 6, -7), p( 5, 2), p(2,-3))); diff --git a/Intersections_3/include/CGAL/Intersection_traits_3.h b/Intersections_3/include/CGAL/Intersection_traits_3.h index c49fc277357..decc1b24475 100644 --- a/Intersections_3/include/CGAL/Intersection_traits_3.h +++ b/Intersections_3/include/CGAL/Intersection_traits_3.h @@ -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(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(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, Ray_3, Point_3, Ray_3)