From a0d5fae2bd57ca85fd160fbe6de9666c8a526478 Mon Sep 17 00:00:00 2001 From: Giles Bathgate Date: Mon, 28 Feb 2022 19:04:09 +0000 Subject: [PATCH] Add Origin based constructor to sphere_point and avoid conditional constructor --- Nef_3/include/CGAL/Nef_3/SNC_constructor.h | 6 ++--- .../CGAL/Nef_3/polygon_mesh_to_nef_3.h | 6 ++--- Nef_S2/include/CGAL/Nef_S2/Sphere_circle.h | 22 ++++++++++++++----- Nef_S2/include/CGAL/Nef_S2/Sphere_segment.h | 3 ++- 4 files changed, 23 insertions(+), 14 deletions(-) diff --git a/Nef_3/include/CGAL/Nef_3/SNC_constructor.h b/Nef_3/include/CGAL/Nef_3/SNC_constructor.h index 23041cff316..0de8e46bed2 100644 --- a/Nef_3/include/CGAL/Nef_3/SNC_constructor.h +++ b/Nef_3/include/CGAL/Nef_3/SNC_constructor.h @@ -2037,7 +2037,7 @@ class SNC_constructor D.link_as_isolated_vertex(v2, f2); D.link_as_loop(l,f1); D.link_as_loop(l->twin(),f2); - l->circle() = Sphere_circle(faces_p->plane()); + l->circle() = Sphere_circle(CGAL::ORIGIN,faces_p->plane()); l->twin()->circle() = l->circle().opposite(); f2->mark() = mf2; l->mark() = l->twin()->mark() = ml; @@ -2053,7 +2053,7 @@ class SNC_constructor SHalfedge_handle se1; SHalfedge_handle se2; SFace_handle sf; - Sphere_circle c(f->plane()); + Sphere_circle c(CGAL::ORIGIN,f->plane()); SHalfedge_handle next_edge; SHalfedge_around_svertex_const_circulator ec(E.out_edges(e)), ee(ec); @@ -2104,7 +2104,7 @@ class SNC_constructor se1 = D.new_shalfedge_pair(ec2->twin(), en->twin(), -1, 1); CGAL_NEF_TRACEN("new edge pair " << ec2->twin()->source()->vector() << " -> " << en->twin()->source()->vector()); - se1->circle() = Sphere_circle(faces_p->plane()); + se1->circle() = Sphere_circle(CGAL::ORIGIN,faces_p->plane()); se1->twin()->circle() = se1->circle().opposite(); se1->mark() = se1->twin()->mark() = BOP(mark_of_right_sface[ec2], faces_p->mark(), inv); diff --git a/Nef_3/include/CGAL/Nef_3/polygon_mesh_to_nef_3.h b/Nef_3/include/CGAL/Nef_3/polygon_mesh_to_nef_3.h index dea41f6eb00..4300fe2765f 100644 --- a/Nef_3/include/CGAL/Nef_3/polygon_mesh_to_nef_3.h +++ b/Nef_3/include/CGAL/Nef_3/polygon_mesh_to_nef_3.h @@ -250,8 +250,7 @@ void polygon_mesh_to_nef_3(PolygonMesh& P, SNC_structure& S, FaceIndexMap fimap, with_border = true; else { std::size_t i = get(fimap,face(pe_prev,P)); - Plane ss_plane( CGAL::ORIGIN, normals[i]); - Sphere_circle ss_circle(ss_plane); + Sphere_circle ss_circle(CGAL::ORIGIN, normals[i]); CGAL_assertion_code(if(num_edges[i] > 3) { CGAL_assertion(ss_circle.has_on(sp)); CGAL_assertion(ss_circle.has_on(sv_prev->point())); @@ -283,8 +282,7 @@ void polygon_mesh_to_nef_3(PolygonMesh& P, SNC_structure& S, FaceIndexMap fimap, e = sv_prev->out_sedge(); } else { std::size_t i = get(fimap,face(pe_prev,P)); - Plane ss_plane( CGAL::ORIGIN, normals[i]); - Sphere_circle ss_circle(ss_plane); + Sphere_circle ss_circle(CGAL::ORIGIN, normals[i]); CGAL_assertion_code(if(num_edges[i] > 3) { CGAL_assertion(ss_circle.has_on(sp_0)); diff --git a/Nef_S2/include/CGAL/Nef_S2/Sphere_circle.h b/Nef_S2/include/CGAL/Nef_S2/Sphere_circle.h index 608b8ac141a..16991cb3f26 100644 --- a/Nef_S2/include/CGAL/Nef_S2/Sphere_circle.h +++ b/Nef_S2/include/CGAL/Nef_S2/Sphere_circle.h @@ -17,6 +17,7 @@ #include +#include namespace CGAL { @@ -47,6 +48,7 @@ typedef std::pair< Sphere_segment,Sphere_segment > typedef typename R_::Plane_3 Plane_3; typedef typename R_::Line_3 Line_3; typedef typename R_::Point_3 Point_3; +typedef typename R_::Vector_3 Vector_3; typedef Sphere_circle Self; typedef typename R_::Plane_3 Base; @@ -78,15 +80,20 @@ create any great circle that contains $p$ and $q$.}*/ } } - Sphere_circle(const Plane_3& h) : Base(h) +Sphere_circle(const Plane_3& h) : Base(h) /*{\Mcreate creates the circle of $S_2$ corresponding to the plane |h|. If |h| does not contain the origin, then |\Mvar| becomes the circle parallel to |h| containing the origin.}*/ { - if(h.d() != 0) *this = Plane_3(h.a(),h.b(),h.c(),RT(0)); + if(h.d() != 0) + *this = Plane_3(h.a(),h.b(),h.c(),RT(0)); } -Sphere_circle(const RT& x, const RT& y, const RT& z): Base(x,y,z,0) {} +Sphere_circle(const Origin& o, const Vector_3& v) : Base(o,v) {} + +Sphere_circle(const Origin&, const Plane_3& h) : Base(h.a(),h.b(),h.c(),RT(0)) {} + +Sphere_circle(const RT& x, const RT& y, const RT& z) : Base(x,y,z,0) {} /*{\Mcreate creates the circle orthogonal to the vector $(x,y,z)$.}*/ @@ -102,10 +109,9 @@ Sphere_circle(Sphere_circle c, const Sphere_point& p) } /*{\Moperations 4 2}*/ - Sphere_circle opposite() const /*{\Mop returns the opposite of |\Mvar|.}*/ -{ return Base::opposite(); } +{ return Sphere_circle(Base::opposite(),Private_tag{}); } bool has_on(const Sphere_point& p) const /*{\Mop returns true iff |\Mvar| contains |p|.}*/ @@ -117,7 +123,7 @@ Plane_3 plane() const { return Base(*this); } Plane_3 plane_through(const Point_3& p) const /*{\Mop returns the plane parallel to |\Mvar| that contains point |p|.}*/ -{ return Plane_3(p,((Base*) this)->orthogonal_direction()); } +{ return Plane_3(p,((Base*) this)->orthogonal_vector()); } Sphere_point orthogonal_pole() const /*{\Mop returns the point that is the pole of the @@ -134,6 +140,10 @@ of splitting |\Mvar| at the $x$-$y$-coordinate plane if |\Mvar| is not part of it. Otherwise |\Mvar| is split at the $x$-$z$-coordinate plane.}*/ +private: +struct Private_tag{}; +Sphere_circle(const Plane_3& h,Private_tag) : Base(h){} + }; // Sphere_circle /*{\Mtext\headerline{Global functions}}*/ diff --git a/Nef_S2/include/CGAL/Nef_S2/Sphere_segment.h b/Nef_S2/include/CGAL/Nef_S2/Sphere_segment.h index 62340fa6055..63996970c80 100644 --- a/Nef_S2/include/CGAL/Nef_S2/Sphere_segment.h +++ b/Nef_S2/include/CGAL/Nef_S2/Sphere_segment.h @@ -20,6 +20,7 @@ #include #include #include +#include #include namespace CGAL { @@ -37,7 +38,7 @@ Sphere_segment_rep() { ps_ = pt_ = Point(); c_ = Circle(); } Sphere_segment_rep(const Point& p1, const Point& p2, bool shorter_arc=true) : - ps_(p1), pt_(p2), c_(Plane_3(p1,p2,Point_3(CGAL::ORIGIN))) + ps_(p1), pt_(p2), c_(CGAL::ORIGIN,CGAL::orthogonal_vector(p1,p2,Point_3(CGAL::ORIGIN))) { // warning stays as reminder that one gets an arbitrary plane equation // in this degenerate case CGAL_warning(p1 != p2.antipode());