Loading [MathJax]/extensions/tex2jax.js
Tatooine
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Modules Pages Concepts
grid_vertex_neighbors.h
Go to the documentation of this file.
1#ifndef TATOOINE_GRID_VERTEX_NEIGHBORS_H
2#define TATOOINE_GRID_VERTEX_NEIGHBORS_H
3//==============================================================================
4#include <cstddef>
5#include "grid_vertex.h"
6#include "subgrid.h"
7//==============================================================================
8namespace tatooine {
9//==============================================================================
10template <typename Real, size_t N>
11struct grid_vertex_neighbors : subgrid<Real, N> {
12 grid_vertex<Real, N> center;
13 //----------------------------------------------------------------------------
14 explicit grid_vertex_neighbors(const grid_vertex<Real, N>& c)
15 : subgrid<Real, N>{c, c}, center(c) {
16 for (size_t i = 0; i < N; ++i) {
17 if (this->m_begin_vertex.iterators[i] !=
18 this->m_begin_vertex.iterators[i].begin()) {
19 --this->m_begin_vertex.iterators[i];
20 }
21 for (size_t j = 0; j < 2; ++j) {
22 if (this->m_end_vertex.iterators[i] !=
23 this->m_end_vertex.iterators[i].end()) {
24 ++this->m_end_vertex.iterators[i];
25 }
26 }
27 }
28 }
29 //----------------------------------------------------------------------------
30 struct iterator : subgrid<Real, N>::vertex_iterator {
31 auto operator++() -> auto& {
33 if (this->v == neighbors()->center) {
35 }
36 return *this;
37 }
38 //--------------------------------------------------------------------------
39 auto operator--() -> auto& {
41 if (this->v == neighbors()->center) {
43 }
44 return *this;
45 }
46 //--------------------------------------------------------------------------
47 auto neighbors() {
48 return reinterpret_cast<grid_vertex_neighbors*>(this->m_subgrid);
49 }
50 };
51 //----------------------------------------------------------------------------
52 auto begin() {
53 iterator it{this->m_begin_vertex, this};
54 if ((this->m_begin_vertex == this->center)) { ++it; }
55 return it;
56 }
57 //----------------------------------------------------------------------------
58 auto end() {
59 auto actual_end_vertex = this->m_begin_vertex;
60 actual_end_vertex.iterators.back() = this->m_end_vertex.iterators.back();
61 return iterator{actual_end_vertex, this};
62 }
63};
64//==============================================================================
65} // namespace tatooine
66//==============================================================================
67#endif
Definition: algorithm.h:6
Definition: grid_vertex_neighbors.h:30
auto operator++() -> auto &
Definition: grid_vertex_neighbors.h:31
auto neighbors()
Definition: grid_vertex_neighbors.h:47
auto operator--() -> auto &
Definition: grid_vertex_neighbors.h:39
Definition: grid_vertex_neighbors.h:11
grid_vertex< Real, N > center
Definition: grid_vertex_neighbors.h:12
grid_vertex_neighbors(const grid_vertex< Real, N > &c)
Definition: grid_vertex_neighbors.h:14
auto end()
Definition: grid_vertex_neighbors.h:58
auto begin()
Definition: grid_vertex_neighbors.h:52
grid_vertex< Real, N > v
Definition: subgrid.h:43
auto operator--() -> auto &
Definition: subgrid.h:57
subgrid< Real, N > * m_subgrid
Definition: subgrid.h:44
auto operator++() -> auto &
Definition: subgrid.h:46
Definition: subgrid.h:14
grid_vertex< Real, N > m_begin_vertex
Definition: subgrid.h:20
grid_vertex< Real, N > m_end_vertex
Definition: subgrid.h:20