src/misc/RingFinder.h

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

mercurial