refactor

Sat, 15 Sep 2018 15:57:56 +0300

author
Teemu Piippo <teemu@hecknology.net>
date
Sat, 15 Sep 2018 15:57:56 +0300
changeset 1430
6ce6d3da584f
parent 1429
80e8aaabeeed
child 1431
2e0e2c696605

refactor

CMakeLists.txt file | annotate | diff | comparison | revisions
src/basics.h file | annotate | diff | comparison | revisions
src/editmodes/circleMode.cpp file | annotate | diff | comparison | revisions
src/generics/functions.h file | annotate | diff | comparison | revisions
--- a/CMakeLists.txt	Tue Aug 07 20:34:32 2018 +0300
+++ b/CMakeLists.txt	Sat Sep 15 15:57:56 2018 +0300
@@ -248,7 +248,7 @@
 		set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DDEBUG")
 	endif()
 	set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror=all -Wextra")
-	set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-implicit-fallthrough")
+	set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-implicit-fallthrough -Wno-noexcept-type")
 endif()
 
 qt5_add_resources (LDFORGE_QRC ${LDFORGE_RESOURCES})
--- a/src/basics.h	Tue Aug 07 20:34:32 2018 +0300
+++ b/src/basics.h	Sat Sep 15 15:57:56 2018 +0300
@@ -74,7 +74,7 @@
  * Special operator definition that implements the XOR operator for windings.
  * However, if either winding is NoWinding, then this function returns NoWinding.
  */
-inline Winding operator^(Winding one, Winding other)
+Winding constexpr operator^(Winding one, Winding other)
 {
 	if (one == NoWinding or other == NoWinding)
 		return NoWinding;
@@ -88,13 +88,13 @@
 	return one;
 }
 
-static const double pi = 3.14159265358979323846;
-static const double inf = std::numeric_limits<double>::infinity();
+constexpr double pi = 3.14159265358979323846;
+constexpr double inf = std::numeric_limits<double>::infinity();
 
 /*
  * Returns the norm of a vector.
  */
-static inline qreal abs(const QVector3D &vector)
+inline qreal abs(const QVector3D &vector)
 {
 	return vector.length();
 }
@@ -105,6 +105,13 @@
 	return qHash(pointer.get());
 }
 
+inline void offset(QMatrix4x4& matrix, const QVector3D& vector)
+{
+	matrix(0, 3) += vector.x();
+	matrix(1, 3) += vector.y();
+	matrix(2, 3) += vector.z();
+}
+
 qreal determinant(qreal a, qreal b, qreal c, qreal d);
 qreal determinant(qreal a, qreal b, qreal c, qreal d, qreal e, qreal f, qreal g, qreal h, qreal i);
 qreal determinant(const QMatrix2x2& matrix);
--- a/src/editmodes/circleMode.cpp	Tue Aug 07 20:34:32 2018 +0300
+++ b/src/editmodes/circleMode.cpp	Sat Sep 15 15:57:56 2018 +0300
@@ -103,7 +103,7 @@
 		// transform = shearMatrixForPlane(renderer());
 		QMatrix4x4 transform = renderer()->currentCamera().transformationMatrix(1);
 		transform.scale(dist0);
-		transform.translate(translation);
+		offset(transform, translation);
 		model.emplace<LDCircularPrimitive>(PrimitiveModel::Circle, section.segments, section.divisions, transform);
 		finishDraw(model);
 		return;
@@ -114,7 +114,7 @@
 		//transform = shearMatrixForPlane(renderer());
 		QMatrix4x4 transform = renderer()->currentCamera().transformationMatrix(1);
 		transform.scale(max(dist0, dist1));
-		transform.translate(translation);
+		offset(transform, translation);
 		model.emplace<LDCircularPrimitive>(PrimitiveModel::Disc, section.segments, section.divisions, transform);
 		finishDraw(model);
 		return;
@@ -133,7 +133,7 @@
 			primitiveModel.ringNumber = component.num;
 			LDDocument* primitiveFile = primitives()->getPrimitive(primitiveModel);
 			QMatrix4x4 matrix = renderer()->currentCamera().transformationMatrix(component.scale);
-			matrix.translate(translation);
+			offset(matrix, translation);
 			// matrix = shearMatrixForPlane(renderer()) * matrix;
 			model.emplace<LDSubfileReference>(primitiveFile->name(), matrix);
 		}
--- a/src/generics/functions.h	Tue Aug 07 20:34:32 2018 +0300
+++ b/src/generics/functions.h	Sat Sep 15 15:57:56 2018 +0300
@@ -37,13 +37,7 @@
 }
 
 template<typename T>
-T squared(T value)
-{
-	return ::pow(value, 2);
-}
-
-template<>
-constexpr int squared<int>(int value)
+auto constexpr squared(T value)
 {
 	return value * value;
 }
@@ -70,13 +64,13 @@
 template<typename T>
 constexpr int rotl10(T x)
 {
-	return (((x) << 10) | (((x) >> 22) & 0x000000ff));
+	return (x << 10) | ((x >> 22) & 0x000000ff);
 }
 
 template<typename T>
 constexpr int rotl20(T x)
 {
-	return (((x) << 20) | (((x) >> 12) & 0x000000ff));
+	return (x << 20) | ((x >> 12) & 0x000000ff);
 }
 
 //

mercurial