src/linetypes/quadrilateral.cpp

changeset 87
93ec4d630346
parent 86
4bec0525ef1b
child 132
488d0ba6070b
equal deleted inserted replaced
86:4bec0525ef1b 87:93ec4d630346
1 #include "quadrilateral.h" 1 #include "quadrilateral.h"
2
3 ldraw::Quadrilateral::Quadrilateral
4 (
5 const glm::vec3& point_1,
6 const glm::vec3& point_2,
7 const glm::vec3& point_3,
8 const glm::vec3& point_4,
9 Color color_index
10 ) :
11 ColoredObject{color_index},
12 points{point_1, point_2, point_3, point_4}
13 {
14 }
15
16 ldraw::Quadrilateral::Quadrilateral
17 (
18 const std::array<glm::vec3, 4>& vertices,
19 const Color color
20 ) :
21 ColoredObject{color},
22 points{vertices[0], vertices[1], vertices[2], vertices[3]}
23 {
24 }
25
26 QVariant ldraw::Quadrilateral::getProperty(const Property id) const
27 {
28 switch (id)
29 {
30 case Property::Point0:
31 return QVariant::fromValue(points[0]);
32 case Property::Point1:
33 return QVariant::fromValue(points[1]);
34 case Property::Point2:
35 return QVariant::fromValue(points[2]);
36 case Property::Point3:
37 return QVariant::fromValue(points[3]);
38 default:
39 return ColoredObject::getProperty(id);
40 }
41 }
42
43 void ldraw::Quadrilateral::setProperty(SetPropertyResult* result, const PropertyKeyValue& pair)
44 {
45 LDRAW_OBJECT_HANDLE_SET_PROPERTY(Point0, {points[0] = value;})
46 LDRAW_OBJECT_HANDLE_SET_PROPERTY(Point1, {points[1] = value;})
47 LDRAW_OBJECT_HANDLE_SET_PROPERTY(Point2, {points[2] = value;})
48 LDRAW_OBJECT_HANDLE_SET_PROPERTY(Point3, {points[3] = value;})
49 ColoredObject::setProperty(result, pair);
50 }
51 2
52 QString ldraw::Quadrilateral::textRepresentation() const 3 QString ldraw::Quadrilateral::textRepresentation() const
53 { 4 {
54 return utility::format("%1 %2 %3 %4", 5 return utility::format("%1 %2 %3 %4",
55 utility::vertexToStringParens(points[0]), 6 utility::vertexToStringParens(this->points[0]),
56 utility::vertexToStringParens(points[1]), 7 utility::vertexToStringParens(this->points[1]),
57 utility::vertexToStringParens(points[2]), 8 utility::vertexToStringParens(this->points[2]),
58 utility::vertexToStringParens(points[3])); 9 utility::vertexToStringParens(this->points[3]));
59 } 10 }
60 11
61 void ldraw::Quadrilateral::getPolygons( 12 void ldraw::Quadrilateral::getPolygons(
62 std::vector<gl::Polygon>& polygons, 13 std::vector<gl::Polygon>& polygons,
63 GetPolygonsContext* context) const 14 GetPolygonsContext* context) const
67 this->points[0], 18 this->points[0],
68 this->points[1], 19 this->points[1],
69 this->points[2], 20 this->points[2],
70 this->points[3], 21 this->points[3],
71 this->colorIndex, 22 this->colorIndex,
72 this->id)); 23 this->id));
73 } 24 }
74 25
75 void ldraw::Quadrilateral::invert() 26 void ldraw::Quadrilateral::invert()
76 { 27 {
77 // 0 1 2 3 28 // 0 1 2 3
78 // -> 2 1 0 3 29 // -> 2 1 0 3
79 std::swap(this->points[0], this->points[2]); 30 std::swap(this->points[0], this->points[2]);
80 } 31 }
81
82 int ldraw::Quadrilateral::numPoints() const
83 {
84 return 4;
85 }
86
87 const glm::vec3& ldraw::Quadrilateral::getPoint(int index) const
88 {
89 if (index >= 0 and index < 4)
90 {
91 return points[index];
92 }
93 else
94 {
95 return ldraw::ColoredObject::getPoint(index);
96 }
97 }

mercurial