src/misc.h

Mon, 23 Dec 2013 16:10:36 +0200

author
Santeri Piippo <crimsondusk64@gmail.com>
date
Mon, 23 Dec 2013 16:10:36 +0200
changeset 590
7aec744ce97b
parent 583
4906c5c1670f
child 596
43c233e91447
permissions
-rw-r--r--

- refactored config code

183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
1 /*
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
2 * LDForge: LDraw parts authoring CAD
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
3 * Copyright (C) 2013 Santeri Piippo
455
c5d14d112034 Code formatting: use same separators everywhere, remove extra spaces from license headers, simplified message manager api a bit
Santeri Piippo <crimsondusk64@gmail.com>
parents: 421
diff changeset
4 *
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
5 * This program is free software: you can redistribute it and/or modify
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
6 * it under the terms of the GNU General Public License as published by
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
7 * the Free Software Foundation, either version 3 of the License, or
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
8 * (at your option) any later version.
455
c5d14d112034 Code formatting: use same separators everywhere, remove extra spaces from license headers, simplified message manager api a bit
Santeri Piippo <crimsondusk64@gmail.com>
parents: 421
diff changeset
9 *
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
10 * This program is distributed in the hope that it will be useful,
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
13 * GNU General Public License for more details.
455
c5d14d112034 Code formatting: use same separators everywhere, remove extra spaces from license headers, simplified message manager api a bit
Santeri Piippo <crimsondusk64@gmail.com>
parents: 421
diff changeset
14 *
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
17 */
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
18
538
2f85d4d286e5 - ensured header files' guards start with LDFORGE_
Santeri Piippo <crimsondusk64@gmail.com>
parents: 513
diff changeset
19 #ifndef LDFORGE_MISC_H
2f85d4d286e5 - ensured header files' guards start with LDFORGE_
Santeri Piippo <crimsondusk64@gmail.com>
parents: 513
diff changeset
20 #define LDFORGE_MISC_H
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
21
513
29eb671b34f6 Added a crash catcher which trigger under Linux. It calls GDB and tries to get a backtrace. Also integrated assertion failure handling to this new system. Removed the print() function in the process (because the new bomb box uses a text edit and QTextDocuments's print method clashes with the macro and I figured it was a good idea to rid it anyway) and replaced all calls with log().
Santeri Piippo <crimsondusk64@gmail.com>
parents: 508
diff changeset
22 #include <QVector>
198
f246725199dc Split some stuff into separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents: 189
diff changeset
23 #include "config.h"
541
0e38beeb050a - Renamed common.h to main.h, split the PROPERTY macro and supporting macros to property.h
Santeri Piippo <crimsondusk64@gmail.com>
parents: 539
diff changeset
24 #include "main.h"
286
7a562bf3d829 Converted to 16-bit strings.. again
Santeri Piippo <crimsondusk64@gmail.com>
parents: 256
diff changeset
25 #include "types.h"
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
26
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
27 #define NUM_PRIMES 500
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
28
583
4906c5c1670f - documents are now refcounted. This should seriously stabilize (and speed up!) the pruning of unused files
Santeri Piippo <crimsondusk64@gmail.com>
parents: 571
diff changeset
29 class LDDocument;
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
30 class QColor;
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
31 class QAction;
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
32
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
33 // Prime numbers
498
791c831c8020 further cleansing - removed most uses of unsigned ints, removed list reversers
Santeri Piippo <crimsondusk64@gmail.com>
parents: 496
diff changeset
34 extern const int g_primes[NUM_PRIMES];
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
35
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
36 // Returns whether a given string represents a floating point number.
508
7ace3537a560 removed some custom functions in favor of Qt implementations
Santeri Piippo <crimsondusk64@gmail.com>
parents: 507
diff changeset
37 bool numeric (const str& tok);
308
4e2425bd4dc7 Added an atof overload to convert from string to float, hopefully without any precision error
Santeri Piippo <crimsondusk64@gmail.com>
parents: 286
diff changeset
38
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
39 // Simplifies the given fraction.
500
cad8cdc42a64 Finally got the ringfinder working! Working on integrating it to ring drawing...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 498
diff changeset
40 void simplify (int& numer, int& denom);
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
41
542
46a33bdc0b36 - Improved coordinate rounding, replaced the hack with a proper implementation, now rounds properly and works on subfiles as well
Santeri Piippo <crimsondusk64@gmail.com>
parents: 541
diff changeset
42 void roundToDecimals (double& a, int decimals);
46a33bdc0b36 - Improved coordinate rounding, replaced the hack with a proper implementation, now rounds properly and works on subfiles as well
Santeri Piippo <crimsondusk64@gmail.com>
parents: 541
diff changeset
43
286
7a562bf3d829 Converted to 16-bit strings.. again
Santeri Piippo <crimsondusk64@gmail.com>
parents: 256
diff changeset
44 str join (initlist<StringFormatArg> vals, str delim = " ");
7a562bf3d829 Converted to 16-bit strings.. again
Santeri Piippo <crimsondusk64@gmail.com>
parents: 256
diff changeset
45
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
46 // Grid stuff
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 473
diff changeset
47 struct gridinfo
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 473
diff changeset
48 { const char* const name;
590
7aec744ce97b - refactored config code
Santeri Piippo <crimsondusk64@gmail.com>
parents: 583
diff changeset
49 float* const confs[4];
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 473
diff changeset
50 };
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
51
461
fbcc91ae1dd2 - added "Go to line" action, renamed the config classes to proper camelcase
Santeri Piippo <crimsondusk64@gmail.com>
parents: 455
diff changeset
52 extern_cfg (Int, grid);
500
cad8cdc42a64 Finally got the ringfinder working! Working on integrating it to ring drawing...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 498
diff changeset
53 static const int g_NumGrids = 3;
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
54 extern const gridinfo g_GridInfo[3];
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
55
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 473
diff changeset
56 inline const gridinfo& currentGrid()
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 473
diff changeset
57 { return g_GridInfo[grid];
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
58 }
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
59
211
8d35e631bef3 Added dialog for rotation points
Santeri Piippo <crimsondusk64@gmail.com>
parents: 198
diff changeset
60 // =============================================================================
332
3013acb1df53 Converted rotation point prompt
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
61 enum RotationPoint
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 473
diff changeset
62 { ObjectOrigin,
332
3013acb1df53 Converted rotation point prompt
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
63 WorldOrigin,
3013acb1df53 Converted rotation point prompt
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
64 CustomPoint
3013acb1df53 Converted rotation point prompt
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
65 };
3013acb1df53 Converted rotation point prompt
Santeri Piippo <crimsondusk64@gmail.com>
parents: 308
diff changeset
66
504
6a1fa662bfc1 Removed the List -> QList alias, use QList directly
Santeri Piippo <crimsondusk64@gmail.com>
parents: 503
diff changeset
67 vertex rotPoint (const QList<LDObject*>& objs);
421
7d26db0be944 style cleanup - it should be all unified now
Santeri Piippo <crimsondusk64@gmail.com>
parents: 406
diff changeset
68 void configRotationPoint();
211
8d35e631bef3 Added dialog for rotation points
Santeri Piippo <crimsondusk64@gmail.com>
parents: 198
diff changeset
69
8d35e631bef3 Added dialog for rotation points
Santeri Piippo <crimsondusk64@gmail.com>
parents: 198
diff changeset
70 // =============================================================================
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 473
diff changeset
71 namespace Grid
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 473
diff changeset
72 { enum Type
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 473
diff changeset
73 { Coarse,
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
74 Medium,
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
75 Fine
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
76 };
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 473
diff changeset
77
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 473
diff changeset
78 enum Config
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 473
diff changeset
79 { X,
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
80 Y,
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
81 Z,
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
82 Angle
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
83 };
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 473
diff changeset
84
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
85 double snap (double value, const Grid::Config axis);
473
2a84149fe642 Changed build system from qmake to CMake.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 461
diff changeset
86 }
183
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
87
f1b8cb53d2a2 Moved source files to src/, removed zz_ prefix off dialog files.
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff changeset
88 // =============================================================================
500
cad8cdc42a64 Finally got the ringfinder working! Working on integrating it to ring drawing...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 498
diff changeset
89 // RingFinder
cad8cdc42a64 Finally got the ringfinder working! Working on integrating it to ring drawing...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 498
diff changeset
90 //
cad8cdc42a64 Finally got the ringfinder working! Working on integrating it to ring drawing...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 498
diff changeset
91 // Provides an algorithm for finding a solution of rings between radii r0 and r1.
cad8cdc42a64 Finally got the ringfinder working! Working on integrating it to ring drawing...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 498
diff changeset
92 // =============================================================================
cad8cdc42a64 Finally got the ringfinder working! Working on integrating it to ring drawing...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 498
diff changeset
93 class RingFinder
cad8cdc42a64 Finally got the ringfinder working! Working on integrating it to ring drawing...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 498
diff changeset
94 { public:
538
2f85d4d286e5 - ensured header files' guards start with LDFORGE_
Santeri Piippo <crimsondusk64@gmail.com>
parents: 513
diff changeset
95 struct Component
2f85d4d286e5 - ensured header files' guards start with LDFORGE_
Santeri Piippo <crimsondusk64@gmail.com>
parents: 513
diff changeset
96 { int num;
2f85d4d286e5 - ensured header files' guards start with LDFORGE_
Santeri Piippo <crimsondusk64@gmail.com>
parents: 513
diff changeset
97 double scale;
2f85d4d286e5 - ensured header files' guards start with LDFORGE_
Santeri Piippo <crimsondusk64@gmail.com>
parents: 513
diff changeset
98 };
2f85d4d286e5 - ensured header files' guards start with LDFORGE_
Santeri Piippo <crimsondusk64@gmail.com>
parents: 513
diff changeset
99
2f85d4d286e5 - ensured header files' guards start with LDFORGE_
Santeri Piippo <crimsondusk64@gmail.com>
parents: 513
diff changeset
100 class Solution
2f85d4d286e5 - ensured header files' guards start with LDFORGE_
Santeri Piippo <crimsondusk64@gmail.com>
parents: 513
diff changeset
101 { public:
2f85d4d286e5 - ensured header files' guards start with LDFORGE_
Santeri Piippo <crimsondusk64@gmail.com>
parents: 513
diff changeset
102 // Components of this solution
2f85d4d286e5 - ensured header files' guards start with LDFORGE_
Santeri Piippo <crimsondusk64@gmail.com>
parents: 513
diff changeset
103 inline const QVector<Component>& getComponents() const
2f85d4d286e5 - ensured header files' guards start with LDFORGE_
Santeri Piippo <crimsondusk64@gmail.com>
parents: 513
diff changeset
104 { return m_components;
2f85d4d286e5 - ensured header files' guards start with LDFORGE_
Santeri Piippo <crimsondusk64@gmail.com>
parents: 513
diff changeset
105 }
2f85d4d286e5 - ensured header files' guards start with LDFORGE_
Santeri Piippo <crimsondusk64@gmail.com>
parents: 513
diff changeset
106
2f85d4d286e5 - ensured header files' guards start with LDFORGE_
Santeri Piippo <crimsondusk64@gmail.com>
parents: 513
diff changeset
107 // Add a component to this solution
2f85d4d286e5 - ensured header files' guards start with LDFORGE_
Santeri Piippo <crimsondusk64@gmail.com>
parents: 513
diff changeset
108 inline void addComponent (const Component& a)
2f85d4d286e5 - ensured header files' guards start with LDFORGE_
Santeri Piippo <crimsondusk64@gmail.com>
parents: 513
diff changeset
109 { m_components.push_back (a);
2f85d4d286e5 - ensured header files' guards start with LDFORGE_
Santeri Piippo <crimsondusk64@gmail.com>
parents: 513
diff changeset
110 }
500
cad8cdc42a64 Finally got the ringfinder working! Working on integrating it to ring drawing...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 498
diff changeset
111
538
2f85d4d286e5 - ensured header files' guards start with LDFORGE_
Santeri Piippo <crimsondusk64@gmail.com>
parents: 513
diff changeset
112 // Compare solutions
2f85d4d286e5 - ensured header files' guards start with LDFORGE_
Santeri Piippo <crimsondusk64@gmail.com>
parents: 513
diff changeset
113 bool operator> (const Solution& other) const;
2f85d4d286e5 - ensured header files' guards start with LDFORGE_
Santeri Piippo <crimsondusk64@gmail.com>
parents: 513
diff changeset
114
2f85d4d286e5 - ensured header files' guards start with LDFORGE_
Santeri Piippo <crimsondusk64@gmail.com>
parents: 513
diff changeset
115 private:
2f85d4d286e5 - ensured header files' guards start with LDFORGE_
Santeri Piippo <crimsondusk64@gmail.com>
parents: 513
diff changeset
116 QVector<Component> m_components;
2f85d4d286e5 - ensured header files' guards start with LDFORGE_
Santeri Piippo <crimsondusk64@gmail.com>
parents: 513
diff changeset
117 };
2f85d4d286e5 - ensured header files' guards start with LDFORGE_
Santeri Piippo <crimsondusk64@gmail.com>
parents: 513
diff changeset
118
2f85d4d286e5 - ensured header files' guards start with LDFORGE_
Santeri Piippo <crimsondusk64@gmail.com>
parents: 513
diff changeset
119 RingFinder() {}
2f85d4d286e5 - ensured header files' guards start with LDFORGE_
Santeri Piippo <crimsondusk64@gmail.com>
parents: 513
diff changeset
120 bool findRings (double r0, double r1);
507
fc76d38c3530 reworked the ring finder algorithm greatly, tries harder to find the optimal solution
Santeri Piippo <crimsondusk64@gmail.com>
parents: 504
diff changeset
121
538
2f85d4d286e5 - ensured header files' guards start with LDFORGE_
Santeri Piippo <crimsondusk64@gmail.com>
parents: 513
diff changeset
122 inline const Solution* bestSolution()
2f85d4d286e5 - ensured header files' guards start with LDFORGE_
Santeri Piippo <crimsondusk64@gmail.com>
parents: 513
diff changeset
123 { return m_bestSolution;
2f85d4d286e5 - ensured header files' guards start with LDFORGE_
Santeri Piippo <crimsondusk64@gmail.com>
parents: 513
diff changeset
124 }
507
fc76d38c3530 reworked the ring finder algorithm greatly, tries harder to find the optimal solution
Santeri Piippo <crimsondusk64@gmail.com>
parents: 504
diff changeset
125
538
2f85d4d286e5 - ensured header files' guards start with LDFORGE_
Santeri Piippo <crimsondusk64@gmail.com>
parents: 513
diff changeset
126 inline const QVector<Solution>& allSolutions() const
2f85d4d286e5 - ensured header files' guards start with LDFORGE_
Santeri Piippo <crimsondusk64@gmail.com>
parents: 513
diff changeset
127 { return m_solutions;
2f85d4d286e5 - ensured header files' guards start with LDFORGE_
Santeri Piippo <crimsondusk64@gmail.com>
parents: 513
diff changeset
128 }
2f85d4d286e5 - ensured header files' guards start with LDFORGE_
Santeri Piippo <crimsondusk64@gmail.com>
parents: 513
diff changeset
129
2f85d4d286e5 - ensured header files' guards start with LDFORGE_
Santeri Piippo <crimsondusk64@gmail.com>
parents: 513
diff changeset
130 inline bool operator() (double r0, double r1)
2f85d4d286e5 - ensured header files' guards start with LDFORGE_
Santeri Piippo <crimsondusk64@gmail.com>
parents: 513
diff changeset
131 { return findRings (r0, r1);
2f85d4d286e5 - ensured header files' guards start with LDFORGE_
Santeri Piippo <crimsondusk64@gmail.com>
parents: 513
diff changeset
132 }
507
fc76d38c3530 reworked the ring finder algorithm greatly, tries harder to find the optimal solution
Santeri Piippo <crimsondusk64@gmail.com>
parents: 504
diff changeset
133
fc76d38c3530 reworked the ring finder algorithm greatly, tries harder to find the optimal solution
Santeri Piippo <crimsondusk64@gmail.com>
parents: 504
diff changeset
134 private:
538
2f85d4d286e5 - ensured header files' guards start with LDFORGE_
Santeri Piippo <crimsondusk64@gmail.com>
parents: 513
diff changeset
135 QVector<Solution> m_solutions;
2f85d4d286e5 - ensured header files' guards start with LDFORGE_
Santeri Piippo <crimsondusk64@gmail.com>
parents: 513
diff changeset
136 const Solution* m_bestSolution;
2f85d4d286e5 - ensured header files' guards start with LDFORGE_
Santeri Piippo <crimsondusk64@gmail.com>
parents: 513
diff changeset
137 int m_stack;
507
fc76d38c3530 reworked the ring finder algorithm greatly, tries harder to find the optimal solution
Santeri Piippo <crimsondusk64@gmail.com>
parents: 504
diff changeset
138
538
2f85d4d286e5 - ensured header files' guards start with LDFORGE_
Santeri Piippo <crimsondusk64@gmail.com>
parents: 513
diff changeset
139 bool findRingsRecursor (double r0, double r1, Solution& currentSolution);
500
cad8cdc42a64 Finally got the ringfinder working! Working on integrating it to ring drawing...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 498
diff changeset
140 };
cad8cdc42a64 Finally got the ringfinder working! Working on integrating it to ring drawing...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 498
diff changeset
141
cad8cdc42a64 Finally got the ringfinder working! Working on integrating it to ring drawing...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 498
diff changeset
142 extern RingFinder g_RingFinder;
cad8cdc42a64 Finally got the ringfinder working! Working on integrating it to ring drawing...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 498
diff changeset
143
381
241f65769a57 restructure; removed g_BBox
Santeri Piippo <crimsondusk64@gmail.com>
parents: 332
diff changeset
144 // -----------------------------------------------------------------------------
571
ec534922f693 - cleanup closing of unused files is now defered to the event loop using a new InvokationDeferer class. This prevents ldforge from closing unused files when it *really* shouldn't be doing that, instead waiting until everything is done before it begins the cleanup process.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 542
diff changeset
145 class InvokationDeferer : public QObject
ec534922f693 - cleanup closing of unused files is now defered to the event loop using a new InvokationDeferer class. This prevents ldforge from closing unused files when it *really* shouldn't be doing that, instead waiting until everything is done before it begins the cleanup process.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 542
diff changeset
146 { Q_OBJECT
ec534922f693 - cleanup closing of unused files is now defered to the event loop using a new InvokationDeferer class. This prevents ldforge from closing unused files when it *really* shouldn't be doing that, instead waiting until everything is done before it begins the cleanup process.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 542
diff changeset
147
ec534922f693 - cleanup closing of unused files is now defered to the event loop using a new InvokationDeferer class. This prevents ldforge from closing unused files when it *really* shouldn't be doing that, instead waiting until everything is done before it begins the cleanup process.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 542
diff changeset
148 public:
ec534922f693 - cleanup closing of unused files is now defered to the event loop using a new InvokationDeferer class. This prevents ldforge from closing unused files when it *really* shouldn't be doing that, instead waiting until everything is done before it begins the cleanup process.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 542
diff changeset
149 using FunctionType = void(*)();
ec534922f693 - cleanup closing of unused files is now defered to the event loop using a new InvokationDeferer class. This prevents ldforge from closing unused files when it *really* shouldn't be doing that, instead waiting until everything is done before it begins the cleanup process.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 542
diff changeset
150
ec534922f693 - cleanup closing of unused files is now defered to the event loop using a new InvokationDeferer class. This prevents ldforge from closing unused files when it *really* shouldn't be doing that, instead waiting until everything is done before it begins the cleanup process.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 542
diff changeset
151 explicit InvokationDeferer (QObject* parent = 0);
ec534922f693 - cleanup closing of unused files is now defered to the event loop using a new InvokationDeferer class. This prevents ldforge from closing unused files when it *really* shouldn't be doing that, instead waiting until everything is done before it begins the cleanup process.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 542
diff changeset
152 void addFunctionCall (FunctionType func);
ec534922f693 - cleanup closing of unused files is now defered to the event loop using a new InvokationDeferer class. This prevents ldforge from closing unused files when it *really* shouldn't be doing that, instead waiting until everything is done before it begins the cleanup process.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 542
diff changeset
153
ec534922f693 - cleanup closing of unused files is now defered to the event loop using a new InvokationDeferer class. This prevents ldforge from closing unused files when it *really* shouldn't be doing that, instead waiting until everything is done before it begins the cleanup process.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 542
diff changeset
154 signals:
ec534922f693 - cleanup closing of unused files is now defered to the event loop using a new InvokationDeferer class. This prevents ldforge from closing unused files when it *really* shouldn't be doing that, instead waiting until everything is done before it begins the cleanup process.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 542
diff changeset
155 void functionAdded();
ec534922f693 - cleanup closing of unused files is now defered to the event loop using a new InvokationDeferer class. This prevents ldforge from closing unused files when it *really* shouldn't be doing that, instead waiting until everything is done before it begins the cleanup process.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 542
diff changeset
156
ec534922f693 - cleanup closing of unused files is now defered to the event loop using a new InvokationDeferer class. This prevents ldforge from closing unused files when it *really* shouldn't be doing that, instead waiting until everything is done before it begins the cleanup process.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 542
diff changeset
157 private:
ec534922f693 - cleanup closing of unused files is now defered to the event loop using a new InvokationDeferer class. This prevents ldforge from closing unused files when it *really* shouldn't be doing that, instead waiting until everything is done before it begins the cleanup process.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 542
diff changeset
158 QList<FunctionType> m_funcs;
ec534922f693 - cleanup closing of unused files is now defered to the event loop using a new InvokationDeferer class. This prevents ldforge from closing unused files when it *really* shouldn't be doing that, instead waiting until everything is done before it begins the cleanup process.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 542
diff changeset
159
ec534922f693 - cleanup closing of unused files is now defered to the event loop using a new InvokationDeferer class. This prevents ldforge from closing unused files when it *really* shouldn't be doing that, instead waiting until everything is done before it begins the cleanup process.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 542
diff changeset
160 private slots:
ec534922f693 - cleanup closing of unused files is now defered to the event loop using a new InvokationDeferer class. This prevents ldforge from closing unused files when it *really* shouldn't be doing that, instead waiting until everything is done before it begins the cleanup process.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 542
diff changeset
161 void invokeFunctions();
ec534922f693 - cleanup closing of unused files is now defered to the event loop using a new InvokationDeferer class. This prevents ldforge from closing unused files when it *really* shouldn't be doing that, instead waiting until everything is done before it begins the cleanup process.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 542
diff changeset
162 };
ec534922f693 - cleanup closing of unused files is now defered to the event loop using a new InvokationDeferer class. This prevents ldforge from closing unused files when it *really* shouldn't be doing that, instead waiting until everything is done before it begins the cleanup process.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 542
diff changeset
163
ec534922f693 - cleanup closing of unused files is now defered to the event loop using a new InvokationDeferer class. This prevents ldforge from closing unused files when it *really* shouldn't be doing that, instead waiting until everything is done before it begins the cleanup process.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 542
diff changeset
164 void invokeLater (InvokationDeferer::FunctionType func);
ec534922f693 - cleanup closing of unused files is now defered to the event loop using a new InvokationDeferer class. This prevents ldforge from closing unused files when it *really* shouldn't be doing that, instead waiting until everything is done before it begins the cleanup process.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 542
diff changeset
165
ec534922f693 - cleanup closing of unused files is now defered to the event loop using a new InvokationDeferer class. This prevents ldforge from closing unused files when it *really* shouldn't be doing that, instead waiting until everything is done before it begins the cleanup process.
Santeri Piippo <crimsondusk64@gmail.com>
parents: 542
diff changeset
166 // -----------------------------------------------------------------------------
381
241f65769a57 restructure; removed g_BBox
Santeri Piippo <crimsondusk64@gmail.com>
parents: 332
diff changeset
167 // Plural expression
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 473
diff changeset
168 template<class T> static inline const char* plural (T n)
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 473
diff changeset
169 { return (n != 1) ? "s" : "";
381
241f65769a57 restructure; removed g_BBox
Santeri Piippo <crimsondusk64@gmail.com>
parents: 332
diff changeset
170 }
241f65769a57 restructure; removed g_BBox
Santeri Piippo <crimsondusk64@gmail.com>
parents: 332
diff changeset
171
241f65769a57 restructure; removed g_BBox
Santeri Piippo <crimsondusk64@gmail.com>
parents: 332
diff changeset
172 // -----------------------------------------------------------------------------
241f65769a57 restructure; removed g_BBox
Santeri Piippo <crimsondusk64@gmail.com>
parents: 332
diff changeset
173 // Templated clamp
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 473
diff changeset
174 template<class T> static inline T clamp (T a, T min, T max)
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 473
diff changeset
175 { return (a > max) ? max : (a < min) ? min : a;
381
241f65769a57 restructure; removed g_BBox
Santeri Piippo <crimsondusk64@gmail.com>
parents: 332
diff changeset
176 }
241f65769a57 restructure; removed g_BBox
Santeri Piippo <crimsondusk64@gmail.com>
parents: 332
diff changeset
177
241f65769a57 restructure; removed g_BBox
Santeri Piippo <crimsondusk64@gmail.com>
parents: 332
diff changeset
178 // Templated minimum
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 473
diff changeset
179 template<class T> static inline T min (T a, T b)
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 473
diff changeset
180 { return (a < b) ? a : b;
381
241f65769a57 restructure; removed g_BBox
Santeri Piippo <crimsondusk64@gmail.com>
parents: 332
diff changeset
181 }
241f65769a57 restructure; removed g_BBox
Santeri Piippo <crimsondusk64@gmail.com>
parents: 332
diff changeset
182
241f65769a57 restructure; removed g_BBox
Santeri Piippo <crimsondusk64@gmail.com>
parents: 332
diff changeset
183 // Templated maximum
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 473
diff changeset
184 template<class T> static inline T max (T a, T b)
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 473
diff changeset
185 { return (a > b) ? a : b;
381
241f65769a57 restructure; removed g_BBox
Santeri Piippo <crimsondusk64@gmail.com>
parents: 332
diff changeset
186 }
241f65769a57 restructure; removed g_BBox
Santeri Piippo <crimsondusk64@gmail.com>
parents: 332
diff changeset
187
241f65769a57 restructure; removed g_BBox
Santeri Piippo <crimsondusk64@gmail.com>
parents: 332
diff changeset
188 // Templated absolute value
493
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 473
diff changeset
189 template<class T> static inline T abs (T a)
16766ac1bbd9 last code reformatting i swear
Santeri Piippo <crimsondusk64@gmail.com>
parents: 473
diff changeset
190 { return (a >= 0) ? a : -a;
381
241f65769a57 restructure; removed g_BBox
Santeri Piippo <crimsondusk64@gmail.com>
parents: 332
diff changeset
191 }
241f65769a57 restructure; removed g_BBox
Santeri Piippo <crimsondusk64@gmail.com>
parents: 332
diff changeset
192
500
cad8cdc42a64 Finally got the ringfinder working! Working on integrating it to ring drawing...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 498
diff changeset
193 template<class T> inline bool isZero (T a)
cad8cdc42a64 Finally got the ringfinder working! Working on integrating it to ring drawing...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 498
diff changeset
194 { return abs<T> (a) < 0.0001;
cad8cdc42a64 Finally got the ringfinder working! Working on integrating it to ring drawing...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 498
diff changeset
195 }
cad8cdc42a64 Finally got the ringfinder working! Working on integrating it to ring drawing...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 498
diff changeset
196
cad8cdc42a64 Finally got the ringfinder working! Working on integrating it to ring drawing...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 498
diff changeset
197 template<class T> inline bool isInteger (T a)
cad8cdc42a64 Finally got the ringfinder working! Working on integrating it to ring drawing...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 498
diff changeset
198 { return isZero (a - (int) a);
cad8cdc42a64 Finally got the ringfinder working! Working on integrating it to ring drawing...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 498
diff changeset
199 }
cad8cdc42a64 Finally got the ringfinder working! Working on integrating it to ring drawing...
Santeri Piippo <crimsondusk64@gmail.com>
parents: 498
diff changeset
200
503
bebe09014dd6 removed the List class in favor of QList
Santeri Piippo <crimsondusk64@gmail.com>
parents: 501
diff changeset
201 template<class T> void removeDuplicates (QList<T>& a)
bebe09014dd6 removed the List class in favor of QList
Santeri Piippo <crimsondusk64@gmail.com>
parents: 501
diff changeset
202 { std::sort (a.begin(), a.end());
539
72ad83a67165 - upgraded the PROPERTY macro, resulting in a major code refactor
Santeri Piippo <crimsondusk64@gmail.com>
parents: 538
diff changeset
203 a.erase (std::unique (a.begin(), a.end()), a.end());
503
bebe09014dd6 removed the List class in favor of QList
Santeri Piippo <crimsondusk64@gmail.com>
parents: 501
diff changeset
204 }
bebe09014dd6 removed the List class in favor of QList
Santeri Piippo <crimsondusk64@gmail.com>
parents: 501
diff changeset
205
538
2f85d4d286e5 - ensured header files' guards start with LDFORGE_
Santeri Piippo <crimsondusk64@gmail.com>
parents: 513
diff changeset
206 #endif // LDFORGE_MISC_H

mercurial