omdl  v0.5
OpenSCAD Mechanical Design Library
Variable Tests

Variable property test primitives. More...

+ Collaboration diagram for Variable Tests:

Files

file  primitives.scad
 Mathematical primitive functions.
 

Functions

function is_defined (v)
 Test if a value is defined. More...
 
function not_defined (v)
 Test if a value is not defined. More...
 
function is_empty (v)
 Test if an iterable value is empty. More...
 
function is_scalar (v)
 Test if a value is a single non-iterable value. More...
 
function is_iterable (v)
 Test if a value has multiple parts and is iterable. More...
 
function is_string (v)
 Test if a value is a string. More...
 
function is_vector (v)
 Test if a value is a vector. More...
 
function is_boolean (v)
 Test if a value is a boolean constant. More...
 
function is_integer (v)
 Test if a value is an integer. More...
 
function is_decimal (v)
 Test if a value is a decimal. More...
 
function is_number (v)
 Test if a value is a number. More...
 
function is_range (v)
 Test if a value is a range definition. More...
 
function is_nan (v)
 Test if a numerical value is invalid. More...
 
function is_inf (v)
 Test if a numerical value is infinite. More...
 
function is_even (v)
 Test if a numerical value is even. More...
 
function is_odd (v)
 Test if a numerical value is odd. More...
 
function all_equal (v, cv)
 Test if all elements of a value equal a comparison value. More...
 
function any_equal (v, cv)
 Test if any element of a value equals a comparison value. More...
 
function all_defined (v)
 Test if no element of a value is undefined. More...
 
function any_undefined (v)
 Test if any element of a value is undefined. More...
 
function all_scalars (v)
 Test if all elements of a value are scalars. More...
 
function all_vectors (v)
 Test if all elements of a value are vectors. More...
 
function all_strings (v)
 Test if all elements of a value are strings. More...
 
function all_numbers (v)
 Test if all elements of a value are numbers. More...
 
function all_len (v, l)
 Test if all elements of a value have a given length. More...
 
function almost_equal (v1, v2, p=4)
 Test if all elements of two values are approximately equal. More...
 
function compare (v1, v2, s=true)
 Compare any two values (may be iterable and/or of different types). More...
 

Detailed Description

Variable property test primitives.

See validation results group1 and group2.

Function Documentation

function all_defined ( )

Test if no element of a value is undefined.

Parameters
v<value> A value or an iterable value.
Returns
<boolean> true when no element is undefined and false otherwise.
Warning
Always returns true when v is empty.
function all_equal ( ,
cv   
)

Test if all elements of a value equal a comparison value.

Parameters
v<value> A value or an iterable value.
cv<value> A comparison value.
Returns
<boolean> true when all elements equal the value cv and false otherwise.
Warning
Always returns true when v is empty.
function all_len ( ,
 
)

Test if all elements of a value have a given length.

Parameters
v<value> A value or an iterable value.
l<integer> The length.
Returns
<boolean> true when all elements have length equal to l and false otherwise. Returns the value of v when it is not defined.
Warning
Always returns true when v is empty.
function all_numbers ( )

Test if all elements of a value are numbers.

Parameters
v<value> A value or an iterable value.
Returns
<boolean> true when all elements are numerical values and false otherwise. Returns true when v is a single numerical value. Returns the value of v when it is not defined.
Warning
Always returns true when v is empty.
function all_scalars ( )

Test if all elements of a value are scalars.

Parameters
v<value> A value or an iterable value.
Returns
<boolean> true when all elements are scalar values and false otherwise. Returns true when v is a single scalar value. Returns the value of v when it is not defined.
Warning
Always returns true when v is empty.
function all_strings ( )

Test if all elements of a value are strings.

Parameters
v<value> A value or an iterable value.
Returns
<boolean> true when all elements are string values and false otherwise. Returns true when v is a single string value. Returns the value of v when it is not defined.
Warning
Always returns true when v is empty.
function all_vectors ( )

Test if all elements of a value are vectors.

Parameters
v<value> A value or an iterable value.
Returns
<boolean> true when all elements are vector values and false otherwise. Returns true when v is a single vector value. Returns the value of v when it is not defined.
Warning
Always returns true when v is empty.
function almost_equal ( v1  ,
v2  ,
= 4 
)

Test if all elements of two values are approximately equal.

Parameters
v1<value> A value or an iterable value 1.
v2<value> A value or an iterable value 2.
p<number> A numerical precision.
Returns
<boolean> true when all elements of each values are sufficiently equal and false otherwise. All numerical comparisons are performed with precision limited by p. All non-numeric comparisons test for exact equality.
Note
The parameter p indicated the number of digits of precision for each numerical comparison.
Warning
Always returns true when v is empty.
function any_equal ( ,
cv   
)

