Jump to content

Total circles area: Difference between revisions

m
→‎{{header|C}}: reduce unnecessary comparisons
m (→‎{{header|C}}: note to self: don't monkey around with code while submitting)
m (→‎{{header|C}}: reduce unnecessary comparisons)
Line 203:
typedef struct { F x0, x1; } sect_t;
sect_t sect[sizeof(circles) / sizeof(circle)];
inline void swap_s(int i, int j) {
sect_t ss;
ss = sect[i], sect[i] = sect[j], sect[j] = ss;
}
 
F spans(circle *c, int n_circs, F ymin, F step, F ymax)
Line 208 ⟶ 212:
F y, total = 0;
int i, j, n, row = 1 + ceil((ymax - ymin) / step);
 
circle cc;
inline void swap_c(int i, int j) {
sect_t ss;
circle cc;
cc = c[i], c[i] = c[j], c[j] = cc;
}
 
while (row--) {
Line 215 ⟶ 222:
 
for (n = n_circs, i = 0; i < n; ) {
if (y <= c[i].y0 || y >= c[i].y1) ++i;
ccelse =if c[i], c[i](y <= c[--ni], c[n] =.y0) cc;{
swap_c(i, --n_circs);
else {
--n;
} else {
F dx = sqrt(c[i].r2 - sq(y - c[i].y));
sect[i].x0 = c[i].x - dx;
Line 231 ⟶ 240:
for (j = 0; j < i; j++)
if (sect[j].x0 > sect[j+1].x0) {
ss = sect[swap_s(j], sect[j] = sect[j+1], sect[j+1] = ss);
cc = c[swap_c(j], c[j] = c[j+1], c[j+1] = cc);
swapped = 1;
}
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.