Hilbert curve: Difference between revisions

Content added Content deleted
m (→‎{{header|Sidef}}: updated code: use round() instead of int())
Line 197: Line 197:
y = (n - 1) - y;
y = (n - 1) - y;
}
}

std::swap(x, 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) {
Point fromD(int n, int d) {
Line 290: Line 271:
std::cout << '\n';
std::cout << '\n';
}
}

return 0;
return 0;
}</lang>
}</lang>