# include # include # include # include "hilbert_curve.h" int main ( ); void d2xy_test ( ); void rot_test ( ); void xy2d_test ( ); void timestamp ( ); /******************************************************************************/ int main ( ) /******************************************************************************/ /* Purpose: hilbert_curve_test() tests hilbert_curve(). Licensing: This code is distributed under the MIT license. Modified: 02 January 2016 Author: John Burkardt */ { timestamp ( ); printf ( "\n" ); printf ( "hilbert_curve_test():\n" ); printf ( " C version\n" ); printf ( " Test hilbert_curve().\n" ); d2xy_test ( ); rot_test ( ); xy2d_test ( ); /* Terminate. */ printf ( "\n" ); printf ( "hilbert_curve_test():\n" ); printf ( " Normal end of execution.\n" ); printf ( "\n" ); timestamp ( ); return 0; } /******************************************************************************/ void d2xy_test ( ) /******************************************************************************/ /* Purpose: d2xy_test() tests d2xy(). Licensing: This code is distributed under the MIT license. Modified: 05 December 2015 Author: John Burkardt */ { int d; int m; int n; int x; int y; printf ( "\n" ); printf ( "d2xy_test():\n" ); printf ( " d2xy() converts a Hilbert linear D coordinate\n" ); printf ( " to an (X,Y) 2D coordinate.\n" ); m = 3; n = i4_power ( 2, m ); printf ( "\n" ); printf ( " D X Y\n" ); printf ( "\n" ); for ( d = 0; d < n * n; d++ ) { d2xy ( m, d, &x, &y ); printf ( " %3d %3d %3d\n", d, x, y ); } return; } /******************************************************************************/ void rot_test ( ) /******************************************************************************/ /* 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; printf ( "\n" ); printf ( "rot_test():\n" ); printf ( " rot() rotates and flips a quadrant appropriately.\n" ); printf ( "\n" ); printf ( " X Y X0 Y0 X1 Y1\n" ); printf ( "\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 ); printf ( " %2d %2d %2d %2d %2d %2d\n", x, y, x0, y0, x1, y1 ); } } return; } /******************************************************************************/ void xy2d_test ( ) /******************************************************************************/ /* Purpose: xy2d_test() tests xy2d(). Licensing: This code is distributed under the MIT license. Modified: 05 December 2015 Author: John Burkardt */ { int d; int m; int n; int x; int y; printf ( "\n" ); printf ( "xy2d_test():\n" ); printf ( " xy2d() converts an (X,Y) 2D coordinate to a Hilbert \n" ); printf ( " linear D coordinate.\n" ); m = 3; n = i4_power ( 2, m ); printf ( "\n" ); printf ( " " ); for ( x = 0; x < n; x++ ) { printf ( "%3d", x ); } printf ( "\n" ); printf ( "\n" ); for ( y = n - 1; 0 <= y; y-- ) { printf ( " %3d: ", y ); for ( x = 0; x < n; x++ ) { d = xy2d ( m, x, y ); printf ( "%3d", d ); } printf ( "\n" ); } return; } /******************************************************************************/ void timestamp ( ) /******************************************************************************/ /* Purpose: timestamp() prints the current YMDHMS date as a time stamp. Example: 17 June 2014 09:45:54 AM Licensing: This code is distributed under the MIT license. Modified: 17 June 2014 Author: John Burkardt */ { # define TIME_SIZE 40 static char time_buffer[TIME_SIZE]; const struct tm *tm; time_t now; now = time ( NULL ); tm = localtime ( &now ); strftime ( time_buffer, TIME_SIZE, "%d %B %Y %I:%M:%S %p", tm ); printf ( "%s\n", time_buffer ); return; # undef TIME_SIZE }