From 7c91654c0bc14665db9db3fbad63dd159041594e Mon Sep 17 00:00:00 2001 From: Dave Pagurek Date: Sat, 25 Nov 2023 10:49:06 -0500 Subject: [PATCH] Fix rounding of values close to 0 when computing smooth normals --- src/webgl/p5.Geometry.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/webgl/p5.Geometry.js b/src/webgl/p5.Geometry.js index 80324f86d3..17f2fffe82 100644 --- a/src/webgl/p5.Geometry.js +++ b/src/webgl/p5.Geometry.js @@ -291,8 +291,10 @@ p5.Geometry = class Geometry { const vertexIndices = {}; const uniqueVertices = []; + const power = Math.pow(10, roundToPrecision); + const rounded = val => Math.round(val * power) / power; const getKey = vert => - `${vert.x.toFixed(roundToPrecision)},${vert.y.toFixed(roundToPrecision)},${vert.z.toFixed(roundToPrecision)}`; + `${rounded(vert.x)},${rounded(vert.y)},${rounded(vert.z)}`; // loop through each vertex and add uniqueVertices for (let i = 0; i < vertices.length; i++) {