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 // ============================================================================= |