Wildmeshing Toolkit
primitive_range_iter.hpp
Go to the documentation of this file.
1 
2 #pragma once
3 
4 #include <vector>
5 #include <wmtk/Primitive.hpp>
6 namespace wmtk::utils {
7 
8 
9 namespace detail {
10 template <
11  std::underlying_type_t<PrimitiveType> Start,
12  std::underlying_type_t<PrimitiveType> End,
13  bool Inverted = (Start > End)>
15 {
16  using integral_type = std::underlying_type_t<PrimitiveType>;
17  class iterator
18  {
19  public:
21  : m_value(pt)
22  {}
24  : m_value(static_cast<integral_type>(pt))
25  {}
27  {
28  if constexpr (Inverted) {
29  return pt - 1;
30  } else {
31  return pt + 1;
32  }
33  }
35  {
36  if constexpr (Inverted) {
37  return pt + 1;
38  } else {
39  return pt - 1;
40  }
41  }
42  auto operator++() -> iterator
43  {
44  m_value = increment(m_value);
45  return *this;
46  }
47  auto operator--() -> iterator
48  {
49  m_value = decrement(m_value);
50  return *this;
51  }
52  auto operator++(int) -> iterator
53  {
54  integral_type pt = m_value;
55  m_value = increment(m_value);
56  return iterator(pt);
57  }
58  auto operator--(int) -> iterator
59  {
60  integral_type pt = m_value;
61  m_value = decrement(m_value);
62  return iterator(pt);
63  }
64 
65  auto operator*() const -> PrimitiveType { return static_cast<PrimitiveType>(m_value); }
66 
67  private:
69  };
70  // using iterator = PrimitiveType;
72 
73  auto begin() const -> iterator { return iterator(Start); }
74  auto end() const -> iterator { return iterator(End); }
75  auto cbegin() const -> const_iterator { return const_iterator(Start); }
76  auto cend() const -> const_iterator { return const_iterator(End); }
77 };
78 } // namespace detail
79 
80 
81 // returns a vector of primitives including the endpoints of the range
82 template <PrimitiveType Start, PrimitiveType End>
84 {
85  using integral_type = std::underlying_type_t<PrimitiveType>;
86  constexpr static auto StartI = static_cast<integral_type>(Start);
87  constexpr static auto EndI = static_cast<integral_type>(End);
89 }
90 // returns a vector of primitives including the endpoint
91 template <PrimitiveType Start, bool LowerToUpper = true>
93 {
94  constexpr static PrimitiveType End = PrimitiveType::Tetrahedron;
95  using integral_type = std::underlying_type_t<PrimitiveType>;
96  constexpr static auto StartI = static_cast<integral_type>(Start);
97  constexpr static auto EndI = static_cast<integral_type>(End);
98  if constexpr (LowerToUpper) {
100  } else {
101  return detail::PrimitiveTypeRange<EndI, StartI - 1>{};
102  }
103 }
104 // returns a vector of primitives including the endpoint
105 template <PrimitiveType End, bool LowerToUpper = true>
107 {
108  constexpr static PrimitiveType Start = PrimitiveType::Vertex;
109  using integral_type = std::underlying_type_t<PrimitiveType>;
110  constexpr static auto StartI = static_cast<integral_type>(Start);
111  constexpr static auto EndI = static_cast<integral_type>(End);
112  if constexpr (LowerToUpper) {
114  } else {
115  return detail::PrimitiveTypeRange<EndI, StartI - 1>{};
116  }
117 }
118 
119 } // namespace wmtk::utils
static auto increment(integral_type pt) -> integral_type
static auto decrement(integral_type pt) -> integral_type
std::underlying_type_t< PrimitiveType > integral_type
std::vector< PrimitiveType > primitive_above(PrimitiveType pt, bool lower_to_upper)
std::vector< PrimitiveType > primitive_range(PrimitiveType pt0, PrimitiveType pt1)
std::vector< PrimitiveType > primitive_below(PrimitiveType pt, bool lower_to_upper)