Commit 6b74dff2 by Philipp Adolf

Implement operator== and operator< in Triangle

Now Triangle can be used as the key of a QMap
parent f93785b6
......@@ -50,6 +50,32 @@ Triangle &Triangle::operator=(const Triangle &other) {
return *this;
}
bool Triangle::operator==(const Triangle &other) const {
return u_ == other.u_ && v_ == other.v_ && w_ == other.w_;
}
bool Triangle::operator<(const Triangle &other) const {
if (u_ < other.u_) {
return true;
} else if (u_ > other.u_) {
return false;
}
if (v_ < other.v_) {
return true;
} else if (v_ > other.v_) {
return false;
}
if (w_ < other.w_) {
return true;
} else if (w_ > other.w_) {
return false;
}
return false;
}
QDebug operator<<(QDebug d, const Triangle &triangle) {
QDebugStateSaver saver(d);
d.nospace() << "Triangle(" << triangle.u_idx() << ", " << triangle.v_idx() << ", " << triangle.w_idx() << "; " << triangle.u().pos << ", " << triangle.v().pos << ", " << triangle.w().pos << ")";
......
......@@ -22,6 +22,11 @@ class Triangle {
Triangle &operator=(const Triangle &other);
// == and < both ignore the vertex buffer, they only compare indices.
// They are implemented so that Triangle can be used as the key of a QMap.
bool operator==(const Triangle &other) const;
bool operator<(const Triangle &other) const;
private:
QVector<Vertex> vertex_buffer_;
int u_;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment