src/basics.cpp

changeset 1217
314e12e23c3a
parent 1011
4fdd74a04790
child 1218
e0b59d183f96
--- a/src/basics.cpp	Thu Jan 04 19:40:52 2018 +0200
+++ b/src/basics.cpp	Thu Jan 04 19:44:26 2018 +0200
@@ -30,42 +30,42 @@
 Vertex::Vertex() :
 	QVector3D() {}
 
-Vertex::Vertex (const QVector3D& a) :
-	QVector3D (a) {}
+Vertex::Vertex(const QVector3D& a) :
+	QVector3D(a) {}
 
-Vertex::Vertex (qreal xpos, qreal ypos, qreal zpos) :
+Vertex::Vertex(qreal xpos, qreal ypos, qreal zpos) :
 	QVector3D(xpos, ypos, zpos) {}
 
 
-void Vertex::transform (const Matrix& matr, const Vertex& pos)
+void Vertex::transform(const Matrix& matr, const Vertex& pos)
 {
-	double x2 = (matr[0] * x()) + (matr[1] * y()) + (matr[2] * z()) + pos.x();
-	double y2 = (matr[3] * x()) + (matr[4] * y()) + (matr[5] * z()) + pos.y();
-	double z2 = (matr[6] * x()) + (matr[7] * y()) + (matr[8] * z()) + pos.z();
-	setX (x2);
-	setY (y2);
-	setZ (z2);
+	double x2 = (matr[0] * x()) +(matr[1] * y()) +(matr[2] * z()) + pos.x();
+	double y2 = (matr[3] * x()) +(matr[4] * y()) +(matr[5] * z()) + pos.y();
+	double z2 = (matr[6] * x()) +(matr[7] * y()) +(matr[8] * z()) + pos.z();
+	setX(x2);
+	setY(y2);
+	setZ(z2);
 }
 
-void Vertex::apply (ApplyFunction func)
+void Vertex::apply(ApplyFunction func)
 {
 	double newX = x(), newY = y(), newZ = z();
-	func (X, newX);
-	func (Y, newY);
-	func (Z, newZ);
-	*this = Vertex (newX, newY, newZ);
+	func(X, newX);
+	func(Y, newY);
+	func(Z, newZ);
+	*this = Vertex(newX, newY, newZ);
 }
 
-void Vertex::apply (ApplyConstFunction func) const
+void Vertex::apply(ApplyConstFunction func) const
 {
-	func (X, x());
-	func (Y, y());
-	func (Z, z());
+	func(X, x());
+	func(Y, y());
+	func(Z, z());
 }
 
