omdl  v0.6.1
OpenSCAD Mechanical Design Library

List data type identification. More...

+ Collaboration diagram for Lists:

Files

file  datatypes-base.scad
 Include file wrapper of data types base primitives.
 

Functions

function n_almost_equal (v1, v2, p=6)
 Test if all elements of two lists of numbers are sufficiently equal. More...
 
function almost_equal (v1, v2, p=6)
 Test if all numerical elements of two lists of values are sufficiently equal. More...
 
function compare (v1, v2, s=true)
 Order to lists of arbitrary values. More...
 

Detailed Description

List data type identification.

See validation results.

Function Documentation

function almost_equal ( v1  ,
v2  ,
= 6 
)

Test if all numerical elements of two lists of values are sufficiently equal.

Parameters
v1<list> A list of values 1.
v2<list> A list of values 2.
p<number> The numerical precision.
Returns
<boolean> true when all elements of each lists are sufficiently equal and false otherwise.

The 'distance' between two numbers must be less than pow(10,-p) to be considered almost equal. All numerical comparisons are performed to the specified precision. All non-numeric comparisons test for equality.

Note
If the lists are scalar numbers, the function n_almost_equal() provides a more efficient test.
Warning
Always returns true when both lists are empty.
function compare ( v1  ,
v2  ,
= true 
)

Order to lists of arbitrary values.

Parameters
v1<list> A list of values 1.
v2<list> A list of values 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 boolean false < true
4 string lexical comparison
5 list 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 lists of equal length, the comparison continue element-by-element until an ordering can be determined. Two lists are equal when all elements have been compared and no ordering has been determined.
Warning
The performance of element-wise comparisons of lists degrades with list size.
The sum of a range may exceeded the intermediate variable storage capacity for long ranges.
function n_almost_equal ( v1  ,
v2  ,
= 6 
)

Test if all elements of two lists of numbers are sufficiently equal.

Parameters
v1<number-list> A list of numbers 1.
v2<number-list> A list of numbers 2.
p<number> The numerical precision.
Returns
<boolean> true when the distance between v1 and v2 is less than d and false otherwise. Returns false when either list contains a non-numerica values, or when the lists are not of the same length.

The 'distance' between two numbers must be less than pow(10,-p) to be considered almost equal.

Note
To compare general lists of values see almost_equal().