Unravel Engine C++ Reference
Loading...
Searching...
No Matches
transform_shape.hpp
Go to the documentation of this file.
1#ifndef GENERATOR_SHAPETRANSLATOR_HPP
2#define GENERATOR_SHAPETRANSLATOR_HPP
3
4#include "shape_vertex.hpp"
5#include "utils.hpp"
6#include <functional>
7
8namespace generator
9{
10
12template<typename shape_t>
14{
15private:
16 using impl_t = shape_t;
17 impl_t shape_;
18
19public:
21 {
22 public:
24 {
25 auto temp = vertices_.generate();
26 shape_->mutate_(temp);
27 return temp;
28 }
29
30 bool done() const noexcept
31 {
32 return vertices_.done();
33 }
34
35 void next()
36 {
37 vertices_.next();
38 }
39
40 private:
41 const transform_shape_t* shape_;
42
43 typename vertex_generator_type<shape_t>::type vertices_;
44
45 explicit vertices_t(const transform_shape_t& shape) : shape_{&shape}, vertices_{shape.shape_.vertices()}
46 {
47 }
48
49 friend class transform_shape_t;
50 };
51
54 transform_shape_t(shape_t shape, const std::function<void(shape_vertex_t&)>& mutate)
55 : shape_{std::move(shape)}
56 , mutate_{mutate}
57 {
58 }
59
60 using edges_t = typename impl_t::edges_t;
61
62 edges_t edges() const noexcept
63 {
64 return shape_.edges();
65 }
66
67 vertices_t vertices() const noexcept
68 {
69 return vertices_t{*this};
70 }
71
72private:
73 std::function<void(shape_vertex_t&)> mutate_;
74};
75
76template<typename shape_t>
77transform_shape_t<shape_t> transform_shape(shape_t shape, const std::function<void(shape_vertex_t&)>& mutate)
78{
79 return transform_shape_t<shape_t>{std::move(shape), std::move(mutate)};
80}
81} // namespace generator
82
83#endif
Apply a mutator function to each vertex.
vertices_t vertices() const noexcept
typename impl_t::edges_t edges_t
edges_t edges() const noexcept
transform_shape_t(shape_t shape, const std::function< void(shape_vertex_t &)> &mutate)
transform_shape_t< shape_t > transform_shape(shape_t shape, const std::function< void(shape_vertex_t &)> &mutate)