From d52c10f03bb7bb56df8df1ba442f21922669f774 Mon Sep 17 00:00:00 2001 From: Revar Desmera Date: Sun, 22 Mar 2020 02:41:47 -0700 Subject: [PATCH] Improved approx() to handle matrices. --- math.scad | 6 +++++- version.scad | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/math.scad b/math.scad index 4dfe845..2bb5684 100644 --- a/math.scad +++ b/math.scad @@ -754,7 +754,11 @@ function is_matrix(A,m,n, square=false) = // approx(0.3333,1/3); // Returns: false // approx(0.3333,1/3,eps=1e-3); // Returns: true // approx(PI,3.1415926536); // Returns: true -function approx(a,b,eps=EPSILON) = let(c=a-b) (is_num(c)? abs(c) : norm(c)) <= eps; +function approx(a,b,eps=EPSILON) = + a==b? true : + a*0!=b*0? false : + is_list(a)? ([for (i=idx(a)) if(!approx(a[i],b[i],eps=eps)) 1] == []) : + (abs(a-b) <= eps); function _type_num(x) = diff --git a/version.scad b/version.scad index 5b6032b..8b47e5c 100644 --- a/version.scad +++ b/version.scad @@ -8,7 +8,7 @@ ////////////////////////////////////////////////////////////////////// -BOSL_VERSION = [2,0,214]; +BOSL_VERSION = [2,0,215]; // Section: BOSL Library Version Functions