From bc3b43190ac5233013c555c9f027c2e6f77a5a00 Mon Sep 17 00:00:00 2001 From: Scott Worley Date: Fri, 28 Dec 2012 23:34:08 -0800 Subject: [PATCH 1/1] Warn about NaNs in the output model --- nt3d.js | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) 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"; -- 2.44.1