]> git.scottworley.com Git - nt3d/blobdiff - nt3d.js
Warn about NaNs in the output model
[nt3d] / nt3d.js
diff --git a/nt3d.js b/nt3d.js
index 28766983fe33341b262ee572f4a09fc01d917d4c..33e271b406648189e2642000cd2785e6ae208681 100644 (file)
--- a/nt3d.js
+++ b/nt3d.js
@@ -318,10 +318,33 @@ nt3d = {
 
                // Run user_function
                this.points = this.user_function.apply(null, params);
+
+               // Do a little validation
                if (this.points.length % 3 != 0) {
                        alert("Points list length not divisble by 3!");
                }
                var n = this.points.length / 3;
+               var nan_count = 0;
+               var nan_point_count = 0;
+               var nan_face_count = 0;
+               for (var i = 0; i < n; i++) {
+                       var nan_in_face = false;
+                       for (var j = 0; j < 3; j++) {
+                               var nan_in_point = false;
+                               for (var k = 0; k < 3; k++) {
+                                       if (isNaN(this.points[i*3+j][k])) {
+                                               nan_count++;
+                                               nan_in_point = true;
+                                               nan_in_face = true;
+                                       }
+                               }
+                               if (nan_in_point) nan_point_count ++;
+                       }
+                       if (nan_in_face) nan_face_count ++;
+               }
+               if (nan_count != 0) {
+                       alert(nan_count + " NaNs in " + nan_point_count + " points in " + nan_face_count + " faces.");
+               }
 
                // Make STL
                this.stl = "solid " + this.user_function.name + "\n";