-double Vertex::operator[] (Axis ax) const
+double Vertex::operator[](Axis ax) const
 {
-	switch (ax)
+	switch(ax)
 	{
 		case X: return x();
 		case Y: return y();
@@ -75,53 +75,53 @@
 	return 0.0;
 }
 
-void Vertex::setCoordinate (Axis ax, qreal value)
+void Vertex::setCoordinate(Axis ax, qreal value)
 {
-	switch (ax)
+	switch(ax)
 	{
-		case X: setX (value); break;
-		case Y: setY (value); break;
-		case Z: setZ (value); break;
+		case X: setX(value); break;
+		case Y: setY(value); break;
+		case Z: setZ(value); break;
 	}
 }
 
-QString Vertex::toString (bool mangled) const
+QString Vertex::toString(bool mangled) const
 {
 	if (mangled)
-		return format ("(%1, %2, %3)", x(), y(), z());
+		return format("(%1, %2, %3)", x(), y(), z());
 
-	return format ("%1 %2 %3", x(), y(), z());
+	return format("%1 %2 %3", x(), y(), z());
 }
 
-Vertex Vertex::operator* (qreal scalar) const
+Vertex Vertex::operator*(qreal scalar) const
 {
-	return Vertex (x() * scalar, y() * scalar, z() * scalar);
+	return Vertex(x() * scalar, y() * scalar, z() * scalar);
 }
 
 Vertex& Vertex::operator+= (const Vertex& other)
 {
-	setX (x() + other.x());
-	setY (y() + other.y());
-	setZ (z() + other.z());
+	setX(x() + other.x());
+	setY(y() + other.y());
+	setZ(z() + other.z());
 	return *this;
 }
 
-Vertex Vertex::operator+ (const Vertex& other) const
+Vertex Vertex::operator+(const Vertex& other) const
 {
-	Vertex result (*this);
+	Vertex result(*this);
 	result += other;
 	return result;
 }
 
 Vertex& Vertex::operator*= (qreal scalar)
 {
-	setX (x() * scalar);
-	setY (y() * scalar);
-	setZ (z() * scalar);
+	setX(x() * scalar);
+	setY(y() * scalar);
+	setZ(z() * scalar);
 	return *this;
 }
 
-bool Vertex::operator< (const Vertex& other) const
+bool Vertex::operator<(const Vertex& other) const
 {
 	if (x() != other.x()) return x() < other.x();
 	if (y() != other.y()) return y() < other.y();
@@ -131,7 +131,7 @@
 
 // =============================================================================
 //
-Matrix::Matrix (double vals[])
+Matrix::Matrix(double vals[])
 {
 	for (int i = 0; i < 9; ++i)
 		m_vals[i] = vals[i];
@@ -139,7 +139,7 @@
 
 // =============================================================================
 //
-Matrix::Matrix (double fillval)
+Matrix::Matrix(double fillval)
 {
 	for (int i = 0; i < 9; ++i)
 		m_vals[i] = fillval;
@@ -147,10 +147,10 @@
 
 // =============================================================================
 //
-Matrix::Matrix (const std::initializer_list<double>& vals)
+Matrix::Matrix(const std::initializer_list<double>& vals)
 {
 	if (vals.size() == 9)
-		memcpy (&m_vals[0], vals.begin(), sizeof m_vals);
+		memcpy(&m_vals[0], vals.begin(), sizeof m_vals);
 }
 
 // =============================================================================
@@ -160,9 +160,9 @@
 	for (int i = 0; i < 3; ++i)
 	{
 		for (int j = 0; j < 3; ++j)
-			print ("%1\t", m_vals[i * 3 + j]);
+			print("%1\t", m_vals[i * 3 + j]);
 
-		print ("\n");
+		print("\n");
 	}
 }
 
@@ -177,7 +177,7 @@
 		if (i > 0)
 			val += ' ';
 
-		val += QString::number (m_vals[i]);
+		val += QString::number(m_vals[i]);
 	}
 
 	return val;
@@ -187,12 +187,12 @@
 //
 void Matrix::zero()
 {
-	memset (&m_vals[0], 0, sizeof m_vals);
+	memset(&m_vals[0], 0, sizeof m_vals);
 }
 
 // =============================================================================
 //
-Matrix Matrix::mult (const Matrix& other) const
+Matrix Matrix::mult(const Matrix& other) const
 {
 	Matrix val;
 	val.zero();
@@ -209,7 +209,7 @@
 //
 Matrix& Matrix::operator= (const Matrix& other)
 {
-	memcpy (&m_vals[0], &other.m_vals[0], sizeof m_vals);
+	memcpy(&m_vals[0], &other.m_vals[0], sizeof m_vals);
 	return *this;
 }
 
@@ -217,12 +217,12 @@
 //
 double Matrix::getDeterminant() const
 {
-	return (value (0) * value (4) * value (8)) +
-		   (value (1) * value (5) * value (6)) +
-		   (value (2) * value (3) * value (7)) -
-		   (value (2) * value (4) * value (6)) -
-		   (value (1) * value (3) * value (8)) -
-		   (value (0) * value (5) * value (7));
+	return (value(0) * value(4) * value(8)) +
+		  (value(1) * value(5) * value(6)) +
+		  (value(2) * value(3) * value(7)) -
+		  (value(2) * value(4) * value(6)) -
+		  (value(1) * value(3) * value(8)) -
+		  (value(0) * value(5) * value(7));
 }
 
 // =============================================================================
@@ -231,7 +231,7 @@
 {
 	for (int i = 0; i < 9; ++i)
 	{
-		if (value (i) != other[i])
+		if (value(i) != other[i])
 			return false;
 	}
 
@@ -247,22 +247,22 @@
 
 // =============================================================================
 //
-void LDBoundingBox::calcObject (LDObject* obj)
+void LDBoundingBox::calcObject(LDObject* obj)
 {
-	switch (obj->type())
+	switch(obj->type())
 	{
 	case OBJ_Line:
 	case OBJ_Triangle:
 	case OBJ_Quad:
 	case OBJ_CondLine:
 		for (int i = 0; i < obj->numVertices(); ++i)
-			calcVertex (obj->vertex (i));
+			calcVertex(obj->vertex(i));
 		break;
 
 	case OBJ_SubfileReference:
-		for (LDObject* it : static_cast<LDSubfileReference*> (obj)->inlineContents (true, false))
+		for (LDObject* it : static_cast<LDSubfileReference*>(obj)->inlineContents(true, false))
 		{
-			calcObject (it);
+			calcObject(it);
 			it->destroy();
 		}
 		break;
@@ -274,30 +274,30 @@
 
 // =============================================================================
 //
-LDBoundingBox& LDBoundingBox::operator<< (const Vertex& v)
+LDBoundingBox& LDBoundingBox::operator<<(const Vertex& v)
 {
-	calcVertex (v);
+	calcVertex(v);
 	return *this;
 }
 
 // =============================================================================
 //
-LDBoundingBox& LDBoundingBox::operator<< (LDObject* obj)
+LDBoundingBox& LDBoundingBox::operator<<(LDObject* obj)
 {
-	calcObject (obj);
+	calcObject(obj);
 	return *this;
 }
 
 // =============================================================================
 //
-void LDBoundingBox::calcVertex (const Vertex& vertex)
+void LDBoundingBox::calcVertex(const Vertex& vertex)
 {
-	m_vertex0.setX (qMin (vertex.x(), m_vertex0.x()));
-	m_vertex0.setY (qMin (vertex.y(), m_vertex0.y()));
-	m_vertex0.setZ (qMin (vertex.z(), m_vertex0.z()));
-	m_vertex1.setX (qMax (vertex.x(), m_vertex1.x()));
-	m_vertex1.setY (qMax (vertex.y(), m_vertex1.y()));
-	m_vertex1.setZ (qMax (vertex.z(), m_vertex1.z()));
+	m_vertex0.setX(qMin(vertex.x(), m_vertex0.x()));
+	m_vertex0.setY(qMin(vertex.y(), m_vertex0.y()));
+	m_vertex0.setZ(qMin(vertex.z(), m_vertex0.z()));
+	m_vertex1.setX(qMax(vertex.x(), m_vertex1.x()));
+	m_vertex1.setY(qMax(vertex.y(), m_vertex1.y()));
+	m_vertex1.setZ(qMax(vertex.z(), m_vertex1.z()));
 	m_isEmpty = false;
 }
 
@@ -307,8 +307,8 @@
 //
 void LDBoundingBox::reset()
 {
-	m_vertex0 = Vertex (10000.0, 10000.0, 10000.0);
-	m_vertex1 = Vertex (-10000.0, -10000.0, -10000.0);
+	m_vertex0 = Vertex(10000.0, 10000.0, 10000.0);
+	m_vertex1 = Vertex(-10000.0, -10000.0, -10000.0);
 	m_isEmpty = true;
 }
 
@@ -331,8 +331,8 @@
 	else if (yscale > zscale)
 		size = yscale;
 
-	if (qAbs (size) >= 2.0)
-		return qAbs (size / 2);
+	if (qAbs(size) >= 2.0)
+		return qAbs(size / 2);
 
 	return 1.0;
 }
@@ -343,7 +343,7 @@
 //
 Vertex LDBoundingBox::center() const
 {
-	return Vertex (
+	return Vertex(
 		(m_vertex0.x() + m_vertex1.x()) / 2,
 		(m_vertex0.y() + m_vertex1.y()) / 2,
 		(m_vertex0.z() + m_vertex1.z()) / 2);

mercurial