Antkeeper  0.0.1
brep-edge.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_EDGE_HPP
21 #define ANTKEEPER_GEOM_BREP_EDGE_HPP
22 
25 #include <array>
26 #include <cstddef>
27 #include <iterator>
28 
29 namespace geom {
30 
31 class brep_vertex;
32 class brep_loop;
33 template <class T>
34 class brep_element_container;
35 
40 {
41 public:
42  friend class brep_mesh;
43  friend class brep_face_container;
44 
46  {
47  public:
48  friend class brep_edge_loop_list;
49 
50  using iterator_category = std::bidirectional_iterator_tag;
51  using iterator_concept = std::bidirectional_iterator_tag;
52  using difference_type = std::ptrdiff_t;
54  using pointer = const value_type*;
55  using reference = const value_type&;
56 
57  [[nodiscard]] inline constexpr value_type operator*() const noexcept
58  {
59  return m_loop;
60  }
61 
62  [[nodiscard]] inline constexpr value_type operator->() const noexcept
63  {
64  return m_loop;
65  }
66 
67  inline const_iterator& operator++() noexcept
68  {
69  m_loop = m_loop->m_edge_next;
70  ++m_position;
71  return *this;
72  }
73 
74  [[nodiscard]] inline const_iterator operator++(int) noexcept
75  {
76  const_iterator tmp = *this;
77  ++(*this);
78  return tmp;
79  }
80 
81  inline const_iterator& operator--() noexcept
82  {
83  m_loop = m_loop->m_edge_previous;
84  --m_position;
85  return *this;
86  }
87 
88  [[nodiscard]] inline const_iterator operator--(int) noexcept
89  {
90  const_iterator tmp = *this;
91  --(*this);
92  return tmp;
93  }
94 
95  [[nodiscard]] inline bool operator==(const const_iterator& other) const noexcept
96  {
97  return m_position == other.m_position;
98  };
99 
100  [[nodiscard]] inline std::weak_ordering operator<=>(const const_iterator& other) const noexcept
101  {
102  return m_position <=> other.m_position;
103  }
104 
105  [[nodiscard]] inline difference_type operator-(const const_iterator& rhs) const noexcept
106  {
107  return m_position - rhs.m_position;
108  }
109 
110  private:
111  brep_loop* m_loop;
112  std::ptrdiff_t m_position;
113  };
114 
115  using const_reverse_iterator = std::reverse_iterator<const_iterator>;
116 
119 
121  [[nodiscard]] inline brep_loop* front() const noexcept
122  {
123  return m_head;
124  }
125 
127  [[nodiscard]] inline brep_loop* back() const noexcept
128  {
129  return m_head->m_edge_previous;
130  }
131 
135 
138  [[nodiscard]] inline constexpr const_iterator begin() const noexcept
139  {
140  const_iterator it;
141  it.m_loop = m_head;
142  it.m_position = 0;
143 
144  return it;
145  }
146  [[nodiscard]] inline constexpr const_iterator cbegin() const noexcept
147  {
148  return begin();
149  }
151 
154  [[nodiscard]] inline constexpr const_iterator end() const noexcept
155  {
156  const_iterator it;
157  it.m_loop = m_head;
158  it.m_position = static_cast<std::ptrdiff_t>(m_size);
159 
160  return it;
161  }
162  [[nodiscard]] inline constexpr const_iterator cend() const noexcept
163  {
164  return end();
165  }
167 
170  [[nodiscard]] inline constexpr const_reverse_iterator rbegin() const noexcept
171  {
172  return std::make_reverse_iterator(end());
173  }
174  [[nodiscard]] inline constexpr const_reverse_iterator crbegin() const noexcept
175  {
176  return rbegin();
177  }
179 
182  [[nodiscard]] inline constexpr const_reverse_iterator rend() const noexcept
183  {
184  return std::make_reverse_iterator(begin());
185  }
186  [[nodiscard]] inline constexpr const_reverse_iterator crend() const noexcept
187  {
188  return rend();
189  }
191 
195 
197  [[nodiscard]] inline constexpr bool empty() const noexcept
198  {
199  return !m_size;
200  }
201 
203  [[nodiscard]] inline constexpr std::size_t size() const noexcept
204  {
205  return m_size;
206  }
207 
211 
217  void push_back(brep_loop* loop);
218 
224  void remove(brep_loop* loop);
225 
227 
228 private:
229  brep_loop* m_head{};
230  std::size_t m_size{};
231 };
232 
237 {
238 public:
239  friend class brep_mesh;
240  friend class brep_vertex_edge_list;
241  friend class brep_element_container<brep_edge>;
242  friend class brep_edge_container;
243  friend class brep_face_container;
244 
250  [[nodiscard]] inline constexpr std::size_t index() const noexcept
251  {
252  return m_index;
253  }
254 
256  [[nodiscard]] inline constexpr const std::array<brep_vertex*, 2>& vertices() const noexcept
257  {
258  return m_vertices;
259  }
260 
262  [[nodiscard]] inline constexpr const brep_edge_loop_list& loops() const noexcept
263  {
264  return m_loops;
265  }
266 
267 private:
268  std::size_t m_index;
269  std::array<brep_vertex*, 2> m_vertices;
270  std::array<brep_edge*, 2> m_vertex_next;
271  std::array<brep_edge*, 2> m_vertex_previous;
272  brep_edge_loop_list m_loops;
273 };
274 
279 {
280 public:
290 
298  void erase(brep_edge* edge) override;
299 
303  void clear() noexcept;
304 
313  [[nodiscard]] brep_edge* find(brep_vertex* a, brep_vertex* b) const;
314 
315 private:
316  friend class brep_mesh;
317 
323  inline explicit brep_edge_container(brep_mesh* mesh) noexcept:
325  {}
326 };
327 
328 } // namespace geom
329 
330 #endif // ANTKEEPER_GEOM_BREP_EDGE_HPP
B-rep edge container.
Definition: brep-edge.hpp:279
void erase(brep_edge *edge) override
Erases an edge and all dependent loops and faces.
Definition: brep-edge.cpp:81
void clear() noexcept
Erases all edges and their dependent loops and faces.
Definition: brep-edge.cpp:97
brep_edge * find(brep_vertex *a, brep_vertex *b) const
Finds an edge bounded by vertices a and b (in any order).
Definition: brep-edge.cpp:105
List of B-rep loops that share a common edge.
Definition: brep-edge.hpp:40
constexpr const_iterator cend() const noexcept
Returns an iterator to the loop following the last loop.
Definition: brep-edge.hpp:162
constexpr bool empty() const noexcept
Returns true if the list is empty, false otherwise.
Definition: brep-edge.hpp:197
brep_loop * front() const noexcept
Returns the first loop.
Definition: brep-edge.hpp:121
void push_back(brep_loop *loop)
Appends a loop to the end of the list.
Definition: brep-edge.cpp:26
void remove(brep_loop *loop)
Removes an loop from the list.
Definition: brep-edge.cpp:47
constexpr const_iterator end() const noexcept
Returns an iterator to the loop following the last loop.
Definition: brep-edge.hpp:154
std::reverse_iterator< const_iterator > const_reverse_iterator
Definition: brep-edge.hpp:115
constexpr const_reverse_iterator rbegin() const noexcept
Returns a reverse iterator to the first loop of the reversed list.
Definition: brep-edge.hpp:170
constexpr const_iterator begin() const noexcept
Returns an iterator to the first loop.
Definition: brep-edge.hpp:138
constexpr const_iterator cbegin() const noexcept
Returns an iterator to the first loop.
Definition: brep-edge.hpp:146
constexpr const_reverse_iterator crbegin() const noexcept
Returns a reverse iterator to the first loop of the reversed list.
Definition: brep-edge.hpp:174
constexpr const_reverse_iterator crend() const noexcept
Returns a reverse iterator to the loop following the last loop of the reversed list.
Definition: brep-edge.hpp:186
constexpr std::size_t size() const noexcept
Returns the number of loops in the list.
Definition: brep-edge.hpp:203
brep_loop * back() const noexcept
Returns the last loop.
Definition: brep-edge.hpp:127
constexpr const_reverse_iterator rend() const noexcept
Returns a reverse iterator to the loop following the last loop of the reversed list.
Definition: brep-edge.hpp:182
Curve segment bounded by two vertices.
Definition: brep-edge.hpp:237
constexpr std::size_t index() const noexcept
Returns the index of this edge in the mesh edge array.
Definition: brep-edge.hpp:250
constexpr const brep_edge_loop_list & loops() const noexcept
Returns the list of loops that share this edge.
Definition: brep-edge.hpp:262
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.
virtual element_type * emplace_back()
Appends a new element to the end of the container.
B-rep face container.
Definition: brep-face.hpp:275
Connected boundary of a single face.
Definition: brep-loop.hpp:38
Boundary representation (B-rep) of a mesh.
Definition: brep-mesh.hpp:34
List of B-rep edges bounded by a common vertex.
Definition: brep-vertex.hpp:40
A point in space.
Geometric algorithms.
@ a
Vertex A region.
@ b
Vertex B region.
constexpr value_type operator*() const noexcept
Definition: brep-edge.hpp:57
const_iterator & operator--() noexcept
Definition: brep-edge.hpp:81
const_iterator operator++(int) noexcept
Definition: brep-edge.hpp:74
std::bidirectional_iterator_tag iterator_concept
Definition: brep-edge.hpp:51
const_iterator operator--(int) noexcept
Definition: brep-edge.hpp:88
bool operator==(const const_iterator &other) const noexcept
Definition: brep-edge.hpp:95
std::bidirectional_iterator_tag iterator_category
Definition: brep-edge.hpp:50
constexpr value_type operator->() const noexcept
Definition: brep-edge.hpp:62
std::weak_ordering operator<=>(const const_iterator &other) const noexcept
Definition: brep-edge.hpp:100
difference_type operator-(const const_iterator &rhs) const noexcept
Definition: brep-edge.hpp:105
const_iterator & operator++() noexcept
Definition: brep-edge.hpp:67