src/ringFinder.cpp

changeset 966
a834e43a57da
parent 958
1dc890c73e01
child 967
eb586d3e1a6a
equal deleted inserted replaced
965:d1b0aa40db91 966:a834e43a57da
34 // Find the scale and number of a ring between r1 and r0. 34 // Find the scale and number of a ring between r1 and r0.
35 double scale = r1 - r0; 35 double scale = r1 - r0;
36 double num = r0 / scale; 36 double num = r0 / scale;
37 37
38 // If the ring number is integral, we have found a fitting ring to r0 -> r1! 38 // If the ring number is integral, we have found a fitting ring to r0 -> r1!
39 if (IsIntegral (num)) 39 if (isInteger (num))
40 { 40 {
41 Component cmp; 41 Component cmp;
42 cmp.scale = scale; 42 cmp.scale = scale;
43 cmp.num = (int) round (num); 43 cmp.num = (int) round (num);
44 currentSolution.addComponent (cmp); 44 currentSolution.addComponent (cmp);
52 } 52 }
53 } 53 }
54 else 54 else
55 { 55 {
56 // Try find solutions by splitting the ring in various positions. 56 // Try find solutions by splitting the ring in various positions.
57 if (IsZero (r1 - r0)) 57 if (isZero (r1 - r0))
58 return false; 58 return false;
59 59
60 double interval; 60 double interval;
61 61
62 // Determine interval. The smaller delta between radii, the more precise 62 // Determine interval. The smaller delta between radii, the more precise
127 // r0=3, r1=7 (scaled up by 2) yields a 2-component solution. We can then 127 // r0=3, r1=7 (scaled up by 2) yields a 2-component solution. We can then
128 // downscale the radii back by dividing the scale fields of the solution 128 // downscale the radii back by dividing the scale fields of the solution
129 // components. 129 // components.
130 double scale = 1.0; 130 double scale = 1.0;
131 131
132 if (not IsZero (scale = r0 - floor (r0)) or not IsZero (scale = r1 - floor (r1))) 132 if (not isZero (scale = r0 - floor (r0)) or not isZero (scale = r1 - floor (r1)))
133 { 133 {
134 double r0f = r0 / scale; 134 double r0f = r0 / scale;
135 double r1f = r1 / scale; 135 double r1f = r1 / scale;
136 136
137 if (IsIntegral (r0f) and IsIntegral (r1f)) 137 if (isInteger (r0f) and isInteger (r1f))
138 { 138 {
139 r0 = r0f; 139 r0 = r0f;
140 r1 = r1f; 140 r1 = r1f;
141 } 141 }
142 // If the numbers are both at most one-decimal fractions, we can use a scale of 10 142 // If the numbers are both at most one-decimal fractions, we can use a scale of 10
143 elif (IsIntegral (r0 * 10) and IsIntegral (r1 * 10)) 143 elif (isInteger (r0 * 10) and isInteger (r1 * 10))
144 { 144 {
145 scale = 0.1; 145 scale = 0.1;
146 r0 *= 10; 146 r0 *= 10;
147 r1 *= 10; 147 r1 *= 10;
148 } 148 }
201 int maxA = 0, 201 int maxA = 0,
202 maxB = 0; 202 maxB = 0;
203 203
204 for (int i = 0; i < getComponents().size(); ++i) 204 for (int i = 0; i < getComponents().size(); ++i)
205 { 205 {
206 maxA = Max (getComponents()[i].num, maxA); 206 maxA = qMax (getComponents()[i].num, maxA);
207 maxB = Max (other->getComponents()[i].num, maxB); 207 maxB = qMax (other->getComponents()[i].num, maxB);
208 } 208 }
209 209
210 if (maxA != maxB) 210 if (maxA != maxB)
211 return maxA < maxB; 211 return maxA < maxB;
212 212

mercurial