Unravel Engine C++ Reference
Loading...
Searching...
No Matches
merge_path.hpp
Go to the documentation of this file.
1#ifndef GENERATOR_MERGEPath_HPP
2#define GENERATOR_MERGEPath_HPP
3
4#include "empty_path.hpp"
5#include "path_vertex.hpp"
6#include "utils.hpp"
7
8namespace generator
9{
10
12template<typename... Path>
13class merge_path_t; // undefined
14
15template<>
16class merge_path_t<> : public empty_path_t
17{
18};
19
20template<typename Head, typename... Tail>
21class merge_path_t<Head, Tail...>
22{
23public:
24 class edges_t
25 {
26 public:
28 {
29 if(!head_.done())
30 return head_.generate();
31 return tail_.generate() + head_vertex_count_;
32 }
33
34 bool done() const noexcept
35 {
36 return all_done_;
37 }
38
39 void next()
40 {
41 if(!head_.done())
42 head_.next();
43 else
44 tail_.next();
45
46 all_done_ = tail_.done() && head_.done();
47 }
48
49 private:
51 typename edge_generator_type<merge_path_t<Tail...>>::type tail_;
52
53 int head_vertex_count_;
54
55 bool all_done_;
56
57 explicit edges_t(const merge_path_t& path)
58 : head_{path.head_.triangles()}
59 , tail_(path.tail_.triangles())
60 , head_vertex_count_{count(path.head_.vertices())}
61 , all_done_{tail_.done() && head_.done()}
62 {
63 }
64
65 friend class merge_path_t<Head, Tail...>;
66 };
67
69 {
70 public:
72 {
73 if(!head_.done())
74 return head_.generate();
75 return tail_.generate();
76 }
77
78 bool done() const noexcept
79 {
80 return all_done_;
81 }
82
83 void next()
84 {
85 if(!head_.done())
86 head_.next();
87 else
88 tail_.next();
89
90 all_done_ = tail_.done() && head_.done();
91 }
92
93 private:
95 typename vertex_generator_type<merge_path_t<Tail...>>::type tail_;
96 bool all_done_;
97
98 explicit vertices_t(const merge_path_t& path)
99 : head_{path.head_.vertices()}
100 , tail_(path.tail_.vertices())
101 , all_done_{tail_.done() && head_.done()}
102 {
103 }
104
105 friend class merge_path_t<Head, Tail...>;
106 };
107
108 merge_path_t(Head head, Tail... tail) : head_{head}, tail_{tail...}
109 {
110 }
111
112 edges_t edges() const noexcept
113 {
114 return edges_t{*this};
115 }
116
117 vertices_t vertices() const noexcept
118 {
119 return vertices_t{*this};
120 }
121
122private:
123 Head head_;
124 merge_path_t<Tail...> tail_;
125};
126
127template<typename... Path>
128merge_path_t<Path...> merge_path(Path... paths)
129{
130 return merge_path_t<Path...>{std::move(paths)...};
131}
132} // namespace generator
133
134#endif
manifold_type type
Empty path with zero vertices and edges.
merge_path_t(Head head, Tail... tail)
vertices_t vertices() const noexcept
Merges (concatenates) multiple paths together.
merge_path_t< Path... > merge_path(Path... paths)
int count(const generator_t &generator) noexcept
Counts the number of steps left in the generator.
Definition utils.hpp:70