From 9dfec6f0d4a083d08e6edcd62d1a0216fb7ffb72 Mon Sep 17 00:00:00 2001 From: Youmu Date: Wed, 17 Jun 2020 17:01:27 -0400 Subject: [PATCH] Add helper functions to navigate in the path based on dart direction --- .../internal/Minimal_quadrangulation.h | 57 +++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/Surface_mesh_topology/include/CGAL/Surface_mesh_topology/internal/Minimal_quadrangulation.h b/Surface_mesh_topology/include/CGAL/Surface_mesh_topology/internal/Minimal_quadrangulation.h index 10ee59b8d90..acd961d68b6 100644 --- a/Surface_mesh_topology/include/CGAL/Surface_mesh_topology/internal/Minimal_quadrangulation.h +++ b/Surface_mesh_topology/include/CGAL/Surface_mesh_topology/internal/Minimal_quadrangulation.h @@ -1867,6 +1867,63 @@ protected: return result; } + size_type get_order_relative_to(Dart_const_handle x, Dart_const_handle ref, size_type num_sides) + { + size_type ref_order = get_dart_id(ref, ref), + x_order = get_dart_id(x, ref); + return x_order <= ref_order ? (x_order + num_sides - ref_order - 1) : (x_order - ref_order - 1); + } + + int get_previous_idx_relative_to(const Path_on_surface&p, std::size_t i, Dart_const_handle ref) const + { + return get_local_map().template belong_to_same_cell<0>(p[i], ref) ? static_cast(i) - 1, static_cast(i) + 1; + } + + bool has_previous_relative_to(const Path_on_surface& p, std::size_t i, Dart_const_handle ref) const + { + CGAL_assertion(get_local_map().template belong_to_same_cell<1>(p[i], ref)); + int j = get_previous_idx_relative_to(p, i, ref); + return j >= 0 && j < p.length(); + } + + Dart_const_handle get_previous_relative_to(const Path_on_surface& p, std::size_t i, Dart_const_handle ref) const + { + CGAL_assertion(get_local_map().template belong_to_same_cell<1>(p[i], ref)); + int j = get_previous_idx_relative_to(p, i, ref); + if (j < 0) { j += p.length(); } + else if (j >= p.length()) { j -= p.length(); } + return p[j]; + } + + int get_next_idx_relative_to(const Path_on_surface&p, std::size_t i, Dart_const_handle ref) const + { + return get_local_map().template belong_to_same_cell<0>(p[i], ref) ? static_cast(i) + 1, static_cast(i) - 1; + } + + bool has_next_relative_to(const Path_on_surface& p, std::size_t i, Dart_const_handle ref) const + { + CGAL_assertion(get_local_map().template belong_to_same_cell<1>(p[i], ref)); + int j = get_next_idx_relative_to(p, i, ref); + return j >= 0 && j < p.length(); + } + + Dart_const_handle get_next_relative_to(const Path_on_surface& p, std::size_t i, Dart_const_handle ref) const + { + CGAL_assertion(get_local_map().template belong_to_same_cell<1>(p[i], ref)); + int j = get_next_idx_relative_to(p, i, ref); + if (j < 0) { j += p.length(); } + else if (j >= p.length()) { j -= p.length(); } + return p[j]; + } + + size_type get_dart_id(Dart_const_handle x, Dart_const_handle ref) + { + return get_local_map().template belong_to_same_cell<0>(x, ref) ? + get_local_map().info(x) : + get_local_map().info(get_local_map().opposite2(x)); + } + } + protected: /// The original map (the mesh seen as a 2-map) const typename Get_map::storage_type m_original_map;