Cleanup miscallenous.cpp/.h

Thu, 19 Nov 2015 00:43:18 +0200

author
Teemu Piippo <crimsondusk64@gmail.com>
date
Thu, 19 Nov 2015 00:43:18 +0200
changeset 1013
fa025ba493d8
parent 1012
413ecd6b9801
child 1014
f0a8ecb6a357

Cleanup miscallenous.cpp/.h

src/basics.cpp file | annotate | diff | comparison | revisions
src/basics.h file | annotate | diff | comparison | revisions
src/editmodes/abstractEditMode.cpp file | annotate | diff | comparison | revisions
src/editmodes/circleMode.cpp file | annotate | diff | comparison | revisions
src/glRenderer.cpp file | annotate | diff | comparison | revisions
src/glRenderer.h file | annotate | diff | comparison | revisions
src/ldObjectMath.cpp file | annotate | diff | comparison | revisions
src/macros.h file | annotate | diff | comparison | revisions
src/mainwindow.cpp file | annotate | diff | comparison | revisions
src/miscallenous.cpp file | annotate | diff | comparison | revisions
src/miscallenous.h file | annotate | diff | comparison | revisions
src/primitives.cpp file | annotate | diff | comparison | revisions
src/toolsets/algorithmtoolset.cpp file | annotate | diff | comparison | revisions
src/toolsets/extprogramtoolset.cpp file | annotate | diff | comparison | revisions
src/toolsets/movetoolset.cpp file | annotate | diff | comparison | revisions
--- a/src/basics.cpp	Wed Nov 18 19:05:22 2015 +0200
+++ b/src/basics.cpp	Thu Nov 19 00:43:18 2015 +0200
@@ -240,14 +240,14 @@
 
 // =============================================================================
 //
-LDBoundingBox::LDBoundingBox()
+BoundingBox::BoundingBox()
 {
 	reset();
 }
 
 // =============================================================================
 //
