Tue, 07 Jan 2014 08:53:27 +0200
- reformatting
596
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
1 | /* |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
2 | * LDForge: LDraw parts authoring CAD |
600
209e3f1f7b2c
- updated copyright year. Best wishes for 2014!
Santeri Piippo <crimsondusk64@gmail.com>
parents:
597
diff
changeset
|
3 | * Copyright (C) 2013, 2014 Santeri Piippo |
596
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
4 | * |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
5 | * This program is free software: you can redistribute it and/or modify |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
6 | * it under the terms of the GNU General Public License as published by |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
7 | * the Free Software Foundation, either version 3 of the License, or |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
8 | * (at your option) any later version. |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
9 | * |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
10 | * This program is distributed in the hope that it will be useful, |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
13 | * GNU General Public License for more details. |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
14 | * |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
15 | * You should have received a copy of the GNU General Public License |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
17 | */ |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
18 | |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
19 | #include "ringFinder.h" |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
20 | #include "../misc.h" |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
21 | |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
22 | RingFinder g_RingFinder; |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
23 | |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
24 | // ============================================================================= |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
25 | // This is the main algorithm of the ring finder. It tries to use math to find |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
26 | // the one ring between r0 and r1. If it fails (the ring number is non-integral), |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
27 | // it finds an intermediate radius (ceil of the ring number times scale) and |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
28 | // splits the radius at this point, calling this function again to try find the |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
29 | // rings between r0 - r and r - r1. |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
30 | // |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
31 | // This does not always yield into usable results. If at some point r == r0 or |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
32 | // r == r1, there is no hope of finding the rings, at least with this algorithm, |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
33 | // as it would fall into an infinite recursion. |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
34 | // ----------------------------------------------------------------------------- |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
35 | bool RingFinder::findRingsRecursor (double r0, double r1, Solution& currentSolution) |
603 | 36 | { |
37 | // Don't recurse too deep. | |
596
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
38 | if (m_stack >= 5) |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
39 | return false; |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
40 | |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
41 | // Find the scale and number of a ring between r1 and r0. |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
42 | assert (r1 >= r0); |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
43 | double scale = r1 - r0; |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
44 | double num = r0 / scale; |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
45 | |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
46 | // If the ring number is integral, we have found a fitting ring to r0 -> r1! |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
47 | if (isInteger (num)) |
603 | 48 | { |
49 | Component cmp; | |
596
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
50 | cmp.scale = scale; |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
51 | cmp.num = (int) round (num); |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
52 | currentSolution.addComponent (cmp); |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
53 | |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
54 | // If we're still at the first recursion, this is the only |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
55 | // ring and there's nothing left to do. Guess we found the winner. |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
56 | if (m_stack == 0) |
603 | 57 | { |
58 | m_solutions.push_back (currentSolution); | |
596
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
59 | return true; |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
60 | } |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
61 | } |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
62 | else |
603 | 63 | { |
64 | // Try find solutions by splitting the ring in various positions. | |
596
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
65 | if (isZero (r1 - r0)) |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
66 | return false; |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
67 | |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
68 | double interval; |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
69 | |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
70 | // Determine interval. The smaller delta between radii, the more precise |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
71 | // interval should be used. We can't really use a 0.5 increment when |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
72 | // calculating rings to 10 -> 105... that would take ages to process! |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
73 | if (r1 - r0 < 0.5) |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
74 | interval = 0.1; |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
75 | else if (r1 - r0 < 10) |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
76 | interval = 0.5; |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
77 | else if (r1 - r0 < 50) |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
78 | interval = 1; |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
79 | else |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
80 | interval = 5; |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
81 | |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
82 | // Now go through possible splits and try find rings for both segments. |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
83 | for (double r = r0 + interval; r < r1; r += interval) |
603 | 84 | { |
85 | Solution sol = currentSolution; | |
596
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
86 | |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
87 | m_stack++; |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
88 | bool res = findRingsRecursor (r0, r, sol) && findRingsRecursor (r, r1, sol); |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
89 | m_stack--; |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
90 | |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
91 | if (res) |
603 | 92 | { |
93 | // We succeeded in finding radii for this segment. If the stack is 0, this | |
596
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
94 | // is the first recursion to this function. Thus there are no more ring segments |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
95 | // to process and we can add the solution. |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
96 | // |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
97 | // If not, when this function ends, it will be called again with more arguments. |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
98 | // Accept the solution to this segment by setting currentSolution to sol, and |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
99 | // return true to continue processing. |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
100 | if (m_stack == 0) |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
101 | m_solutions.push_back (sol); |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
102 | else |
603 | 103 | { |
104 | currentSolution = sol; | |
596
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
105 | return true; |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
106 | } |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
107 | } |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
108 | } |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
109 | |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
110 | return false; |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
111 | } |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
112 | |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
113 | return true; |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
114 | } |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
115 | |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
116 | // ============================================================================= |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
117 | // Main function. Call this with r0 and r1. If this returns true, use bestSolution |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
118 | // for the solution that was presented. |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
119 | // ----------------------------------------------------------------------------- |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
120 | bool RingFinder::findRings (double r0, double r1) |
603 | 121 | { |
122 | m_solutions.clear(); | |
596
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
123 | Solution sol; |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
124 | |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
125 | // Recurse in and try find solutions. |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
126 | findRingsRecursor (r0, r1, sol); |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
127 | |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
128 | // Compare the solutions and find the best one. The solution class has an operator> |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
129 | // overload to compare two solutions. |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
130 | m_bestSolution = null; |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
131 | |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
132 | for (QVector<Solution>::iterator solp = m_solutions.begin(); solp != m_solutions.end(); ++solp) |
603 | 133 | { |
134 | const Solution& sol = *solp; | |
596
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
135 | |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
136 | if (m_bestSolution == null || sol > *m_bestSolution) |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
137 | m_bestSolution = / |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
138 | } |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
139 | |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
140 | return (m_bestSolution != null); |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
141 | } |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
142 | |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
143 | // ============================================================================= |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
144 | // ----------------------------------------------------------------------------- |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
145 | bool RingFinder::Solution::operator> (const RingFinder::Solution& other) const |
603 | 146 | { |
147 | // If this solution has less components than the other one, this one | |
596
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
148 | // is definitely better. |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
149 | if (getComponents().size() < other.getComponents().size()) |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
150 | return true; |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
151 | |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
152 | // vice versa |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
153 | if (other.getComponents().size() < getComponents().size()) |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
154 | return false; |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
155 | |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
156 | // Calculate the maximum ring number. Since the solutions have equal |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
157 | // ring counts, the solutions with lesser maximum rings should result |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
158 | // in cleaner code and less new primitives, right? |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
159 | int maxA = 0, |
597 | 160 | maxB = 0; |
596
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
161 | |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
162 | for (int i = 0; i < getComponents().size(); ++i) |
603 | 163 | { |
164 | maxA = max (getComponents()[i].num, maxA); | |
597 | 165 | maxB = max (other.getComponents()[i].num, maxB); |
596
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
166 | } |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
167 | |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
168 | if (maxA < maxB) |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
169 | return true; |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
170 | |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
171 | if (maxB < maxA) |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
172 | return false; |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
173 | |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
174 | // Solutions have equal rings and equal maximum ring numbers. Let's |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
175 | // just say this one is better, at this point it does not matter which |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
176 | // one is chosen. |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
177 | return true; |
43c233e91447
- split the ring finder to separate files
Santeri Piippo <crimsondusk64@gmail.com>
parents:
diff
changeset
|
178 | } |