src/misc/RingFinder.cc

changeset 690
9e9c52ca955e
parent 648
ed6170728ae4
equal deleted inserted replaced
689:397870c6ed38 690:9e9c52ca955e
20 #include "../Misc.h" 20 #include "../Misc.h"
21 21
22 RingFinder g_RingFinder; 22 RingFinder g_RingFinder;
23 23
24 // ============================================================================= 24 // =============================================================================
25 // This is the main algorithm of the ring finder. It tries to use math to find
26 // the one ring between r0 and r1. If it fails (the ring number is non-integral),
27 // it finds an intermediate radius (ceil of the ring number times scale) and
28 // splits the radius at this point, calling this function again to try find the
29 // rings between r0 - r and r - r1.
30 //
31 // This does not always yield into usable results. If at some point r == r0 or
32 // r == r1, there is no hope of finding the rings, at least with this algorithm,
33 // as it would fall into an infinite recursion.
34 // 25 //
35 bool RingFinder::findRingsRecursor (double r0, double r1, Solution& currentSolution) 26 bool RingFinder::findRingsRecursor (double r0, double r1, Solution& currentSolution)
36 { 27 {
37 // Don't recurse too deep. 28 // Don't recurse too deep.
38 if (m_stack >= 5) 29 if (m_stack >= 5)
131 122
132 for (QVector<Solution>::iterator solp = m_solutions.begin(); solp != m_solutions.end(); ++solp) 123 for (QVector<Solution>::iterator solp = m_solutions.begin(); solp != m_solutions.end(); ++solp)
133 { 124 {
134 const Solution& sol = *solp; 125 const Solution& sol = *solp;
135 126
136 if (m_bestSolution == null || sol.isBetterThan (m_bestSolution)) 127 if (m_bestSolution == null || sol.isSuperiorTo (m_bestSolution))
137 m_bestSolution = &sol; 128 m_bestSolution = &sol;
138 } 129 }
139 130
140 return (m_bestSolution != null); 131 return (m_bestSolution != null);
141 } 132 }
142 133
143 // ============================================================================= 134 // =============================================================================
144 // 135 //
145 bool RingFinder::Solution::isBetterThan (const Solution* other) const 136 bool RingFinder::Solution::isSuperiorTo (const Solution* other) const
146 { 137 {
147 // If this solution has less components than the other one, this one 138 // If this solution has less components than the other one, this one
148 // is definitely better. 139 // is definitely better.
149 if (getComponents().size() < other->getComponents().size()) 140 if (getComponents().size() < other->getComponents().size())
150 return true; 141 return true;

mercurial