From 37ae0cbba00fecd27bb78ba4d7975a55019ada4e Mon Sep 17 00:00:00 2001 From: Garth Minette Date: Mon, 28 Sep 2020 16:52:17 -0700 Subject: [PATCH] Simplify sqr(x) to x*x --- math.scad | 10 ++++------ tests/test_math.scad | 2 +- version.scad | 2 +- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/math.scad b/math.scad index 3569866..574f098 100644 --- a/math.scad +++ b/math.scad @@ -27,18 +27,16 @@ NAN = acos(2); // The value `nan`, useful for comparisons. // sqr(x); // Description: // If given a number, returns the square of that number, -// If given a vector, returns a vector of the squares of each element in the input vector. +// If given a vector, returns the sum-of-squares/dot product of the vector elements. // If given a matrix, returns the matrix multiplication of the matrix with itself. // Examples: // sqr(3); // Returns: 9 // sqr(-4); // Returns: 16 -// sqr([3,4]); // Returns: [9,16] +// sqr([2,3,4]); // Returns: 29 // sqr([[1,2],[3,4]]); // Returns [[7,10],[15,22]] function sqr(x) = - is_finite(x) ? x*x : - is_vector(x) ? vmul(x,x) : - is_matrix(x) ? x*x : - assert(is_finite(x) || is_vector(x) || is_matrix(x), "Input is not a number nor a list of numbers."); + assert(is_finite(x) || is_vector(x) || is_matrix(x), "Input is not a number nor a list of numbers.") + x*x; // Function: log2() diff --git a/tests/test_math.scad b/tests/test_math.scad index 69f6fbd..2ba6a1a 100644 --- a/tests/test_math.scad +++ b/tests/test_math.scad @@ -313,7 +313,7 @@ module test_sqr() { assert_equal(sqr(2.5), 6.25); assert_equal(sqr(3), 9); assert_equal(sqr(16), 256); - assert_equal(sqr([2,3,4]), [4,9,16]); + assert_equal(sqr([2,3,4]), 29); assert_equal(sqr([[2,3,4],[3,5,7],[3,5,1]]), [[25,41,33],[42,69,54],[24,39,48]]); } test_sqr(); diff --git a/version.scad b/version.scad index afcf663..6da91fa 100644 --- a/version.scad +++ b/version.scad @@ -8,7 +8,7 @@ ////////////////////////////////////////////////////////////////////// -BOSL_VERSION = [2,0,432]; +BOSL_VERSION = [2,0,433]; // Section: BOSL Library Version Functions