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  public:
17  using integral_type = std::underlying_type_t<PrimitiveType>;
18  class iterator
19  {
20  public:
22  : m_value(pt)
23  {}
25  : m_value(static_cast<integral_type>(pt))
26  {}
28  {
29  if constexpr (Inverted) {
30  return pt - 1;
31  } else {
32  return pt + 1;
33  }
34  }
36  {
37  if constexpr (Inverted) {
38  return pt + 1;
39  } else {
40  return pt - 1;
41  }
42  }
43  auto operator++() -> iterator
44  {
45  m_value = increment(m_value);
46  return *this;
47  }
48  auto operator--() -> iterator
49  {
50  m_value = decrement(m_value);
51  return *this;
52  }
53  auto operator++(int) -> iterator
54  {
55  integral_type pt = m_value;
56  m_value = increment(m_value);
57  return iterator(pt);
58  }
59  auto operator--(int) -> iterator
60  {
61  integral_type pt = m_value;
62  m_value = decrement(m_value);
63  return iterator(pt);
64  }
65 
66  auto operator*() const -> PrimitiveType { return static_cast<PrimitiveType>(m_value); }
67 
68  private:
70  };
71  // using iterator = PrimitiveType;
73 
74  auto begin() const -> iterator { return iterator(Start); }
75  auto end() const -> iterator { return iterator(End); }
76  auto cbegin() const -> const_iterator { return const_iterator(Start); }
77  auto cend() const -> const_iterator { return const_iterator(End); }
78 };
79 } // namespace detail
80 
81 
82 // returns a vector of primitives including the endpoints of the range
83 template <PrimitiveType Start, PrimitiveType End>
85 {
86  using integral_type = std::underlying_type_t<PrimitiveType>;
87  constexpr static auto StartI = static_cast<integral_type>(Start);
88  constexpr static auto EndI = static_cast<integral_type>(End);
90 }
91 // returns a vector of primitives including the endpoint
92 template <PrimitiveType Start, bool LowerToUpper = true>
94 {
95  constexpr static PrimitiveType End = PrimitiveType::Tetrahedron;
96  using integral_type = std::underlying_type_t<PrimitiveType>;
97  constexpr static auto StartI = static_cast<integral_type>(Start);
98  constexpr static auto EndI = static_cast<integral_type>(End);
99  if constexpr (LowerToUpper) {
101  } else {
102  return detail::PrimitiveTypeRange<EndI, StartI - 1>{};
103  }
104 }
105 // returns a vector of primitives including the endpoint
106 template <PrimitiveType End, bool LowerToUpper = true>
108 {
109  constexpr static PrimitiveType Start = PrimitiveType::Vertex;
110  using integral_type = std::underlying_type_t<PrimitiveType>;
111  constexpr static auto StartI = static_cast<integral_type>(Start);
112  constexpr static auto EndI = static_cast<integral_type>(End);
113  if constexpr (LowerToUpper) {
115  } else {
116  return detail::PrimitiveTypeRange<EndI, StartI - 1>{};
117  }
118 }
119 
120 } // 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)