mirror of
https://github.com/BelfrySCAD/BOSL2.git
synced 2024-12-29 16:29:40 +00:00
Optimizations for is_vector(), is_matrix(). Added is_finite().
This commit is contained in:
parent
efa76fe9f5
commit
feba482396
5 changed files with 16 additions and 16 deletions
|
@ -82,6 +82,14 @@ function is_integer(n) = is_num(n) && n == round(n);
|
|||
function is_nan(x) = (x!=x);
|
||||
|
||||
|
||||
// Function: is_finite()
|
||||
// Usage:
|
||||
// is_finite(x);
|
||||
// Description:
|
||||
// Returns true if a given value `x` is a finite number.
|
||||
function is_finite(v) = is_num(0*v);
|
||||
|
||||
|
||||
// Function: is_range()
|
||||
// Description:
|
||||
// Returns true if its argument is a range
|
||||
|
|
11
math.scad
11
math.scad
|
@ -733,14 +733,9 @@ function determinant(M) =
|
|||
// m = optional height of matrix
|
||||
// n = optional width of matrix
|
||||
// square = set to true to require a square matrix. Default: false
|
||||
function is_matrix(A,m,n, square=false) =
|
||||
is_list(A) && len(A)>0 &&
|
||||
(is_undef(m) || len(A)==m) &&
|
||||
is_vector(A[0]) &&
|
||||
(is_undef(n) || len(A[0])==n) &&
|
||||
(!square || n==m) &&
|
||||
is_consistent(A);
|
||||
|
||||
function is_matrix(A,n,m,square=false) =
|
||||
is_vector(A[0],n) && is_vector(A*(0*A[0]),m) &&
|
||||
(!square || len(A)==len(A[0]));
|
||||
|
||||
|
||||
// Section: Comparisons and Logic
|
||||
|
|
|
@ -43,7 +43,7 @@ include <triangulation.scad>
|
|||
// dim = list of allowed dimensions of the vectors in the path. Default: [2,3]
|
||||
// fast = set to true for fast check that only looks at first entry. Default: false
|
||||
function is_path(list, dim=[2,3], fast=false) =
|
||||
fast? is_list(list) && is_vector(list[0],fast=true) :
|
||||
fast? is_list(list) && is_vector(list[0]) :
|
||||
is_list(list) && is_list(list[0]) && len(list)>1 &&
|
||||
(is_undef(dim) || in_list(len(list[0]), force_list(dim))) &&
|
||||
is_list_of(list, repeat(0,len(list[0])));
|
||||
|
|
|
@ -13,13 +13,12 @@
|
|||
|
||||
// Function: is_vector()
|
||||
// Usage:
|
||||
// is_vector(v, [length], [fast]);
|
||||
// is_vector(v, [length]);
|
||||
// Description:
|
||||
// Returns true if v is a list of finite numbers.
|
||||
// Arguments:
|
||||
// v = The value to test to see if it is a vector.
|
||||
// length = If given, make sure the vector is `length` items long.
|
||||
// fast = If true, do a shallow test that is faster.
|
||||
// Example:
|
||||
// is_vector(4); // Returns false
|
||||
// is_vector([4,true,false]); // Returns false
|
||||
|
@ -29,10 +28,8 @@
|
|||
// is_vector([3,4,5],3); // Returns true
|
||||
// is_vector([3,4,5],4); // Returns true
|
||||
// is_vector([]); // Returns false
|
||||
// is_vector([3,undef,undef,true], fast=true); // Returns true
|
||||
function is_vector(v,length,fast=false) =
|
||||
(fast? (is_list(v) && is_num(v[0])) : is_list_of(v,0)) &&
|
||||
len(v) && (is_undef(length) || length==len(v));
|
||||
function is_vector(v,length) =
|
||||
is_list(v) && is_num(0*(v*v)) && (is_undef(length)||len(v)==length);
|
||||
|
||||
|
||||
// Function: add_scalar()
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
BOSL_VERSION = [2,0,384];
|
||||
BOSL_VERSION = [2,0,385];
|
||||
|
||||
|
||||
// Section: BOSL Library Version Functions
|
||||
|
|
Loading…
Reference in a new issue