src/linetypes/triangle.cpp

Thu, 09 Mar 2017 12:50:14 +0200

author
Teemu Piippo <teemu@hecknology.net>
date
Thu, 09 Mar 2017 12:50:14 +0200
changeset 1209
c2723022b173
parent 1148
96cb15a7611f
child 1261
5d2c9d36da9d
permissions
-rw-r--r--

Laid groundwork for library collection support.

1148
96cb15a7611f Moved LDTriangle into its own source pair.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
1 /*
96cb15a7611f Moved LDTriangle into its own source pair.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
2 * LDForge: LDraw parts authoring CAD
96cb15a7611f Moved LDTriangle into its own source pair.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
3 * Copyright (C) 2013 - 2017 Teemu Piippo
96cb15a7611f Moved LDTriangle into its own source pair.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
4 *
96cb15a7611f Moved LDTriangle into its own source pair.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
5 * This program is free software: you can redistribute it and/or modify
96cb15a7611f Moved LDTriangle into its own source pair.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
6 * it under the terms of the GNU General Public License as published by
96cb15a7611f Moved LDTriangle into its own source pair.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
7 * the Free Software Foundation, either version 3 of the License, or
96cb15a7611f Moved LDTriangle into its own source pair.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
8 * (at your option) any later version.
96cb15a7611f Moved LDTriangle into its own source pair.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
9 *
96cb15a7611f Moved LDTriangle into its own source pair.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
10 * This program is distributed in the hope that it will be useful,
96cb15a7611f Moved LDTriangle into its own source pair.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
96cb15a7611f Moved LDTriangle into its own source pair.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
96cb15a7611f Moved LDTriangle into its own source pair.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
13 * GNU General Public License for more details.
96cb15a7611f Moved LDTriangle into its own source pair.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
14 *
96cb15a7611f Moved LDTriangle into its own source pair.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License
96cb15a7611f Moved LDTriangle into its own source pair.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
96cb15a7611f Moved LDTriangle into its own source pair.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
17 */
96cb15a7611f Moved LDTriangle into its own source pair.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
18
96cb15a7611f Moved LDTriangle into its own source pair.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
19 #include "triangle.h"
96cb15a7611f Moved LDTriangle into its own source pair.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
20
96cb15a7611f Moved LDTriangle into its own source pair.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
21 LDTriangle::LDTriangle(Model *model) :
96cb15a7611f Moved LDTriangle into its own source pair.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
22 LDObject {model} {}
96cb15a7611f Moved LDTriangle into its own source pair.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
23
96cb15a7611f Moved LDTriangle into its own source pair.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
24 LDTriangle::LDTriangle(const Vertex& v1, const Vertex& v2, const Vertex& v3, Model* model) :
96cb15a7611f Moved LDTriangle into its own source pair.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
25 LDObject {model}
96cb15a7611f Moved LDTriangle into its own source pair.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
26 {
96cb15a7611f Moved LDTriangle into its own source pair.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
27 setVertex(0, v1);
96cb15a7611f Moved LDTriangle into its own source pair.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
28 setVertex(1, v2);
96cb15a7611f Moved LDTriangle into its own source pair.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
29 setVertex(2, v3);
96cb15a7611f Moved LDTriangle into its own source pair.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
30 }
96cb15a7611f Moved LDTriangle into its own source pair.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
31
96cb15a7611f Moved LDTriangle into its own source pair.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
32 int LDTriangle::triangleCount() const
96cb15a7611f Moved LDTriangle into its own source pair.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
33 {
96cb15a7611f Moved LDTriangle into its own source pair.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
34 return 1;
96cb15a7611f Moved LDTriangle into its own source pair.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
35 }
96cb15a7611f Moved LDTriangle into its own source pair.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
36
96cb15a7611f Moved LDTriangle into its own source pair.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
37 QString LDTriangle::asText() const
96cb15a7611f Moved LDTriangle into its own source pair.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
38 {
96cb15a7611f Moved LDTriangle into its own source pair.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
39 QString result = format("3 %1", color());
96cb15a7611f Moved LDTriangle into its own source pair.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
40
96cb15a7611f Moved LDTriangle into its own source pair.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
41 for (int i = 0; i < 3; ++i)
96cb15a7611f Moved LDTriangle into its own source pair.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
42 result += format(" %1", vertex (i));
96cb15a7611f Moved LDTriangle into its own source pair.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
43
96cb15a7611f Moved LDTriangle into its own source pair.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
44 return result;
96cb15a7611f Moved LDTriangle into its own source pair.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
45 }
96cb15a7611f Moved LDTriangle into its own source pair.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
46
96cb15a7611f Moved LDTriangle into its own source pair.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
47 void LDTriangle::invert()
96cb15a7611f Moved LDTriangle into its own source pair.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
48 {
96cb15a7611f Moved LDTriangle into its own source pair.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
49 // Triangle goes 0 -> 1 -> 2, reversed: 0 -> 2 -> 1.
96cb15a7611f Moved LDTriangle into its own source pair.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
50 // Thus, we swap 1 and 2.
96cb15a7611f Moved LDTriangle into its own source pair.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
51 Vertex temp = vertex(1);
96cb15a7611f Moved LDTriangle into its own source pair.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
52 setVertex(1, vertex(2));
96cb15a7611f Moved LDTriangle into its own source pair.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
53 setVertex(2, temp);
96cb15a7611f Moved LDTriangle into its own source pair.
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
54 }

mercurial