91 // |
92 // |
92 // Provides an algorithm for finding a solution of rings between radii r0 and r1. |
93 // Provides an algorithm for finding a solution of rings between radii r0 and r1. |
93 // ============================================================================= |
94 // ============================================================================= |
94 class RingFinder |
95 class RingFinder |
95 { public: |
96 { public: |
96 struct SolutionComponent |
97 struct Component |
97 { int num; |
98 { int num; |
98 double scale; |
99 double scale; |
99 }; |
100 }; |
100 |
101 |
101 typedef QList<SolutionComponent> SolutionType; |
102 class Solution |
|
103 { public: |
|
104 // Components of this solution |
|
105 inline const QVector<Component>& components() const |
|
106 { return m_components; |
|
107 } |
|
108 |
|
109 // Add a component to this solution |
|
110 void addComponent (const Component& a) |
|
111 { m_components.push_back (a); |
|
112 } |
|
113 |
|
114 // Compare solutions |
|
115 bool operator> (const Solution& other) const; |
|
116 |
|
117 private: |
|
118 QVector<Component> m_components; |
|
119 }; |
102 |
120 |
103 RingFinder() {} |
121 RingFinder() {} |
104 bool findRings (double r0, double r1); |
122 bool findRings (double r0, double r1); |
105 |
123 |
106 inline const SolutionType& solution() |
124 inline const Solution* bestSolution() |
107 { return m_solution; |
125 { return m_bestSolution; |
|
126 } |
|
127 |
|
128 inline const QVector<Solution>& allSolutions() const |
|
129 { return m_solutions; |
108 } |
130 } |
109 |
131 |
110 inline bool operator() (double r0, double r1) |
132 inline bool operator() (double r0, double r1) |
111 { return findRings (r0, r1); |
133 { return findRings (r0, r1); |
112 } |
134 } |
113 |
135 |
114 private: |
136 private: |
115 SolutionType m_solution; |
137 QVector<Solution> m_solutions; |
|
138 const Solution* m_bestSolution; |
|
139 int m_stack; |
116 |
140 |
117 bool findRingsRecursor (double r0, double r1); |
141 bool findRingsRecursor (double r0, double r1, Solution& currentSolution); |
118 }; |
142 }; |
119 |
143 |
120 extern RingFinder g_RingFinder; |
144 extern RingFinder g_RingFinder; |
121 |
145 |
122 // ============================================================================= |
146 // ============================================================================= |