src/basics.cpp

changeset 1315
23d48a709ffc
parent 1314
d94cf95608ac
child 1318
568fcfc6da71
--- 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)

mercurial