Antkeeper  0.0.1
brep-vertex.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2023 Christopher J. Howard
3  *
4  * This file is part of Antkeeper source code.
5  *
6  * Antkeeper source code is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * Antkeeper source code is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #ifndef ANTKEEPER_GEOM_BREP_VERTEX_HPP
21 #define ANTKEEPER_GEOM_BREP_VERTEX_HPP
22 
25 #include <cstddef>
26 #include <iterator>
27 
28 namespace geom {
29 
30 class brep_mesh;
31 class brep_edge;
32 class brep_vertex;
33 template <class T>
34 class brep_element_container;
35 
40 {
41 public:
42  friend class brep_mesh;
43  friend class brep_vertex_container;
44  friend class brep_edge_container;
45 
47  {
48  public:
49  friend class brep_vertex_edge_list;
50 
51  using iterator_category = std::bidirectional_iterator_tag;
52  using iterator_concept = std::bidirectional_iterator_tag;
53  using difference_type = std::ptrdiff_t;
55  using pointer = const value_type*;
56  using reference = const value_type&;
57 
58  [[nodiscard]] inline constexpr value_type operator*() const noexcept
59  {
60  return m_edge;
61  }
62 
63  [[nodiscard]] inline constexpr value_type operator->() const noexcept
64  {
65  return m_edge;
66  }
67 
68  inline const_iterator& operator++() noexcept
69  {
70  m_edge = m_edge->m_vertex_next[m_edge->vertices()[1] == m_vertex];
71  ++m_position;
72  return *this;
73  }
74 
75  [[nodiscard]] inline const_iterator operator++(int) noexcept
76  {
77  const_iterator tmp = *this;
78  ++(*this);
79  return tmp;
80  }
81 
82  inline const_iterator& operator--() noexcept
83  {
84  m_edge = m_edge->m_vertex_previous[m_edge->vertices()[1] == m_vertex];
85  --m_position;
86  return *this;
87  }
88 
89  [[nodiscard]] inline const_iterator operator--(int) noexcept
90  {
91  const_iterator tmp = *this;
92  --(*this);
93  return tmp;
94  }
95 
96  [[nodiscard]] inline bool operator==(const const_iterator& other) const noexcept
97  {
98  return m_position == other.m_position;
99  };
100 
101  [[nodiscard]] inline std::weak_ordering operator<=>(const const_iterator& other) const noexcept
102  {
103  return m_position <=> other.m_position;
104  }
105 
106  [[nodiscard]] inline difference_type operator-(const const_iterator& rhs) const noexcept
107  {
108  return m_position - rhs.m_position;
109  }
110 
111  private:
112  brep_vertex* m_vertex;
113  brep_edge* m_edge;
114  std::ptrdiff_t m_position;
115  };
116 
117  using const_reverse_iterator = std::reverse_iterator<const_iterator>;
118 
121 
123  [[nodiscard]] inline brep_edge* front() const noexcept
124  {
125  return m_head;
126  }
127 
129  [[nodiscard]] inline brep_edge* back() const noexcept
130  {
131  return m_head->m_vertex_previous[m_head->vertices()[1] == m_vertex];
132  }
133 
137 
140  [[nodiscard]] inline constexpr const_iterator begin() const noexcept
141  {
142  const_iterator it;
143  it.m_vertex = m_vertex;
144  it.m_edge = m_head;
145  it.m_position = 0;
146 
147  return it;
148  }
149  [[nodiscard]] inline constexpr const_iterator cbegin() const noexcept
150  {
151  return begin();
152  }
154 
157  [[nodiscard]] inline constexpr const_iterator end() const noexcept
158  {
159  const_iterator it;
160  it.m_vertex = m_vertex;
161  it.m_edge = m_head;
162  it.m_position = static_cast<std::ptrdiff_t>(m_size);
163 
164  return it;
165  }
166  [[nodiscard]] inline constexpr const_iterator cend() const noexcept
167  {
168  return end();
169  }
171 
174  [[nodiscard]] inline constexpr const_reverse_iterator rbegin() const noexcept
175  {
176  return std::make_reverse_iterator(end());
177  }
178  [[nodiscard]] inline constexpr const_reverse_iterator crbegin() const noexcept
179  {
180  return rbegin();
181  }
183 
186  [[nodiscard]] inline constexpr const_reverse_iterator rend() const noexcept
187  {
188  return std::make_reverse_iterator(begin());
189  }
190  [[nodiscard]] inline constexpr const_reverse_iterator crend() const noexcept
191  {
192  return rend();
193  }
195 
199 
201  [[nodiscard]] inline constexpr bool empty() const noexcept
202  {
203  return !m_size;
204  }
205 
207  [[nodiscard]] inline constexpr std::size_t size() const noexcept
208  {
209  return m_size;
210  }
211 
215 
221  void push_back(brep_edge* edge);
222 
228  void remove(brep_edge* edge);
229 
231 
232 private:
233  brep_vertex* m_vertex{};
234  brep_edge* m_head{};
235  std::size_t m_size{};
236 };
237 
242 {
243 public:
244  friend class brep_mesh;
245  friend class brep_element_container<brep_vertex>;
246  friend class brep_vertex_container;
247  friend class brep_edge_container;
248 
254  [[nodiscard]] inline constexpr std::size_t index() const noexcept
255  {
256  return m_index;
257  }
258 
260  [[nodiscard]] inline constexpr const brep_vertex_edge_list& edges() const noexcept
261  {
262  return m_edges;
263  }
264 
265 private:
266  std::size_t m_index;
267  brep_vertex_edge_list m_edges;
268 };
269 
274 {
275 public:
281  brep_vertex* emplace_back() override;
282 
290  void erase(brep_vertex* vertex) override;
291 
295  void clear() noexcept;
296 
297 private:
298  friend class brep_mesh;
299 
305  inline explicit brep_vertex_container(brep_mesh* mesh) noexcept:
307  {}
308 };
309 
310 } // namespace geom
311 
312 #endif // ANTKEEPER_GEOM_BREP_VERTEX_HPP
B-rep edge container.
Definition: brep-edge.hpp:279
Curve segment bounded by two vertices.
Definition: brep-edge.hpp:237
constexpr const std::array< brep_vertex *, 2 > & vertices() const noexcept
Returns the pair of vertices that bound this edge.
Definition: brep-edge.hpp:256
Container for B-rep elements.
Boundary representation (B-rep) of a mesh.
Definition: brep-mesh.hpp:34
B-rep vertex container.
void erase(brep_vertex *vertex) override
Erases a vertex and all dependent edges, loops, and faces.
Definition: brep-vertex.cpp:82
brep_vertex * emplace_back() override
Appends a new vertex to the end of the container.
Definition: brep-vertex.cpp:74
void clear() noexcept
Erases all vertices and their dependent edges, loops, and faces.
Definition: brep-vertex.cpp:94
List of B-rep edges bounded by a common vertex.
Definition: brep-vertex.hpp:40
brep_edge * back() const noexcept
Returns the last edge.
constexpr const_iterator end() const noexcept
Returns an iterator to the edge following the last edge.
std::reverse_iterator< const_iterator > const_reverse_iterator
constexpr const_reverse_iterator crend() const noexcept
Returns a reverse iterator to the edge following the last edge of the reversed list.
constexpr const_reverse_iterator rend() const noexcept
Returns a reverse iterator to the edge following the last edge of the reversed list.
void push_back(brep_edge *edge)
Appends an edge to the end of the list.
Definition: brep-vertex.cpp:25
void remove(brep_edge *edge)
Removes an edge from the list.
Definition: brep-vertex.cpp:52
constexpr const_iterator cbegin() const noexcept
Returns an iterator to the first edge.
constexpr const_iterator begin() const noexcept
Returns an iterator to the first edge.
constexpr std::size_t size() const noexcept
Returns the number of edges in the list.
constexpr bool empty() const noexcept
Returns true if the list is empty, false otherwise.
constexpr const_reverse_iterator rbegin() const noexcept
Returns a reverse iterator to the first edge of the reversed list.
constexpr const_reverse_iterator crbegin() const noexcept
Returns a reverse iterator to the first edge of the reversed list.
brep_edge * front() const noexcept
Returns the first edge.
constexpr const_iterator cend() const noexcept
Returns an iterator to the edge following the last edge.
A point in space.
constexpr std::size_t index() const noexcept
Returns the index of this vertex in the mesh vertex array.
constexpr const brep_vertex_edge_list & edges() const noexcept
Returns the list of edges bounded by this vertex.
Geometric algorithms.
bool operator==(const const_iterator &other) const noexcept
Definition: brep-vertex.hpp:96
constexpr value_type operator->() const noexcept
Definition: brep-vertex.hpp:63
const_iterator operator--(int) noexcept
Definition: brep-vertex.hpp:89
const_iterator & operator++() noexcept
Definition: brep-vertex.hpp:68
const_iterator operator++(int) noexcept
Definition: brep-vertex.hpp:75
difference_type operator-(const const_iterator &rhs) const noexcept
constexpr value_type operator*() const noexcept
Definition: brep-vertex.hpp:58
std::weak_ordering operator<=>(const const_iterator &other) const noexcept
const_iterator & operator--() noexcept
Definition: brep-vertex.hpp:82
std::bidirectional_iterator_tag iterator_concept
Definition: brep-vertex.hpp:52
std::bidirectional_iterator_tag iterator_category
Definition: brep-vertex.hpp:51