# include # include # include using namespace std; # include "hilbert_curve.hpp" int main ( ); void d2xy_test ( ); void rot_test ( ); void xy2d_test ( ); void timestamp ( ); //****************************************************************************80 int main ( ) //****************************************************************************80 // // Purpose: // // hilbert_curve_test() tests hilbert_curve(). // // Licensing: // // This code is distributed under the MIT license. // // Modified: // // 02 January 2016 // // Author: // // John Burkardt // { timestamp ( ); cout << "\n"; cout << "hilbert_curve_test():\n"; cout << " C++ version\n"; cout << " Test HILBERT_CURVE().\n"; d2xy_test ( ); rot_test ( ); xy2d_test ( ); // // Terminate. // cout << "\n"; cout << "HILBERT_CURVE_TEST():\n"; cout << " Normal end of execution.\n"; cout << "\n"; timestamp ( ); return 0; } //****************************************************************************80 void d2xy_test ( ) //****************************************************************************80 // // Purpose: // // d2xy_test tests d2xy. // // Licensing: // // This code is distributed under the MIT license. // // Modified: // // 24 December 2015 // // Author: // // John Burkardt // { int d; int m; int n; int x; int y; cout << "\n"; cout << "d2xy_test:\n"; cout << " d2xy converts a Hilbert linear D coordinate to an (X,Y) 2D coordinate.\n"; m = 3; n = i4_power ( 2, m ); cout << "\n"; cout << " D X Y\n"; cout << "\n"; for ( d = 0; d < n * n; d++ ) { d2xy ( m, d, x, y ); cout << " " << setw(3) << d << " " << setw(3) << x << " " << setw(3) << y << "\n"; } return; } //****************************************************************************80 void rot_test ( ) //****************************************************************************80 // // Purpose: // // rot_test() tests rot(). // // Licensing: // // This code is distributed under the MIT license. // // Modified: // // 02 January 2016 // // Author: // // John Burkardt // { int m; int n; int rx; int ry; int x; int x0; int x1; int y; int y0; int y1; cout << "\n"; cout << "rot_test():\n"; cout << " rot() rotates and flips a quadrant appropriately.\n"; cout << "\n"; cout << " X Y X0 Y0 X1 Y1\n"; cout << "\n"; m = 3; n = i4_power ( 2, m ); ry = 0; for ( y = 0; y < 8; y++ ) { for ( x = 0; x < 8; x++ ) { rx = 0; x0 = x; y0 = y; rot ( n, x0, y0, rx, ry ); rx = 1; x1 = x; y1 = y; rot ( n, x1, y1, rx, ry ); cout << " " << setw(2) << x << " " << setw(2) << y << " " << setw(2) << x0 << " " << setw(2) << y0 << " " << setw(2) << x1 << " " << setw(2) << y1 << "\n"; } } return; } //****************************************************************************80 void xy2d_test ( ) //****************************************************************************80 // // Purpose: // // xy2d_test() tests xy2d(). // // Licensing: // // This code is distributed under the MIT license. // // Modified: // // 24 December 2015 // // Author: // // John Burkardt // { int d; int m; int n; int x; int y; cout << "\n"; cout << "xy2d_test():\n"; cout << " xy2d() converts an (X,Y) 2D coordinate to \n"; cout << " a Hilbert linear D coordinate.\n"; m = 3; n = i4_power ( 2, m ); cout << "\n"; cout << " "; for ( x = 0; x < n; x++ ) { cout << setw(3) << x; } cout << "\n"; cout << "\n"; for ( y = n - 1; 0 <= y; y-- ) { cout << " " << setw(3) << y << ": "; for ( x = 0; x < n; x++ ) { d = xy2d ( m, x, y ); cout << setw(3) << d; } cout << "\n"; } return; } //****************************************************************************80 void timestamp ( ) //****************************************************************************80 // // Purpose: // // timestamp() prints the current YMDHMS date as a time stamp. // // Example: // // 31 May 2001 09:45:54 AM // // Licensing: // // This code is distributed under the MIT license. // // Modified: // // 08 July 2009 // // Author: // // John Burkardt // { # define TIME_SIZE 40 static char time_buffer[TIME_SIZE]; const struct std::tm *tm_ptr; std::time_t now; now = std::time ( NULL ); tm_ptr = std::localtime ( &now ); std::strftime ( time_buffer, TIME_SIZE, "%d %B %Y %I:%M:%S %p", tm_ptr ); std::cout << time_buffer << "\n"; return; # undef TIME_SIZE }