diff --git a/common.scad b/common.scad index f0be6c1..d8941ee 100644 --- a/common.scad +++ b/common.scad @@ -148,7 +148,7 @@ function _list_pattern(list) = // 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_pattern(list[0])); + /*is_list(list) &&*/ is_list_of(list, _list_pattern(list[0])); //Internal function @@ -346,6 +346,19 @@ function segs(r) = +// Module: no_children() +// Usage: +// no_children($children); +// Description: +// Assert that the calling module does not support children. Prints an error message to this effect and fails if children are present, +// as indicated by its argument. +// Arguments: +// $children = number of children the module has. +module no_children(count) { + assert(count==0, str("Module ",parent_module(1),"() does not support child modules")); +} + + // Section: Testing Helpers diff --git a/errors.scad b/errors.scad deleted file mode 100644 index 8c174d9..0000000 --- a/errors.scad +++ /dev/null @@ -1,126 +0,0 @@ -////////////////////////////////////////////////////////////////////// -// LibFile: errors.scad -// Functions and modules to facilitate error reporting. -// To use, include this line at the top of your file: -// ``` -// use -// ``` -////////////////////////////////////////////////////////////////////// - - - -// Section: Warnings and Errors - - -// Module: no_children() -// Usage: -// no_children($children); -// Description: -// Assert that the calling module does not support children. Prints an error message to this effect and fails if children are present, -// as indicated by its argument. -// Arguments: -// $children = number of children the module has. -module no_children(count) { - assert(count==0, str("Module ",parent_module(1),"() does not support child modules")); -} - - -// Function&Module: echo_error() -// Usage: -// echo_error(msg, [pfx]); -// Description: -// Emulates printing of an error message. The text will be shaded red. -// You can also use this as a function call from a function. -// Arguments: -// msg = The message to print. -// pfx = The prefix to print before `msg`. Default: `ERROR` -module echo_error(msg, pfx="ERROR") { - echo(str("

", pfx, ": ", msg, "

")); -} - -function echo_error(msg, pfx="ERROR") = - echo(str("

", pfx, ": ", msg, "

")); - - -// Function&Module: echo_warning() -// Usage: -// echo_warning(msg, [pfx]); -// Description: -// Emulates printing of a warning message. The text will be shaded yellow. -// You can also use this as a function call from a function. -// Arguments: -// msg = The message to print. -// pfx = The prefix to print before `msg`. Default: `WARNING` -module echo_warning(msg, pfx="WARNING") { - echo(str("

", pfx, ": ", msg, "

")); -} - -function echo_warning(msg, pfx="WARNING") = - echo(str("

", pfx, ": ", msg, "

