Antkeeper  0.0.1
brep-face.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_FACE_HPP
21 #define ANTKEEPER_GEOM_BREP_FACE_HPP
22 
25 #include <cstddef>
26 #include <iterator>
27 #include <span>
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 
45  {
46  public:
47  friend class brep_face_loop_list;
48 
49  using iterator_category = std::bidirectional_iterator_tag;
50  using iterator_concept = std::bidirectional_iterator_tag;
51  using difference_type = std::ptrdiff_t;
53  using pointer = const value_type*;
54  using reference = const value_type&;
55 
56  [[nodiscard]] inline constexpr value_type operator*() const noexcept
57  {
58  return m_loop;
59  }
60 
61  [[nodiscard]] inline constexpr value_type operator->() const noexcept
62  {
63  return m_loop;
64  }
65 
66  inline const_iterator& operator++() noexcept
67  {
68  m_loop = m_loop->m_face_next;
69  ++m_position;
70  return *this;
71  }
72 
73  [[nodiscard]] inline const_iterator operator++(int) noexcept
74  {
75  const_iterator tmp = *this;
76  ++(*this);
77  return tmp;
78  }
79 
80  inline const_iterator& operator--() noexcept
81  {
82  m_loop = m_loop->m_face_previous;
83  --m_position;
84  return *this;
85  }
86 
87  [[nodiscard]] inline const_iterator operator--(int) noexcept
88  {
89  const_iterator tmp = *this;
90  --(*this);
91  return tmp;
92  }
93 
94  [[nodiscard]] inline bool operator==(const const_iterator& other) const noexcept
95  {
96  return m_position == other.m_position;
97  };
98 
99  [[nodiscard]] inline std::weak_ordering operator<=>(const const_iterator& other) const noexcept
100  {
101  return m_position <=> other.m_position;
102  }
103 
104  [[nodiscard]] inline difference_type operator-(const const_iterator& rhs) const noexcept
105  {
106  return m_position - rhs.m_position;
107  }
108 
109  private:
110  brep_loop* m_loop;
111  std::ptrdiff_t m_position;
112  };
113 
114  using const_reverse_iterator = std::reverse_iterator<const_iterator>;
115 
118 
120  [[nodiscard]] inline brep_loop* front() const noexcept
121  {
122  return m_head;
123  }
124 
126  [[nodiscard]] inline brep_loop* back() const noexcept
127  {
128  return m_head->m_face_previous;
129  }
130 
134 
137  [[nodiscard]] inline constexpr const_iterator begin() const noexcept
138  {
139  const_iterator it;
140  it.m_loop = m_head;
141  it.m_position = 0;
142 
143  return it;
144  }
145  [[nodiscard]] inline constexpr const_iterator cbegin() const noexcept
146  {
147  return begin();
148  }
150 
153  [[nodiscard]] inline constexpr const_iterator end() const noexcept
154  {
155  const_iterator it;
156  it.m_loop = m_head;
157  it.m_position = static_cast<std::ptrdiff_t>(m_size);
158 
159  return it;
160  }
161  [[nodiscard]] inline constexpr const_iterator cend() const noexcept
162  {
163  return end();
164  }
166 
169  [[nodiscard]] inline constexpr const_reverse_iterator rbegin() const noexcept
170  {
171  return std::make_reverse_iterator(end());
172  }
173  [[nodiscard]] inline constexpr const_reverse_iterator crbegin() const noexcept
174  {
175  return rbegin();
176  }
178 
181  [[nodiscard]] inline constexpr const_reverse_iterator rend() const noexcept
182  {
183  return std::make_reverse_iterator(begin());
184  }
185  [[nodiscard]] inline constexpr const_reverse_iterator crend() const noexcept
186  {
187  return rend();
188  }
190 
194 
196  [[nodiscard]] inline constexpr bool empty() const noexcept
197  {
198  return !m_size;
199  }
200 
202  [[nodiscard]] inline constexpr std::size_t size() const noexcept
203  {
204  return m_size;
205  }
206 
210 
216  void push_back(brep_loop* loop);
217 
224  void insert(brep_loop* next, brep_loop* loop);
225 
231  void remove(brep_loop* loop);
232 
234 
235 private:
236  brep_loop* m_head{};
237  std::size_t m_size{};
238 };
239 
244 {
245 public:
246  friend class brep_mesh;
247  friend class brep_element_container<brep_face>;
248  friend class brep_face_container;
249 
255  [[nodiscard]] inline constexpr std::size_t index() const noexcept
256  {
257  return m_index;
258  }
259 
261  [[nodiscard]] inline constexpr const brep_face_loop_list& loops() const noexcept
262  {
263  return m_loops;
264  }
265 
266 private:
267  std::size_t m_index;
268  brep_face_loop_list m_loops;
269 };
270 
275 {
276 public:
284  brep_face* emplace_back(const std::span<brep_vertex*> vertices);
285 
293  void erase(brep_face* face) override;
294 
298  void clear() noexcept;
299 
305  void reverse(brep_face* face);
306 
307 private:
308  friend class brep_mesh;
309 
315  inline explicit brep_face_container(brep_mesh* mesh) noexcept:
317  {}
318 };
319 
320 } // namespace geom
321 
322 #endif // ANTKEEPER_GEOM_BREP_FACE_HPP
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
void clear() noexcept
Erases all faces and their loops.
Definition: brep-face.cpp:138
void erase(brep_face *face) override
Erases a face and all of its loops.
Definition: brep-face.cpp:117
void reverse(brep_face *face)
Reverses the direction of a face's bounding loops.
Definition: brep-face.cpp:146
List of B-rep loops that bound a common face.
Definition: brep-face.hpp:40
std::reverse_iterator< const_iterator > const_reverse_iterator
Definition: brep-face.hpp:114
constexpr const_reverse_iterator crend() const noexcept
Returns a reverse iterator to the loop following the last loop of the reversed list.
Definition: brep-face.hpp:185
brep_loop * front() const noexcept
Returns the first loop.
Definition: brep-face.hpp:120
constexpr const_iterator cend() const noexcept
Returns an iterator to the loop following the last loop.
Definition: brep-face.hpp:161
constexpr const_iterator begin() const noexcept
Returns an iterator to the first loop.
Definition: brep-face.hpp:137
constexpr const_reverse_iterator rend() const noexcept
Returns a reverse iterator to the loop following the last loop of the reversed list.
Definition: brep-face.hpp:181
constexpr const_reverse_iterator rbegin() const noexcept
Returns a reverse iterator to the first loop of the reversed list.
Definition: brep-face.hpp:169
constexpr std::size_t size() const noexcept
Returns the number of loops in the list.
Definition: brep-face.hpp:202
constexpr const_reverse_iterator crbegin() const noexcept
Returns a reverse iterator to the first loop of the reversed list.
Definition: brep-face.hpp:173
constexpr bool empty() const noexcept
Returns true if the list is empty, false otherwise.
Definition: brep-face.hpp:196
brep_loop * back() const noexcept
Returns the last loop.
Definition: brep-face.hpp:126
void push_back(brep_loop *loop)
Appends a loop to the end of the list.
Definition: brep-face.cpp:27
void insert(brep_loop *next, brep_loop *loop)
Inserts a loop before a given loop.
Definition: brep-face.cpp:48
constexpr const_iterator end() const noexcept
Returns an iterator to the loop following the last loop.
Definition: brep-face.hpp:153
constexpr const_iterator cbegin() const noexcept
Returns an iterator to the first loop.
Definition: brep-face.hpp:145
void remove(brep_loop *loop)
Removes an loop from the list.
Definition: brep-face.cpp:58
Portion of a shell bounded by loops.
Definition: brep-face.hpp:244
constexpr const brep_face_loop_list & loops() const noexcept
Returns the list of loops associated with this face.
Definition: brep-face.hpp:261
constexpr std::size_t index() const noexcept
Returns the index of this face in the mesh face array.
Definition: brep-face.hpp:255
Connected boundary of a single face.
Definition: brep-loop.hpp:38
Boundary representation (B-rep) of a mesh.
Definition: brep-mesh.hpp:34
Geometric algorithms.
bool operator==(const const_iterator &other) const noexcept
Definition: brep-face.hpp:94
difference_type operator-(const const_iterator &rhs) const noexcept
Definition: brep-face.hpp:104
std::bidirectional_iterator_tag iterator_concept
Definition: brep-face.hpp:50
const_iterator operator--(int) noexcept
Definition: brep-face.hpp:87
const_iterator & operator++() noexcept
Definition: brep-face.hpp:66
const_iterator operator++(int) noexcept
Definition: brep-face.hpp:73
std::weak_ordering operator<=>(const const_iterator &other) const noexcept
Definition: brep-face.hpp:99
const_iterator & operator--() noexcept
Definition: brep-face.hpp:80
constexpr value_type operator*() const noexcept
Definition: brep-face.hpp:56
std::bidirectional_iterator_tag iterator_category
Definition: brep-face.hpp:49
constexpr value_type operator->() const noexcept
Definition: brep-face.hpp:61