Sun, 29 Dec 2013 17:03:30 +0200
- when configuration options are default, they need to be removed from the settings
596
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1 | /* |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
2 | * LDForge: LDraw parts authoring CAD |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
3 | * Copyright (C) 2013 Santeri Piippo |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
4 | * |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
5 | * This program is free software: you can redistribute it and/or modify |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
6 | * it under the terms of the GNU General Public License as published by |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
7 | * the Free Software Foundation, either version 3 of the License, or |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
8 | * (at your option) any later version. |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
9 | * |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
10 | * This program is distributed in the hope that it will be useful, |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
13 | * GNU General Public License for more details. |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
14 | * |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
15 | * You should have received a copy of the GNU General Public License |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
17 | */ |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
18 | |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
19 | #ifndef LDFORGE_MISC_RINGFINDER_H |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
20 | #define LDFORGE_MISC_RINGFINDER_H |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
21 | |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
22 | #include "../main.h" |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
23 | |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
24 | // ============================================================================= |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
25 | // RingFinder |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
26 | // |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
27 | // Provides an algorithm for finding a solution of rings between radii r0 and r1. |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
28 | // ============================================================================= |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
29 | class RingFinder |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
30 | { public: |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
31 | struct Component |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
32 | { int num; |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
33 | double scale; |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
34 | }; |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
35 | |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
36 | class Solution |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
37 | { public: |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
38 | // Components of this solution |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
39 | inline const QVector<Component>& getComponents() const |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
40 | { return m_components; |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
41 | } |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
42 | |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
43 | // Add a component to this solution |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
44 | inline void addComponent (const Component& a) |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
45 | { m_components.push_back (a); |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
46 | } |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
47 | |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
48 | // Compare solutions |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
49 | bool operator> (const Solution& other) const; |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
50 | |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
51 | private: |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
52 | QVector<Component> m_components; |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
53 | }; |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
54 | |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
55 | RingFinder() {} |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
56 | bool findRings (double r0, double r1); |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
57 | |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
58 | inline const Solution* bestSolution() |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
59 | { return m_bestSolution; |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
60 | } |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
61 | |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
62 | inline const QVector<Solution>& allSolutions() const |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
63 | { return m_solutions; |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
64 | } |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
65 | |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
66 | inline bool operator() (double r0, double r1) |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
67 | { return findRings (r0, r1); |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
68 | } |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
69 | |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
70 | private: |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
71 | QVector<Solution> m_solutions; |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
72 | const Solution* m_bestSolution; |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
73 | int m_stack; |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
74 | |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
75 | bool findRingsRecursor (double r0, double r1, Solution& currentSolution); |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
76 | }; |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
77 | |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
78 | extern RingFinder g_RingFinder; |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
79 | |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
80 | #endif // LDFORGE_MISC_RINGFINDER_H |