CeresEngine 0.2.0
A game development framework
Loading...
Searching...
No Matches
MergeShape.hpp
Go to the documentation of this file.
1//
2// CeresEngine - A game development framework
3//
4// Created by Rogiel Sulzbach.
5// Copyright (c) 2018-2022 Rogiel Sulzbach. All rights reserved.
6//
7
8#pragma once
9
10#include "EmptyShape.hpp"
11#include "ShapeVertex.hpp"
12#include "Utility.hpp"
13
15
17 template<typename... Shape> class MergeShape; // undefined
18
19 template<> class MergeShape<> : public EmptyShape {};
20
21 template<typename Head, typename... Tail> class MergeShape<Head, Tail...> {
22 public:
23 class Edges {
24 public:
25 [[nodiscard]] Edge generate() const {
26 if(!mHead.done())
27 return mHead.generate();
28
29 Edge edge = mTail.generate();
30 edge.vertices += mHeadVertexCount;
31 return edge;
32 }
33
34 [[nodiscard]] bool done() const noexcept { return mAllDone; }
35
36 void next() {
37 if(!mHead.done())
38 mHead.next();
39 else
40 mTail.next();
41
42 mAllDone = mTail.done() && mHead.done();
43 }
44
45 private:
47 typename EdgeGeneratorType<MergeShape<Tail...>>::Type mTail;
48
50
52
53 Edges(const MergeShape& shape)
54 : mHead{shape.mHead.edges()},
55 mTail(shape.mTail.edges()), mHeadVertexCount{count(shape.mHead.vertices())}, mAllDone{mTail.done() && mHead.done()} {}
56
57 friend class MergeShape<Head, Tail...>;
58 };
59
60 class Vertices {
61 public:
63 if(!mHead.done())
64 return mHead.generate();
65 return mTail.generate();
66 }
67
68 [[nodiscard]] bool done() const noexcept { return mAllDone; }
69
70 void next() {
71 if(!mHead.done())
72 mHead.next();
73 else
74 mTail.next();
75
76 mAllDone = mTail.done() && mHead.done();
77 }
78
79 private:
81 typename VertexGeneratorType<MergeShape<Tail...>>::Type mTail;
83
84 Vertices(const MergeShape& shape) : mHead{shape.mHead.vertices()}, mTail(shape.mTail.vertices()), mAllDone{mTail.done() && mHead.done()} {}
85
86 friend class MergeShape<Head, Tail...>;
87 };
88
89 MergeShape(Head head, Tail... tail) : mHead{head}, mTail{tail...} {}
90
91 [[nodiscard]] Edges edges() const noexcept { return *this; }
92 [[nodiscard]] Vertices vertices() const noexcept { return *this; }
93
94 private:
95 Head mHead;
96 MergeShape<Tail...> mTail;
97 };
98
99 template<typename... Shape> MergeShape<Shape...> mergeShape(Shape... shapes) { return MergeShape<Shape...>{std::move(shapes)...}; }
100
101} // namespace CeresEngine::MeshGenerator
Will have a type named "Type" that has same type as value returned by method edges() for type Primiti...
Definition Utility.hpp:23
decltype(std::declval< const Primitive * >() ->edges()) Type
Definition Utility.hpp:25
Definition Edge.hpp:14
Vector2i vertices
Definition Edge.hpp:16
Empty shape with zero vertices and edges.
Definition EmptyShape.hpp:16
Edges(const MergeShape &shape)
Definition MergeShape.hpp:53
EdgeGeneratorType< Head >::Type mHead
Definition MergeShape.hpp:46
EdgeGeneratorType< MergeShape< Tail... > >::Type mTail
Definition MergeShape.hpp:47
Edge generate() const
Definition MergeShape.hpp:25
bool done() const noexcept
Definition MergeShape.hpp:34
VertexGeneratorType< MergeShape< Tail... > >::Type mTail
Definition MergeShape.hpp:81
VertexGeneratorType< Head >::Type mHead
Definition MergeShape.hpp:80
ShapeVertex generate() const
Definition MergeShape.hpp:62
bool done() const noexcept
Definition MergeShape.hpp:68
Vertices vertices() const noexcept
Definition MergeShape.hpp:92
Edges edges() const noexcept
Definition MergeShape.hpp:91
MergeShape< Tail... > mTail
Definition MergeShape.hpp:96
MergeShape(Head head, Tail... tail)
Definition MergeShape.hpp:89
Merges (concatenates) multiple shapes together.
Definition MergeShape.hpp:17
A point on a path.
Definition ShapeVertex.hpp:16
Will have a type named "Type" that has same type as value returned by method vertices() for type Prim...
Definition Utility.hpp:37
decltype(std::declval< const Primitive * >() ->vertices()) Type
Definition Utility.hpp:39
A type that describes a conjunction of shapes that can be filled and stroked.
Definition Shape.hpp:198
Definition AnyGenerator.hpp:12
MergeShape< Shape... > mergeShape(Shape... shapes)
Definition MergeShape.hpp:99
constexpr CountAlgorithmFunctor count
Returns the number of elements matching an element.
Definition Count.hpp:82
constexpr size_t hash(const T &v)
Generates a hash for the provided type.
Definition Hash.hpp:25