| 322 |
322 |
| 323 bool RingFinder::findRingsRecursor (double r0, double r1) |
323 bool RingFinder::findRingsRecursor (double r0, double r1) |
| 324 { // Find the scale and number of a ring between r1 and r0. |
324 { // Find the scale and number of a ring between r1 and r0. |
| 325 double scale = r1 - r0; |
325 double scale = r1 - r0; |
| 326 double num = r0 / scale; |
326 double num = r0 / scale; |
| 327 print ("r0: %1, r1: %2, scale: %3, num: %4\n", r0, r1, scale, num); |
|
| 328 |
327 |
| 329 // If the ring number is integral, we have found a fitting ring to r0 -> r1! |
328 // If the ring number is integral, we have found a fitting ring to r0 -> r1! |
| 330 if (isInteger (num)) |
329 if (isInteger (num)) |
| 331 { SolutionComponent cmp; |
330 { SolutionComponent cmp; |
| 332 cmp.scale = scale; |
331 cmp.scale = scale; |
| 334 m_solution << cmp; |
333 m_solution << cmp; |
| 335 } |
334 } |
| 336 else |
335 else |
| 337 { // If not, find an intermediate <r> between the radii |
336 { // If not, find an intermediate <r> between the radii |
| 338 double r = ceil (num) * scale; |
337 double r = ceil (num) * scale; |
| 339 print ("\tr: %1\n", r); |
|
| 340 |
338 |
| 341 // If r is the same as r0 or r1, we simply cannot find any rings between |
339 // If r is the same as r0 or r1, we simply cannot find any rings between |
| 342 // r0 and r1. Stop and return failure. |
340 // r0 and r1. Stop and return failure. |
| 343 if (isZero (r0 - r) || isZero (r1 - r)) |
341 if (isZero (r0 - r) || isZero (r1 - r)) |
| 344 { print ("failure!\n"); |
|
| 345 return false; |
342 return false; |
| 346 } |
|
| 347 |
343 |
| 348 // Split this ring into r0 -> r and r -> r1. Recurse to possibly find |
344 // Split this ring into r0 -> r and r -> r1. Recurse to possibly find |
| 349 // the rings for these. If either recurse fails, the entire algorithm |
345 // the rings for these. If either recurse fails, the entire algorithm |
| 350 // fails as well. |
346 // fails as well. |
| 351 if (!findRingsRecursor (r0, r) || !findRingsRecursor (r, r1)) |
347 if (!findRingsRecursor (r0, r) || !findRingsRecursor (r, r1)) |