From 3ea790985381aa433627385388537751ea141140 Mon Sep 17 00:00:00 2001 From: Justin Lin Date: Sat, 10 Jul 2021 09:39:28 +0800 Subject: [PATCH] refactor --- src/__comm__/_face_normal.scad | 3 +++ src/__comm__/_vertex_normals.scad | 6 ++---- src/surface/sf_thickenT.scad | 8 +++----- 3 files changed, 8 insertions(+), 9 deletions(-) create mode 100644 src/__comm__/_face_normal.scad diff --git a/src/__comm__/_face_normal.scad b/src/__comm__/_face_normal.scad new file mode 100644 index 00000000..a72b482e --- /dev/null +++ b/src/__comm__/_face_normal.scad @@ -0,0 +1,3 @@ +function _face_normal(points) = + let(v = cross(points[2] - points[0], points[1] - points[0])) v / norm(v); + \ No newline at end of file diff --git a/src/__comm__/_vertex_normals.scad b/src/__comm__/_vertex_normals.scad index 2d8f0853..c475be86 100644 --- a/src/__comm__/_vertex_normals.scad +++ b/src/__comm__/_vertex_normals.scad @@ -1,4 +1,5 @@ +use <_face_normal.scad>; use <../util/slice.scad>; use <../util/sort.scad>; use <../util/find_index.scad>; @@ -23,9 +24,6 @@ function _connected_faces(faces, leng, leng_pts, cnt_faces, i = 0) = ] ) _connected_faces(faces, leng, leng_pts, n_cnt_faces, i + 1); - -function face_normal(points) = - let(v = cross(points[2] - points[0], points[1] - points[0])) v / norm(v); function _vertex_normals(points, faces) = let( @@ -37,7 +35,7 @@ function _vertex_normals(points, faces) = let( face_normals = [ for(face = cnn_faces[i]) - face_normal([for(i = face) points[i]]) + _face_normal([for(i = face) points[i]]) ] ) sum(face_normals) / len(face_normals) diff --git a/src/surface/sf_thickenT.scad b/src/surface/sf_thickenT.scad index 35dfceb6..fa207f8d 100644 --- a/src/surface/sf_thickenT.scad +++ b/src/surface/sf_thickenT.scad @@ -8,6 +8,7 @@ * **/ +use <../__comm__/_face_normal.scad>; use <../util/sort.scad>; use <../util/find_index.scad>; use <../util/sum.scad>; @@ -40,9 +41,6 @@ module sf_thickenT(points, thickness, triangles = undef, direction = "BOTH") { ) _connected_tris(triangles, leng, leng_pts, n_cnt_tris, i + 1); - function tri_normal(tri) = - let(v = cross(tri[2] - tri[0], tri[1] - tri[0])) v / norm(v); - leng_pts = len(points); cnn_tris = connected_tris(leng_pts, tris); @@ -50,7 +48,7 @@ module sf_thickenT(points, thickness, triangles = undef, direction = "BOTH") { dir_v = direction / norm(direction); mid = sort(points)[leng_pts / 2]; tri = cnn_tris[find_index(points, function(p) p == mid)][0]; - nv = tri_normal([points[tri[0]], points[tri[1]], points[tri[2]]]); + nv = _face_normal([points[tri[0]], points[tri[1]], points[tri[2]]]); pts = [for(p = points) p + dir_v * thickness]; if(nv * dir_v > 0) { @@ -66,7 +64,7 @@ module sf_thickenT(points, thickness, triangles = undef, direction = "BOTH") { let( normals = [ for(tri = cnn_tris[i]) - tri_normal([ + _face_normal([ points[tri[0]], points[tri[1]], points[tri[2]]]