")); - - -// Function&Module: deprecate() -// Usage: -// deprecate(name, [suggest]); -// Description: -// Show module deprecation warnings. -// You can also use this as a function call from a function. -// Arguments: -// name = The name of the module that is deprecated. -// suggest = If given, the module to recommend using instead. -module deprecate(name, suggest=undef) { - echo_warning(pfx="DEPRECATED", - str( - "`", name, "` is deprecated and should not be used.", - is_undef(suggest)? "" : str( - " You should use `", suggest, "` instead." - ) - ) - ); -} - -function deprecate(name, suggest=undef) = - echo_warning(pfx="DEPRECATED", - str( - "`", name, "` is deprecated and should not be used.", - is_undef(suggest)? "" : str( - " You should use `", suggest, "` instead." - ) - ) - ); - - -// Function&Module: deprecate_argument() -// Usage: -// deprecate(name, arg, [suggest]); -// Description: -// Show argument deprecation warnings. -// You can also use this as a function call from a function. -// Arguments: -// name = The name of the module/function the deprecated argument is used in. -// arg = The name of the deprecated argument. -// suggest = If given, the argument to recommend using instead. -module deprecate_argument(name, arg, suggest=undef) { - echo_warning(pfx="DEPRECATED ARG", str( - "In `", name, "`, ", - "the argument `", arg, "` ", - "is deprecated and should not be used.", - is_undef(suggest)? "" : str( - " You should use `", suggest, "` instead." - ) - )); -} - -function deprecate_argument(name, arg, suggest=undef) = - echo_warning(pfx="DEPRECATED ARG", str( - "In `", name, "`, ", - "the argument `", arg, "` ", - "is deprecated and should not be used.", - is_undef(suggest)? "" : str( - " You should use `", suggest, "` instead." - ) - )); - - - -// vim: expandtab tabstop=4 shiftwidth=4 softtabstop=4 nowrap diff --git a/math.scad b/math.scad index d91ffec..7bc7924 100644 --- a/math.scad +++ b/math.scad @@ -641,17 +641,6 @@ function mean(v) = sum(v)/len(v); -// Function: median() -// Usage: -// x = median(v); -// Description: -// Given a list of numbers or vectors, finds the median value or midpoint. -// If passed a list of vectors, returns the vector of the median of each component. -function median(v) = - is_vector(v) ? (min(v)+max(v))/2 : - is_matrix(v) ? [for(ti=transpose(v)) (min(ti)+max(ti))/2 ] - : assert(false , "Invalid input."); - // Function: convolve() // Usage: // x = convolve(p,q); diff --git a/polyhedra.scad b/polyhedra.scad index b199fe9..e845acd 100644 --- a/polyhedra.scad +++ b/polyhedra.scad @@ -710,7 +710,7 @@ function regular_polyhedron_info( info == "center" ? translation : info == "type" ? entry[class] : info == "name" ? entry[pname] : - echo_warning(str("Unknown info type '",info,"' requested")); + assert(false, str("Unknown info type '",info,"' requested")); diff --git a/regions.scad b/regions.scad index 6169337..fa761f0 100644 --- a/regions.scad +++ b/regions.scad @@ -339,7 +339,7 @@ function region_faces(region, transform, reverse=false, vnf=EMPTY_VNF) = // linear_sweep(orgn,height=20,convexity=16) show_anchors(); module linear_sweep(region, height=1, center, twist=0, scale=1, slices, maxseg, style="default", convexity, anchor_isect=false, anchor, spin=0, orient=UP) { region = is_path(region)? [region] : region; - cp = median(flatten(region)); + cp = mean(pointlist_bounds(flatten(region))); anchor = get_anchor(anchor, center, "origin", "origin"); vnf = linear_sweep( region, height=height, diff --git a/scripts/make_all_docs.sh b/scripts/make_all_docs.sh index ddd9937..fa05079 100755 --- a/scripts/make_all_docs.sh +++ b/scripts/make_all_docs.sh @@ -19,7 +19,7 @@ done if [[ "$FILES" != "" ]]; then PREVIEW_LIBS="$FILES" else - PREVIEW_LIBS="affine arrays attachments beziers bottlecaps common constants coords cubetruss debug distributors edges errors geometry hingesnaps hull involute_gears joiners knurling linear_bearings masks math metric_screws mutators nema_steppers partitions paths phillips_drive polyhedra primitives quaternions queues regions rounding screws shapes shapes2d skin sliders stacks strings structs threading torx_drive transforms triangulation vectors version vnf walls wiring" + PREVIEW_LIBS="affine arrays attachments beziers bottlecaps common constants coords cubetruss debug distributors edges geometry hingesnaps hull involute_gears joiners knurling linear_bearings masks math metric_screws mutators nema_steppers partitions paths phillips_drive polyhedra primitives quaternions queues regions rounding screws shapes shapes2d skin sliders stacks strings structs threading torx_drive transforms triangulation vectors version vnf walls wiring" fi dir="$(basename $PWD)" diff --git a/skin.scad b/skin.scad index 920f4ed..30d8a17 100644 --- a/skin.scad +++ b/skin.scad @@ -1202,7 +1202,7 @@ function path_sweep(shape, path, method="incremental", normal, closed=false, twi let (pathnormal = path_normals(path, tangents, closed)) assert(all_defined(pathnormal),"Natural normal vanishes on your curve, select a different method") let( testnormals = [for(i=[0:len(pathnormal)-1-(closed?1:2)]) pathnormal[i]*select(pathnormal,i+2)], - dummy = min(testnormals) < .5 ? echo_warning("abrupt change in normal direction. Consider a different method") :0 + dummy = min(testnormals) < .5 ? echo("WARNING: ***** Abrupt change in normal direction. Consider a different method *****") :0 ) [for(i=[0:L-(closed?0:1)]) let( rotation = affine_frame_map(x=pathnormal[i%L], z=tangents[i%L]) @@ -1216,7 +1216,7 @@ function path_sweep(shape, path, method="incremental", normal, closed=false, twi end = reindex_polygon(start, apply(transform_list[L],path3d(shape))) ) all([for(i=idx(start)) approx(start[i],end[i])]), - dummy = ends_match ? 0 :echo_warning("The points do not match when closing the model") + dummy = ends_match ? 0 : echo("WARNING: ***** The points do not match when closing the model *****") ) transforms ? transform_list : sweep(shape, transform_list, closed=false, caps=fullcaps); diff --git a/std.scad b/std.scad index 8375fcc..1c2e45e 100644 --- a/std.scad +++ b/std.scad @@ -14,7 +14,6 @@ include include include include -include include include include diff --git a/tests/test_errors.scad b/tests/test_errors.scad deleted file mode 100644 index fffe9eb..0000000 --- a/tests/test_errors.scad +++ /dev/null @@ -1,11 +0,0 @@ -include <../std.scad> - - -// Can't test echo output as yet. Include these for coverage calculations. -module test_echo_error() {} -module test_echo_warning() {} -module test_deprecate() {} -module test_deprecate_argument() {} - - -// vim: expandtab tabstop=4 shiftwidth=4 softtabstop=4 nowrap diff --git a/tests/test_math.scad b/tests/test_math.scad index f1b36b9..e5b1a41 100644 --- a/tests/test_math.scad +++ b/tests/test_math.scad @@ -391,11 +391,13 @@ module test_mean() { } test_mean(); +/* module test_median() { assert_equal(median([2,3,7]), 4.5); assert_equal(median([[1,2,3], [3,4,5], [8,9,10]]), [4.5,5.5,6.5]); } test_median(); +*/ module test_convolve() {