Sat, 24 Mar 2018 12:06:22 +0200
Moved includes, added squared() function
--- a/src/basics.h Sat Mar 24 11:57:24 2018 +0200 +++ b/src/basics.h Sat Mar 24 12:06:22 2018 +0200 @@ -17,6 +17,8 @@ */ #pragma once +#include <cstdio> +#include <cstdlib> #include <QFile> #include <QMatrix4x4> #include <QMetaType> @@ -24,6 +26,8 @@ #include <QSet> #include <QString> #include <QStringList> +#include <QTextFormat> +#include <QVariant> #include <QVector> #include <QVector3D> #include "generics/functions.h"
--- a/src/editmodes/abstractEditMode.cpp Sat Mar 24 11:57:24 2018 +0200 +++ b/src/editmodes/abstractEditMode.cpp Sat Mar 24 12:06:22 2018 +0200 @@ -120,7 +120,7 @@ QList<Vertex> vertices = currentDocument()->inlineVertices().toList(); // Sort the vertices in order of distance to camera - std::sort(vertices.begin(), vertices.end(), [&](const Vertex& a, const Vertex& b) -> bool + sort(vertices.begin(), vertices.end(), [&](const Vertex& a, const Vertex& b) -> bool { if (renderer()->currentCamera().isAxisNegated(Z)) return a[depthAxis] > b[depthAxis]; @@ -132,16 +132,16 @@ { // If the vertex in 2d space is very close to the cursor then we use it regardless of depth. QPoint vect2d = renderer()->currentCamera().convert3dTo2d(vertex) - cursorPosition2D; - double distance2DSquared = std::pow(vect2d.x(), 2) + std::pow(vect2d.y(), 2); + double distance2DSquared = ::squared(vect2d.x()) + ::squared(vect2d.y()); - if (distance2DSquared < 16.0 * 16.0) + if (distance2DSquared < ::squared(16.0)) { closest = &vertex; break; } // Check if too far away from the cursor. - if (distance2DSquared > 64.0 * 64.0) + if (distance2DSquared > ::squared(64.0)) continue; // Not very close to the cursor. Compare using true distance,
--- a/src/generics/functions.h Sat Mar 24 11:57:24 2018 +0200 +++ b/src/generics/functions.h Sat Mar 24 12:06:22 2018 +0200 @@ -4,11 +4,14 @@ #include "../basics.h" using std::abs; +using std::atan2; using std::ceil; using std::cos; using std::floor; using std::hypot; +using std::pow; using std::sin; +using std::sort; using std::sqrt; /* @@ -26,6 +29,18 @@ return (::abs(a - ::floor(a)) < 0.00001) or (::abs(a - ::ceil(a)) < 0.00001); } +template<typename T> +T squared(T value) +{ + return ::pow(value, 2); +} + +template<> +inline int squared<int>(int value) +{ + return value * value; +} + // // Returns true if first arg is equal to any of the other args //
--- a/src/main.h Sat Mar 24 11:57:24 2018 +0200 +++ b/src/main.h Sat Mar 24 12:06:22 2018 +0200 @@ -21,14 +21,6 @@ // Stuff defined and included here is universally included. #pragma once -#include <stdio.h> -#include <stdlib.h> -#include <stdint.h> -#include <stdarg.h> -#include <QSet> -#include <QString> -#include <QTextFormat> -#include <QVariant> #include "basics.h" #include "version.h" #include "format.h"
--- a/src/primitives.cpp Sat Mar 24 11:57:24 2018 +0200 +++ b/src/primitives.cpp Sat Mar 24 12:06:22 2018 +0200 @@ -172,7 +172,7 @@ } // Sort the categories. Note that we only do this here because we needed the original order for pattern matching. - qSort (m_categories.begin(), m_categories.end(), + ::sort(m_categories.begin(), m_categories.end(), [](PrimitiveCategory* const& one, PrimitiveCategory* const& other) -> bool { return one->name() < other->name();
--- a/src/toolsets/algorithmtoolset.cpp Sat Mar 24 11:57:24 2018 +0200 +++ b/src/toolsets/algorithmtoolset.cpp Sat Mar 24 12:06:22 2018 +0200 @@ -241,7 +241,7 @@ // Make a reference distance from the threshold value. // If we're only comparing one dimension, this is the square of the threshold. // If we're comparing multiple dimensions, the distance is multiplied to adjust. - double thresholdDistanceSquared = countof(axes) * std::pow(ui.threshold->value(), 2); + double thresholdDistanceSquared = countof(axes) * pow(ui.threshold->value(), 2); // Add some tiny leeway to fix rounding errors in the rounding error fixer. thresholdDistanceSquared += 1e-10; @@ -250,7 +250,7 @@ double distanceSquared = 0.0; for (Axis axis : axes) - distanceSquared += std::pow(vertex[axis] - referencePoint[axis], 2); + distanceSquared += pow(vertex[axis] - referencePoint[axis], 2); if (distanceSquared < thresholdDistanceSquared) {