Skip to content
Revar Desmera edited this page Mar 31, 2019 · 4 revisions

Library File compat.scad

Backwards Compatability library To use, include this line at the top of your file:

use <compat.scad>

Table of Contents

  1. Functions

  2. Modules


1. Functions

default()

Description: Returns the value given as v if it is not undef. Otherwise, returns the value of dflt.

Argument What it does
v Value to pass through if not undef.
dflt Value to return if v is undef.

is_def()

Description: Returns true if given value is not undef.


is_str()

Description: Given a value, returns true if it is a string.


is_boolean()

Description: Given a value, returns true if it is a boolean.


is_scalar()

Description: Given a value, returns true if it is a scalar number.


is_array()

Description: Given a value, returns true if it is an array/list/vector.


get_radius()

Description: Given various radii and diameters, returns the most specific radius. If a diameter is most specific, returns half its value, giving the radius. If no radii or diameters are defined, returns the value of dflt. Value specificity order is r1, d1, r, d, then dflt

Argument What it does
r1 Most specific radius.
d1 Most specific Diameter.
r Most general radius.
d Most general diameter.
dflt Value to return if all other values given are undef.

Len()

Description: Given an array, returns number of items in array. Otherwise returns undef.


remove_undefs()

Description: Removes all undefs from a list.


first_defined()

Description: Returns the first item in the list that is not undef. If all items are undef, or list is empty, returns undef.


any_defined()

Description: Returns true if any item in the given array is not undef.


scalar_vec3()

Usage:

  • scalar_vec3(v, [dflt]);

Description: If v is a scalar, and dflt==undef, returns [v, v, v]. If v is a scalar, and dflt!=undef, returns [v, dflt, dflt]. If v is a vector, returns the first 3 items, with any missing values replaced by dflt. If v is undef, returns undef.

Argument What it does
v Value to return vector from.
dflt Default value to set empty vector parts from.

f_echo()

Description: If possible, echo a message from a function.


2. Modules

assert_in_list()

Usage:

  • assert_in_list(argname, val, l, [idx]);

Description: Emulates the newer OpenSCAD assert() with an in_list() test. You can also use this as a function call from a function.

Argument What it does
argname The name of the argument value being tested.
val The value to test if it exists in the list.
l The list to look for val in.
idx If given, and l is a list of lists, look for val in the given index of each sublist.

assertion()

Usage:

  • assertion(succ, msg);

Description: Backwards compatible assert() semi-replacement. If succ is false, then print an error with msg. You can also use this as a function call from a function.

Argument What it does
succ If this is false, trigger the assertion.
msg The message to emit if succ is false.

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.

Argument What it does
msg The message to print.
pfx The prefix to print before msg. Default: ERROR

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.

Argument What it does
msg The message to print.
pfx The prefix to print before msg. Default: WARNING

deprecate()

Usage:

  • deprecate(name, [suggest]);

Description: Show module deprecation warnings. You can also use this as a function call from a function.

Argument What it does
name The name of the module that is deprecated.
suggest If given, the module to recommend using instead.

deprecate_argument()

Usage:

  • deprecate(name, arg, [suggest]);

Description: Show argument deprecation warnings. You can also use this as a function call from a function.

Argument What it does
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.