src/misc.h

changeset 538
2f85d4d286e5
parent 513
29eb671b34f6
child 539
72ad83a67165
equal deleted inserted replaced
537:1add0ee96fb3 538:2f85d4d286e5
14 * 14 *
15 * You should have received a copy of the GNU General Public License 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/>. 16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */ 17 */
18 18
19 #ifndef MISC_H 19 #ifndef LDFORGE_MISC_H
20 #define MISC_H 20 #define LDFORGE_MISC_H
21 21
22 #include <QVector> 22 #include <QVector>
23 #include "config.h" 23 #include "config.h"
24 #include "common.h" 24 #include "common.h"
25 #include "types.h" 25 #include "types.h"
87 // 87 //
88 // Provides an algorithm for finding a solution of rings between radii r0 and r1. 88 // Provides an algorithm for finding a solution of rings between radii r0 and r1.
89 // ============================================================================= 89 // =============================================================================
90 class RingFinder 90 class RingFinder
91 { public: 91 { public:
92 struct Component 92 struct Component
93 { int num; 93 { int num;
94 double scale; 94 double scale;
95 }; 95 };
96 96
97 class Solution 97 class Solution
98 { public: 98 { public:
99 // Components of this solution 99 // Components of this solution
100 inline const QVector<Component>& components() const 100 inline const QVector<Component>& getComponents() const
101 { return m_components; 101 { return m_components;
102 } 102 }
103 103
104 // Add a component to this solution 104 // Add a component to this solution
105 void addComponent (const Component& a) 105 inline void addComponent (const Component& a)
106 { m_components.push_back (a); 106 { m_components.push_back (a);
107 } 107 }
108 108
109 // Compare solutions 109 // Compare solutions
110 bool operator> (const Solution& other) const; 110 bool operator> (const Solution& other) const;
111
112 private:
113 QVector<Component> m_components;
114 };
115
116 RingFinder() {}
117 bool findRings (double r0, double r1);
118
119 inline const Solution* bestSolution()
120 { return m_bestSolution;
121 }
122
123 inline const QVector<Solution>& allSolutions() const
124 { return m_solutions;
125 }
126
127 inline bool operator() (double r0, double r1)
128 { return findRings (r0, r1);
129 }
111 130
112 private: 131 private:
113 QVector<Component> m_components; 132 QVector<Solution> m_solutions;
114 }; 133 const Solution* m_bestSolution;
134 int m_stack;
115 135
116 RingFinder() {} 136 bool findRingsRecursor (double r0, double r1, Solution& currentSolution);
117 bool findRings (double r0, double r1);
118
119 inline const Solution* bestSolution()
120 { return m_bestSolution;
121 }
122
123 inline const QVector<Solution>& allSolutions() const
124 { return m_solutions;
125 }
126
127 inline bool operator() (double r0, double r1)
128 { return findRings (r0, r1);
129 }
130
131 private:
132 QVector<Solution> m_solutions;
133 const Solution* m_bestSolution;
134 int m_stack;
135
136 bool findRingsRecursor (double r0, double r1, Solution& currentSolution);
137 }; 137 };
138 138
139 extern RingFinder g_RingFinder; 139 extern RingFinder g_RingFinder;
140 140
141 // ============================================================================= 141 // =============================================================================
184 { std::sort (a.begin(), a.end()); 184 { std::sort (a.begin(), a.end());
185 typename QList<T>::iterator pos = std::unique (a.begin(), a.end()); 185 typename QList<T>::iterator pos = std::unique (a.begin(), a.end());
186 a.erase (pos, a.end()); 186 a.erase (pos, a.end());
187 } 187 }
188 188
189 #endif // MISC_H 189 #endif // LDFORGE_MISC_H

mercurial