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); |
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 } |