moved Vertex and BoundingBox into new code units

Fri, 23 Mar 2018 21:53:03 +0200

author
Teemu Piippo <teemu@hecknology.net>
date
Fri, 23 Mar 2018 21:53:03 +0200
changeset 1315
23d48a709ffc
parent 1314
d94cf95608ac
child 1316
31f4293cec30

moved Vertex and BoundingBox into new code units

CMakeLists.txt file | annotate | diff | comparison | revisions
src/basics.cpp file | annotate | diff | comparison | revisions
src/basics.h file | annotate | diff | comparison | revisions
src/geometry/linesegment.h file | annotate | diff | comparison | revisions
src/glShared.h file | annotate | diff | comparison | revisions
src/main.h file | annotate | diff | comparison | revisions
src/mathfunctions.cpp file | annotate | diff | comparison | revisions
src/types/boundingbox.cpp file | annotate | diff | comparison | revisions
src/types/boundingbox.h file | annotate | diff | comparison | revisions
src/types/vertex.cpp file | annotate | diff | comparison | revisions
src/types/vertex.h file | annotate | diff | comparison | revisions
--- a/CMakeLists.txt	Fri Mar 23 21:36:37 2018 +0200
+++ b/CMakeLists.txt	Fri Mar 23 21:53:03 2018 +0200
@@ -94,7 +94,9 @@
 	src/toolsets/movetoolset.cpp
 	src/toolsets/toolset.cpp
 	src/toolsets/viewtoolset.cpp
+	src/types/boundingbox.cpp
 	src/types/matrix.cpp
+	src/types/vertex.cpp
 	src/widgets/headeredit.cpp
 	src/widgets/vertexobjecteditor.cpp
 )
@@ -169,7 +171,9 @@
 	src/toolsets/movetoolset.h
 	src/toolsets/toolset.h
 	src/toolsets/viewtoolset.h
+	src/types/boundingbox.h
 	src/types/matrix.h
+	src/types/vertex.h
 	src/widgets/headeredit.h
 	src/widgets/vertexobjecteditor.h
 )
--- a/src/basics.cpp	Fri Mar 23 21:36:37 2018 +0200
+++ b/src/basics.cpp	Fri Mar 23 21:53:03 2018 +0200
@@ -20,268 +20,6 @@
 #include "linetypes/modelobject.h"
 #include "lddocument.h"
 
