src/linetypes/edge.cpp

Wed, 18 Mar 2020 15:52:16 +0200

author
Teemu Piippo <teemu@hecknology.net>
date
Wed, 18 Mar 2020 15:52:16 +0200
changeset 83
b8bd338eb602
parent 81
62373840e33a
child 86
4bec0525ef1b
permissions
-rw-r--r--

refactor, added splitter

3
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
1 #include "edge.h"
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
2
35
98906a94732f renamed the linetypes namespace to ldraw namespace and added more structures to it
Teemu Piippo <teemu@hecknology.net>
parents: 33
diff changeset
3 ldraw::Edge::Edge(
33
4c41bfe2ec6e replaced matrix and vertex classes with glm
Teemu Piippo <teemu@hecknology.net>
parents: 21
diff changeset
4 const glm::vec3& point_1,
4c41bfe2ec6e replaced matrix and vertex classes with glm
Teemu Piippo <teemu@hecknology.net>
parents: 21
diff changeset
5 const glm::vec3& point_2,
3
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
6 const Color color_index) :
13
6e838748867b renamings
Teemu Piippo <teemu@hecknology.net>
parents: 8
diff changeset
7 ColoredObject{color_index},
3
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
8 point_1{point_1},
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
9 point_2{point_2} {}
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
10
77
028798a72591 added some meta stuff, simplified quadrilateral splitting and tested it
Teemu Piippo <teemu@hecknology.net>
parents: 35
diff changeset
11 ldraw::Edge::Edge(const std::array<glm::vec3, 2>& vertices, const Color color) :
13
6e838748867b renamings
Teemu Piippo <teemu@hecknology.net>
parents: 8
diff changeset
12 ColoredObject{color},
8
44679e468ba9 major update with many things
Teemu Piippo <teemu@hecknology.net>
parents: 6
diff changeset
13 point_1{vertices[0]},
44679e468ba9 major update with many things
Teemu Piippo <teemu@hecknology.net>
parents: 6
diff changeset
14 point_2{vertices[1]}
44679e468ba9 major update with many things
Teemu Piippo <teemu@hecknology.net>
parents: 6
diff changeset
15 {
44679e468ba9 major update with many things
Teemu Piippo <teemu@hecknology.net>
parents: 6
diff changeset
16 }
44679e468ba9 major update with many things
Teemu Piippo <teemu@hecknology.net>
parents: 6
diff changeset
17
35
98906a94732f renamed the linetypes namespace to ldraw namespace and added more structures to it
Teemu Piippo <teemu@hecknology.net>
parents: 33
diff changeset
18 QVariant ldraw::Edge::getProperty(Property property) const
3
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
19 {
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
20 switch (property)
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
21 {
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
22 case Property::Point1:
33
4c41bfe2ec6e replaced matrix and vertex classes with glm
Teemu Piippo <teemu@hecknology.net>
parents: 21
diff changeset
23 return QVariant::fromValue(point_1);
3
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
24 case Property::Point2:
33
4c41bfe2ec6e replaced matrix and vertex classes with glm
Teemu Piippo <teemu@hecknology.net>
parents: 21
diff changeset
25 return QVariant::fromValue(point_2);
3
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
26 default:
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
27 return BaseClass::getProperty(property);
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
28 }
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
29 }
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
30
35
98906a94732f renamed the linetypes namespace to ldraw namespace and added more structures to it
Teemu Piippo <teemu@hecknology.net>
parents: 33
diff changeset
31 auto ldraw::Edge::setProperty(Property property, const QVariant& value)
3
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
32 -> SetPropertyResult
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
33 {
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
34 switch (property)
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
35 {
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
36 case Property::Point1:
33
4c41bfe2ec6e replaced matrix and vertex classes with glm
Teemu Piippo <teemu@hecknology.net>
parents: 21
diff changeset
37 point_1 = value.value<glm::vec3>();
3
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
38 return SetPropertyResult::Success;
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
39 case Property::Point2:
33
4c41bfe2ec6e replaced matrix and vertex classes with glm
Teemu Piippo <teemu@hecknology.net>
parents: 21
diff changeset
40 point_2 = value.value<glm::vec3>();
3
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
41 return SetPropertyResult::Success;
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
42 default:
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
43 return BaseClass::setProperty(property, value);
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
44 }
55a55a9ec2c2 Added lots of code
Teemu Piippo <teemu@hecknology.net>
parents:
diff changeset
45 }
6
73e448b2943d language support
Teemu Piippo <teemu@hecknology.net>
parents: 3
diff changeset
46
35
98906a94732f renamed the linetypes namespace to ldraw namespace and added more structures to it
Teemu Piippo <teemu@hecknology.net>
parents: 33
diff changeset
47 QString ldraw::Edge::textRepresentation() const
6
73e448b2943d language support
Teemu Piippo <teemu@hecknology.net>
parents: 3
diff changeset
48 {
33
4c41bfe2ec6e replaced matrix and vertex classes with glm
Teemu Piippo <teemu@hecknology.net>
parents: 21
diff changeset
49 return utility::format("%1 %2", utility::vertexToStringParens(point_1), utility::vertexToStringParens(point_2));
6
73e448b2943d language support
Teemu Piippo <teemu@hecknology.net>
parents: 3
diff changeset
50 }
21
Teemu Piippo <teemu@hecknology.net>
parents: 18
diff changeset
51
35
98906a94732f renamed the linetypes namespace to ldraw namespace and added more structures to it
Teemu Piippo <teemu@hecknology.net>
parents: 33
diff changeset
52 void ldraw::Edge::getPolygons(
21
Teemu Piippo <teemu@hecknology.net>
parents: 18
diff changeset
53 std::vector<gl::Polygon>& polygons,
Teemu Piippo <teemu@hecknology.net>
parents: 18
diff changeset
54 GetPolygonsContext* context) const
Teemu Piippo <teemu@hecknology.net>
parents: 18
diff changeset
55 {
Teemu Piippo <teemu@hecknology.net>
parents: 18
diff changeset
56 Q_UNUSED(context)
Teemu Piippo <teemu@hecknology.net>
parents: 18
diff changeset
57 polygons.push_back(gl::edgeLine(this->point_1, this->point_2, this->colorIndex, this->id));
Teemu Piippo <teemu@hecknology.net>
parents: 18
diff changeset
58 }
81
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents: 77
diff changeset
59
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents: 77
diff changeset
60 int ldraw::Edge::numPoints() const
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents: 77
diff changeset
61 {
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents: 77
diff changeset
62 return 2;
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents: 77
diff changeset
63 }
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents: 77
diff changeset
64
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents: 77
diff changeset
65 const glm::vec3& ldraw::Edge::getPoint(int index) const
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents: 77
diff changeset
66 {
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents: 77
diff changeset
67 switch (index)
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents: 77
diff changeset
68 {
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents: 77
diff changeset
69 case 0:
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents: 77
diff changeset
70 return this->point_1;
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents: 77
diff changeset
71 case 1:
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents: 77
diff changeset
72 return this->point_2;
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents: 77
diff changeset
73 default:
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents: 77
diff changeset
74 return ldraw::ColoredObject::getPoint(index);
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents: 77
diff changeset
75 }
62373840e33a object editor widgets start to form up
Teemu Piippo <teemu@hecknology.net>
parents: 77
diff changeset
76 }

mercurial