src/vertex.cpp

changeset 5
593a658cba8e
parent 3
55a55a9ec2c2
child 6
73e448b2943d
equal deleted inserted replaced
4:68988ebc2a68 5:593a658cba8e
29 this->y = y2; 29 this->y = y2;
30 this->z = z2; 30 this->z = z2;
31 } 31 }
32 */ 32 */
33 33
34 double& Vertex::operator[](Axis axis) 34 Vertex::ValueType& Vertex::operator[](Axis axis)
35 { 35 {
36 switch (axis) 36 switch (axis)
37 { 37 {
38 case X: 38 case X:
39 return this->x; 39 return this->x;
44 default: 44 default:
45 throw std::runtime_error("Non-axis given to Vertex::operator[]"); 45 throw std::runtime_error("Non-axis given to Vertex::operator[]");
46 } 46 }
47 } 47 }
48 48
49 double Vertex::operator[](Axis axis) const 49 Vertex::ValueType Vertex::operator[](Axis axis) const
50 { 50 {
51 switch (axis) 51 switch (axis)
52 { 52 {
53 case X: 53 case X:
54 return this->x; 54 return this->x;
55 case Y: 55 case Y:
56 return this->y; 56 return this->y;
57 case Z: 57 case Z:
58 return this->z; 58 return this->z;
59 default: 59 default:
60 return 0.0; 60 return 0;
61 } 61 }
62 } 62 }
63 63
64 void Vertex::setCoordinate(Axis axis, qreal value) 64 void Vertex::setCoordinate(Axis axis, ValueType value)
65 { 65 {
66 (*this)[axis] = value; 66 (*this)[axis] = value;
67 } 67 }
68 68
69 Vertex VertexFromVector(const QVector3D& vector) 69 Vertex VertexFromVector(const QVector3D& vector)
70 { 70 {
71 return {vector.x(), vector.y(), vector.z()}; 71 return {vector.x(), vector.y(), vector.z()};
72 } 72 }
73 73
74 Vertex Vertex::operator*(qreal scalar) const 74 Vertex Vertex::operator*(ValueType scalar) const
75 { 75 {
76 return {this->x * scalar, this->y * scalar, this->z * scalar}; 76 return {this->x * scalar, this->y * scalar, this->z * scalar};
77 } 77 }
78 78
79 Vertex& Vertex::operator+=(const QVector3D& other) 79 Vertex& Vertex::operator+=(const QVector3D& other)
123 static_cast<float>(this->y - other.y), 123 static_cast<float>(this->y - other.y),
124 static_cast<float>(this->z - other.z) 124 static_cast<float>(this->z - other.z)
125 }; 125 };
126 } 126 }
127 127
128 Vertex& Vertex::operator*=(qreal scalar) 128 Vertex& Vertex::operator*=(ValueType scalar)
129 { 129 {
130 x *= scalar; 130 x *= scalar;
131 y *= scalar; 131 y *= scalar;
132 z *= scalar; 132 z *= scalar;
133 return *this; 133 return *this;

mercurial