2020-07-23 23:10:36 +00:00
|
|
|
include <../std.scad>
|
2019-05-01 06:45:05 +00:00
|
|
|
|
|
|
|
|
2019-10-23 00:10:04 +00:00
|
|
|
module test_is_vector() {
|
2020-05-30 02:04:34 +00:00
|
|
|
assert(is_vector([1,2,3]) == true);
|
|
|
|
assert(is_vector([[1,2,3]]) == false);
|
|
|
|
assert(is_vector(["foo"]) == false);
|
|
|
|
assert(is_vector([]) == false);
|
|
|
|
assert(is_vector(1) == false);
|
|
|
|
assert(is_vector("foo") == false);
|
|
|
|
assert(is_vector(true) == false);
|
2020-07-24 13:47:25 +00:00
|
|
|
|
2020-07-21 23:15:02 +00:00
|
|
|
assert(is_vector([0,0,0],zero=true) == true);
|
|
|
|
assert(is_vector([0,0,0],zero=false) == false);
|
|
|
|
assert(is_vector([0,1,0],zero=true) == false);
|
|
|
|
assert(is_vector([0,0,1],zero=false) == true);
|
2020-09-08 06:10:39 +00:00
|
|
|
assert(is_vector([1,1,1],zero=false) == true);
|
|
|
|
|
|
|
|
assert(is_vector([0,0,0],all_nonzero=true) == false);
|
|
|
|
assert(is_vector([0,1,0],all_nonzero=true) == false);
|
|
|
|
assert(is_vector([0,0,1],all_nonzero=true) == false);
|
|
|
|
assert(is_vector([1,1,1],all_nonzero=true) == true);
|
|
|
|
assert(is_vector([-1,1,1],all_nonzero=true) == true);
|
|
|
|
assert(is_vector([-1,-1,-1],all_nonzero=true) == true);
|
2019-10-23 00:10:04 +00:00
|
|
|
}
|
|
|
|
test_is_vector();
|
|
|
|
|
|
|
|
|
2020-06-21 04:42:22 +00:00
|
|
|
module test_vfloor() {
|
|
|
|
assert_equal(vfloor([2.0, 3.14, 18.9, 7]), [2,3,18,7]);
|
|
|
|
assert_equal(vfloor([-2.0, -3.14, -18.9, -7]), [-2,-4,-19,-7]);
|
|
|
|
}
|
|
|
|
test_vfloor();
|
|
|
|
|
|
|
|
|
|
|
|
module test_vceil() {
|
|
|
|
assert_equal(vceil([2.0, 3.14, 18.9, 7]), [2,4,19,7]);
|
|
|
|
assert_equal(vceil([-2.0, -3.14, -18.9, -7]), [-2,-3,-18,-7]);
|
|
|
|
}
|
|
|
|
test_vceil();
|
|
|
|
|
|
|
|
|
2019-05-01 06:45:05 +00:00
|
|
|
module test_vmul() {
|
2020-09-29 00:35:05 +00:00
|
|
|
assert_equal(vmul([3,4,5], [8,7,6]), [24,28,30]);
|
|
|
|
assert_equal(vmul([1,2,3], [4,5,6]), [4,10,18]);
|
|
|
|
assert_equal(vmul([[1,2,3],[4,5,6],[7,8,9]], [[4,5,6],[3,2,1],[5,9,3]]), [32,28,134]);
|
2019-05-01 06:45:05 +00:00
|
|
|
}
|
|
|
|
test_vmul();
|
|
|
|
|
|
|
|
|
|
|
|
module test_vdiv() {
|
2020-05-30 02:04:34 +00:00
|
|
|
assert(vdiv([24,28,30], [8,7,6]) == [3, 4, 5]);
|
2019-05-01 06:45:05 +00:00
|
|
|
}
|
|
|
|
test_vdiv();
|
|
|
|
|
|
|
|
|
|
|
|
module test_vabs() {
|
2020-05-30 02:04:34 +00:00
|
|
|
assert(vabs([2,4,8]) == [2,4,8]);
|
|
|
|
assert(vabs([-2,-4,-8]) == [2,4,8]);
|
|
|
|
assert(vabs([-2,4,8]) == [2,4,8]);
|
|
|
|
assert(vabs([2,-4,8]) == [2,4,8]);
|
|
|
|
assert(vabs([2,4,-8]) == [2,4,8]);
|
2019-05-01 06:45:05 +00:00
|
|
|
}
|
|
|
|
test_vabs();
|
|
|
|
|
2020-07-23 23:10:36 +00:00
|
|
|
include <../strings.scad>
|
2020-01-16 04:13:07 +00:00
|
|
|
module test_vang() {
|
2020-05-30 02:04:34 +00:00
|
|
|
assert(vang([1,0])==0);
|
|
|
|
assert(vang([0,1])==90);
|
|
|
|
assert(vang([-1,0])==180);
|
|
|
|
assert(vang([0,-1])==-90);
|
|
|
|
assert(vang([1,1])==45);
|
|
|
|
assert(vang([-1,1])==135);
|
|
|
|
assert(vang([1,-1])==-45);
|
|
|
|
assert(vang([-1,-1])==-135);
|
|
|
|
assert(vang([0,0,1])==[0,90]);
|
|
|
|
assert(vang([0,1,1])==[90,45]);
|
|
|
|
assert(vang([0,1,-1])==[90,-45]);
|
|
|
|
assert(vang([1,0,0])==[0,0]);
|
|
|
|
assert(vang([0,1,0])==[90,0]);
|
|
|
|
assert(vang([0,-1,0])==[-90,0]);
|
|
|
|
assert(vang([-1,0,0])==[180,0]);
|
|
|
|
assert(vang([1,0,1])==[0,45]);
|
|
|
|
assert(vang([0,1,1])==[90,45]);
|
|
|
|
assert(vang([0,-1,1])==[-90,45]);
|
|
|
|
assert(approx(vang([1,1,1]),[45, 35.2643896828]));
|
2020-01-16 04:13:07 +00:00
|
|
|
}
|
|
|
|
test_vang();
|
|
|
|
|
2019-05-01 06:45:05 +00:00
|
|
|
|
2020-03-03 03:30:20 +00:00
|
|
|
module test_unit() {
|
2020-05-30 02:04:34 +00:00
|
|
|
assert(unit([10,0,0]) == [1,0,0]);
|
|
|
|
assert(unit([0,10,0]) == [0,1,0]);
|
|
|
|
assert(unit([0,0,10]) == [0,0,1]);
|
|
|
|
assert(abs(norm(unit([10,10,10]))-1) < EPSILON);
|
|
|
|
assert(abs(norm(unit([-10,-10,-10]))-1) < EPSILON);
|
|
|
|
assert(abs(norm(unit([-10,0,0]))-1) < EPSILON);
|
|
|
|
assert(abs(norm(unit([0,-10,0]))-1) < EPSILON);
|
|
|
|
assert(abs(norm(unit([0,0,-10]))-1) < EPSILON);
|
2019-05-01 06:45:05 +00:00
|
|
|
}
|
2020-03-03 03:30:20 +00:00
|
|
|
test_unit();
|
2019-05-01 06:45:05 +00:00
|
|
|
|
|
|
|
|
|
|
|
module test_vector_angle() {
|
2020-05-30 02:04:34 +00:00
|
|
|
vecs = [[10,0,0], [-10,0,0], [0,10,0], [0,-10,0], [0,0,10], [0,0,-10]];
|
|
|
|
for (a=vecs, b=vecs) {
|
|
|
|
if(a==b) {
|
|
|
|
assert(vector_angle(a,b)==0);
|
|
|
|
assert(vector_angle([a,b])==0);
|
|
|
|
} else if(a==-b) {
|
|
|
|
assert(vector_angle(a,b)==180);
|
|
|
|
assert(vector_angle([a,b])==180);
|
|
|
|
} else {
|
|
|
|
assert(vector_angle(a,b)==90);
|
|
|
|
assert(vector_angle([a,b])==90);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
assert(abs(vector_angle([10,10,0],[10,0,0])-45) < EPSILON);
|
|
|
|
assert(abs(vector_angle([[10,10,0],[10,0,0]])-45) < EPSILON);
|
|
|
|
assert(abs(vector_angle([11,11,1],[1,1,1],[11,-9,1])-90) < EPSILON);
|
|
|
|
assert(abs(vector_angle([[11,11,1],[1,1,1],[11,-9,1]])-90) < EPSILON);
|
2019-05-01 06:45:05 +00:00
|
|
|
}
|
|
|
|
test_vector_angle();
|
|
|
|
|
|
|
|
|
|
|
|
module test_vector_axis() {
|
2020-05-30 02:04:34 +00:00
|
|
|
assert(norm(vector_axis([10,0,0],[10,10,0]) - [0,0,1]) < EPSILON);
|
|
|
|
assert(norm(vector_axis([[10,0,0],[10,10,0]]) - [0,0,1]) < EPSILON);
|
|
|
|
assert(norm(vector_axis([10,0,0],[0,10,0]) - [0,0,1]) < EPSILON);
|
|
|
|
assert(norm(vector_axis([[10,0,0],[0,10,0]]) - [0,0,1]) < EPSILON);
|
|
|
|
assert(norm(vector_axis([0,10,0],[10,0,0]) - [0,0,-1]) < EPSILON);
|
|
|
|
assert(norm(vector_axis([[0,10,0],[10,0,0]]) - [0,0,-1]) < EPSILON);
|
|
|
|
assert(norm(vector_axis([0,0,10],[10,0,0]) - [0,1,0]) < EPSILON);
|
|
|
|
assert(norm(vector_axis([[0,0,10],[10,0,0]]) - [0,1,0]) < EPSILON);
|
|
|
|
assert(norm(vector_axis([10,0,0],[0,0,10]) - [0,-1,0]) < EPSILON);
|
|
|
|
assert(norm(vector_axis([[10,0,0],[0,0,10]]) - [0,-1,0]) < EPSILON);
|
|
|
|
assert(norm(vector_axis([10,0,10],[0,-10,0]) - [sin(45),0,-sin(45)]) < EPSILON);
|
|
|
|
assert(norm(vector_axis([[10,0,10],[0,-10,0]]) - [sin(45),0,-sin(45)]) < EPSILON);
|
|
|
|
assert(norm(vector_axis([11,1,11],[1,1,1],[1,-9,1]) - [sin(45),0,-sin(45)]) < EPSILON);
|
|
|
|
assert(norm(vector_axis([[11,1,11],[1,1,1],[1,-9,1]]) - [sin(45),0,-sin(45)]) < EPSILON);
|
2019-05-01 06:45:05 +00:00
|
|
|
}
|
|
|
|
test_vector_axis();
|
|
|
|
|
|
|
|
|
2019-10-24 05:49:40 +00:00
|
|
|
cube();
|
|
|
|
|
|
|
|
|
2020-05-30 02:04:34 +00:00
|
|
|
// vim: expandtab tabstop=4 shiftwidth=4 softtabstop=4 nowrap
|