diff -r c595cfb4791c -r 31540c1f22ea src/misc.h
--- a/src/misc.h Wed Oct 23 13:14:17 2013 +0300
+++ b/src/misc.h Mon Jan 20 15:04:26 2014 +0200
@@ -1,6 +1,6 @@
/*
* LDForge: LDraw parts authoring CAD
- * Copyright (C) 2013 Santeri Piippo
+ * Copyright (C) 2013, 2014 Santeri Piippo
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -16,16 +16,17 @@
* along with this program. If not, see .
*/
-#ifndef MISC_H
-#define MISC_H
+#ifndef LDFORGE_MISC_H
+#define LDFORGE_MISC_H
#include
#include "config.h"
-#include "common.h"
+#include "main.h"
#include "types.h"
#define NUM_PRIMES 500
+class LDDocument;
class QColor;
class QAction;
@@ -33,17 +34,20 @@
extern const int g_primes[NUM_PRIMES];
// Returns whether a given string represents a floating point number.
-bool numeric (const str& tok);
+bool numeric (const QString& tok);
// Simplifies the given fraction.
void simplify (int& numer, int& denom);
-str join (initlist vals, str delim = " ");
+void roundToDecimals (double& a, int decimals);
+
+QString join (initlist vals, QString delim = " ");
// Grid stuff
struct gridinfo
-{ const char* const name;
- FloatConfig* const confs[4];
+{
+ const char* const name;
+ float* const confs[4];
};
extern_cfg (Int, grid);
@@ -51,29 +55,34 @@
extern const gridinfo g_GridInfo[3];
inline const gridinfo& currentGrid()
-{ return g_GridInfo[grid];
+{
+ return g_GridInfo[grid];
}
// =============================================================================
-enum RotationPoint
-{ ObjectOrigin,
- WorldOrigin,
- CustomPoint
+enum ERotationPoint
+{
+ EObjectOrigin,
+ EWorldOrigin,
+ ECustomPoint
};
-vertex rotPoint (const QList& objs);
+Vertex rotPoint (const LDObjectList& objs);
void configRotationPoint();
// =============================================================================
namespace Grid
-{ enum Type
- { Coarse,
+{
+ enum Type
+ {
+ Coarse,
Medium,
Fine
};
enum Config
- { X,
+ {
+ X,
Y,
Z,
Angle
@@ -82,108 +91,52 @@
double snap (double value, const Grid::Config axis);
}
-// =============================================================================
-// RingFinder
-//
-// Provides an algorithm for finding a solution of rings between radii r0 and r1.
-// =============================================================================
-class RingFinder
-{ public:
- struct Component
- { int num;
- double scale;
- };
-
- class Solution
- { public:
- // Components of this solution
- inline const QVector& components() const
- { return m_components;
- }
-
- // Add a component to this solution
- void addComponent (const Component& a)
- { m_components.push_back (a);
- }
-
- // Compare solutions
- bool operator> (const Solution& other) const;
-
- private:
- QVector m_components;
- };
-
- RingFinder() {}
- bool findRings (double r0, double r1);
-
- inline const Solution* bestSolution()
- { return m_bestSolution;
- }
-
- inline const QVector& allSolutions() const
- { return m_solutions;
- }
-
- inline bool operator() (double r0, double r1)
- { return findRings (r0, r1);
- }
-
-private:
- QVector m_solutions;
- const Solution* m_bestSolution;
- int m_stack;
-
- bool findRingsRecursor (double r0, double r1, Solution& currentSolution);
-};
-
-extern RingFinder g_RingFinder;
-
-// =============================================================================
-template void dataswap (T& a, T& b)
-{ T c = a;
- a = b;
- b = c;
-}
-
// -----------------------------------------------------------------------------
// Plural expression
template static inline const char* plural (T n)
-{ return (n != 1) ? "s" : "";
+{
+ return (n != 1) ? "s" : "";
}
// -----------------------------------------------------------------------------
// Templated clamp
template static inline T clamp (T a, T min, T max)
-{ return (a > max) ? max : (a < min) ? min : a;
+{
+ return (a > max) ? max : (a < min) ? min : a;
}
// Templated minimum
template static inline T min (T a, T b)
-{ return (a < b) ? a : b;
+{
+ return (a < b) ? a : b;
}
// Templated maximum
template static inline T max (T a, T b)
-{ return (a > b) ? a : b;
+{
+ return (a > b) ? a : b;
}
// Templated absolute value
template static inline T abs (T a)
-{ return (a >= 0) ? a : -a;
+{
+ return (a >= 0) ? a : -a;
}
template inline bool isZero (T a)
-{ return abs (a) < 0.0001;
+{
+ return abs (a) < 0.0001;
}
template inline bool isInteger (T a)
-{ return isZero (a - (int) a);
+{
+ return isZero (a - (int) a);
}
template void removeDuplicates (QList& a)
-{ std::sort (a.begin(), a.end());
- typename QList::iterator pos = std::unique (a.begin(), a.end());
- a.erase (pos, a.end());
+{
+ std::sort (a.begin(), a.end());
+ a.erase (std::unique (a.begin(), a.end()), a.end());
}
-#endif // MISC_H
+#endif // LDFORGE_MISC_H