things

Fri, 13 Dec 2019 21:35:59 +0200

author
Teemu Piippo <teemu@hecknology.net>
date
Fri, 13 Dec 2019 21:35:59 +0200
changeset 18
918b6c0f8b5b
parent 17
a5111f4e6412
child 19
ed9685f44ab3

things

CMakeLists.txt file | annotate | diff | comparison | revisions
src/basics.h file | annotate | diff | comparison | revisions
src/gl/partrenderer.cpp file | annotate | diff | comparison | revisions
src/gl/partrenderer.h file | annotate | diff | comparison | revisions
src/linetypes/conditionaledge.cpp file | annotate | diff | comparison | revisions
src/linetypes/conditionaledge.h file | annotate | diff | comparison | revisions
src/linetypes/edge.cpp file | annotate | diff | comparison | revisions
src/linetypes/edge.h file | annotate | diff | comparison | revisions
src/linetypes/quadrilateral.cpp file | annotate | diff | comparison | revisions
src/linetypes/quadrilateral.h file | annotate | diff | comparison | revisions
src/linetypes/subfilereference.cpp file | annotate | diff | comparison | revisions
src/linetypes/subfilereference.h file | annotate | diff | comparison | revisions
src/linetypes/triangle.cpp file | annotate | diff | comparison | revisions
src/linetypes/triangle.h file | annotate | diff | comparison | revisions
src/main.h file | annotate | diff | comparison | revisions
src/math.h file | annotate | diff | comparison | revisions
src/parser.cpp file | annotate | diff | comparison | revisions
src/vertex.cpp file | annotate | diff | comparison | revisions
src/vertex.h file | annotate | diff | comparison | revisions
--- a/CMakeLists.txt	Fri Dec 13 15:55:56 2019 +0200
+++ b/CMakeLists.txt	Fri Dec 13 21:35:59 2019 +0200
@@ -55,6 +55,7 @@
 	src/libraries.h
 	src/main.h
 	src/mainwindow.h
+	src/math.h
 	src/matrix.h
 	src/model.h
 	src/modeleditcontext.h
--- a/src/basics.h	Fri Dec 13 15:55:56 2019 +0200
+++ b/src/basics.h	Fri Dec 13 21:35:59 2019 +0200
@@ -65,6 +65,3 @@
 	one = one ^ other;
 	return one;
 }
-
-constexpr double infinity = std::numeric_limits<double>::infinity();
-static constexpr long double pi = M_PIl;
--- a/src/gl/partrenderer.cpp	Fri Dec 13 15:55:56 2019 +0200
+++ b/src/gl/partrenderer.cpp	Fri Dec 13 21:35:59 2019 +0200
@@ -21,15 +21,6 @@
 	this->rotation *= QQuaternion::fromAxisAndAngle({0, 1, 0}, 330);
 }
 
-// https://stackoverflow.com/a/12943456
-static void perspectiveGL(GLdouble fovY, GLdouble aspect, GLdouble zNear, GLdouble zFar)
-{
-	//fH = tan( (fovY / 2) / 180 * pi ) * zNear;
-	const GLdouble fH = std::tan(fovY / 360 * pi) * zNear;
-	const GLdouble fW = fH * aspect;
-	glFrustum(-fW, fW, -fH, fH, zNear, zFar);
-}
-
 /*
  * Pads a 3×3 matrix into a 4×4 one by adding cells from the identity matrix.
  */
