1. Peter Shinners
  2. nrnr

Source

nrnr / test.c

Diff from to

File test.c

  • Ignore whitespace
 #include <time.h>
 
 
-#define DOCHECKS 0
+#define DOCHECKS 1
 
 
 float GetTime(void);
     // Create random points
 
     srand(1234);
-    size_t numPoints = 10000000;
+    size_t numPoints = 180;
     start = GetTime();
     float* points = (float*)malloc(sizeof(float) * 3 * numPoints);
 	for(size_t i=0; i<numPoints; i++) {
 		p[0] = ((float)rand() / RAND_MAX) * 200.0 - 100.0;
 		p[1] = ((float)rand() / RAND_MAX) * 200.0 - 100.0;
 		p[2] = ((float)rand() / RAND_MAX) * 200.0 - 100.0;
-		p[3] = ((float)rand() / RAND_MAX) * 200.0 - 100.0;
         //printf("  pt %zu: %.1f %.1f %.1f\n",i, p[0], p[1], p[2]);
     }
 	//printf("Create random points (%zu): %.3f sec\n", numPoints, GetTime() - start);
 	printf("Create neighborhood: %.3f sec\n", GetTime() - start);
 
     // Search block
-
     start = GetTime();
     float minPos[3] = {-40.0f,-20.0f,-60.0f};
     float maxPos[3] = { 40.0,  60.0f, 20.0f};
-    //printf("Searching: %.1f - %.1f,  %.1f - %.1f, %.1f - %.1f\n", minPos[0], maxPos[0], minPos[1], maxPos[1], minPos[2],maxPos[2]);
+    printf("Searching: %.1f - %.1f,  %.1f - %.1f, %.1f - %.1f\n", minPos[0], maxPos[0], minPos[1], maxPos[1], minPos[2],maxPos[2]);
 
     size_t* results;
     size_t count = NrNrSearchBlock(hood, &results, minPos, maxPos);
     printf("Search complete %zu: %.3f sec\n", count, GetTime() - start);
 
-#if 0
+#if 1
 for(size_t z = 0; z < count; ++z) {
     float* pos = points + results[z] * 3;
     printf("  found %zu: %.1f %.1f %.1f\n", results[z], pos[0], pos[1], pos[2]);
     // Cleanup
 
     start = GetTime();
-    free(points);
     results = NrNrFreeResults(results);
+
+    free(points);
     hood = NrNrFreeNeighborhood(hood);
     printf("Cleanup: %.3f sec\n", GetTime() - start);
 
 
 
 void CheckSearch(struct NrNrHood* hood, size_t numResults, const size_t* results, const float* minimum, const float* maximum) {
+    int foundError = 0;
     for (size_t i = 0; i < hood->numPoints; ++i) {
         const float* pos = hood->points + i * hood->dimensions;
         int inside = 1;
             }
         }
         if (inside && !inresults) {
-            printf("Error with results, points should be inside: index=%zu, %.2f %.2f %.2f\n", i,
+            printf("Error with results, points should be inside: index=%zu, %.1f %.1f %.1f\n", i,
                         hood->points[i * hood->dimensions], hood->points[i * hood->dimensions + 1], hood->points[i * hood->dimensions + 2]);
-            exit(1);
+            foundError = 1;
         } else if (!inside && inresults) {
-            printf("Error with results, points should not be inside: index=%zu, %.2f %.2f %.2f\n", i,
+            printf("Error with results, points should not be inside: index=%zu, %.1f %.1f %.1f\n", i,
                         hood->points[i * hood->dimensions], hood->points[i * hood->dimensions + 1], hood->points[i * hood->dimensions + 2]);
-            exit(1);
+            foundError = 1;
         }
     }
+    if (foundError) {
+        exit(1);
+    }
 }