# HG changeset patch # User Teemu Piippo # Date 1521885982 -7200 # Node ID bdb4804bc09c1704aaa637093f9573bbe9d51e7a # Parent 39d7a9642eeaf41d1746eee8f9b0fd4b8c246eb9 Moved includes, added squared() function diff -r 39d7a9642eea -r bdb4804bc09c src/basics.h --- 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 +#include #include #include #include @@ -24,6 +26,8 @@ #include #include #include +#include +#include #include #include #include "generics/functions.h" diff -r 39d7a9642eea -r bdb4804bc09c src/editmodes/abstractEditMode.cpp --- 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 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, diff -r 39d7a9642eea -r bdb4804bc09c src/generics/functions.h --- 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 +T squared(T value) +{ + return ::pow(value, 2); +} + +template<> +inline int squared(int value) +{ + return value * value; +} + // // Returns true if first arg is equal to any of the other args // diff -r 39d7a9642eea -r bdb4804bc09c src/main.h --- 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 -#include -#include -#include -#include -#include -#include -#include #include "basics.h" #include "version.h" #include "format.h" diff -r 39d7a9642eea -r bdb4804bc09c src/primitives.cpp --- 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(); diff -r 39d7a9642eea -r bdb4804bc09c src/toolsets/algorithmtoolset.cpp --- 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) {