@@ -63,17 +54,27 @@
 void PartRenderer::resizeGL(int width, int height)
 {
 	constexpr GLfloat near = 1.0f;
-	constexpr GLfloat far = 1.0e+05f;
+	constexpr GLfloat far = 1e+05f;
 	glViewport (0, 0, width, height);
 	glMatrixMode(GL_PROJECTION);
 	glLoadIdentity();
-	::perspectiveGL(45.0f, static_cast<double>(width) / static_cast<double>(height), near, far);
+	gluPerspective(45.0f, static_cast<double>(width) / static_cast<double>(height), near, far);
 	glMatrixMode(GL_MODELVIEW);
 }
 
 // https://www.codemiles.com/c-opengl-examples/drawing-teapot-using-opengl-t9010.html?mobile=on
 void PartRenderer::paintGL()
 {
+	switch (this->renderStyle)
+	{
+	case gl::RenderStyle::Normal:
+	case gl::RenderStyle::BfcRedGreen:
+	case gl::RenderStyle::RandomColors:
+		break;
+	case gl::RenderStyle::Wireframe:
+		glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
+		break;
+	}
 	glMatrixMode(GL_MODELVIEW);
 	// clear the drawing buffer.
 	glClear(GL_COLOR_BUFFER_BIT);
@@ -116,3 +117,10 @@
 	}
 	this->lastMousePosition = pointToPointF(event->pos());
 }
+
+void PartRenderer::setRenderStyle(const gl::RenderStyle newStyle)
+{
+	this->renderStyle = newStyle;
+	this->update();
+}
+
--- a/src/gl/partrenderer.h	Fri Dec 13 15:55:56 2019 +0200
+++ b/src/gl/partrenderer.h	Fri Dec 13 21:35:59 2019 +0200
@@ -3,6 +3,7 @@
 #include <QOpenGLFunctions>
 #include <QQuaternion>
 #include "main.h"
+#include "gl/common.h"
 
 class PartRenderer : public QOpenGLWidget, protected QOpenGLFunctions
 {
@@ -13,9 +14,12 @@
 	void resizeGL(int width, int height) override;
 	void paintGL() override;
 	void mouseMoveEvent(QMouseEvent* event) override;
+private slots:
+	void setRenderStyle(const gl::RenderStyle newStyle);
 private:
 	QPointF lastMousePosition;
 	bool initialized = false;
+	gl::RenderStyle renderStyle = gl::RenderStyle::Normal;
 	QQuaternion rotation;
 	void initializeLighting();
 };
--- a/src/linetypes/conditionaledge.cpp	Fri Dec 13 15:55:56 2019 +0200
+++ b/src/linetypes/conditionaledge.cpp	Fri Dec 13 21:35:59 2019 +0200
@@ -1,10 +1,10 @@
 #include "conditionaledge.h"
 
 linetypes::ConditionalEdge::ConditionalEdge(
-	const Vertex& point_1,
-	const Vertex& point_2,
-	const Vertex& controlPoint_1,
-	const Vertex& controlPoint_2,
+	const Point3D& point_1,
+	const Point3D& point_2,
+	const Point3D& controlPoint_1,
+	const Point3D& controlPoint_2,
 	const Color color_index) :
 	Edge{point_1, point_2, color_index},
 	controlPoint_1{controlPoint_1},
@@ -12,7 +12,7 @@
 {
 }
 
-linetypes::ConditionalEdge::ConditionalEdge(const QVector<Vertex>& vertices, const Color color) :
+linetypes::ConditionalEdge::ConditionalEdge(const QVector<Point3D>& vertices, const Color color) :
 	Edge{vertices[0], vertices[1], color},
 	controlPoint_1{vertices[2]},
 	controlPoint_2{vertices[3]}
@@ -40,9 +40,9 @@
 	switch (property)
 	{
 	case Property::ControlPoint1:
-		controlPoint_1 = value.value<Vertex>();
+		controlPoint_1 = value.value<Point3D>();
 	case Property::ControlPoint2:
-		controlPoint_2 = value.value<Vertex>();
+		controlPoint_2 = value.value<Point3D>();
 	default:
 		return Edge::setProperty(property, value);
 	}
--- a/src/linetypes/conditionaledge.h	Fri Dec 13 15:55:56 2019 +0200
+++ b/src/linetypes/conditionaledge.h	Fri Dec 13 21:35:59 2019 +0200
@@ -11,18 +11,18 @@
 public:
 	ConditionalEdge() = default;
 	ConditionalEdge(
-		const Vertex& point_1,
-		const Vertex& point_2,
-		const Vertex& controlPoint_1,
-		const Vertex& controlPoint_2,
+		const Point3D& point_1,
+		const Point3D& point_2,
+		const Point3D& controlPoint_1,
+		const Point3D& controlPoint_2,
 		const Color colorIndex = colors::edge);
