CeresEngine 0.2.0
A game development framework
Loading...
Searching...
No Matches
RepeatShape.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
11#include "Edge.hpp"
12#include "ShapeVertex.hpp"
13#include "Utility.hpp"
14
16
18 template<typename Shape> class RepeatShape {
19 public:
20 class Edges {
21 public:
23
24 [[nodiscard]] Edge generate() const {
25 Edge temp = mEdges.generate();
26 temp.vertices += mDelta;
27 return temp;
28 }
29
30 void next() noexcept {
31 mEdges.next();
32
33 if(mEdges.done()) {
34 ++mIndex;
36 mEdges = mRepeatShape->mShape.edges();
37 }
38 }
39
40 private:
42
44
45 int mIndex;
46
47 int mDelta;
48
50 : mRepeatShape{repeatShape}, mEdges{repeatShape->mShape.edges()}, mIndex{repeatShape->mVertexCount > 0 ? 0 : repeatShape->mInstances}, mDelta{
51 0} {}
52
55 return 0;
56
57 return count(mRepeatShape->mShape.edges()) * (mRepeatShape->mInstances - mIndex - 1) + count(mEdges);
58 }
59
60 friend int count(const Edges& generator) noexcept { return generator.countEdges(); }
61
62 friend class RepeatShape;
63 };
64
65 class Vertices {
66 public:
68
70 ShapeVertex temp = mVertices.generate();
71 temp.position += mDelta;
72 return temp;
73 }
74
75 void next() {
76 mVertices.next();
77
78 if(mVertices.done()) {
79 ++mIndex;
81 mVertices = mRepeatShape->mShape.vertices();
82 }
83 }
84
85 private:
89
91
93
94 int mIndex;
95
97
100 return 0;
101
103 }
104
105 friend int count(const Vertices& generator) noexcept { return generator.countVertices(); }
106
107 friend class RepeatShape;
108 };
109
113 explicit RepeatShape(Shape shape, const int instances, const Vector2& delta) noexcept
114 : mShape{std::move(shape)}, mInstances{instances}, mDelta{delta}, mVertexCount{count(mShape.vertices())} {}
115
116 [[nodiscard]] Edges edges() const noexcept { return Edges{this}; }
117
119
120 private:
122
124
126
128 };
129
130 template<typename Shape> RepeatShape<Shape> repeatShape(Shape shape, int instances, const Vector2& delta) noexcept {
131 return RepeatShape<Shape>{std::move(shape), instances, delta};
132 }
133
134} // namespace CeresEngine::MeshGenerator
decltype(std::declval< const Primitive * >() ->edges()) Type
Definition Utility.hpp:25
Definition Edge.hpp:14
const RepeatShape * mRepeatShape
Definition RepeatShape.hpp:41
Edges(const RepeatShape *repeatShape) noexcept
Definition RepeatShape.hpp:49
bool done() const noexcept
Definition RepeatShape.hpp:22
EdgeGeneratorType< Shape >::Type mEdges
Definition RepeatShape.hpp:43
int mDelta
Definition RepeatShape.hpp:47
Edge generate() const
Definition RepeatShape.hpp:24
void next() noexcept
Definition RepeatShape.hpp:30
int mIndex
Definition RepeatShape.hpp:45
friend int count(const Edges &generator) noexcept
Definition RepeatShape.hpp:60
int countEdges() const noexcept
Definition RepeatShape.hpp:53
bool done() const noexcept
Definition RepeatShape.hpp:67
void next()
Definition RepeatShape.hpp:75
int countVertices() const noexcept
Definition RepeatShape.hpp:98
const RepeatShape * mRepeatShape
Definition RepeatShape.hpp:90
ShapeVertex generate() const
Definition RepeatShape.hpp:69
friend int count(const Vertices &generator) noexcept
Definition RepeatShape.hpp:105
Vertices(const RepeatShape *repeatShape)
Definition RepeatShape.hpp:86
int mIndex
Definition RepeatShape.hpp:94
VertexGeneratorType< Shape >::Type mVertices
Definition RepeatShape.hpp:92
Vector2 mDelta
Definition RepeatShape.hpp:96
Repeats the same shape a given number of time at given intervals.
Definition RepeatShape.hpp:18
RepeatShape(Shape shape, const int instances, const Vector2 &delta) noexcept
Definition RepeatShape.hpp:113
Vector2 mDelta
Definition RepeatShape.hpp:125
Shape mShape
Definition RepeatShape.hpp:121
Edges edges() const noexcept
Definition RepeatShape.hpp:116
Vertices vertices() const noexcept
Definition RepeatShape.hpp:118
int mInstances
Definition RepeatShape.hpp:123
int mVertexCount
Definition RepeatShape.hpp:127
A point on a path.
Definition ShapeVertex.hpp:16
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
RepeatShape< Shape > repeatShape(Shape shape, int instances, const Vector2 &delta) noexcept
Definition RepeatShape.hpp:130
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