--- a/src/vertex.cpp Fri Dec 13 15:55:56 2019 +0200 +++ b/src/vertex.cpp Fri Dec 13 21:35:59 2019 +0200 @@ -31,7 +31,7 @@ } */ -Vertex::ValueType& Vertex::operator[](Axis axis) +Point3D::CoordinateType& Point3D::get(Axis axis) { switch (axis) { @@ -46,7 +46,7 @@ } } -Vertex::ValueType Vertex::operator[](Axis axis) const +Point3D::CoordinateType Point3D::get(Axis axis) const { switch (axis) { @@ -61,38 +61,37 @@ } } -void Vertex::setCoordinate(Axis axis, ValueType value) +void Point3D::assign(Axis axis, CoordinateType value) { - (*this)[axis] = value; + this->get(axis) = value; } -Vertex VertexFromVector(const QVector3D& vector) +Point3D VertexFromVector(const QVector3D& vector) { return {vector.x(), vector.y(), vector.z()}; } -Vertex Vertex::operator*(ValueType scalar) const +Point3D operator*(const Point3D& point, Point3D::CoordinateType scalar) { - return {this->x * scalar, this->y * scalar, this->z * scalar}; + return {point.x * scalar, point.y * scalar, point.z * scalar}; } -Vertex& Vertex::operator+=(const QVector3D& other) +Point3D& operator+=(Point3D& point, const QVector3D& other) { - this->x += other.x(); - this->y += other.y(); - this->z += other.z(); - return *this; + point.x += other.x(); + point.y += other.y(); + point.z += other.z(); + return point; } -Vertex Vertex::operator+(const QVector3D& other) const +Point3D operator+(Point3D point, const QVector3D& other) { - Vertex result(*this); - result += other; - return result; + point += other; + return point; } -QVector3D vertexToVector(const Vertex& vertex) +QVector3D vertexToVector(const Point3D& vertex) { return { static_cast<float>(vertex.x), @@ -101,85 +100,79 @@ }; } -Vertex Vertex::operator-(const QVector3D& vector) const +Point3D operator-(Point3D point, const QVector3D& vector) { - Vertex result = *this; - result -= vector; - return result; + point -= vector; + return point; } -Vertex& Vertex::operator-=(const QVector3D& vector) +Point3D& operator-=(Point3D& point, const QVector3D& vector) { - this->x -= vector.x(); - this->y -= vector.y(); - this->z -= vector.z(); - return *this; + point.x -= vector.x(); + point.y -= vector.y(); + point.z -= vector.z(); + return point; } -QVector3D Vertex::operator-(const Vertex& other) const +QVector3D operator-(const Point3D& point, const Point3D& other) { return { - static_cast<float>(this->x - other.x), - static_cast<float>(this->y - other.y), - static_cast<float>(this->z - other.z) + static_cast<float>(point.x - other.x), + static_cast<float>(point.y - other.y), + static_cast<float>(point.z - other.z) }; } -Vertex& Vertex::operator*=(ValueType scalar) +Point3D& operator*=(Point3D& point, Point3D::CoordinateType scalar) { - x *= scalar; - y *= scalar; - z *= scalar; - return *this; + point.x *= scalar; + point.y *= scalar; + point.z *= scalar; + return point; } -bool Vertex::operator==(const Vertex& other) const +bool operator==(const Point3D& point, const Point3D& other) { - return this->x == other.x and this->y == other.y and this->z == other.z; + return point.x == other.x and point.y == other.y and point.z == other.z; } -bool Vertex::operator!=(const Vertex& other) const +bool operator!=(const Point3D& point, const Point3D& other) { - return not(*this == other); + return not (point == other); } -Vertex::operator QVariant() const -{ - return QVariant::fromValue<Vertex>(*this); -} - -bool Vertex::operator<(const Vertex& other) const +bool operator<(const Point3D& point, const Point3D& other) { - if (not qFuzzyCompare(this->x, other.x)) - return this->x < other.x; - else if (not qFuzzyCompare(this->y, other.y)) - return this->y < other.y; + if (not qFuzzyCompare(point.x, other.x)) + return point.x < other.x; + else if (not qFuzzyCompare(point.y, other.y)) + return point.y < other.y; else - return this->z < other.z; + return point.z < other.z; } /* * Transforms this vertex with a tranformation matrix and returns the result. */ -Vertex Vertex::transformed(const GLRotationMatrix& matrix) const +Point3D math::transform(const Point3D point, const GLRotationMatrix& matrix) { return { - matrix(0, 0) * this->x - + matrix(0, 1) * this->y - + matrix(0, 2) * this->z, - matrix(1, 0) * this->x - + matrix(1, 1) * this->y - + matrix(1, 2) * this->z, - matrix(2, 0) * this->x - + matrix(2, 1) * this->y - + matrix(2, 2) * this->z, + matrix(0, 0) * point.x + + matrix(0, 1) * point.y + + matrix(0, 2) * point.z, + matrix(1, 0) * point.x + + matrix(1, 1) * point.y + + matrix(1, 2) * point.z, + matrix(2, 0) * point.x + + matrix(2, 1) * point.y + + matrix(2, 2) * point.z, }; } /* * Returns the distance from one vertex to another. */ -qreal distance(const Vertex& one, const Vertex& other) +qreal math::distance(const Point3D& one, const Point3D& other) { return (one - other).length(); } @@ -187,7 +180,7 @@ /* * Returns a vertex with all coordinates inverted. */ -Vertex operator-(const Vertex& vertex) +Point3D operator-(const Point3D& vertex) { return {-vertex.x, -vertex.y, -vertex.z}; } @@ -196,7 +189,7 @@ * Inserts this vertex into a data stream. This is needed for vertices to be * stored in QSettings. */ -QDataStream& operator<<(QDataStream& out, const Vertex& vertex) +QDataStream& operator<<(QDataStream& out, const Point3D& vertex) { return out << vertex.x << vertex.y << vertex.z; } @@ -204,17 +197,17 @@ /* * Takes a vertex from a data stream. */ -QDataStream& operator>>(QDataStream& in, Vertex& vertex) +QDataStream& operator>>(QDataStream& in, Point3D& vertex) { return in >> vertex.x >> vertex.y >> vertex.z; } -unsigned int qHash(const Vertex& key) +unsigned int qHash(const Point3D& key) { return qHash(key.x) ^ utility::rotl10(qHash(key.y)) ^ utility::rotl20(qHash(key.z)); } -QString vertexToStringParens(const Vertex& vertex) +QString vertexToStringParens(const Point3D& vertex) { return utility::format("(%1, %2, %3)", vertex.x, vertex.y, vertex.z); }