-	ConditionalEdge(const QVector<Vertex>& vertices, const Color color);
+	ConditionalEdge(const QVector<Point3D>& vertices, const Color color);
 	QVariant getProperty(Property property) const override;
 	SetPropertyResult setProperty(
 		Property property,
 		const QVariant& value) override;
 	QString textRepresentation() const override;
 private:
-	Vertex controlPoint_1 = {};
-	Vertex controlPoint_2 = {};
+	Point3D controlPoint_1 = {};
+	Point3D controlPoint_2 = {};
 };
--- a/src/linetypes/edge.cpp	Fri Dec 13 15:55:56 2019 +0200
+++ b/src/linetypes/edge.cpp	Fri Dec 13 21:35:59 2019 +0200
@@ -1,14 +1,14 @@
 #include "edge.h"
 
 linetypes::Edge::Edge(
-	const Vertex& point_1,
-	const Vertex& point_2,
+	const Point3D& point_1,
+	const Point3D& point_2,
 	const Color color_index) :
 	ColoredObject{color_index},
 	point_1{point_1},
 	point_2{point_2} {}
 
-linetypes::Edge::Edge(const QVector<Vertex>& vertices, const Color color) :
+linetypes::Edge::Edge(const QVector<Point3D>& vertices, const Color color) :
 	ColoredObject{color},
 	point_1{vertices[0]},
 	point_2{vertices[1]}
