Anonymous user
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;
cc = c[i], c[i] = c[j], c[j] = cc;
}
while (row--) {
Line 215 ⟶ 222:
for (n = n_circs, i = 0; i < n; ) {
if (
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) {
swapped = 1;
}
|