-void Vertex::transform(const Matrix& matrix, const Vertex& pos)
-{
-	double x2 = (matrix(0, 0) * x) + (matrix(0, 1) * y) + (matrix(0, 2) * z) + pos.x;
-	double y2 = (matrix(1, 0) * x) + (matrix(1, 1) * y) + (matrix(1, 2) * z) + pos.y;
-	double z2 = (matrix(2, 0) * x) + (matrix(2, 1) * y) + (matrix(2, 2) * z) + pos.z;
-	this->x = x2;
-	this->y = y2;
-	this->z = z2;
-}
-
-void Vertex::apply(ApplyFunction func)
-{
-	func(X, this->x);
-	func(Y, this->y);
-	func(Z, this->z);
-}
-
-void Vertex::apply(ApplyConstFunction func) const
-{
-	func(X, this->x);
-	func(Y, this->y);
-	func(Z, this->z);
-}
-
-double& Vertex::operator[](Axis axis)
-{
-	switch (axis)
-	{
-	case X:
-		return this->x;
-
-	case Y:
-		return this->y;
-
-	case Z:
-		return this->z;
-
-	default:
-		return ::sink<double>();
-	}
-}
-
-double Vertex::operator[] (Axis axis) const
-{
-	switch (axis)
-	{
-	case X:
-		return this->x;
-
-	case Y:
-		return this->y;
-
-	case Z:
-		return this->z;
-
-	default:
-		return 0.0;
-	}
-}
-
-void Vertex::setCoordinate (Axis axis, qreal value)
-{
-	(*this)[axis] = value;
-}
-
-QString Vertex::toString (bool mangled) const
-{
-	if (mangled)
-		return ::format("(%1, %2, %3)", this->x, this->y, this->z);
-	else
-		return ::format("%1 %2 %3", this->x, this->y, this->z);
-}
-
-Vertex Vertex::operator* (qreal scalar) const
-{
-	return {this->x * scalar, this->y * scalar, this->z * scalar};
-}
-
-Vertex& Vertex::operator+=(const QVector3D& other)
-{
-	this->x += other.x();
-	this->y += other.y();
-	this->z += other.z();
-	return *this;
-}
-
-Vertex Vertex::operator+(const QVector3D& other) const
-{
-	Vertex result (*this);
-	result += other;
-	return result;
-}
-
-QVector3D Vertex::toVector() const
-{
-	return {
-		static_cast<float>(this->x),
-		static_cast<float>(this->y),
-		static_cast<float>(this->z)
-	};
-}
-
-Vertex Vertex::operator- (const QVector3D& vector) const
-{
-	Vertex result = *this;
-	result -= vector;
-	return result;
-}
-
-Vertex& Vertex::operator-= (const QVector3D& vector)
-{
-	this->x -= vector.x();
-	this->y -= vector.y();
-	this->z -= vector.z();
-	return *this;
-}
-
-QVector3D Vertex::operator- (const Vertex& other) const
-{
-	return {
-		static_cast<float>(this->x - other.x),
-		static_cast<float>(this->y - other.y),
-		static_cast<float>(this->z - other.z)
-	};
-}
-
-Vertex& Vertex::operator*= (qreal scalar)
-{
-	x *= scalar;
-	y *= scalar;
-	z *= scalar;
-	return *this;
-}
-
-bool Vertex::operator==(const Vertex& other) const
-{
-	return this->x == other.x and this->y == other.y and this->z == other.z;
-}
-
-bool Vertex::operator!=(const Vertex& other) const
-{
-	return not (*this == other);
-}
-
-bool Vertex::operator< (const Vertex& other) const
-{
-	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;
-	else
-		return this->z < other.z;
-}
-
-/*
- * Transforms this vertex with a tranformation matrix and returns the result.
- */
-Vertex Vertex::transformed(const GLRotationMatrix& matrix) const
-{
-	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,
-	};
-}
-
-QDataStream& operator<<(QDataStream& out, const Vertex& vertex)
-{
-	return out << vertex.x << vertex.y << vertex.z;
-}
-
-QDataStream& operator>>(QDataStream& in, Vertex& vertex)
-{
-	return in >> vertex.x >> vertex.y >> vertex.z;
-}
-
-// =============================================================================
-//
-BoundingBox::BoundingBox()
-{
-	reset();
-}
-
-// =============================================================================
-//
-BoundingBox& BoundingBox::operator<< (const Vertex& v)
-{
-	calcVertex (v);
-	return *this;
-}
-
-// =============================================================================
-//
-void BoundingBox::calcVertex (const Vertex& vertex)
-{
-	m_vertex0.x = qMin(vertex.x, m_vertex0.x);
-	m_vertex0.y = qMin(vertex.y, m_vertex0.y);
-	m_vertex0.z = qMin(vertex.z, m_vertex0.z);
-	m_vertex1.x = qMax(vertex.x, m_vertex1.x);
-	m_vertex1.y = qMax(vertex.y, m_vertex1.y);
-	m_vertex1.z = qMax(vertex.z, m_vertex1.z);
-	m_isEmpty = false;
-}
-
-// =============================================================================
-//
-// Clears the bounding box
-//
-void BoundingBox::reset()
-{
-	m_vertex0 = {10000.0, 10000.0, 10000.0};
-	m_vertex1 = {-10000.0, -10000.0, -10000.0};
-	m_isEmpty = true;
-}
-
-// =============================================================================
-//
-// Returns the length of the bounding box on the longest measure.
-//
-double BoundingBox::longestMeasurement() const
-{
-	double xscale = m_vertex0.x - m_vertex1.x;
-	double yscale = m_vertex0.y - m_vertex1.y;
-	double zscale = m_vertex0.z - m_vertex1.z;
-	double size = qMax(xscale, qMax(yscale, zscale));
-	return qMax(qAbs(size / 2.0), 1.0);
-}
-
-// =============================================================================
-//
-// Yields the center of the bounding box.
-//
-Vertex BoundingBox::center() const
-{
-	return {
-		(m_vertex0.x + m_vertex1.x) / 2,
-		(m_vertex0.y + m_vertex1.y) / 2,
-		(m_vertex0.z + m_vertex1.z) / 2
-	};
-}
-
-bool BoundingBox::isEmpty() const
-{
-	return m_isEmpty;
-}
-
-const Vertex& BoundingBox::vertex0() const
-{
-	return m_vertex0;
-}
-
-const Vertex& BoundingBox::vertex1() const
-{
-	return m_vertex1;
-}
-
 // http://stackoverflow.com/a/18204188/3629665
 template<typename T>
 inline int rotl10(T x)
