mirror of
https://github.com/BelfrySCAD/BOSL2.git
synced 2025-01-30 08:19:36 +00:00
Minor change in is_matrix_symmetric
This commit is contained in:
parent
c5799d6539
commit
5062ee1605
1 changed files with 9 additions and 7 deletions
16
arrays.scad
16
arrays.scad
|
@ -41,6 +41,7 @@ function is_homogeneous(l, depth=10) =
|
||||||
[] == [for(i=[1:len(l)-1]) if( ! _same_type(l[i],l0, depth+1) ) 0 ];
|
[] == [for(i=[1:len(l)-1]) if( ! _same_type(l[i],l0, depth+1) ) 0 ];
|
||||||
|
|
||||||
function is_homogenous(l, depth=10) = is_homogeneous(l, depth);
|
function is_homogenous(l, depth=10) = is_homogeneous(l, depth);
|
||||||
|
|
||||||
|
|
||||||
function _same_type(a,b, depth) =
|
function _same_type(a,b, depth) =
|
||||||
(depth==0) ||
|
(depth==0) ||
|
||||||
|
@ -50,7 +51,7 @@ function _same_type(a,b, depth) =
|
||||||
(is_string(a) && is_string(b)) ||
|
(is_string(a) && is_string(b)) ||
|
||||||
(is_list(a) && is_list(b) && len(a)==len(b)
|
(is_list(a) && is_list(b) && len(a)==len(b)
|
||||||
&& []==[for(i=idx(a)) if( ! _same_type(a[i],b[i],depth-1) ) 0] );
|
&& []==[for(i=idx(a)) if( ! _same_type(a[i],b[i],depth-1) ) 0] );
|
||||||
|
|
||||||
|
|
||||||
// Function: select()
|
// Function: select()
|
||||||
// Topics: List Handling
|
// Topics: List Handling
|
||||||
|
@ -97,7 +98,6 @@ function select(list, start, end) =
|
||||||
|
|
||||||
|
|
||||||
// Function: slice()
|
// Function: slice()
|
||||||
// Topics: List Handling
|
|
||||||
// Usage:
|
// Usage:
|
||||||
// list = slice(list,s,e);
|
// list = slice(list,s,e);
|
||||||
// Description:
|
// Description:
|
||||||
|
@ -476,7 +476,7 @@ function reverse(x) =
|
||||||
// l9 = list_rotate([1,2,3,4,5],6); // Returns: [2,3,4,5,1]
|
// l9 = list_rotate([1,2,3,4,5],6); // Returns: [2,3,4,5,1]
|
||||||
function list_rotate(list,n=1) =
|
function list_rotate(list,n=1) =
|
||||||
assert(is_list(list)||is_string(list), "Invalid list or string.")
|
assert(is_list(list)||is_string(list), "Invalid list or string.")
|
||||||
assert(is_finite(n), "Invalid number")
|
assert(is_int(n), "The rotation number should be integer")
|
||||||
let (
|
let (
|
||||||
ll = len(list),
|
ll = len(list),
|
||||||
n = ((n % ll) + ll) % ll,
|
n = ((n % ll) + ll) % ll,
|
||||||
|
@ -990,7 +990,7 @@ function _sort_vectors(arr, idxlist, _i=0) =
|
||||||
_sort_vectors(equal, idxlist, _i+1),
|
_sort_vectors(equal, idxlist, _i+1),
|
||||||
_sort_vectors(greater, idxlist, _i ) );
|
_sort_vectors(greater, idxlist, _i ) );
|
||||||
|
|
||||||
|
|
||||||
// sorting using compare_vals(); returns indexed list when `indexed==true`
|
// sorting using compare_vals(); returns indexed list when `indexed==true`
|
||||||
function _sort_general(arr, idx=undef, indexed=false) =
|
function _sort_general(arr, idx=undef, indexed=false) =
|
||||||
(len(arr)<=1) ? arr :
|
(len(arr)<=1) ? arr :
|
||||||
|
@ -1332,6 +1332,8 @@ function permutations(l,n=2) =
|
||||||
// pairs = zip(a,b);
|
// pairs = zip(a,b);
|
||||||
// triples = zip(a,b,c);
|
// triples = zip(a,b,c);
|
||||||
// quads = zip([LIST1,LIST2,LIST3,LIST4]);
|
// quads = zip([LIST1,LIST2,LIST3,LIST4]);
|
||||||
|
// Topics: List Handling, Iteration
|
||||||
|
// See Also: zip_long()
|
||||||
// Description:
|
// Description:
|
||||||
// Zips together two or more lists into a single list. For example, if you have two
|
// Zips together two or more lists into a single list. For example, if you have two
|
||||||
// lists [3,4,5], and [8,7,6], and zip them together, you get [[3,8],[4,7],[5,6]].
|
// lists [3,4,5], and [8,7,6], and zip them together, you get [[3,8],[4,7],[5,6]].
|
||||||
|
@ -1357,6 +1359,8 @@ function zip(a,b,c) =
|
||||||
// pairs = zip_long(a,b);
|
// pairs = zip_long(a,b);
|
||||||
// triples = zip_long(a,b,c);
|
// triples = zip_long(a,b,c);
|
||||||
// quads = zip_long([LIST1,LIST2,LIST3,LIST4]);
|
// quads = zip_long([LIST1,LIST2,LIST3,LIST4]);
|
||||||
|
// Topics: List Handling, Iteration
|
||||||
|
// See Also: zip()
|
||||||
// Description:
|
// Description:
|
||||||
// Zips together two or more lists into a single list. For example, if you have two
|
// Zips together two or more lists into a single list. For example, if you have two
|
||||||
// lists [3,4,5], and [8,7,6], and zip them together, you get [[3,8],[4,7],[5,6]].
|
// lists [3,4,5], and [8,7,6], and zip them together, you get [[3,8],[4,7],[5,6]].
|
||||||
|
@ -1526,7 +1530,6 @@ function subindex(M, idx) =
|
||||||
// [[4,2], 91, false],
|
// [[4,2], 91, false],
|
||||||
// [6, [3,4], undef]];
|
// [6, [3,4], undef]];
|
||||||
// submatrix(A,[0,2],[1,2]); // Returns [[17, "test"], [[3, 4], undef]]
|
// submatrix(A,[0,2],[1,2]); // Returns [[17, "test"], [[3, 4], undef]]
|
||||||
|
|
||||||
function submatrix(M,idx1,idx2) =
|
function submatrix(M,idx1,idx2) =
|
||||||
[for(i=idx1) [for(j=idx2) M[i][j] ] ];
|
[for(i=idx1) [for(j=idx2) M[i][j] ] ];
|
||||||
|
|
||||||
|
@ -1629,7 +1632,6 @@ function block_matrix(M) =
|
||||||
assert(badrows==[], "Inconsistent or invalid input")
|
assert(badrows==[], "Inconsistent or invalid input")
|
||||||
bigM;
|
bigM;
|
||||||
|
|
||||||
|
|
||||||
// Function: diagonal_matrix()
|
// Function: diagonal_matrix()
|
||||||
// Usage:
|
// Usage:
|
||||||
// mat = diagonal_matrix(diag, <offdiag>);
|
// mat = diagonal_matrix(diag, <offdiag>);
|
||||||
|
@ -1855,7 +1857,7 @@ function transpose(arr, reverse=false) =
|
||||||
// A = matrix to test
|
// A = matrix to test
|
||||||
// eps = epsilon for comparing equality. Default: 1e-12
|
// eps = epsilon for comparing equality. Default: 1e-12
|
||||||
function is_matrix_symmetric(A,eps=1e-12) =
|
function is_matrix_symmetric(A,eps=1e-12) =
|
||||||
approx(A,transpose(A));
|
approx(A,transpose(A), eps);
|
||||||
|
|
||||||
|
|
||||||
// vim: expandtab tabstop=4 shiftwidth=4 softtabstop=4 nowrap
|
// vim: expandtab tabstop=4 shiftwidth=4 softtabstop=4 nowrap
|
||||||
|
|
Loading…
Reference in a new issue