-void LDBoundingBox::calcObject (LDObject* obj)
+void BoundingBox::calcObject (LDObject* obj)
 {
 	switch (obj->type())
 	{
@@ -274,7 +274,7 @@
 
 // =============================================================================
 //
-LDBoundingBox& LDBoundingBox::operator<< (const Vertex& v)
+BoundingBox& BoundingBox::operator<< (const Vertex& v)
 {
 	calcVertex (v);
 	return *this;
@@ -282,7 +282,7 @@
 
 // =============================================================================
 //
-LDBoundingBox& LDBoundingBox::operator<< (LDObject* obj)
+BoundingBox& BoundingBox::operator<< (LDObject* obj)
 {
 	calcObject (obj);
 	return *this;
@@ -290,7 +290,7 @@
 
 // =============================================================================
 //
-void LDBoundingBox::calcVertex (const Vertex& vertex)
+void BoundingBox::calcVertex (const Vertex& vertex)
 {
 	m_vertex0.setX (qMin (vertex.x(), m_vertex0.x()));
 	m_vertex0.setY (qMin (vertex.y(), m_vertex0.y()));
@@ -305,7 +305,7 @@
 //
 // Clears the bounding box
 //
-void LDBoundingBox::reset()
+void BoundingBox::reset()
 {
 	m_vertex0 = Vertex (10000.0, 10000.0, 10000.0);
 	m_vertex1 = Vertex (-10000.0, -10000.0, -10000.0);
@@ -316,7 +316,7 @@
 //
 // Returns the length of the bounding box on the longest measure.
 //
-double LDBoundingBox::longestMeasurement() const
+double BoundingBox::longestMeasurement() const
 {
 	double xscale = (m_vertex0.x() - m_vertex1.x());
 	double yscale = (m_vertex0.y() - m_vertex1.y());
@@ -341,7 +341,7 @@
 //
 // Yields the center of the bounding box.
 //
-Vertex LDBoundingBox::center() const
+Vertex BoundingBox::center() const
 {
 	return Vertex (
 		(m_vertex0.x() + m_vertex1.x()) / 2,
@@ -349,17 +349,17 @@
 		(m_vertex0.z() + m_vertex1.z()) / 2);
 }
 
-bool LDBoundingBox::isEmpty() const
+bool BoundingBox::isEmpty() const
 {
 	return m_isEmpty;
 }
 
-const Vertex& LDBoundingBox::vertex0() const
+const Vertex& BoundingBox::vertex0() const
 {
 	return m_vertex0;
 }
 
-const Vertex& LDBoundingBox::vertex1() const
+const Vertex& BoundingBox::vertex1() const
 {
 	return m_vertex1;
 }
\ No newline at end of file
--- a/src/basics.h	Wed Nov 18 19:05:22 2015 +0200
+++ b/src/basics.h	Thu Nov 19 00:43:18 2015 +0200
@@ -161,10 +161,10 @@
 // Defines a bounding box that encompasses a given set of objects.
 // vertex0 is the minimum vertex, vertex1 is the maximum vertex.
 //
-class LDBoundingBox
+class BoundingBox
 {
 public:
-	LDBoundingBox();
+	BoundingBox();
 
 	void calcObject (LDObject* obj);
 	void calcVertex (const Vertex& vertex);
@@ -175,8 +175,8 @@
 	const Vertex& vertex0() const;
 	const Vertex& vertex1() const;
 
-	LDBoundingBox& operator<< (LDObject* obj);
-	LDBoundingBox& operator<< (const Vertex& v);
+	BoundingBox& operator<< (LDObject* obj);
+	BoundingBox& operator<< (const Vertex& v);
 
 private:
 	bool m_isEmpty;
--- a/src/editmodes/abstractEditMode.cpp	Wed Nov 18 19:05:22 2015 +0200
+++ b/src/editmodes/abstractEditMode.cpp	Thu Nov 19 00:43:18 2015 +0200
@@ -291,8 +291,8 @@
 		renderer()->getRelativeAxes (relX, relY);
 		QLineF ln (v0[relX], v0[relY], v1[relX], v1[relY]);
 		ln.setAngle (intervalClamp<int> (ln.angle(), 45));
-		result.setCoordinate (relX, Grid::Snap (ln.x2(), Grid::Coordinate));
-		result.setCoordinate (relY, Grid::Snap (ln.y2(), Grid::Coordinate));
+		result.setCoordinate (relX, snapToGrid (ln.x2(), Grid::Coordinate));
+		result.setCoordinate (relY, snapToGrid (ln.y2(), Grid::Coordinate));
 	}
 
 	return result;
--- a/src/editmodes/circleMode.cpp	Wed Nov 18 19:05:22 2015 +0200
+++ b/src/editmodes/circleMode.cpp	Thu Nov 19 00:43:18 2015 +0200
@@ -45,7 +45,7 @@
 		renderer()->getRelativeAxes (localx, localy);
 		double dx = m_drawedVerts[0][localx] - v1[localx];
 		double dy = m_drawedVerts[0][localy] - v1[localy];
-		return Grid::Snap (sqrt ((dx * dx) + (dy * dy)), Grid::Coordinate);
+		return snapToGrid (sqrt ((dx * dx) + (dy * dy)), Grid::Coordinate);
 	}
 
 	return 0.0;
--- a/src/glRenderer.cpp	Wed Nov 18 19:05:22 2015 +0200
+++ b/src/glRenderer.cpp	Thu Nov 19 00:43:18 2015 +0200
@@ -541,10 +541,10 @@
 
 	Vertex pos3d;
 	const LDFixedCamera* cam = &g_FixedCameras[camera()];
-	const Axis axisX = cam->localX;
-	const Axis axisY = cam->localY;
-	const int negXFac = cam->negatedX ? -1 : 1,
-				negYFac = cam->negatedY ? -1 : 1;
+	Axis axisX = cam->localX;
+	Axis axisY = cam->localY;
+	int signX = cam->negatedX ? -1 : 1;
+	int signY = cam->negatedY ? -1 : 1;
 
 	// Calculate cx and cy - these are the LDraw unit coords the cursor is at.
 	double cx = (-m_virtualWidth + ((2 * pos2d.x() * m_virtualWidth) / m_width) - panning (X));
@@ -552,15 +552,15 @@
 
 	if (snap)
 	{
-		cx = Grid::Snap (cx, Grid::Coordinate);
-		cy = Grid::Snap (cy, Grid::Coordinate);
+		cx = snapToGrid (cx, Grid::Coordinate);
+		cy = snapToGrid (cy, Grid::Coordinate);
 	}
 
-	cx *= negXFac;
-	cy *= negYFac;
+	cx *= signX;
+	cy *= signY;
 
-	RoundToDecimals (cx, 4);
-	RoundToDecimals (cy, 4);
+	roundToDecimals (cx, 4);
+	roundToDecimals (cy, 4);
 
 	// Create the vertex from the coordinates
 	pos3d.setCoordinate (axisX, cx);
@@ -616,15 +616,16 @@
 //
 void GLRenderer::paintEvent (QPaintEvent*)
 {
-	doMakeCurrent();
+	makeCurrent();
 	m_virtualWidth = zoom();
 	m_virtualHeight = (m_height * m_virtualWidth) / m_width;
 	initGLData();
 	drawGLScene();
 
-	QPainter paint (this);
+	QPainter painter (this);
 	QFontMetrics metrics = QFontMetrics (QFont());
-	paint.setRenderHint (QPainter::HighQualityAntialiasing);
+	painter.setRenderHint (QPainter::Antialiasing);
+	painter.setRenderHint (QPainter::HighQualityAntialiasing);
 
 	// If we wish to only draw the brick, stop here
 	if (isDrawOnly())
@@ -636,8 +637,8 @@
 		QString text = format ("Rotation: (%1°, %2°, %3°)\nPanning: (%4, %5), Zoom: %6",
 			rotation(X), rotation(Y), rotation(Z), panning(X), panning(Y), zoom());
 		QRect textSize = metrics.boundingRect (0, 0, m_width, m_height, Qt::AlignCenter, text);
-		paint.setPen (textPen());
-		paint.drawText ((width() - textSize.width()) / 2, height() - textSize.height(), textSize.width(),
+		painter.setPen (textPen());
+		painter.drawText ((width() - textSize.width()) / 2, height() - textSize.height(), textSize.width(),
 			textSize.height(), Qt::AlignCenter, text);
 	}
 #endif
@@ -653,27 +654,27 @@
 			QPoint v1 = convert3dTo2d (currentDocumentData().overlays[camera()].v1);
 			QRect targetRect (v0.x(), v0.y(), qAbs (v1.x() - v0.x()), qAbs (v1.y() - v0.y()));
 			QRect sourceRect (0, 0, overlay.img->width(), overlay.img->height());
-			paint.drawImage (targetRect, *overlay.img, sourceRect);
+			painter.drawImage (targetRect, *overlay.img, sourceRect);
 		}
 
 		// Paint the coordinates onto the screen.
 		QString text = format (tr ("X: %1, Y: %2, Z: %3"), m_position3D[X], m_position3D[Y], m_position3D[Z]);
 		QFontMetrics metrics = QFontMetrics (font());
 		QRect textSize = metrics.boundingRect (0, 0, m_width, m_height, Qt::AlignCenter, text);
-		paint.setPen (textPen());
-		paint.drawText (m_width - textSize.width(), m_height - 16, textSize.width(),
+		painter.setPen (textPen());
+		painter.drawText (m_width - textSize.width(), m_height - 16, textSize.width(),
 			textSize.height(), Qt::AlignCenter, text);
 	}
 
 	if (not isPicking())
 	{
 		// Draw edit mode HUD
-		m_currentEditMode->render (paint);
+		m_currentEditMode->render (painter);
 
 		// Draw a background for the selected camera
-		paint.setPen (m_thinBorderPen);
-		paint.setBrush (QBrush (QColor (0, 128, 160, 128)));
-		paint.drawRect (m_cameraIcons[camera()].selRect);
+		painter.setPen (m_thinBorderPen);
+		painter.setBrush (QBrush (QColor (0, 128, 160, 128)));
+		painter.drawRect (m_cameraIcons[camera()].selRect);
 
 		// Draw the camera icons
 		for (CameraIcon& info : m_cameraIcons)
@@ -682,14 +683,14 @@
 			if (&info == &m_cameraIcons[EFreeCamera] and not m_currentEditMode->allowFreeCamera())
 				continue;
 
-			paint.drawPixmap (info.targetRect, *info.image, info.sourceRect);
+			painter.drawPixmap (info.targetRect, *info.image, info.sourceRect);
 		}
 
 		// Draw a label for the current camera in the bottom left corner
 		{
 			const int margin = 4;
-			paint.setPen (textPen());
-			paint.drawText (QPoint (margin, height() - (margin + metrics.descent())), currentCameraName());
+			painter.setPen (textPen());
+			painter.drawText (QPoint (margin, height() - (margin + metrics.descent())), currentCameraName());
 		}
 
 		// Tool tips
@@ -712,8 +713,8 @@
 		for (const MessageManager::Line& line : messageLog()->getLines())
 		{
 			penColor.setAlphaF (line.alpha);
-			paint.setPen (penColor);
-			paint.drawText (QPoint (margin, y + margin + metrics.ascent()), line.text);
+			painter.setPen (penColor);
+			painter.drawText (QPoint (margin, y + margin + metrics.ascent()), line.text);
 			y += metrics.height();
 		}
 	}
@@ -879,8 +880,7 @@
 //
 void GLRenderer::wheelEvent (QWheelEvent* ev)
 {
-	doMakeCurrent();
-
+	makeCurrent();
 	zoomNotch (ev->delta() > 0);
 	zoom() = qBound (0.01, zoom(), 10000.0);
 	m_isCameraMoving = true;
@@ -929,7 +929,7 @@
 //
 void GLRenderer::pick (QRect const& range, bool additive)
 {
-	doMakeCurrent();
+	makeCurrent();
 
 	// Clear the selection if we do not wish to add to it.
 	if (not additive)
@@ -960,31 +960,26 @@
 	const qint32 numpixels = areawidth * areaheight;
 
 	// Allocate space for the pixel data.
-	uchar* const pixeldata = new uchar[4 * numpixels];
-	uchar* pixelptr = &pixeldata[0];
+	QVector<unsigned char> pixeldata (4 * numpixels);
+	unsigned char* pixelcursor = pixeldata.data();
 
 	// Read pixels from the color buffer.
-	glReadPixels (x0, m_height - y1, areawidth, areaheight, GL_RGBA, GL_UNSIGNED_BYTE, pixeldata);
+	glReadPixels (x0, m_height - y1, areawidth, areaheight, GL_RGBA, GL_UNSIGNED_BYTE, pixeldata.data());
 
 	LDObject* removedObj = nullptr;
-	QList<qint32> indices;
+	QSet<qint32> indices;
 
 	// Go through each pixel read and add them to the selection.
 	// Note: black is background, those indices are skipped.
 	for (qint32 i = 0; i < numpixels; ++i)
 	{
-		qint32 idx =
-			(*(pixelptr + 0) * 0x10000) +
-			(*(pixelptr + 1) * 0x100) +
-			*(pixelptr + 2);
-		pixelptr += 4;
+		qint32 idx = (pixelcursor[0] * 0x10000) + (pixelcursor[1] * 0x100) + pixelcursor[2];
+		pixelcursor += 4;
 
 		if (idx != 0)
 			indices << idx;
 	}
 
-	removeDuplicates (indices);
-
 	for (qint32 idx : indices)
 	{
 		LDObject* obj = LDObject::fromID (idx);
@@ -1007,8 +1002,6 @@
 		obj->select();
 	}
 
-	delete[] pixeldata;
-
 	// Update everything now.
 	m_window->updateSelection();
 
@@ -1024,12 +1017,12 @@
 }
 
 //
-// Simpler version of GLRenderer::pick which simply picks whatever object on the screen
+// Simpler version of GLRenderer::pick which simply picks whatever object on the cursor
 //
 LDObject* GLRenderer::pickOneObject (int mouseX, int mouseY)
 {
 	uchar pixel[4];
-	doMakeCurrent();
+	makeCurrent();
 	setPicking (true);
 	drawGLScene();
 	glReadPixels (mouseX, m_height - mouseY, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixel);
@@ -1629,9 +1622,9 @@
 	return m_mousePositionF;
 }
 
-void GLRenderer::doMakeCurrent()
+void GLRenderer::makeCurrent()
 {
-	makeCurrent();
+	QGLWidget::makeCurrent();
 	initializeOpenGLFunctions();
 }
 
--- a/src/glRenderer.h	Wed Nov 18 19:05:22 2015 +0200
+++ b/src/glRenderer.h	Thu Nov 19 00:43:18 2015 +0200
@@ -170,6 +170,7 @@
 	bool isPicking() const;
 	Qt::KeyboardModifiers keyboardModifiers() const;
 	QPen linePen() const;
+	void makeCurrent();
 	MessageManager* messageLog() const;
 	bool mouseHasMoved() const;
 	QPoint const& mousePosition() const;
@@ -251,7 +252,6 @@
 	void clampAngle (double& angle) const;
 	LDGLData& currentDocumentData() const;
 	void drawVbos (SurfaceVboType surface, ComplementVboType colors, GLenum type);
-	void doMakeCurrent();
 	LDOverlay* findOverlayObject (ECamera cam);
 	double& panning (Axis ax);
 	double panning (Axis ax) const;
--- a/src/ldObjectMath.cpp	Wed Nov 18 19:05:22 2015 +0200
+++ b/src/ldObjectMath.cpp	Thu Nov 19 00:43:18 2015 +0200
@@ -34,7 +34,7 @@
 void RotateObjects (const int l, const int m, const int n, double angle, LDObjectList const& objects)
 {
 	QList<Vertex*> queue;
-	const Vertex rotpoint = GetRotationPoint (objects);
+	const Vertex rotpoint = getRotationPoint (objects);
 	const double cosangle = cos (angle),
 				 sinangle = sin (angle);
 
--- a/src/macros.h	Wed Nov 18 19:05:22 2015 +0200
+++ b/src/macros.h	Thu Nov 19 00:43:18 2015 +0200
@@ -65,3 +65,27 @@
 		NAME = ENUM::NumValues)
 
 #define ConfigOption(...)
+
+// once-statement
+struct OnceGuard
+{
+	bool triggered;
+	OnceGuard() : triggered (false) {}
+
+	bool pass()
+	{
+		if (triggered)
+		{
+			return false;
+		}
+		else
+		{
+			triggered = true;
+			return true;
+		}
+	}
+};
+
+#define TEE_2(A,B) A ## B
+#define TEE(A,B) TEE_2(A,B)
+#define once static OnceGuard TEE(_once_, __LINE__); if (TEE(_once_, __LINE__).pass())
--- a/src/mainwindow.cpp	Wed Nov 18 19:05:22 2015 +0200
+++ b/src/mainwindow.cpp	Thu Nov 19 00:43:18 2015 +0200
@@ -860,7 +860,7 @@
 		if (doc == m_currentDocument)
 			updateTitle();
 
-		print ("Saved to %1 (%2)", path, MakePrettyFileSize (savesize));
+		print ("Saved to %1 (%2)", path, formatFileSize (savesize));
 
 		// Add it to recent files
 		m_documents->addRecentFile (path);
@@ -1177,7 +1177,7 @@
 {
 	int numerator (ui.ringToolSegments->value());
 	int denominator (ui.ringToolHiRes->isChecked() ? HighResolution : LowResolution);
-	Simplify (numerator, denominator);
+	simplify (numerator, denominator);
 	ui.ringToolSegmentsLabel->setText (format ("%1 / %2", numerator, denominator));
 }
 
--- a/src/miscallenous.cpp	Wed Nov 18 19:05:22 2015 +0200
+++ b/src/miscallenous.cpp	Thu Nov 19 00:43:18 2015 +0200
@@ -26,65 +26,6 @@
 #include "ldDocument.h"
 #include "ui_rotpoint.h"
 
-// Prime number table.
-static const int PrimeNumbers[] =
-{
-	2,    3,    5,    7,    11,   13,   17,   19,   23,   29,
-	31,   37,   41,   43,   47,   53,   59,   61,   67,   71,
-	73,   79,   83,   89,   97,   101,  103,  107,  109,  113,
-	127,  131,  137,  139,  149,  151,  157,  163,  167,  173,
-	179,  181,  191,  193,  197,  199,  211,  223,  227,  229,
-	233,  239,  241,  251,  257,  263,  269,  271,  277,  281,
-	283,  293,  307,  311,  313,  317,  331,  337,  347,  349,
-	353,  359,  367,  373,  379,  383,  389,  397,  401,  409,
-	419,  421,  431,  433,  439,  443,  449,  457,  461,  463,
-	467,  479,  487,  491,  499,  503,  509,  521,  523,  541,
-	547,  557,  563,  569,  571,  577,  587,  593,  599,  601,
-	607,  613,  617,  619,  631,  641,  643,  647,  653,  659,
-	661,  673,  677,  683,  691,  701,  709,  719,  727,  733,
-	739,  743,  751,  757,  761,  769,  773,  787,  797,  809,
-	811,  821,  823,  827,  829,  839,  853,  857,  859,  863,
-	877,  881,  883,  887,  907,  911,  919,  929,  937,  941,
-	947,  953,  967,  971,  977,  983,  991,  997, 1009, 1013,
-	1019, 1021, 1031, 1033, 1039, 1049, 1051, 1061, 1063, 1069,
-	1087, 1091, 1093, 1097, 1103, 1109, 1117, 1123, 1129, 1151,
-	1153, 1163, 1171, 1181, 1187, 1193, 1201, 1213, 1217, 1223,
-	1229, 1231, 1237, 1249, 1259, 1277, 1279, 1283, 1289, 1291,
-	1297, 1301, 1303, 1307, 1319, 1321, 1327, 1361, 1367, 1373,
-	1381, 1399, 1409, 1423, 1427, 1429, 1433, 1439, 1447, 1451,
-	1453, 1459, 1471, 1481, 1483, 1487, 1489, 1493, 1499, 1511,
-	1523, 1531, 1543, 1549, 1553, 1559, 1567, 1571, 1579, 1583,
-	1597, 1601, 1607, 1609, 1613, 1619, 1621, 1627, 1637, 1657,
-	1663, 1667, 1669, 1693, 1697, 1699, 1709, 1721, 1723, 1733,
-	1741, 1747, 1753, 1759, 1777, 1783, 1787, 1789, 1801, 1811,
-	1823, 1831, 1847, 1861, 1867, 1871, 1873, 1877, 1879, 1889,
-	1901, 1907, 1913, 1931, 1933, 1949, 1951, 1973, 1979, 1987,
-	1993, 1997, 1999, 2003, 2011, 2017, 2027, 2029, 2039, 2053,
-	2063, 2069, 2081, 2083, 2087, 2089, 2099, 2111, 2113, 2129,
-	2131, 2137, 2141, 2143, 2153, 2161, 2179, 2203, 2207, 2213,
-	2221, 2237, 2239, 2243, 2251, 2267, 2269, 2273, 2281, 2287,
-	2293, 2297, 2309, 2311, 2333, 2339, 2341, 2347, 2351, 2357,
-	2371, 2377, 2381, 2383, 2389, 2393, 2399, 2411, 2417, 2423,
-	2437, 2441, 2447, 2459, 2467, 2473, 2477, 2503, 2521, 2531,
-	2539, 2543, 2549, 2551, 2557, 2579, 2591, 2593, 2609, 2617,
-	2621, 2633, 2647, 2657, 2659, 2663, 2671, 2677, 2683, 2687,
-	2689, 2693, 2699, 2707, 2711, 2713, 2719, 2729, 2731, 2741,
-	2749, 2753, 2767, 2777, 2789, 2791, 2797, 2801, 2803, 2819,
-	2833, 2837, 2843, 2851, 2857, 2861, 2879, 2887, 2897, 2903,
-	2909, 2917, 2927, 2939, 2953, 2957, 2963, 2969, 2971, 2999,
-	3001, 3011, 3019, 3023, 3037, 3041, 3049, 3061, 3067, 3079,
-	3083, 3089, 3109, 3119, 3121, 3137, 3163, 3167, 3169, 3181,
-	3187, 3191, 3203, 3209, 3217, 3221, 3229, 3251, 3253, 3257,
-	3259, 3271, 3299, 3301, 3307, 3313, 3319, 3323, 3329, 3331,
-	3343, 3347, 3359, 3361, 3371, 3373, 3389, 3391, 3407, 3413,
-	3433, 3449, 3457, 3461, 3463, 3467, 3469, 3491, 3499, 3511,
-	3517, 3527, 3529, 3533, 3539, 3541, 3547, 3557, 3559, 3571,
-};
-
-// =============================================================================
-//
-// Grid stuff
-//
 ConfigOption (int Grid = 1)
 ConfigOption (float GridCoarseCoordinateSnap = 5.0f)
 ConfigOption (float GridCoarseAngleSnap = 45.0f)
@@ -98,29 +39,30 @@
 ConfigOption (int RotationPointType = 0)
 ConfigOption (Vertex CustomRotationPoint = Origin)
 
+
 float gridCoordinateSnap()
 {
 	switch (Config->grid())
 	{
+	default:
 	case Grid::Coarse: return Config->gridCoarseCoordinateSnap();
 	case Grid::Medium: return Config->gridMediumCoordinateSnap();
 	case Grid::Fine: return Config->gridFineCoordinateSnap();
 	}
+}
 
-	return 1.0f;
-}
 
 float gridAngleSnap()
 {
 	switch (Config->grid())
 	{
+	default:
 	case Grid::Coarse: return Config->gridCoarseAngleSnap();
 	case Grid::Medium: return Config->gridMediumAngleSnap();
 	case Grid::Fine: return Config->gridFineAngleSnap();
 	}
+}
 
-	return 45.0f;
-}
 
 float gridBezierCurveSegments()
 {
@@ -133,13 +75,10 @@
 	}
 }
 
-// =============================================================================
-//
-// Snap the given coordinate value on the current grid's given axis.
-//
-double Grid::Snap (double value, const Grid::Config type)
+// Snaps the given coordinate value on the current grid's given axis.
+double snapToGrid (double value, const Grid::Config type)
 {
-	double snapvalue = (type == Coordinate) ? gridCoordinateSnap() : gridAngleSnap();
+	double snapvalue = (type == Grid::Coordinate) ? gridCoordinateSnap() : gridAngleSnap();
 	double mult = floor (qAbs<double> (value / snapvalue));
 	double out = mult * snapvalue;
 
@@ -152,43 +91,39 @@
 	return out;
 }
 
-// =============================================================================
-//
-void Simplify (int& numer, int& denom)
+
+int gcd (int a, int b)
 {
-	bool repeat;
-
-	do
+	if (a > 0 and b > 0)
 	{
-		repeat = false;
-
-		for (int x = 0; x < countof (PrimeNumbers); x++)
+		while (a != b)
 		{
-			int const prime = PrimeNumbers[x];
-
-			if (numer < prime and denom < prime)
-				break;
+			if (a < b)
+				b -= a;
+			else
+				a -= b;
+		}
+	}
 
-			if ((numer % prime == 0) and (denom % prime == 0))
-			{
-				numer /= prime;
-				denom /= prime;
-				repeat = true;
-				break;
-			}
-		}
-	} while (repeat);
+	return a;
 }
 
-// =============================================================================
-//
-Vertex GetRotationPoint (const LDObjectList& objs)
+
+void simplify (int& numer, int& denom)
+{
+	int factor = gcd (numer, denom);
+	numer /= factor;
+	denom /= factor;
+}
+
+
+Vertex getRotationPoint (const LDObjectList& objs)
 {
 	switch (RotationPoint (Config->rotationPointType()))
 	{
 	case RotationPoint::ObjectOrigin:
 		{
-			LDBoundingBox box;
+			BoundingBox box;
 
 			// Calculate center vertex
 			for (LDObject* obj : objs)
@@ -215,9 +150,8 @@
 	return Vertex();
 }
 
-// =============================================================================
-//
-void ConfigureRotationPoint()
+
+void configureRotationPoint()
 {
 	QDialog* dlg = new QDialog;
 	Ui::RotPointUI ui;
@@ -260,9 +194,8 @@
 	Config->setCustomRotationPoint (custompoint);
 }
 
-// =============================================================================
-//
-QString Join (QList<StringFormatArg> vals, QString delim)
+
+QString joinStrings (QList<StringFormatArg> vals, QString delim)
 {
 	QStringList list;
 
@@ -272,62 +205,29 @@
 	return list.join (delim);
 }
 
-// =============================================================================
-//
-void RoundToDecimals (double& a, int decimals)
+
+void roundToDecimals (double& a, int decimals)
 {
-	static const long e10[] =
-	{
-		1l,
-		10l,
-		100l,
-		1000l,
-		10000l,
-		100000l,
-		1000000l,
-		10000000l,
-		100000000l,
-		1000000000l,
-	};
-
-	if (decimals >= 0 and decimals < countof (e10))
-		a = round (a * e10[decimals]) / e10[decimals];
+	static const double factors[] = { 1e0, 1e1, 1e2, 1e3, 1e4, 1e5, 1e6, 1e7, 1e8, 1e9 };
+	if (decimals >= 0 and decimals < countof (factors))
+		a = round (a * factors[decimals]) / factors[decimals];
 }
 
-// =============================================================================
-//
-void ApplyToMatrix (Matrix& a, ApplyToMatrixFunction func)
+
+void applyToMatrix (Matrix& a, ApplyToMatrixFunction func)
 {
 	for (int i = 0; i < 9; ++i)
 		func (i, a[i]);
 }
 
-// =============================================================================
-//
-void ApplyToMatrix (const Matrix& a, ApplyToMatrixConstFunction func)
+void applyToMatrix (const Matrix& a, ApplyToMatrixConstFunction func)
 {
 	for (int i = 0; i < 9; ++i)
 		func (i, a[i]);
 }
 
-// =============================================================================
-//
-double GetCoordinateOf (const Vertex& a, Axis ax)
-{
-	switch (ax)
-	{
-		case X: return a.x();
-		case Y: return a.y();
-		case Z: return a.z();
-	}
 
-	return 0.0;
-}
-
-
-// =============================================================================
-//
-QString MakePrettyFileSize (qint64 size)
+QString formatFileSize (qint64 size)
 {
 	if (size < 1024LL)
 		return QString::number (size) + " bytes";
--- a/src/miscallenous.h	Wed Nov 18 19:05:22 2015 +0200
+++ b/src/miscallenous.h	Thu Nov 19 00:43:18 2015 +0200
@@ -26,27 +26,9 @@
 class QColor;
 class QAction;
 
-// Simplifies the given fraction.
-void Simplify (int& numer, int& denom);
-
 using ApplyToMatrixFunction = std::function<void (int, double&)>;
 using ApplyToMatrixConstFunction = std::function<void (int, double)>;
 
-void RoundToDecimals (double& a, int decimals);
-void ApplyToMatrix (Matrix& a, ApplyToMatrixFunction func);
-void ApplyToMatrix (const Matrix& a, ApplyToMatrixConstFunction func);
-
-double GetCoordinateOf (const Vertex& a, Axis ax);
-QString MakePrettyFileSize (qint64 size);
-
-QString Join (QList<StringFormatArg> vals, QString delim = " ");
-
-// Grid stuff
-float gridCoordinateSnap();
-float gridAngleSnap();
-float gridBezierCurveSegments();
-
-// =============================================================================
 enum class RotationPoint
 {
 	ObjectOrigin,
@@ -55,10 +37,6 @@
 	NumValues
 };
 
-Vertex GetRotationPoint (const LDObjectList& objs);
-void ConfigureRotationPoint();
-
-// =============================================================================
 namespace Grid
 {
 	enum Type
@@ -73,6 +51,18 @@
 		Coordinate,
 		Angle
 	};
+}
 
-	double Snap (double value, const Grid::Config type);
-}
+void applyToMatrix (Matrix& a, ApplyToMatrixFunction func);
+void applyToMatrix (const Matrix& a, ApplyToMatrixConstFunction func);
+void configureRotationPoint();
+QString formatFileSize (qint64 size);
+int gcd (int a, int b);
+Vertex getRotationPoint (const LDObjectList& objs);
+float gridAngleSnap();
+float gridBezierCurveSegments();
+float gridCoordinateSnap();
+QString joinStrings (QList<StringFormatArg> vals, QString delim = " ");
+void roundToDecimals (double& a, int decimals);
+void simplify (int& numer, int& denom);
+double snapToGrid (double value, const Grid::Config type);
--- a/src/primitives.cpp	Wed Nov 18 19:05:22 2015 +0200
+++ b/src/primitives.cpp	Thu Nov 19 00:43:18 2015 +0200
@@ -567,7 +567,7 @@
 			denom = divs;
 
 	// Simplify the fractional part, but the denominator must be at least 4.
-	Simplify (numer, denom);
+	simplify (numer, denom);
 
 	if (denom < 4)
 	{
--- a/src/toolsets/algorithmtoolset.cpp	Wed Nov 18 19:05:22 2015 +0200
+++ b/src/toolsets/algorithmtoolset.cpp	Thu Nov 19 00:43:18 2015 +0200
@@ -161,12 +161,12 @@
 
 			v.apply ([&](Axis, double& a)
 			{
-				RoundToDecimals (a, Config->roundPositionPrecision());
+				roundToDecimals (a, Config->roundPositionPrecision());
 			});
 
-			ApplyToMatrix (t, [&](int, double& a)
+			applyToMatrix (t, [&](int, double& a)
 			{
-				RoundToDecimals (a, Config->roundMatrixPrecision());
+				roundToDecimals (a, Config->roundMatrixPrecision());
 			});
 
 			mo->setPosition (v);
@@ -180,7 +180,7 @@
 				Vertex v = obj->vertex (i);
 				v.apply ([&](Axis, double& a)
 				{
-					RoundToDecimals (a, Config->roundPositionPrecision());
+					roundToDecimals (a, Config->roundPositionPrecision());
 				});
 				obj->setVertex (i, v);
 				num += 3;
--- a/src/toolsets/extprogramtoolset.cpp	Wed Nov 18 19:05:22 2015 +0200
+++ b/src/toolsets/extprogramtoolset.cpp	Thu Nov 19 00:43:18 2015 +0200
@@ -391,7 +391,7 @@
 		return;
 
 	// Compose the command-line arguments
-	QString argv = Join (
+	QString argv = joinStrings (
 	{
 		(axis == X) ? "-x" : (axis == Y) ? "-y" : "-z",
 		(mode == Distance) ? "-d" : (mode == Symmetry) ? "-s" : (mode == Projection) ? "-p" : "-r",
@@ -435,7 +435,7 @@
 		return;
 
 	// Compose arguments
-	QString argv = Join (
+	QString argv = joinStrings (
 	{
 		(not ui.cb_condense->isChecked()) ? "-q" : "",
 		(not ui.cb_subst->isChecked()) ? "-r" : "",
@@ -512,7 +512,7 @@
 		return;
 	}
 
-	QString parms = Join (
+	QString parms = joinStrings (
 	{
 		(ui.cb_colorize->isChecked()) ? "-c" : "",
 		(ui.cb_nocondense->isChecked()) ? "-t" : "",
@@ -520,7 +520,7 @@
 		ui.dsb_prescale->value()
 	});
 
-	QString argv_normal = Join (
+	QString argv_normal = joinStrings (
 	{
 		parms,
 		inDATName,
@@ -528,7 +528,7 @@
 		outDATName
 	});
 
-	QString argv_inverse = Join (
+	QString argv_inverse = joinStrings (
 	{
 		parms,
 		cutDATName,
@@ -549,7 +549,7 @@
 
 	if (ui.cb_edges->isChecked()
 		and checkExtProgramPath (Isecalc)
-		and runExtProgram (Isecalc, Join ({inDATName, cutDATName, edgesDATName})))
+		and runExtProgram (Isecalc, joinStrings ({inDATName, cutDATName, edgesDATName})))
 	{
 		insertOutput (edgesDATName, false, {});
 	}
@@ -599,7 +599,7 @@
 		return;
 	}
 
-	QString argv = Join (
+	QString argv = joinStrings (
 	{
 		(ui.cb_oldsweep->isChecked() ? "-s" : ""),
 		(ui.cb_reverse->isChecked() ? "-r" : ""),
@@ -665,7 +665,7 @@
 		return;
 	}
 
-	QString argv = Join (
+	QString argv = joinStrings (
 	{
 		in1DATName,
 		in2DATName,
@@ -702,7 +702,7 @@
 
 	int unmatched = ui.unmatched->currentIndex();
 
-	QString argv = Join (
+	QString argv = joinStrings (
 	{
 		format ("-p %1", ui.precision->value()),
 		format ("-af %1", ui.flatAngle->value()),
--- a/src/toolsets/movetoolset.cpp	Wed Nov 18 19:05:22 2015 +0200
+++ b/src/toolsets/movetoolset.cpp	Thu Nov 19 00:43:18 2015 +0200
@@ -136,5 +136,5 @@
 
 void MoveToolset::configureRotationPoint()
 {
-	ConfigureRotationPoint();
+	configureRotationPoint();
 }
\ No newline at end of file

mercurial