--- a/src/basics.h	Fri Mar 23 21:36:37 2018 +0200
+++ b/src/basics.h	Fri Mar 23 21:53:03 2018 +0200
@@ -73,6 +73,7 @@
 #endif
 
 class Matrix;
+struct Vertex;
 using GLRotationMatrix = QMatrix4x4;
 
 template<typename T, typename R>
@@ -95,76 +96,11 @@
 Winding operator^(Winding one, Winding other);
 Winding& operator^=(Winding& one, Winding other);
 
-struct Vertex
-{
-	qreal x, y, z;
-
-	using ApplyFunction = std::function<void (Axis, double&)>;
-	using ApplyConstFunction = std::function<void (Axis, double)>;
-
-	void	apply (ApplyFunction func);
-	void	apply (ApplyConstFunction func) const;
-	QString	toString (bool mangled = false) const;
-	QVector3D toVector() const;
-	void	transform (const Matrix& matr, const Vertex& pos);
-	Vertex	transformed(const GLRotationMatrix& matrix) const;
-	void	setCoordinate (Axis ax, qreal value);
-
-	Vertex&	operator+= (const QVector3D& other);
-	Vertex	operator+ (const QVector3D& other) const;
-	QVector3D operator- (const Vertex& other) const;
-	Vertex operator- (const QVector3D& vector) const;
-	Vertex& operator-= (const QVector3D& vector);
-	Vertex&	operator*= (qreal scalar);
-	Vertex	operator* (qreal scalar) const;
-	bool	operator< (const Vertex& other) const;
-	double&	operator[] (Axis ax);
-	double	operator[] (Axis ax) const;
-	bool operator==(const Vertex& other) const;
-	bool operator!=(const Vertex& other) const;
-};
-
-inline Vertex operator* (qreal scalar, const Vertex& vertex)
-{
-	return vertex * scalar;
-}
-
-Q_DECLARE_METATYPE (Vertex)
-uint qHash(const Vertex& key);
-QDataStream& operator<<(QDataStream& out, const Vertex& vertex);
-QDataStream& operator>>(QDataStream& in, Vertex& vertex);
-
-
 static inline qreal abs(const QVector3D &vector)
 {
 	return vector.length();
 }
 
-//
-// Defines a bounding box that encompasses a given set of objects.
-// vertex0 is the minimum vertex, vertex1 is the maximum vertex.
-//
-class BoundingBox
-{
-public:
-	BoundingBox();
-
-	void calcVertex (const Vertex& vertex);
-	Vertex center() const;
-	bool isEmpty() const;
-	double longestMeasurement() const;
-	void reset(); 
-	const Vertex& vertex0() const;
-	const Vertex& vertex1() const;
-
-	BoundingBox& operator<< (const Vertex& v);
-
-private:
-	bool m_isEmpty;
-	Vertex m_vertex0;
-	Vertex m_vertex1;
-};
-
 static const double pi = 3.14159265358979323846;
 
 
