|
1 /* |
|
2 * LDForge: LDraw parts authoring CAD |
|
3 * Copyright (C) 2013 - 2017 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 |
|
19 #include "triangle.h" |
|
20 |
|
21 LDTriangle::LDTriangle(Model *model) : |
|
22 LDObject {model} {} |
|
23 |
|
24 LDTriangle::LDTriangle(const Vertex& v1, const Vertex& v2, const Vertex& v3, Model* model) : |
|
25 LDObject {model} |
|
26 { |
|
27 setVertex(0, v1); |
|
28 setVertex(1, v2); |
|
29 setVertex(2, v3); |
|
30 } |
|
31 |
|
32 int LDTriangle::triangleCount() const |
|
33 { |
|
34 return 1; |
|
35 } |
|
36 |
|
37 QString LDTriangle::asText() const |
|
38 { |
|
39 QString result = format("3 %1", color()); |
|
40 |
|
41 for (int i = 0; i < 3; ++i) |
|
42 result += format(" %1", vertex (i)); |
|
43 |
|
44 return result; |
|
45 } |
|
46 |
|
47 void LDTriangle::invert() |
|
48 { |
|
49 // Triangle goes 0 -> 1 -> 2, reversed: 0 -> 2 -> 1. |
|
50 // Thus, we swap 1 and 2. |
|
51 Vertex temp = vertex(1); |
|
52 setVertex(1, vertex(2)); |
|
53 setVertex(2, temp); |
|
54 } |