Sun, 03 Jul 2022 14:35:06 +0300
Cleanup polygonize a bit
264
76a025db4948
Convert all includes to be relative to project root directory. Files that cannot be found in this manner use angle brackets.
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
262
diff
changeset
|
1 | #include "src/ldrawalgorithm.h" |
154 | 2 | |
200 | 3 | std::pair<Triangle, Triangle> splitTriangles( |
4 | const Quadrilateral& q, | |
5 | ldraw::Diagonal diagonal) | |
154 | 6 | { |
200 | 7 | std::pair<Triangle, Triangle> result; |
154 | 8 | switch (diagonal) |
9 | { | |
10 | case ldraw::Diagonal::Diagonal_13: | |
200 | 11 | result = {Triangle{q.p1, q.p2, q.p3}, {q.p1, q.p3, q.p4}}; |
154 | 12 | break; |
13 | case ldraw::Diagonal::Diagonal_24: | |
200 | 14 | result = {Triangle{q.p1, q.p2, q.p3}, {q.p2, q.p3, q.p4}}; |
154 | 15 | break; |
16 | } | |
17 | return result; | |
18 | } | |
19 | ||
262
dc33f8a707c4
Add action to make a model unofficial (modifies the !LDRAW_ORG line)
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
248
diff
changeset
|
20 | std::vector<ModelAction> ldraw::makeUnofficial(const Model* model) |
154 | 21 | { |
262
dc33f8a707c4
Add action to make a model unofficial (modifies the !LDRAW_ORG line)
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
248
diff
changeset
|
22 | std::vector<ModelAction> actions; |
dc33f8a707c4
Add action to make a model unofficial (modifies the !LDRAW_ORG line)
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
248
diff
changeset
|
23 | if (model->size() >= 4) { |
dc33f8a707c4
Add action to make a model unofficial (modifies the !LDRAW_ORG line)
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
248
diff
changeset
|
24 | if (const Comment* comment = std::get_if<Comment>(&(*model)[3])) { |
dc33f8a707c4
Add action to make a model unofficial (modifies the !LDRAW_ORG line)
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
248
diff
changeset
|
25 | const QString& body = comment->text; |
154 | 26 | if (body.startsWith("!LDRAW_ORG ") and not body.startsWith("!LDRAW_ORG Unofficial_")) |
27 | { | |
28 | // Add Unofficial_ to part type | |
29 | QStringList tokens = body.split(" "); | |
30 | tokens[1] = "Unofficial_" + tokens[1]; | |
31 | // Remove the UPDATE tag if it's there | |
32 | if (tokens.size() >= 4 && tokens[2] == "UPDATE") | |
33 | { | |
34 | tokens.removeAt(3); | |
35 | tokens.removeAt(2); | |
36 | } | |
262
dc33f8a707c4
Add action to make a model unofficial (modifies the !LDRAW_ORG line)
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
248
diff
changeset
|
37 | actions.push_back(ModifyModel{ |
dc33f8a707c4
Add action to make a model unofficial (modifies the !LDRAW_ORG line)
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
248
diff
changeset
|
38 | .position = 3, |
dc33f8a707c4
Add action to make a model unofficial (modifies the !LDRAW_ORG line)
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
248
diff
changeset
|
39 | .newElement = Comment{.text = tokens.join(" ")} |
dc33f8a707c4
Add action to make a model unofficial (modifies the !LDRAW_ORG line)
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
248
diff
changeset
|
40 | }); |
154 | 41 | } |
42 | } | |
43 | } | |
262
dc33f8a707c4
Add action to make a model unofficial (modifies the !LDRAW_ORG line)
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
248
diff
changeset
|
44 | return actions; |
200 | 45 | } |
46 | ||
47 | ModelElement inverted(const ModelElement& element) | |
48 | { | |
49 | return std::visit(overloaded{ | |
50 | [](Colored<SubfileReference> ref) -> ModelElement { | |
51 | ref.inverted = not ref.inverted; | |
52 | return ref; | |
53 | }, | |
248
29986dfd1750
Fix invertnext not working with circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
200
diff
changeset
|
54 | [](Colored<CircularPrimitive> circ) -> ModelElement { |
29986dfd1750
Fix invertnext not working with circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
200
diff
changeset
|
55 | circ.inverted = not circ.inverted; |
29986dfd1750
Fix invertnext not working with circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
200
diff
changeset
|
56 | return circ; |
29986dfd1750
Fix invertnext not working with circular primitives
Teemu Piippo <teemu.s.piippo@gmail.com>
parents:
200
diff
changeset
|
57 | }, |
200 | 58 | [](Colored<Triangle> triangle) -> ModelElement { |
59 | std::swap(triangle.p1, triangle.p2); | |
60 | return triangle; | |
61 | }, | |
62 | [](Colored<Quadrilateral> quad) -> ModelElement { | |
63 | std::swap(quad.p2, quad.p4); | |
64 | return quad; | |
65 | }, | |
66 | [](const ModelElement& x) { return x; } | |
67 | }, element); | |
68 | } |