From 045ea3085a24e22f3236ea049153def018a5a6a8 Mon Sep 17 00:00:00 2001 From: Adrian Mariano Date: Tue, 28 Jul 2020 21:26:35 -0400 Subject: [PATCH] Fixed bugs in same_shape and is_consistent --- common.scad | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/common.scad b/common.scad index 8d0655ac..3f66095e 100644 --- a/common.scad +++ b/common.scad @@ -114,6 +114,11 @@ function is_list_of(list,pattern) = is_list(list) && []==[for(entry=list) if (entry*0 != pattern) entry]; +function _list_pattern(list) = + [for(entry=list) is_list(entry) ? _list_pattern(entry) : 0]; + + + // Function: is_consistent() // Usage: @@ -128,7 +133,7 @@ function is_list_of(list,pattern) = // is_consistent([[3,[3,4,[5]]], [5,[2,9,[9]]]]); // Returns true // is_consistent([[3,[3,4,[5]]], [5,[2,9,9]]]); // Returns false function is_consistent(list) = - is_list(list) && is_list_of(list, list[0]); + is_list(list) && is_list_of(list, _list_pattern(list[0])); // Function: same_shape() @@ -139,7 +144,7 @@ function is_consistent(list) = // Example: // same_shape([3,[4,5]],[7,[3,4]]); // Returns true // same_shape([3,4,5], [7,[3,4]]); // Returns false -function same_shape(a,b) = a*0 == b*0; +function same_shape(a,b) = _list_pattern(a) == b*0; // Section: Handling `undef`s.