omdl
v0.9.5
OpenSCAD Mechanical Design Library
scalar_operate.scad
Go to the documentation of this file.
1
//! Scalar data type operations.
2
/***************************************************************************/
/**
3
\file
4
\author Roy Allen Sutton
5
\date 2015-2023
6
7
\copyright
8
9
This file is part of [omdl] (https://github.com/royasutton/omdl),
10
an OpenSCAD mechanical design library.
11
12
The \em omdl is free software; you can redistribute it and/or modify
13
it under the terms of the [GNU Lesser General Public License]
14
(http://www.gnu.org/licenses/lgpl.html) as published by the Free
15
Software Foundation; either version 2.1 of the License, or (at
16
your option) any later version.
17
18
The \em omdl is distributed in the hope that it will be useful,
19
but WITHOUT ANY WARRANTY; without even the implied warranty of
20
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21
Lesser General Public License for more details.
22
23
You should have received a copy of the GNU Lesser General Public
24
License along with the \em omdl; if not, write to the Free Software
25
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
26
02110-1301, USA; or see <http://www.gnu.org/licenses/>.
27
28
\details
29
30
\amu_define group_name (Scalar Operations)
31
\amu_define group_brief (Operations for scalar data types.)
32
33
\amu_include (include/amu/pgid_path_pstem_pg.amu)
34
*******************************************************************************/
35
36
//----------------------------------------------------------------------------//
37
// validation.
38
//----------------------------------------------------------------------------//
39
40
/***************************************************************************/
/**
41
\amu_include (include/amu/validate_log_th.amu)
42
\amu_include (include/amu/validate_log_td.amu)
43
\amu_include (include/amu/validate_results.amu)
44
*******************************************************************************/
45
46
//----------------------------------------------------------------------------//
47
// group.
48
//----------------------------------------------------------------------------//
49
50
/***************************************************************************/
/**
51
\amu_include (include/amu/group_in_parent_start.amu)
52
\amu_include (include/amu/includes_required.amu)
53
54
\details
55
56
\amu_include (include/amu/validate_summary.amu)
57
*******************************************************************************/
58
59
//----------------------------------------------------------------------------//
60
61
//! Return given value, if defined, or a secondary value, if primary is not defined.
62
/***************************************************************************/
/**
63
\param v <value> A primary value.
64
\param d <value> A secondary value.
65
66
\returns <value> \p v when it is defined and \p d otherwise.
67
68
The value \p d is returned only when \p v is equal to \b undef.
69
*******************************************************************************/
70
function
defined_or
71
(
72
v,
73
d
74
) = is_undef(v) ? d : v;
75
76
//! Return a circular index position.
77
/***************************************************************************/
/**
78
\param i <integer> A integer position.
79
\param l <integer> The range length.
80
\param f <integer> The starting index position.
81
82
\returns <integer> The index position mapped into a circular list
83
within the range <tt>[f : l+f-1]</tt>.
84
*******************************************************************************/
85
function
index_c
86
(
87
i,
88
l,
89
f = 0
90
) = f + (((i % l) + l) % l);
91
92
//! @}
93
//! @}
94
95
//----------------------------------------------------------------------------//
96
// openscad-amu auxiliary scripts
97
//----------------------------------------------------------------------------//
98
99
/*
100
BEGIN_SCOPE validate;
101
BEGIN_OPENSCAD;
102
include <omdl-base.scad>;
103
include <common/validation.scad>;
104
105
function fmt( id, td, ev, v1, v2, v3 ) = map_validate_fmt(id, td, ev, v1, v2, v3);
106
function v1( db, id ) = map_validate_get_v1(db, id);
107
function v2( db, id ) = map_validate_get_v2(db, id);
108
109
map_test_defined_or =
110
[
111
fmt("t01", "Undefined", 1, undef, 1),
112
fmt("t02", "A small value", eps, eps, 2),
113
fmt("t03", "Infinity", number_inf, number_inf, 3),
114
fmt("t04", "Max number", number_max, number_max, 4),
115
fmt("t05", "Undefined list", [undef], [undef], 5),
116
fmt("t06", "Short range", [0:9], [0:9], 6),
117
fmt("t07", "Empty string", empty_str, empty_str, 7),
118
fmt("t08", "Empty list", empty_lst, empty_lst, 8)
119
];
120
121
db = map_validate_init( map_test_defined_or, "defined_or" );
122
map_validate_start( db );
123
124
for ( id = map_validate_get_ids( db ) )
125
map_validate( db, id, 2, defined_or ( v1(db, id), v2(db, id) ) );
126
127
// end_include
128
END_OPENSCAD;
129
130
BEGIN_MFSCRIPT;
131
include --path "${INCLUDE_PATH}" {var_init,var_gen_term}.mfs;
132
include --path "${INCLUDE_PATH}" scr_make_mf.mfs;
133
END_MFSCRIPT;
134
END_SCOPE;
135
*/
136
137
//----------------------------------------------------------------------------//
138
// end of file
139
//----------------------------------------------------------------------------//
index_c
function index_c(i, l, f=0)
Return a circular index position.
defined_or
function defined_or(v, d)
Return given value, if defined, or a secondary value, if primary is not defined.
datatypes
scalar_operate.scad
Generated on Thu Nov 14 2024 11:12:07 for omdl by
doxygen
with
openscad-amu