Hilbert curve: Difference between revisions

m (→‎{{header|Sidef}}: updated code: use round() instead of int())
Line 197:
y = (n - 1) - y;
}
 
std::swap(x, y);
}
}
 
int calcD(int n) {
bool rx, ry;
int d = 0;
for (int s = n >> 1; s > 0; s >>= 1) {
rx = ((x & s) != 0);
ry = ((y & s) != 0);
d += s * s * ((rx ? 3 : 0) ^ (ry ? 1 : 0));
rot(s, rx, ry);
}
return d;
}
 
friend std::ostream &operator<<(std::ostream &, const Point &);
};
 
std::ostream &operator<<(std::ostream &out, const Point &p) {
return out << '(' << p.x << ", " << p.y << ')';
}
 
Point fromD(int n, int d) {
Line 290 ⟶ 271:
std::cout << '\n';
}
 
return 0;
}</lang>
Anonymous user