From: Scott Worley Date: Sat, 29 Dec 2012 07:34:08 +0000 (-0800) Subject: Warn about NaNs in the output model X-Git-Url: http://git.scottworley.com/nt3d/commitdiff_plain/bc3b43190ac5233013c555c9f027c2e6f77a5a00?ds=sidebyside Warn about NaNs in the output model --- diff --git a/nt3d.js b/nt3d.js index 2876698..33e271b 100644 --- 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";