25 // RingFinder |
25 // RingFinder |
26 // |
26 // |
27 // Provides an algorithm for finding a solution of rings between radii r0 and r1. |
27 // Provides an algorithm for finding a solution of rings between radii r0 and r1. |
28 // ============================================================================= |
28 // ============================================================================= |
29 class RingFinder |
29 class RingFinder |
30 { public: |
30 { |
|
31 public: |
31 struct Component |
32 struct Component |
32 { int num; |
33 { |
|
34 int num; |
33 double scale; |
35 double scale; |
34 }; |
36 }; |
35 |
37 |
36 class Solution |
38 class Solution |
37 { public: |
39 { |
|
40 public: |
38 // Components of this solution |
41 // Components of this solution |
39 inline const QVector<Component>& getComponents() const |
42 inline const QVector<Component>& getComponents() const |
40 { return m_components; |
43 { |
|
44 return m_components; |
41 } |
45 } |
42 |
46 |
43 // Add a component to this solution |
47 // Add a component to this solution |
44 inline void addComponent (const Component& a) |
48 inline void addComponent (const Component& a) |
45 { m_components.push_back (a); |
49 { |
|
50 m_components.push_back (a); |
46 } |
51 } |
47 |
52 |
48 // Compare solutions |
53 // Compare solutions |
49 bool operator> (const Solution& other) const; |
54 bool operator> (const Solution& other) const; |
50 |
55 |
54 |
59 |
55 RingFinder() {} |
60 RingFinder() {} |
56 bool findRings (double r0, double r1); |
61 bool findRings (double r0, double r1); |
57 |
62 |
58 inline const Solution* bestSolution() |
63 inline const Solution* bestSolution() |
59 { return m_bestSolution; |
64 { |
|
65 return m_bestSolution; |
60 } |
66 } |
61 |
67 |
62 inline const QVector<Solution>& allSolutions() const |
68 inline const QVector<Solution>& allSolutions() const |
63 { return m_solutions; |
69 { |
|
70 return m_solutions; |
64 } |
71 } |
65 |
72 |
66 inline bool operator() (double r0, double r1) |
73 inline bool operator() (double r0, double r1) |
67 { return findRings (r0, r1); |
74 { |
|
75 return findRings (r0, r1); |
68 } |
76 } |
69 |
77 |
70 private: |
78 private: |
71 QVector<Solution> m_solutions; |
79 QVector<Solution> m_solutions; |
72 const Solution* m_bestSolution; |
80 const Solution* m_bestSolution; |