Antkeeper  0.0.1
brep-vertex.cpp
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 
22 
23 namespace geom {
24 
26 {
27  // Determine index of vertex in new edge vertex array
28  const std::size_t i = (edge->m_vertices[1] == m_vertex);
29 
30  if (empty())
31  {
32  // List empty, initialize
33  m_head = edge;
34  edge->m_vertex_next[i] = edge;
35  edge->m_vertex_previous[i] = edge;
36  }
37  else
38  {
39  // Determine index of vertex in head edge vertex array
40  const std::size_t j = (m_head->m_vertices[1] == m_vertex);
41 
42  // Append edge
43  edge->m_vertex_next[i] = m_head;
44  edge->m_vertex_previous[i] = m_head->m_vertex_previous[j];
45  edge->m_vertex_previous[i]->m_vertex_next[edge->m_vertex_previous[i]->m_vertices[1] == m_vertex] = edge;
46  m_head->m_vertex_previous[j] = edge;
47  }
48 
49  ++m_size;
50 }
51 
53 {
54  // Determine index of vertex in edge vertex array
55  const std::size_t i = (edge->m_vertices[1] == m_vertex);
56 
57  // Get pointers to the next and previous edges
58  brep_edge* next = edge->m_vertex_next[i];
59  brep_edge* previous = edge->m_vertex_previous[i];
60 
61  // Directly link next and previous edges
62  next->m_vertex_previous[next->m_vertices[1] == m_vertex] = previous;
63  previous->m_vertex_next[previous->m_vertices[1] == m_vertex] = next;
64 
65  // If edge was the list head, update head
66  if (m_head == edge)
67  {
68  m_head = next;
69  }
70 
71  --m_size;
72 }
73 
75 {
77  vertex->m_index = size() - 1;
78  vertex->m_edges.m_vertex = vertex;
79  return vertex;
80 };
81 
83 {
84  // Erase all edges bounded by this vertex
85  while (!vertex->edges().empty())
86  {
87  m_mesh->edges().erase(vertex->edges().back());
88  }
89 
90  // Erase vertex
92 }
93 
95 {
96  while (!empty())
97  {
98  erase(back());
99  }
100 }
101 
102 } // namespace geom
void erase(brep_edge *edge) override
Erases an edge and all dependent loops and faces.
Definition: brep-edge.cpp:81
Curve segment bounded by two vertices.
Definition: brep-edge.hpp:237
constexpr std::size_t size() const noexcept
Returns the number of elements in the container.
virtual void erase(element_type *element)
Erases an element from the container.
constexpr bool empty() const noexcept
Returns true if the container is empty, false otherwise.
constexpr element_type * back() const noexcept
Returns the last element.
virtual element_type * emplace_back()
Appends a new element to the end of the container.
const brep_edge_container & edges() const noexcept
Returns the mesh edges.
Definition: brep-mesh.hpp:81
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
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 bool empty() const noexcept
Returns true if the list is empty, false otherwise.
A point in space.
Geometric algorithms.