--- a/src/geometry/linesegment.h	Fri Mar 23 21:36:37 2018 +0200
+++ b/src/geometry/linesegment.h	Fri Mar 23 21:53:03 2018 +0200
@@ -18,6 +18,7 @@
 
 #pragma once
 #include "../basics.h"
+#include "../types/vertex.h"
 
 /*
  * Models a 3D line segment.
--- a/src/glShared.h	Fri Mar 23 21:36:37 2018 +0200
+++ b/src/glShared.h	Fri Mar 23 21:53:03 2018 +0200
@@ -21,6 +21,7 @@
 #include <QOpenGLFunctions>
 #include <QGenericMatrix>
 #include "basics.h"
+#include "types/vertex.h"
 
 inline void glMultMatrixf(const GLRotationMatrix& matrix)
 {
--- a/src/main.h	Fri Mar 23 21:36:37 2018 +0200
+++ b/src/main.h	Fri Mar 23 21:53:03 2018 +0200
@@ -33,5 +33,6 @@
 #include "format.h"
 #include "configuration.h"
 #include "generics/range.h"
+#include "types/vertex.h"
 
 extern Configuration* config;
--- a/src/mathfunctions.cpp	Fri Mar 23 21:36:37 2018 +0200
+++ b/src/mathfunctions.cpp	Fri Mar 23 21:53:03 2018 +0200
@@ -19,7 +19,7 @@
 #include "mathfunctions.h"
 #include "linetypes/modelobject.h"
 #include "miscallenous.h"
-
+#include "types/boundingbox.h"
 
 MathFunctions::MathFunctions(QObject* parent) :
 	HierarchyElement(parent) {}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/types/boundingbox.cpp	Fri Mar 23 21:53:03 2018 +0200
@@ -0,0 +1,99 @@
+/*
+ *  LDForge: LDraw parts authoring CAD
+ *  Copyright (C) 2013 - 2017 Teemu Piippo
+ *
+ *  This program is free software: you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation, either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "boundingbox.h"
+
+// =============================================================================
+//
+BoundingBox::BoundingBox()
+{
+	reset();
+}
+
+// =============================================================================
+//
+BoundingBox& BoundingBox::operator<< (const Vertex& v)
+{
+	calcVertex (v);
+	return *this;
+}
+
+// =============================================================================
+//
+void BoundingBox::calcVertex (const Vertex& vertex)
+{
+	m_vertex0.x = qMin(vertex.x, m_vertex0.x);
+	m_vertex0.y = qMin(vertex.y, m_vertex0.y);
+	m_vertex0.z = qMin(vertex.z, m_vertex0.z);
+	m_vertex1.x = qMax(vertex.x, m_vertex1.x);
+	m_vertex1.y = qMax(vertex.y, m_vertex1.y);
+	m_vertex1.z = qMax(vertex.z, m_vertex1.z);
+	m_isEmpty = false;
+}
+
+// =============================================================================
+//
+// Clears the bounding box
+//
+void BoundingBox::reset()
+{
+	m_vertex0 = {10000.0, 10000.0, 10000.0};
+	m_vertex1 = {-10000.0, -10000.0, -10000.0};
+	m_isEmpty = true;
+}
+
+// =============================================================================
+//
+// Returns the length of the bounding box on the longest measure.
+//
+double BoundingBox::longestMeasurement() const
+{
+	double xscale = m_vertex0.x - m_vertex1.x;
+	double yscale = m_vertex0.y - m_vertex1.y;
+	double zscale = m_vertex0.z - m_vertex1.z;
+	double size = qMax(xscale, qMax(yscale, zscale));
+	return qMax(qAbs(size / 2.0), 1.0);
+}
+
+// =============================================================================
+//
+// Yields the center of the bounding box.
+//
+Vertex BoundingBox::center() const
+{
+	return {
+		(m_vertex0.x + m_vertex1.x) / 2,
+		(m_vertex0.y + m_vertex1.y) / 2,
+		(m_vertex0.z + m_vertex1.z) / 2
+	};
+}
+
+bool BoundingBox::isEmpty() const
+{
+	return m_isEmpty;
+}
+
+const Vertex& BoundingBox::vertex0() const
+{
+	return m_vertex0;
+}
+
+const Vertex& BoundingBox::vertex1() const
+{
+	return m_vertex1;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/types/boundingbox.h	Fri Mar 23 21:53:03 2018 +0200
@@ -0,0 +1,45 @@
+/*
+ *  LDForge: LDraw parts authoring CAD
+ *  Copyright (C) 2013 - 2017 Teemu Piippo
+ *
+ *  This program is free software: you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation, either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#pragma once
+#include "vertex.h"
+
+//
+// Defines a bounding box that encompasses a given set of objects.
+// vertex0 is the minimum vertex, vertex1 is the maximum vertex.
+//
+class BoundingBox
+{
+public:
+	BoundingBox();
+
+	void calcVertex(const Vertex& vertex);
+	Vertex center() const;
+	bool isEmpty() const;
+	double longestMeasurement() const;
+	void reset();
+	const Vertex& vertex0() const;
+	const Vertex& vertex1() const;
+
+	BoundingBox& operator<<(const Vertex& v);
+
+private:
+	bool m_isEmpty;
+	Vertex m_vertex0;
+	Vertex m_vertex1;
+};
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/types/vertex.cpp	Fri Mar 23 21:53:03 2018 +0200
@@ -0,0 +1,202 @@
+/*
+ *  LDForge: LDraw parts authoring CAD
+ *  Copyright(C) 2013 - 2017 Teemu Piippo
+ *
+ *  This program is free software: you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "vertex.h"
+#include "../format.h"
+
+void Vertex::transform(const Matrix& matrix, const Vertex& pos)
+{
+	double x2 = (matrix(0, 0) * x) + (matrix(0, 1) * y) + (matrix(0, 2) * z) + pos.x;
+	double y2 = (matrix(1, 0) * x) + (matrix(1, 1) * y) + (matrix(1, 2) * z) + pos.y;
+	double z2 = (matrix(2, 0) * x) + (matrix(2, 1) * y) + (matrix(2, 2) * z) + pos.z;
+	this->x = x2;
+	this->y = y2;
+	this->z = z2;
+}
+
+void Vertex::apply(ApplyFunction func)
+{
+	func(X, this->x);
+	func(Y, this->y);
+	func(Z, this->z);
+}
+
+void Vertex::apply(ApplyConstFunction func) const
+{
+	func(X, this->x);
+	func(Y, this->y);
+	func(Z, this->z);
+}
+
+double& Vertex::operator[](Axis axis)
+{
+	switch (axis)
+	{
+	case X:
+		return this->x;
+
+	case Y:
+		return this->y;
+
+	case Z:
+		return this->z;
+
+	default:
+		return ::sink<double>();
+	}
+}
+
+double Vertex::operator[](Axis axis) const
+{
+	switch (axis)
+	{
+	case X:
+		return this->x;
+
+	case Y:
+		return this->y;
+
+	case Z:
+		return this->z;
+
+	default:
+		return 0.0;
+	}
+}
+
+void Vertex::setCoordinate(Axis axis, qreal value)
+{
+	(*this)[axis] = value;
+}
+
+QString Vertex::toString(bool mangled) const
+{
+	if (mangled)
+		return ::format("(%1, %2, %3)", this->x, this->y, this->z);
+	else
+		return ::format("%1 %2 %3", this->x, this->y, this->z);
+}
+
+Vertex Vertex::operator*(qreal scalar) const
+{
+	return {this->x * scalar, this->y * scalar, this->z * scalar};
+}
+
+Vertex& Vertex::operator+= (const QVector3D& other)
+{
+	this->x += other.x();
+	this->y += other.y();
+	this->z += other.z();
+	return *this;
+}
+
+Vertex Vertex::operator+ (const QVector3D& other) const
+{
+	Vertex result(*this);
+	result += other;
+	return result;
+}
+
+QVector3D Vertex::toVector() const
+{
+	return {
+		static_cast<float>(this->x),
+		static_cast<float>(this->y),
+		static_cast<float>(this->z)
+	};
+}
+
+Vertex Vertex::operator-(const QVector3D& vector) const
+{
+	Vertex result = *this;
+	result -= vector;
+	return result;
+}
+
+Vertex& Vertex::operator-= (const QVector3D& vector)
+{
+	this->x -= vector.x();
+	this->y -= vector.y();
+	this->z -= vector.z();
+	return *this;
+}
+
+QVector3D Vertex::operator-(const Vertex& other) const
+{
+	return {
+		static_cast<float>(this->x - other.x),
+		static_cast<float>(this->y - other.y),
+		static_cast<float>(this->z - other.z)
+	};
+}
+
+Vertex& Vertex::operator*= (qreal scalar)
+{
+	x *= scalar;
+	y *= scalar;
+	z *= scalar;
+	return *this;
+}
+
+bool Vertex::operator== (const Vertex& other) const
+{
+	return this->x == other.x and this->y == other.y and this->z == other.z;
+}
+
+bool Vertex::operator!= (const Vertex& other) const
+{
+	return not(*this == other);
+}
+
+bool Vertex::operator<(const Vertex& other) const
+{
+	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;
+	else
+		return this->z < other.z;
+}
+
+/*
+ * Transforms this vertex with a tranformation matrix and returns the result.
+ */
+Vertex Vertex::transformed(const GLRotationMatrix& matrix) const
+{
+	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,
+	};
+}
+
+QDataStream& operator<<(QDataStream& out, const Vertex& vertex)
+{
+	return out << vertex.x << vertex.y << vertex.z;
+}
+
+QDataStream& operator>>(QDataStream& in, Vertex& vertex)
+{
+	return in >> vertex.x >> vertex.y >> vertex.z;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/types/vertex.h	Fri Mar 23 21:53:03 2018 +0200
@@ -0,0 +1,61 @@
+/*
+ *  LDForge: LDraw parts authoring CAD
+ *  Copyright (C) 2013 - 2017 Teemu Piippo
+ *
+ *  This program is free software: you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation, either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#pragma once
+#include <functional>
+#include <QVector3D>
+#include "../basics.h"
+
+struct Vertex
+{
+	qreal x, y, z;
+
+	using ApplyFunction = std::function<void(Axis, double&)>;
+	using ApplyConstFunction = std::function<void(Axis, double)>;
+
+	void apply(ApplyFunction func);
+	void apply(ApplyConstFunction func) const;
+	QString toString(bool mangled = false) const;
+	QVector3D toVector() const;
+	void transform(const Matrix& matr, const Vertex& pos);
+	Vertex transformed(const GLRotationMatrix& matrix) const;
+	void setCoordinate(Axis ax, qreal value);
+
+	Vertex& operator+=(const QVector3D& other);
+	Vertex operator+(const QVector3D& other) const;
+	QVector3D operator-(const Vertex& other) const;
+	Vertex operator-(const QVector3D& vector) const;
+	Vertex& operator-=(const QVector3D& vector);
+	Vertex& operator*=(qreal scalar);
+	Vertex operator*(qreal scalar) const;
+	bool operator<(const Vertex& other) const;
+	double& operator[](Axis ax);
+	double operator[](Axis ax) const;
+	bool operator==(const Vertex& other) const;
+	bool operator!=(const Vertex& other) const;
+};
+
+inline Vertex operator*(qreal scalar, const Vertex& vertex)
+{
+	return vertex * scalar;
+}
+
+Q_DECLARE_METATYPE(Vertex)
+uint qHash(const Vertex& key);
+QDataStream& operator<<(QDataStream& out, const Vertex& vertex);
+QDataStream& operator>>(QDataStream& in, Vertex& vertex);

mercurial