Mon, 20 Jun 2022 21:14:27 +0300
removed some newlines
24 | 1 | /* |
2 | * LDForge: LDraw parts authoring CAD | |
3 | * Copyright (C) 2013 - 2020 Teemu Piippo | |
4 | * | |
5 | * This program is free software: you can redistribute it and/or modify | |
6 | * it under the terms of the GNU General Public License as published by | |
7 | * the Free Software Foundation, either version 3 of the License, or | |
8 | * (at your option) any later version. | |
9 | * | |
10 | * This program is distributed in the hope that it will be useful, | |
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | * GNU General Public License for more details. | |
14 | * | |
15 | * You should have received a copy of the GNU General Public License | |
16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
17 | */ | |
18 | ||
3 | 19 | #pragma once |
8
44679e468ba9
major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
6
diff
changeset
|
20 | #include <QAbstractListModel> |
3 | 21 | #include <memory> |
206
654661eab7f3
More refactor, merged main.h, basics.h and utility.h into one header file basics.h and removed plenty of unused code
Teemu Piippo <teemu@hecknology.net>
parents:
200
diff
changeset
|
22 | #include "basics.h" |
200 | 23 | #include "colors.h" |
24 | ||
25 | struct SubfileReference | |
26 | { | |
27 | QString name; | |
28 | glm::mat4 transformation; | |
29 | bool inverted = false; | |
30 | }; | |
31 | ||
32 | template<typename T> | |
33 | struct Colored : T | |
34 | { | |
35 | ldraw::Color color; | |
36 | }; | |
37 | ||
38 | struct Comment | |
39 | { | |
40 | QString text; | |
41 | }; | |
3 | 42 | |
200 | 43 | struct ParseError |
8
44679e468ba9
major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
6
diff
changeset
|
44 | { |
200 | 45 | QString code; |
8
44679e468ba9
major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
6
diff
changeset
|
46 | }; |
44679e468ba9
major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
6
diff
changeset
|
47 | |
200 | 48 | struct Empty {}; |
49 | ||
232
8efa3a33172e
Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
218
diff
changeset
|
50 | struct CircularFraction |
8efa3a33172e
Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
218
diff
changeset
|
51 | { |
8efa3a33172e
Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
218
diff
changeset
|
52 | unsigned int segments; |
8efa3a33172e
Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
218
diff
changeset
|
53 | unsigned int divisions; |
8efa3a33172e
Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
218
diff
changeset
|
54 | }; |
8efa3a33172e
Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
218
diff
changeset
|
55 | |
8efa3a33172e
Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
218
diff
changeset
|
56 | constexpr bool operator<(const CircularFraction& p, const CircularFraction& q) |
8efa3a33172e
Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
218
diff
changeset
|
57 | { |
8efa3a33172e
Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
218
diff
changeset
|
58 | // a/b < c/d |
8efa3a33172e
Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
218
diff
changeset
|
59 | // a < c * b / d |
8efa3a33172e
Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
218
diff
changeset
|
60 | // a * d < c * b |
8efa3a33172e
Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
218
diff
changeset
|
61 | return p.segments * q.divisions < q.segments / p.divisions; |
8efa3a33172e
Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
218
diff
changeset
|
62 | } |
8efa3a33172e
Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
218
diff
changeset
|
63 | |
8efa3a33172e
Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
218
diff
changeset
|
64 | struct CircularPrimitive |
8efa3a33172e
Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
218
diff
changeset
|
65 | { |
8efa3a33172e
Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
218
diff
changeset
|
66 | enum Type |
8efa3a33172e
Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
218
diff
changeset
|
67 | { |
8efa3a33172e
Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
218
diff
changeset
|
68 | Circle, |
8efa3a33172e
Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
218
diff
changeset
|
69 | Disc, |
8efa3a33172e
Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
218
diff
changeset
|
70 | Cylinder, |
8efa3a33172e
Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
218
diff
changeset
|
71 | CylinderOpen, |
8efa3a33172e
Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
218
diff
changeset
|
72 | CylinderClosed, |
8efa3a33172e
Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
218
diff
changeset
|
73 | DiscNegative, |
8efa3a33172e
Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
218
diff
changeset
|
74 | Chord, |
8efa3a33172e
Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
218
diff
changeset
|
75 | } type; |
8efa3a33172e
Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
218
diff
changeset
|
76 | static constexpr int NUM_TYPES = Chord + 1; |
8efa3a33172e
Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
218
diff
changeset
|
77 | CircularFraction fraction; |
8efa3a33172e
Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
218
diff
changeset
|
78 | glm::mat4 transformation; |
8efa3a33172e
Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
218
diff
changeset
|
79 | }; |
8efa3a33172e
Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
218
diff
changeset
|
80 | |
233 | 81 | Q_DECLARE_METATYPE(CircularPrimitive::Type) |
82 | ||
232
8efa3a33172e
Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
218
diff
changeset
|
83 | struct CircleToolOptions |
8efa3a33172e
Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
218
diff
changeset
|
84 | { |
8efa3a33172e
Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
218
diff
changeset
|
85 | CircularFraction fraction; |
8efa3a33172e
Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
218
diff
changeset
|
86 | CircularPrimitive::Type type; |
8efa3a33172e
Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
218
diff
changeset
|
87 | }; |
8efa3a33172e
Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
218
diff
changeset
|
88 | |
200 | 89 | using ModelElement = std::variant< |
90 | Colored<SubfileReference>, | |
91 | Colored<LineSegment>, | |
92 | Colored<Triangle>, | |
93 | Colored<Quadrilateral>, | |
94 | Colored<ConditionalEdge>, | |
232
8efa3a33172e
Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
218
diff
changeset
|
95 | Colored<CircularPrimitive>, |
200 | 96 | Comment, |
97 | Empty, | |
98 | ParseError>; | |
99 | ||
210
232e7634cc8a
more refactoring, dosn't build yet
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
206
diff
changeset
|
100 | using PolygonElement = Colored<std::variant< |
232e7634cc8a
more refactoring, dosn't build yet
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
206
diff
changeset
|
101 | LineSegment, |
232e7634cc8a
more refactoring, dosn't build yet
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
206
diff
changeset
|
102 | Triangle, |
232e7634cc8a
more refactoring, dosn't build yet
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
206
diff
changeset
|
103 | Quadrilateral, |
232e7634cc8a
more refactoring, dosn't build yet
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
206
diff
changeset
|
104 | ConditionalEdge>>; |
232e7634cc8a
more refactoring, dosn't build yet
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
206
diff
changeset
|
105 | |
232e7634cc8a
more refactoring, dosn't build yet
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
206
diff
changeset
|
106 | template<typename T> |
211 | 107 | struct remove_color {}; |
210
232e7634cc8a
more refactoring, dosn't build yet
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
206
diff
changeset
|
108 | |
232e7634cc8a
more refactoring, dosn't build yet
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
206
diff
changeset
|
109 | template<typename T> |
232e7634cc8a
more refactoring, dosn't build yet
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
206
diff
changeset
|
110 | struct remove_color<Colored<T>> { using type = T; }; |
232e7634cc8a
more refactoring, dosn't build yet
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
206
diff
changeset
|
111 | |
232e7634cc8a
more refactoring, dosn't build yet
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
206
diff
changeset
|
112 | template<typename T> |
232e7634cc8a
more refactoring, dosn't build yet
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
206
diff
changeset
|
113 | struct remove_color<Colored<T>&> { using type = T&; }; |
232e7634cc8a
more refactoring, dosn't build yet
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
206
diff
changeset
|
114 | |
232e7634cc8a
more refactoring, dosn't build yet
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
206
diff
changeset
|
115 | template<typename T> |
211 | 116 | struct remove_color<const Colored<T>&> { using type = const T&; }; |
117 | ||
118 | template<typename T> | |
210
232e7634cc8a
more refactoring, dosn't build yet
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
206
diff
changeset
|
119 | struct remove_color<Colored<T>&&> { using type = T&&; }; |
232e7634cc8a
more refactoring, dosn't build yet
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
206
diff
changeset
|
120 | |
232e7634cc8a
more refactoring, dosn't build yet
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
206
diff
changeset
|
121 | template<typename T> |
232e7634cc8a
more refactoring, dosn't build yet
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
206
diff
changeset
|
122 | using remove_color_t = typename remove_color<T>::type; |
232e7634cc8a
more refactoring, dosn't build yet
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
206
diff
changeset
|
123 | |
211 | 124 | static_assert(std::is_same_v<remove_color_t<Colored<Triangle>>, Triangle>); |
125 | static_assert(std::is_same_v<remove_color_t<Colored<Triangle>&>, Triangle&>); | |
126 | static_assert(std::is_same_v<remove_color_t<const Colored<Triangle>&>, const Triangle&>); | |
127 | ||
210
232e7634cc8a
more refactoring, dosn't build yet
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
206
diff
changeset
|
128 | template<typename T> |
232e7634cc8a
more refactoring, dosn't build yet
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
206
diff
changeset
|
129 | constexpr remove_color_t<T&&> extract_colored(T&& x) |
232e7634cc8a
more refactoring, dosn't build yet
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
206
diff
changeset
|
130 | { |
232e7634cc8a
more refactoring, dosn't build yet
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
206
diff
changeset
|
131 | return static_cast<remove_color_t<T&&>>(x); |
232e7634cc8a
more refactoring, dosn't build yet
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
206
diff
changeset
|
132 | } |
232e7634cc8a
more refactoring, dosn't build yet
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
206
diff
changeset
|
133 | |
211 | 134 | template<typename Ret, typename Fn1, typename Fn2, typename Fn3, typename Fn4, typename T> |
135 | constexpr auto visitPolygon(Fn1&& f1, Fn2&& f2, Fn3&& f3, Fn4&& f4, T&& element) | |
210
232e7634cc8a
more refactoring, dosn't build yet
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
206
diff
changeset
|
136 | { |
211 | 137 | if (std::holds_alternative<LineSegment>(element)) { |
138 | return f1(std::get<LineSegment>(element)); | |
139 | } | |
140 | else if (std::holds_alternative<Triangle>(element)) { | |
141 | return f2(std::get<Triangle>(element)); | |
142 | } | |
143 | else if (std::holds_alternative<Quadrilateral>(element)) { | |
144 | return f3(std::get<Quadrilateral>(element)); | |
145 | } | |
146 | else { | |
147 | return f4(std::get<ConditionalEdge>(element)); | |
148 | } | |
210
232e7634cc8a
more refactoring, dosn't build yet
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
206
diff
changeset
|
149 | } |
232e7634cc8a
more refactoring, dosn't build yet
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
206
diff
changeset
|
150 | |
232e7634cc8a
more refactoring, dosn't build yet
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
206
diff
changeset
|
151 | template<typename T, typename Fn> |
211 | 152 | constexpr void visitPoints(Fn&& func, T&& element) |
210
232e7634cc8a
more refactoring, dosn't build yet
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
206
diff
changeset
|
153 | { |
232e7634cc8a
more refactoring, dosn't build yet
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
206
diff
changeset
|
154 | visitPolygon<void>( |
218
63125c36de73
Replace config collector with a simpler system
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
212
diff
changeset
|
155 | [&func](transfer_cvref_t<T&&, LineSegment> edge) |
210
232e7634cc8a
more refactoring, dosn't build yet
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
206
diff
changeset
|
156 | { |
232e7634cc8a
more refactoring, dosn't build yet
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
206
diff
changeset
|
157 | func(edge.p1); |
232e7634cc8a
more refactoring, dosn't build yet
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
206
diff
changeset
|
158 | func(edge.p2); |
232e7634cc8a
more refactoring, dosn't build yet
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
206
diff
changeset
|
159 | }, |
218
63125c36de73
Replace config collector with a simpler system
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
212
diff
changeset
|
160 | [&func](transfer_cvref_t<T&&, Triangle>& tri) |
210
232e7634cc8a
more refactoring, dosn't build yet
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
206
diff
changeset
|
161 | { |
232e7634cc8a
more refactoring, dosn't build yet
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
206
diff
changeset
|
162 | func(tri.p1); |
232e7634cc8a
more refactoring, dosn't build yet
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
206
diff
changeset
|
163 | func(tri.p2); |
232e7634cc8a
more refactoring, dosn't build yet
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
206
diff
changeset
|
164 | func(tri.p3); |
232e7634cc8a
more refactoring, dosn't build yet
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
206
diff
changeset
|
165 | }, |
218
63125c36de73
Replace config collector with a simpler system
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
212
diff
changeset
|
166 | [&func](transfer_cvref_t<T&&, Quadrilateral>& quad) |
210
232e7634cc8a
more refactoring, dosn't build yet
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
206
diff
changeset
|
167 | { |
232e7634cc8a
more refactoring, dosn't build yet
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
206
diff
changeset
|
168 | func(quad.p1); |
232e7634cc8a
more refactoring, dosn't build yet
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
206
diff
changeset
|
169 | func(quad.p2); |
232e7634cc8a
more refactoring, dosn't build yet
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
206
diff
changeset
|
170 | func(quad.p3); |
232e7634cc8a
more refactoring, dosn't build yet
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
206
diff
changeset
|
171 | func(quad.p4); |
232e7634cc8a
more refactoring, dosn't build yet
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
206
diff
changeset
|
172 | }, |
218
63125c36de73
Replace config collector with a simpler system
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
212
diff
changeset
|
173 | [&func](transfer_cvref_t<T&&, ConditionalEdge>& cedge) |
210
232e7634cc8a
more refactoring, dosn't build yet
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
206
diff
changeset
|
174 | { |
232e7634cc8a
more refactoring, dosn't build yet
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
206
diff
changeset
|
175 | func(cedge.p1); |
232e7634cc8a
more refactoring, dosn't build yet
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
206
diff
changeset
|
176 | func(cedge.p2); |
232e7634cc8a
more refactoring, dosn't build yet
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
206
diff
changeset
|
177 | func(cedge.c1); |
232e7634cc8a
more refactoring, dosn't build yet
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
206
diff
changeset
|
178 | func(cedge.c2); |
232e7634cc8a
more refactoring, dosn't build yet
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
206
diff
changeset
|
179 | }, |
232e7634cc8a
more refactoring, dosn't build yet
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
206
diff
changeset
|
180 | element); |
232e7634cc8a
more refactoring, dosn't build yet
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
206
diff
changeset
|
181 | } |
232e7634cc8a
more refactoring, dosn't build yet
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
206
diff
changeset
|
182 | |
200 | 183 | QString modelElementToString(const ModelElement& element); |
184 | struct ModelId | |
185 | { | |
186 | std::int32_t value; | |
187 | constexpr auto operator<=>(const ModelId& other) const = default; | |
188 | }; | |
189 | ||
190 | constexpr int qHash(ModelId id) | |
191 | { | |
192 | return qHash(id.value); | |
193 | } | |
194 | ||
8
44679e468ba9
major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
6
diff
changeset
|
195 | class Model : public QAbstractListModel |
3 | 196 | { |
197 | Q_OBJECT | |
200 | 198 | struct Entry { |
199 | ModelElement data; | |
200 | ModelId id; | |
201 | }; | |
202 | std::vector<Entry> body; | |
203 | std::map<ModelId, int> positions; | |
204 | ModelId runningId = {1}; | |
3 | 205 | public: |
200 | 206 | Model(QObject* parent); |
207 | virtual ~Model(); | |
208 | ModelId append(const ModelElement& value); | |
209 | const ModelElement& at(int position) const; | |
210 | ModelId idAt(int position) const; | |
211 | void assignAt(int position, const ModelElement& element); | |
212 | std::optional<int> find(ModelId id) const; | |
213 | void remove(int index); | |
8
44679e468ba9
major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
6
diff
changeset
|
214 | int rowCount(const QModelIndex&) const override; |
44679e468ba9
major update with many things
Teemu Piippo <teemu@hecknology.net>
parents:
6
diff
changeset
|
215 | QVariant data(const QModelIndex& index, int role) const override; |
200 | 216 | const ModelElement& operator[](int index) const; |
217 | int size() const; | |
218 | auto operator[](int index) { | |
219 | struct { | |
220 | Model& model; | |
221 | int index; | |
222 | operator const ModelElement&() { | |
223 | return model.at(index); | |
224 | } | |
225 | auto& operator=(const ModelElement& newData) { | |
226 | model.assignAt(index, newData); | |
227 | return *this; | |
228 | } | |
229 | const auto* operator&() { | |
230 | return &(this->operator const ModelElement&()); | |
231 | } | |
232 | } result{*this, index}; | |
233 | return result; | |
234 | } | |
3 | 235 | }; |
236 | ||
151 | 237 | void save(const Model& model, QIODevice *device); |
200 | 238 | void updateHeaderNameField(Model& model, const QString &name); |
212
27259810da6d
Rewrite dependency loading
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
211
diff
changeset
|
239 | |
27259810da6d
Rewrite dependency loading
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
211
diff
changeset
|
240 | template<typename T> |
27259810da6d
Rewrite dependency loading
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
211
diff
changeset
|
241 | void iterate(const Model& model, std::function<void(const T&)> fn) |
27259810da6d
Rewrite dependency loading
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
211
diff
changeset
|
242 | { |
27259810da6d
Rewrite dependency loading
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
211
diff
changeset
|
243 | for (int i = 0; i < model.size(); ++i) { |
27259810da6d
Rewrite dependency loading
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
211
diff
changeset
|
244 | if (std::holds_alternative<T>(model[i])) { |
27259810da6d
Rewrite dependency loading
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
211
diff
changeset
|
245 | fn(std::get<T>(model[i])); |
27259810da6d
Rewrite dependency loading
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
211
diff
changeset
|
246 | } |
27259810da6d
Rewrite dependency loading
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
211
diff
changeset
|
247 | } |
27259810da6d
Rewrite dependency loading
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
211
diff
changeset
|
248 | } |
232
8efa3a33172e
Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
218
diff
changeset
|
249 | |
8efa3a33172e
Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
218
diff
changeset
|
250 | constexpr Colored<LineSegment> edge(const glm::vec3& p1, const glm::vec3& p2) |
8efa3a33172e
Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
218
diff
changeset
|
251 | { |
8efa3a33172e
Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
218
diff
changeset
|
252 | return Colored<LineSegment>{{.p1 = p1, .p2 = p2}, EDGE_COLOR}; |
8efa3a33172e
Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
218
diff
changeset
|
253 | } |
8efa3a33172e
Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
218
diff
changeset
|
254 | |
8efa3a33172e
Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
218
diff
changeset
|
255 | constexpr Colored<Triangle> triangle(const glm::vec3& p1, const glm::vec3& p2, const glm::vec3& p3) |
8efa3a33172e
Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
218
diff
changeset
|
256 | { |
8efa3a33172e
Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
218
diff
changeset
|
257 | return Colored<Triangle>{{.p1 = p1, .p2 = p2, .p3 = p3}, MAIN_COLOR}; |
8efa3a33172e
Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
218
diff
changeset
|
258 | } |
8efa3a33172e
Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
218
diff
changeset
|
259 | |
8efa3a33172e
Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
218
diff
changeset
|
260 | constexpr Colored<Quadrilateral> quadrilateral( |
8efa3a33172e
Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
218
diff
changeset
|
261 | const glm::vec3& p1, |
8efa3a33172e
Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
218
diff
changeset
|
262 | const glm::vec3& p2, |
8efa3a33172e
Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
218
diff
changeset
|
263 | const glm::vec3& p3, |
8efa3a33172e
Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
218
diff
changeset
|
264 | const glm::vec3& p4) |
8efa3a33172e
Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
218
diff
changeset
|
265 | { |
8efa3a33172e
Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
218
diff
changeset
|
266 | return Colored<Quadrilateral>{{.p1 = p1, .p2 = p2, .p3 = p3, .p4 = p4}, MAIN_COLOR}; |
8efa3a33172e
Add base code for circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
218
diff
changeset
|
267 | } |