mirror of
https://github.com/revarbat/BOSL2.git
synced 2025-08-30 23:50:08 +02:00
Optimizations for is_vector(), is_matrix(). Added is_finite().
This commit is contained in:
@@ -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()
|
||||
|
Reference in New Issue
Block a user