From 2d9186184d1e8be3450a7d8dcacb801035c3b82b Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Wed, 23 Aug 2023 14:52:00 +0100 Subject: [PATCH] make less copies of points --- Nef_2/include/CGAL/Nef_2/PM_checker.h | 6 +-- Nef_2/include/CGAL/Nef_2/PM_overlayer.h | 48 +++++++++---------- Nef_2/include/CGAL/Nef_2/PM_persistent_PL.h | 15 +++--- Nef_2/include/CGAL/Nef_2/PM_point_locator.h | 34 ++++++------- .../CGAL/Nef_2/Segment_overlay_traits.h | 18 ++++--- 5 files changed, 63 insertions(+), 58 deletions(-) diff --git a/Nef_2/include/CGAL/Nef_2/PM_checker.h b/Nef_2/include/CGAL/Nef_2/PM_checker.h index 4000d0d497e..89d60c6cd7e 100644 --- a/Nef_2/include/CGAL/Nef_2/PM_checker.h +++ b/Nef_2/include/CGAL/Nef_2/PM_checker.h @@ -203,7 +203,7 @@ check_boundary_is_clockwise_weakly_polygon() const for (vit = v_min = this->vertices_begin() ; vit != this->vertices_end(); ++vit) if ( K.compare_xy(point(vit), point(v_min))<0 ) v_min = vit; CGAL_assertion_msg(!is_isolated(v_min),"Minimal vertex not connected."); - Point p_min = point(v_min); + const Point& p_min = point(v_min); // determine boundary edge incident to v_min: Halfedge_const_handle e_boundary_at_v_min = first_out_edge(v_min); // all out edges are forward oriented due to minimality @@ -211,8 +211,8 @@ check_boundary_is_clockwise_weakly_polygon() const hvit(e_boundary_at_v_min), hend(hvit); do { --hvit; - Point p1 = point(target(e_boundary_at_v_min)); - Point p2 = point(target(hvit)); + const Point& p1 = point(target(e_boundary_at_v_min)); + const Point& p2 = point(target(hvit)); if ( K.orientation(p_min,p1,p2) > 0 ) { // left_turn e_boundary_at_v_min = hvit; break; diff --git a/Nef_2/include/CGAL/Nef_2/PM_overlayer.h b/Nef_2/include/CGAL/Nef_2/PM_overlayer.h index 0d7fe0dd01f..d32088fa0c5 100644 --- a/Nef_2/include/CGAL/Nef_2/PM_overlayer.h +++ b/Nef_2/include/CGAL/Nef_2/PM_overlayer.h @@ -605,18 +605,18 @@ avoid the simplification for edge pairs referenced by |e|.}*/ CGAL_For_all(hfc,hend) { set_face(hfc,f); if(target(hfc) == target(e_min)) { - Point p1 = point(source(hfc)), - p2 = point(target(hfc)), - p3 = point(target(next(hfc))); + const Point& p1 = point(source(hfc)); + const Point& p2 = point(target(hfc)); + const Point& p3 = point(target(next(hfc))); if (!K.left_turn(p1,p2,p3) ) e_min = hfc; } else if ( K.compare_xy(point(target(hfc)), point(target(e_min))) < 0 ) e_min = hfc; linked[hfc]=true; } - Point p1 = point(source(e_min)), - p2 = point(target(e_min)), - p3 = point(target(next(e_min))); + const Point& p1 = point(source(e_min)); + const Point& p2 = point(target(e_min)); + const Point& p3 = point(target(next(e_min))); if ( K.orientation(p1,p2,p3) > 0 ) set_halfedge(f,e_min); // outer else set_hole(f,e_min); // store as inner } @@ -633,8 +633,8 @@ avoid the simplification for edge pairs referenced by |e|.}*/ } } else { // v not isolated Halfedge_handle e2 = first_out_edge(v), e1 = previous(e2); - Point p1 = point(source(e1)), p2 = point(v), - p3 = point(target(e2)); + const Point& p1 = point(source(e1)), p2 = point(v); + const Point& p3 = point(target(e2)); if ( has_outdeg_two(v) && mark(v) == mark(e1) && mark(v) == mark(e2) && (K.orientation(p1,p2,p3) == 0) ) @@ -838,9 +838,9 @@ void create_face_objects(const Below_info& D) const CGAL_For_all(hfc,hend) { FaceCycle[hfc]=i; // assign face cycle number if(target(hfc) == target(e_min)) { - Point p1 = point(source(hfc)), - p2 = point(target(hfc)), - p3 = point(target(next(hfc))); + const Point& p1 = point(source(hfc)); + const Point&p2 = point(target(hfc)); + const Point&p3 = point(target(next(hfc))); if (!K.left_turn(p1,p2,p3) ) e_min = hfc; } else if ( K.compare_xy(point(target(hfc)), point(target(e_min))) < 0 ) @@ -854,10 +854,10 @@ void create_face_objects(const Below_info& D) const Face_handle f_outer = this->new_face(); for (int j=0; j outer face cycle CGAL_NEF_TRACEN(" creating new face object"); Face_handle f = this->new_face(); @@ -899,9 +899,9 @@ void create_face_objects_pl(const Below_info& D) const CGAL_For_all(hfc,hend) { FaceCycle[hfc]=i; // assign face cycle number if(target(hfc) == target(e_min)) { - Point p1 = point(source(hfc)), - p2 = point(target(hfc)), - p3 = point(target(next(hfc))); + const Point& p1 = point(source(hfc)); + const Point& p2 = point(target(hfc)); + const Point& p3 = point(target(next(hfc))); if (!K.left_turn(p1,p2,p3) ) e_min = hfc; } else if ( K.compare_xy(point(target(hfc)), point(target(e_min))) < 0 ) @@ -915,10 +915,10 @@ void create_face_objects_pl(const Below_info& D) const (void)/* Face_handle f_outer = */ this->new_face(); for (int j=0; j outer face cycle CGAL_NEF_TRACEN(" creating new face object"); Face_handle f = this->new_face(); @@ -963,8 +963,8 @@ Segment segment(const Const_decorator& N, bool is_forward_edge(const Const_decorator& N, Halfedge_const_iterator hit) const -{ Point p1 = N.point(N.source(hit)); - Point p2 = N.point(N.target(hit)); +{ const Point& p1 = N.point(N.source(hit)); + const Point& p2 = N.point(N.target(hit)); return (K.compare_xy(p1,p2) < 0); } void assert_type_precondition() const diff --git a/Nef_2/include/CGAL/Nef_2/PM_persistent_PL.h b/Nef_2/include/CGAL/Nef_2/PM_persistent_PL.h index 221387e096b..278ae4589db 100644 --- a/Nef_2/include/CGAL/Nef_2/PM_persistent_PL.h +++ b/Nef_2/include/CGAL/Nef_2/PM_persistent_PL.h @@ -72,8 +72,8 @@ struct PM_persistent_PL_traits EdgeCategory ClassifyEdge(const Graph& G, const Edge& e, const Node& u) { - Point p_u = G.point(u); - Point p_v = G.point(opposite(G,e,u)); + const Point& p_u = G.point(u); + const Point& p_v = G.point(opposite(G,e,u)); int cmpX = pK->compare_x(p_u, p_v); if ( cmpX < 0 ) return StartingNonVertical; @@ -111,7 +111,8 @@ struct PM_persistent_PL_traits Curve makeCurve(const Graph& G, const Node& n) const { return makeCurve(G.point(n)); } Curve makeCurve(const Graph& G, const Edge& e) const - { Point ps = G.point(G.source(e)), pt = G.point(G.target(e)); + { const Point& ps = G.point(G.source(e)); + const Point& pt = G.point(G.target(e)); Curve res(G.point(G.source(e)),G.point(G.target(e))); if ( pK->compare_xy(ps,pt) < 0 ) res = pK->construct_segment(ps,pt); else res = pK->construct_segment(pt,ps); @@ -135,10 +136,10 @@ struct PM_persistent_PL_traits int operator()(const Curve& s1, const Curve& s2) const { - Point a = pK->source(s1); - Point b = pK->target(s1); - Point c = pK->source(s2); - Point d = pK->target(s2); + const Point& a = pK->source(s1); + const Point& b = pK->target(s1); + const Point& c = pK->source(s2); + const Point& d = pK->target(s2); if ( a==b ) if ( c==d ) return pK->compare_y(a,c); else return cmppntseg(a, s2); diff --git a/Nef_2/include/CGAL/Nef_2/PM_point_locator.h b/Nef_2/include/CGAL/Nef_2/PM_point_locator.h index ede8d2b033a..6b12933e450 100644 --- a/Nef_2/include/CGAL/Nef_2/PM_point_locator.h +++ b/Nef_2/include/CGAL/Nef_2/PM_point_locator.h @@ -165,7 +165,7 @@ public: { CGAL_NEF_TRACEN("out_wedge "<number_of_vertices() == 0) CGAL_error_msg("PM_naive_point_locator: plane map is empty."); - Point p = K.source(s); + const Point& p = K.source(s); Vertex_const_iterator vit; for(vit = this->vertices_begin(); vit != this->vertices_end(); ++vit) { if ( p == point(vit) ) return make_object(vit); @@ -236,7 +236,7 @@ public: Direction dso = K.construct_direction(K.target(s),p), d_res; CGAL::Unique_hash_map visited(false); for(vit = this->vertices_begin(); vit != this->vertices_end(); ++vit) { - Point p_res, vp = point(vit); + const Point& vp = point(vit); if ( K.contains(ss,vp) ) { CGAL_NEF_TRACEN(" location via vertex at "<halfedges_begin(); eit != this->halfedges_end(); ++eit) { if ( visited[eit] ) continue; - Point se = point(source(eit)), - te = point(target(eit)); + const Point& se = point(source(eit)); + const Point& te = point(target(eit)); int o1 = K.orientation(ss,se); int o2 = K.orientation(ss,te); if ( o1 == -o2 && // internal intersection @@ -298,7 +298,7 @@ public: along |s| does not hit any object |h| of |P| with |M(h)|.}*/ { CGAL_NEF_TRACEN("naive ray_shoot "<vertices_begin(); v != this->vertices_end(); ++v) { - Point pv = point(v); + const Point& pv = point(v); if ( !K.contains(ss,pv) ) continue; CGAL_NEF_TRACEN("candidate "<K.orientation(b,d,a) > 0 && // left_turn this->K.orientation(b,d,c) < 0) ) // right_turn @@ -731,7 +731,7 @@ public: Halfedge_const_handle& e, const Tag_false& ) const { CGAL_NEF_TRACEN("target on outer facet"); - Point p = this->K.source(s); + const Point& p = this->K.source(s); Vertex_const_handle v1 = CT.vertices_begin(); Halfedge_const_handle e1 = CT.twin(CT.first_out_edge(v1)); Halfedge_around_face_const_circulator circ(e1), end(circ); @@ -782,7 +782,7 @@ public: { Segment s(ss); CGAL_NEF_TRACEN("ray_shoot "<K.is_degenerate(s) ); - Point p = this->K.source(s); + const Point& p = this->K.source(s); Direction d = this->K.construct_direction(p,s.target()); Vertex_const_handle v; Halfedge_const_handle e; @@ -813,9 +813,9 @@ public: if ( M(input_face(e)) ) // face mark return make_object(input_face(e)); - Point p1 = CT.point(CT.source(e)), - p2 = CT.point(CT.target(e)), - p3 = CT.point(CT.target(next(e))); + const Point& p1 = CT.point(CT.source(e)); + const Point& p2 = CT.point(CT.target(e)); + const Point& p3 = CT.point(CT.target(next(e))); int or1 = this->K.orientation(p,s.target(),p1); int or2 = this->K.orientation(p,s.target(),p2); int or3 = this->K.orientation(p,s.target(),p3); @@ -999,7 +999,7 @@ PM_point_locator::walk_in_triangulation(const Point& q) const return Object_handle(); Halfedge_const_handle e; - Point p = CT.point(v); + const Point& p = CT.point(v); if ( p == q ) return make_object(v); // Segment s = this->K.construct_segment(p,q); Direction dir = this->K.construct_direction(p,q); diff --git a/Nef_2/include/CGAL/Nef_2/Segment_overlay_traits.h b/Nef_2/include/CGAL/Nef_2/Segment_overlay_traits.h index 7e4bfc619b6..6ecc25669e0 100644 --- a/Nef_2/include/CGAL/Nef_2/Segment_overlay_traits.h +++ b/Nef_2/include/CGAL/Nef_2/Segment_overlay_traits.h @@ -161,11 +161,13 @@ public: } - Point_2 source(ISegment is) const + Point_2 source(const ISegment& is) const { return K.source(is->first()); } - Point_2 target(ISegment is) const + + Point_2 target(const ISegment& is) const { return K.target(is->first()); } - ITERATOR original(ISegment s) const + + ITERATOR original(xonst ISegment& s) const { return s->second(); } int orientation(ST_item sit, const Point_2& p) const @@ -474,7 +476,7 @@ public: public: compare_segs_at_sweepline(const Point_2& pi, - ISegment s1, ISegment s2, + ISegment s1, ISegment s2, const GEOMETRY& k) : p(pi), s_bottom(s1), s_top(s2), K(k) {} @@ -673,6 +675,7 @@ public: Point_2 source(ISegment is) const { return K.source(is->first); } + Point_2 target(ISegment is) const { return K.target(is->first); } @@ -687,7 +690,8 @@ public: *sit1 == &sh || *sit2 == &sl || *sit2 == &sh) return false; - Point_2 ps = source(*sit2), pt = target(*sit2); + const Point_2& ps = source(*sit2); + const Point_2& pt = target(*sit2); return ( orientation(sit1,ps)==0 && orientation(sit1,pt)==0 ); } @@ -758,8 +762,8 @@ public: continue; // ignore zero-length segments regarding YS } - Point_2 p = *it1; - Point_2 q = *it2; + const Point_2& p = *it1; + const Point_2& q = *it2; Segment_2 s1; if ( K.compare_xy(p,q) < 0 )