mirror of
https://github.com/BelfrySCAD/BOSL2.git
synced 2025-01-01 09:49:45 +00:00
commit
76eb822aad
10 changed files with 21 additions and 155 deletions
15
common.scad
15
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
|
||||
|
||||
|
||||
|
|
126
errors.scad
126
errors.scad
|
@ -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 <BOSL2/std.scad>
|
||||
// ```
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
|
||||
// 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("<p style=\"background-color: #ffb0b0\"><b>", pfx, ":</b> ", msg, "</p>"));
|
||||
}
|
||||
|
||||
function echo_error(msg, pfx="ERROR") =
|
||||
echo(str("<p style=\"background-color: #ffb0b0\"><b>", pfx, ":</b> ", msg, "</p>"));
|
||||
|
||||
|
||||
// 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("<p style=\"background-color: #ffffb0\"><b>", pfx, ":</b> ", msg, "</p>"));
|
||||
}
|
||||
|
||||
function echo_warning(msg, pfx="WARNING") =
|
||||
echo(str("<p style=\"background-color: #ffffb0\"><b>", pfx, ":</b> ", msg, "</p>"));
|
||||
|
||||
|
||||
// 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(
|
||||
"`<code>", name, "</code>` is deprecated and should not be used.",
|
||||
is_undef(suggest)? "" : str(
|
||||
" You should use `<code>", suggest, "</code>` instead."
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
function deprecate(name, suggest=undef) =
|
||||
echo_warning(pfx="DEPRECATED",
|
||||
str(
|
||||
"`<code>", name, "</code>` is deprecated and should not be used.",
|
||||
is_undef(suggest)? "" : str(
|
||||
" You should use `<code>", suggest, "</code>` 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 `<code>", name, "</code>`, ",
|
||||
"the argument `<code>", arg, "</code>` ",
|
||||
"is deprecated and should not be used.",
|
||||
is_undef(suggest)? "" : str(
|
||||
" You should use `<code>", suggest, "</code>` instead."
|
||||
)
|
||||
));
|
||||
}
|
||||
|
||||
function deprecate_argument(name, arg, suggest=undef) =
|
||||
echo_warning(pfx="DEPRECATED ARG", str(
|
||||
"In `<code>", name, "</code>`, ",
|
||||
"the argument `<code>", arg, "</code>` ",
|
||||
"is deprecated and should not be used.",
|
||||
is_undef(suggest)? "" : str(
|
||||
" You should use `<code>", suggest, "</code>` instead."
|
||||
)
|
||||
));
|
||||
|
||||
|
||||
|
||||
// vim: expandtab tabstop=4 shiftwidth=4 softtabstop=4 nowrap
|
11
math.scad
11
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);
|
||||
|
|
|
@ -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"));
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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)"
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
1
std.scad
1
std.scad
|
@ -14,7 +14,6 @@ include <version.scad>
|
|||
include <constants.scad>
|
||||
include <edges.scad>
|
||||
include <common.scad>
|
||||
include <errors.scad>
|
||||
include <arrays.scad>
|
||||
include <strings.scad>
|
||||
include <vnf.scad>
|
||||
|
|
|
@ -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
|
|
@ -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() {
|
||||
|
|
Loading…
Reference in a new issue