@@ -34,10 +34,10 @@
 	switch (property)
 	{
 	case Property::Point1:
-		point_1 = value.value<Vertex>();
+		point_1 = value.value<Point3D>();
 		return SetPropertyResult::Success;
 	case Property::Point2:
-		point_2 = value.value<Vertex>();
+		point_2 = value.value<Point3D>();
 		return SetPropertyResult::Success;
 	default:
 		return BaseClass::setProperty(property, value);
--- a/src/linetypes/edge.h	Fri Dec 13 15:55:56 2019 +0200
+++ b/src/linetypes/edge.h	Fri Dec 13 21:35:59 2019 +0200
@@ -11,15 +11,15 @@
 public:
 	using BaseClass = ColoredObject;
 	Edge() = default;
-	Edge(const Vertex& point_1, const Vertex& point_2,
+	Edge(const Point3D& point_1, const Point3D& point_2,
 		 const Color colorIndex = colors::edge);
-	Edge(const QVector<Vertex>& vertices, const Color color);
+	Edge(const QVector<Point3D>& vertices, const Color color);
 	QVariant getProperty(Property property) const override;
 	SetPropertyResult setProperty(
 		Property property,
 		const QVariant& value) override;
 	QString textRepresentation() const override;
 private:
-	Vertex point_1 = {};
-	Vertex point_2 = {};
+	Point3D point_1 = {};
+	Point3D point_2 = {};
 };
--- a/src/linetypes/quadrilateral.cpp	Fri Dec 13 15:55:56 2019 +0200
+++ b/src/linetypes/quadrilateral.cpp	Fri Dec 13 21:35:59 2019 +0200
@@ -1,17 +1,17 @@
 #include "quadrilateral.h"
 
 linetypes::Quadrilateral::Quadrilateral(
-	const Vertex& point_1,
-	const Vertex& point_2,
-	const Vertex& point_3,
-	const Vertex& point_4,
+	const Point3D& point_1,
+	const Point3D& point_2,
+	const Point3D& point_3,
+	const Point3D& point_4,
 	Color color_index) :
 	ColoredObject{color_index},
 	points{point_1, point_2, point_3, point_4}
 {
 }
 
-linetypes::Quadrilateral::Quadrilateral(const QVector<Vertex>& vertices, const Color color) :
+linetypes::Quadrilateral::Quadrilateral(const QVector<Point3D>& vertices, const Color color) :
 	ColoredObject{color},
 	points{vertices[0], vertices[1], vertices[2], vertices[3]}
 {
@@ -42,16 +42,16 @@
 	switch (id)
 	{
 	case Property::Point1:
-		points[0] = value.value<Vertex>();
+		points[0] = value.value<Point3D>();
 		return SetPropertyResult::Success;
 	case Property::Point2:
-		points[1] = value.value<Vertex>();
+		points[1] = value.value<Point3D>();
 		return SetPropertyResult::Success;
 	case Property::Point3:
-		points[2] = value.value<Vertex>();
+		points[2] = value.value<Point3D>();
 		return SetPropertyResult::Success;
 	case Property::Point4:
-		points[3] = value.value<Vertex>();
+		points[3] = value.value<Point3D>();
 		return SetPropertyResult::Success;
 	default:
 		return ColoredObject::setProperty(id, value);
--- a/src/linetypes/quadrilateral.h	Fri Dec 13 15:55:56 2019 +0200
+++ b/src/linetypes/quadrilateral.h	Fri Dec 13 21:35:59 2019 +0200
@@ -11,15 +11,15 @@
 public:
 	Quadrilateral() = default;
 	Quadrilateral(
-	const Vertex &point_1,
-	const Vertex &point_2,
-	const Vertex &point_3,
-	const Vertex &point_4,
+	const Point3D &point_1,
+	const Point3D &point_2,
+	const Point3D &point_3,
+	const Point3D &point_4,
 	Color colorIndex = colors::main);
-	Quadrilateral(const QVector<Vertex>& vertices, const Color color);
+	Quadrilateral(const QVector<Point3D>& vertices, const Color color);
 	QVariant getProperty(Property id) const override;
 	SetPropertyResult setProperty(Property id, const QVariant& value) override;
 	QString textRepresentation() const override;
 private:
-	Vertex points[4] = {{}};
+	Point3D points[4] = {{}};
 };
--- a/src/linetypes/subfilereference.cpp	Fri Dec 13 15:55:56 2019 +0200
+++ b/src/linetypes/subfilereference.cpp	Fri Dec 13 21:35:59 2019 +0200
@@ -1,7 +1,7 @@
 #include "subfilereference.h"
 
 linetypes::SubfileReference::SubfileReference(
-	const Vertex& position,
+	const Point3D& position,
 	const Matrix3x3& transformation,
 	const QString& referenceName,
 	const Color color) :
@@ -35,7 +35,7 @@
 	switch (property)
 	{
 	case Property::Position:
-		this->position = value.value<Vertex>();
+		this->position = value.value<Point3D>();
 		return SetPropertyResult::Success;
 	case Property::Transformation:
 		this->transformation = value.value<Matrix3x3>();
--- a/src/linetypes/subfilereference.h	Fri Dec 13 15:55:56 2019 +0200
+++ b/src/linetypes/subfilereference.h	Fri Dec 13 21:35:59 2019 +0200
@@ -12,7 +12,7 @@
 public:
 	SubfileReference() = default;
 	SubfileReference(
-		const Vertex& position,
+		const Point3D& position,
 		const Matrix3x3& transformation,
 		const QString &referenceName,
 		const Color color = colors::main);
@@ -20,7 +20,7 @@
 	SetPropertyResult setProperty(Property property, const QVariant& value) override;
 	QString textRepresentation() const override;
 private:
-	Vertex position;
+	Point3D position;
 	Matrix3x3 transformation;
 	QString referenceName;
 };
--- a/src/linetypes/triangle.cpp	Fri Dec 13 15:55:56 2019 +0200
+++ b/src/linetypes/triangle.cpp	Fri Dec 13 21:35:59 2019 +0200
@@ -1,16 +1,16 @@
 #include "triangle.h"
 
 linetypes::Triangle::Triangle(
-	const Vertex& point_1,
-	const Vertex& point_2,
-	const Vertex& point_3,
+	const Point3D& point_1,
+	const Point3D& point_2,
+	const Point3D& point_3,
 	Color color_index) :
 	ColoredObject{color_index},
 	points{point_1, point_2, point_3}
 {
 }
 
-linetypes::Triangle::Triangle(const QVector<Vertex>& vertices, const Color color) :
+linetypes::Triangle::Triangle(const QVector<Point3D>& vertices, const Color color) :
 	ColoredObject{color},
 	points{vertices[0], vertices[1], vertices[2]}
 {
@@ -37,13 +37,13 @@
 	switch (id)
 	{
 	case Property::Point1:
-		points[0] = value.value<Vertex>();
+		points[0] = value.value<Point3D>();
 		return SetPropertyResult::Success;
 	case Property::Point2:
-		points[1] = value.value<Vertex>();
+		points[1] = value.value<Point3D>();
 		return SetPropertyResult::Success;
 	case Property::Point3:
-		points[2] = value.value<Vertex>();
+		points[2] = value.value<Point3D>();
 		return SetPropertyResult::Success;
 	default:
 		return ColoredObject::setProperty(id, value);
--- a/src/linetypes/triangle.h	Fri Dec 13 15:55:56 2019 +0200
+++ b/src/linetypes/triangle.h	Fri Dec 13 21:35:59 2019 +0200
@@ -10,15 +10,15 @@
 public:
 	Triangle() = default;
 	Triangle(
-		const Vertex &point_1,
-		const Vertex &point_2,
-		const Vertex &point_3,
+		const Point3D &point_1,
+		const Point3D &point_2,
+		const Point3D &point_3,
 		Color colorIndex = colors::main);
-	Triangle(const QVector<Vertex>& vertices, const Color color);
+	Triangle(const QVector<Point3D>& vertices, const Color color);
 	QVariant getProperty(Property id) const override;
 	SetPropertyResult setProperty(Property id, const QVariant& value) override;
 	QString textRepresentation() const override;
 private:
-	Vertex points[3] = {{}};
+	Point3D points[3] = {{}};
 };
 
--- a/src/main.h	Fri Dec 13 15:55:56 2019 +0200
+++ b/src/main.h	Fri Dec 13 21:35:59 2019 +0200
@@ -5,6 +5,7 @@
 #include <memory>
 #include "basics.h"
 #include "utility.h"
+#include "main.h"
 
 namespace settingGroups
 {
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/math.h	Fri Dec 13 21:35:59 2019 +0200
@@ -0,0 +1,42 @@
+#pragma once
+#include <cmath>
+
+namespace math
+{
+	using std::abs;
+	using std::sqrt;
+	using std::sin;
+	using std::cos;
+	using std::tan;
+	using std::atan;
+	using std::atan2;
+	using std::acos;
+	using std::asin;
+	using std::exp;
+	using std::log;
+	using std::log10;
+	using std::hypot;
+	using std::min;
+	using std::max;
+	using std::floor;
+	using std::ceil;
+	using std::trunc;
+	using std::round;
+	template<typename T, typename... Rest>
+	auto hypot(T&& x, Rest&&... rest)
+	{
+		return math::hypot(x, math::hypot(rest...));
+	}
+	template<typename T, typename... Rest>
+	auto max(T&& x, Rest&&... rest)
+	{
+		return math::max(x, math::max(rest...));
+	}
+	template<typename T, typename... Rest>
+	auto min(T&& x, Rest&&... rest)
+	{
+		return math::min(x, math::min(rest...));
+	}
+	constexpr double infinity = std::numeric_limits<double>::infinity();
+	constexpr double pi = M_PIl;
+}
--- a/src/parser.cpp	Fri Dec 13 15:55:56 2019 +0200
+++ b/src/parser.cpp	Fri Dec 13 21:35:59 2019 +0200
@@ -279,7 +279,7 @@
 	}
 }
 
-static Vertex vertexFromStrings(
+static Point3D vertexFromStrings(
 	const QStringList& tokens,
 	const int startingPosition)
 {
@@ -347,7 +347,7 @@
 		throw BodyParseError{"wrong amount of tokens in a type-1 line"};
 	}
 	const Color color = colorFromString(tokens[colorPosition]);
-	const Vertex position = vertexFromStrings(tokens, positionPosition);
+	const Point3D position = vertexFromStrings(tokens, positionPosition);
 	const Matrix3x3 transform = matrixFromStrings(tokens, transformPosition);
 	const QString& name = tokens[namePosition];
 	return std::make_unique<linetypes::SubfileReference>(position, transform, name, color);
@@ -366,7 +366,7 @@
 		throw BodyParseError{"wrong amount of tokens"};
 	}
 	const Color color = colorFromString(tokens[colorPosition]);
-	QVector<Vertex> vertices;
+	QVector<Point3D> vertices;
 	vertices.reserve(NumVertices);
 	for (int i = 0; i < NumVertices; i += 1)
 	{
--- 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);
 }
--- a/src/vertex.h	Fri Dec 13 15:55:56 2019 +0200
+++ b/src/vertex.h	Fri Dec 13 21:35:59 2019 +0200
@@ -21,41 +21,42 @@
 #include <QVector3D>
 #include "basics.h"
 
-struct Vertex
+struct Point3D
 {
-	using ValueType = double;
-	ValueType x;
-	ValueType y;
-	ValueType z;
-	// void transform(const class Matrix& matrix, const Vertex& pos);
-	Vertex transformed(const GLRotationMatrix& matrix) const;
-	void setCoordinate(Axis ax, ValueType 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*=(ValueType scalar);
-	Vertex operator*(ValueType scalar) const;
-	bool operator<(const Vertex& other) const;
-	ValueType& operator[](Axis ax);
-	ValueType operator[](Axis ax) const;
-	bool operator==(const Vertex& other) const;
-	bool operator!=(const Vertex& other) const;
-	operator QVariant() const;
+	double x, y, z;
+	using CoordinateType = decltype(x);
+	void assign(Axis axis, CoordinateType value);
+	CoordinateType& get(Axis ax);
+	CoordinateType get(Axis ax) const;
 };
 
-inline Vertex operator*(qreal scalar, const Vertex& vertex)
+namespace math
+{
+	Point3D transform(const Point3D point, const GLRotationMatrix& matrix);
+	qreal distance(const Point3D& one, const Point3D& other);
+}
+
+Point3D& operator+=(Point3D &point, const QVector3D& other);
+Point3D operator+(Point3D point, const QVector3D& other);
+QVector3D operator-(const Point3D& point, const Point3D& other);
+Point3D operator-(Point3D point, const QVector3D& vector);
+Point3D& operator-=(Point3D &point, const QVector3D& vector);
+Point3D& operator*=(Point3D &point, Point3D::CoordinateType scalar);
+Point3D operator*(const Point3D &point, Point3D::CoordinateType scalar);
+bool operator<(const Point3D &point, const Point3D& other);
+bool operator==(const Point3D &point, const Point3D& other);
+bool operator!=(const Point3D &point, const Point3D& other);
+
+inline Point3D operator*(qreal scalar, const Point3D& vertex)
 {
 	return vertex * scalar;
 }
 
-Q_DECLARE_METATYPE(Vertex)
-qreal distance(const Vertex& one, const Vertex& other);
-Vertex vertexFromVector(const QVector3D& vector);
-QVector3D vertexToVector(const Vertex &vertex);
-QString vertexToStringParens(const Vertex& vertex);
-unsigned int qHash(const Vertex& key);
-Vertex operator-(const Vertex& vertex);
-QDataStream& operator<<(QDataStream& out, const Vertex& vertex);
-QDataStream& operator>>(QDataStream& in, Vertex& vertex);
+Q_DECLARE_METATYPE(Point3D)
+Point3D vertexFromVector(const QVector3D& vector);
+QVector3D vertexToVector(const Point3D &vertex);
+QString vertexToStringParens(const Point3D& vertex);
+unsigned int qHash(const Point3D& key);
+Point3D operator-(const Point3D& vertex);
+QDataStream& operator<<(QDataStream& out, const Point3D& vertex);
+QDataStream& operator>>(QDataStream& in, Point3D& vertex);

mercurial