Test if any element of a value equals a comparison value.

Parameters
v<value> A value or an iterable value.
cv<value> A comparison value.
Returns
<boolean> true when any element equals the value cv and false otherwise.
Warning
Always returns false when v is empty.
function any_undefined ( )

Test if any element of a value is undefined.

Parameters
v<value> A value or an iterable value.
Returns
<boolean> true when any element is undefined and false otherwise.
Warning
Always returns false when v is empty.
function compare ( v1  ,
v2  ,
= true 
)

Compare any two values (may be iterable and/or of different types).

Parameters
v1<value> A value or an iterable value 1.
v2<value> A value or an iterable value 2.
s<boolean> Order ranges by their numerical sum.
Returns
<integer> -1 when (v2 < v1), +1 when (v2 > v1), and 0 when (v2 == v1).

The following table summarizes how values are ordered.

order type s intra-type ordering
1 undef (singular)
2 number numerical comparison
3 string lexical comparison
4 boolean false < true
5 vector lengths then element-wise comparison
6 range true compare sum of range elements
6 range false lengths then element-wise comparison
Note
When comparing two vectors of equal length, the comparison continue element-by-element until an ordering can be determined. Two vectors are declared equal when all elements have been compared and no ordering has been determined.
Warning
The performance of element-wise comparisons of vectors degrades exponentially with vector size.
The sum of a range may quickly exceeded the intermediate variable storage capacity for long ranges.
function is_boolean ( )

Test if a value is a boolean constant.

Parameters
v<value> A value.
Returns
<boolean> true when the value is one of the predefined boolean constants [true|false] and false otherwise.
function is_decimal ( )

Test if a value is a decimal.

Parameters
v<value> A value.
Returns
<boolean> true when the value is a decimal and false otherwise.
function is_defined ( )

Test if a value is defined.

Parameters
v<value> A value.
Returns
<boolean> true when the value is defined and false otherwise.
function is_empty ( )

Test if an iterable value is empty.

Parameters
v<value> An iterable value.
Returns
<boolean> true when the iterable value has zero elements and false otherwise.
function is_even ( )

Test if a numerical value is even.

Parameters
v<value> A numerical value.
Returns
<boolean> true when the value is determined to be even and false otherwise.
Note
The value must be valid and defined but may be positive or negative. Any value that is not an integer returns false.
function is_inf ( )

Test if a numerical value is infinite.

Parameters
v<value> A numerical value.
Returns
<boolean> true when the value is determined to be inf (greater than the largest representable number) and false otherwise.
function is_integer ( )

Test if a value is an integer.

Parameters
v<value> A value.
Returns
<boolean> true when the value is an integer and false otherwise.
function is_iterable ( )

Test if a value has multiple parts and is iterable.

Parameters
v<value> A value.
Returns
<boolean> true when the value is an iterable multi-part value and false otherwise.
value is defined result
undef false
inf false
nan false
integer false
decimal false
boolean false
string true
vector true
range not defined
function is_nan ( )

Test if a numerical value is invalid.

Parameters
v<value> A numerical value.
Returns
<boolean> true when the value is determined to be nan (Not A Number) and false otherwise.
function is_number ( )

Test if a value is a number.

Parameters
v<value> A value.
Returns
<boolean> true when the value is a number and false otherwise.
Warning
Returns true even for numerical values that are considered infinite and invalid.
function is_odd ( )

Test if a numerical value is odd.

Parameters
v<value> A numerical value.
Returns
<boolean> true when the value is determined to be odd and false otherwise.
Note
The value must be valid and defined but may be positive or negative. Any value that is not an integer returns false.
function is_range ( )

Test if a value is a range definition.

Parameters
v<value> A value.
Returns
<boolean> true when the value is a range definition and false otherwise.
function is_scalar ( )

Test if a value is a single non-iterable value.

Parameters
v<value> A value.
Returns
<boolean> true when the value is a single non-iterable value and false otherwise.
value is defined result
undef true
inf true
nan true
integer true
decimal true
boolean true
string false
vector false
range not defined
function is_string ( )

Test if a value is a string.

Parameters
v<value> A value.
Returns
<boolean> true when the value is a string and false otherwise.
function is_vector ( )

Test if a value is a vector.

Parameters
v<value> A value.
Returns
<boolean> true when the value is a vector and false otherwise.
function not_defined ( )

Test if a value is not defined.

Parameters
v<value> A value.
Returns
<boolean> true when the value is not defined and false otherwise.