Unravel Engine C++ Reference
Loading...
Searching...
No Matches
repeat_shape.hpp
Go to the documentation of this file.
1#ifndef GENERATOR_REPEATSHAPE_HPP
2#define GENERATOR_REPEATSHAPE_HPP
3
4#include "edge.hpp"
5#include "shape_vertex.hpp"
6#include "utils.hpp"
7
8namespace generator
9{
10
14template<typename shape_t>
16{
17public:
18 class edges_t
19 {
20 public:
21 bool done() const noexcept
22 {
23 return index_ >= repeat_shape_->instances_;
24 }
25
27 {
28 edge_t temp = edges_.generate();
29 temp.vertices += delta_;
30 return temp;
31 }
32
33 void next() noexcept
34 {
35 edges_.next();
36
37 if(edges_.done())
38 {
39 ++index_;
40 delta_ += repeat_shape_->vertex_count_;
41 edges_ = repeat_shape_->shape_.edges();
42 }
43 }
44
45 private:
46 const repeat_shape_t* repeat_shape_;
47
49
50 int index_;
51
52 int delta_;
53
54 explicit edges_t(const repeat_shape_t* repeatShape) noexcept
55 : repeat_shape_{repeatShape}
56 , edges_{repeatShape->shape_.edges()}
57 , index_{repeatShape->vertex_count_ > 0 ? 0 : repeatShape->instances_}
58 , delta_{0}
59 {
60 }
61
62 int countEdges() const noexcept
63 {
64 if(repeat_shape_->instances_ < 1)
65 return 0;
66
67 return count(repeat_shape_->shape_.edges()) * (repeat_shape_->instances_ - index_ - 1) + count(edges_);
68 }
69
70 friend int count(const edges_t& generator) noexcept
71 {
72 return generator.countEdges();
73 }
74
75 friend class repeat_shape_t;
76 };
77
79 {
80 public:
81 bool done() const noexcept
82 {
83 return index_ >= repeat_shape_->instances_;
84 }
85
87 {
88 shape_vertex_t temp = vertices_.generate();
89 temp.position += delta_;
90 return temp;
91 }
92
93 void next()
94 {
95 vertices_.next();
96
97 if(vertices_.done())
98 {
99 ++index_;
100 delta_ += repeat_shape_->delta_;
101 vertices_ = repeat_shape_->shape_.vertices();
102 }
103 }
104
105 private:
106 explicit vertices_t(const repeat_shape_t* repeatShape)
107 : repeat_shape_{repeatShape}
108 , vertices_{repeatShape->shape_.vertices()}
109 , index_{repeatShape->vertex_count_ > 0 ? 0 : repeatShape->instances_}
110 , delta_{}
111 {
112 }
113
114 const repeat_shape_t* repeat_shape_;
115
116 typename vertex_generator_type<shape_t>::type vertices_;
117
118 int index_;
119
120 gml::dvec2 delta_;
121
122 int countvertices_t() const noexcept
123 {
124 if(repeat_shape_->instances_ < 1)
125 return 0;
126
127 return repeat_shape_->vertex_count_ * (repeat_shape_->instances_ - index_ - 1) + count(vertices_);
128 }
129
130 friend int count(const vertices_t& generator) noexcept
131 {
132 return generator.countvertices_t();
133 }
134
135 friend class repeat_shape_t;
136 };
137
141 explicit repeat_shape_t(shape_t shape, int instances, const gml::dvec2& delta) noexcept
142 : shape_{std::move(shape)}
143 , instances_{instances}
144 , delta_{delta}
145 , vertex_count_{count(shape_.vertices())}
146 {
147 }
148
149 edges_t edges() const noexcept
150 {
151 return edges_t{this};
152 }
153
154 vertices_t vertices() const noexcept
155 {
156 return vertices_t{this};
157 }
158
159private:
160 shape_t shape_;
161
162 int instances_;
163
164 gml::dvec2 delta_;
165
166 int vertex_count_;
167};
168
169template<typename shape_t>
170repeat_shape_t<shape_t> repeat_shape(shape_t shape, int instances, const gml::dvec2& delta) noexcept
171{
172 return repeat_shape_t<shape_t>{std::move(shape), instances, delta};
173}
174} // namespace generator
175
176#endif
gml::ivec2 vertices
Definition edge.hpp:12
friend int count(const edges_t &generator) noexcept
friend int count(const vertices_t &generator) noexcept
edges_t edges() const noexcept
vertices_t vertices() const noexcept
repeat_shape_t(shape_t shape, int instances, const gml::dvec2 &delta) noexcept
int count(const generator_t &generator) noexcept
Counts the number of steps left in the generator.
Definition utils.hpp:70
repeat_shape_t< shape_t > repeat_shape(shape_t shape, int instances, const gml::dvec2 &delta) noexcept