Standardize indention on spaces, not tabs.

This commit is contained in:
Revar Desmera
2020-05-29 19:04:34 -07:00
parent 5fe35de963
commit 53c1e25395
89 changed files with 13618 additions and 13618 deletions

View File

@@ -3,12 +3,12 @@ include <BOSL2/hull.scad>
testpoints_on_sphere = [ for(p =
[
[1,PHI,0], [-1,PHI,0], [1,-PHI,0], [-1,-PHI,0],
[0,1,PHI], [0,-1,PHI], [0,1,-PHI], [0,-1,-PHI],
[PHI,0,1], [-PHI,0,1], [PHI,0,-1], [-PHI,0,-1]
])
unit(p)
[
[1,PHI,0], [-1,PHI,0], [1,-PHI,0], [-1,-PHI,0],
[0,1,PHI], [0,-1,PHI], [0,1,-PHI], [0,-1,-PHI],
[PHI,0,1], [-PHI,0,1], [PHI,0,-1], [-PHI,0,-1]
])
unit(p)
];
testpoints_circular = [ for(a = [0:15:360-EPSILON]) [cos(a),sin(a)] ];
@@ -44,30 +44,30 @@ visualize_hull(testpoints3d);
module visualize_hull(points) {
hull = hull(points);
%if (len(hull) > 0 && is_list(hull[0]) && len(hull[0]) > 0)
polyhedron(points=points, faces = hull);
else
polyhedron(points=points, faces = [hull]);
for (i = [0:len(points)-1]) {
p = points[i];
$fn = 16;
translate(p) {
if (hull_contains_index(hull,i)) {
color("blue") sphere(1);
} else {
color("red") sphere(1);
}
}
}
function hull_contains_index(hull, index) =
search(index,hull,1,0) ||
search(index,hull,1,1) ||
search(index,hull,1,2);
hull = hull(points);
%if (len(hull) > 0 && is_list(hull[0]) && len(hull[0]) > 0)
polyhedron(points=points, faces = hull);
else
polyhedron(points=points, faces = [hull]);
for (i = [0:len(points)-1]) {
p = points[i];
$fn = 16;
translate(p) {
if (hull_contains_index(hull,i)) {
color("blue") sphere(1);
} else {
color("red") sphere(1);
}
}
}
function hull_contains_index(hull, index) =
search(index,hull,1,0) ||
search(index,hull,1,1) ||
search(index,hull,1,2);
}
// vim: noexpandtab tabstop=4 shiftwidth=4 softtabstop=4 nowrap
// vim: expandtab tabstop=4 shiftwidth=4 softtabstop=4 nowrap

View File

@@ -4,259 +4,259 @@ include <BOSL2/std.scad>
// List/Array Ops
module test_repeat() {
assert(repeat(1, 4) == [1,1,1,1]);
assert(repeat(8, [2,3]) == [[8,8,8], [8,8,8]]);
assert(repeat(0, [2,2,3]) == [[[0,0,0],[0,0,0]], [[0,0,0],[0,0,0]]]);
assert(repeat([1,2,3],3) == [[1,2,3], [1,2,3], [1,2,3]]);
assert(repeat(1, 4) == [1,1,1,1]);
assert(repeat(8, [2,3]) == [[8,8,8], [8,8,8]]);
assert(repeat(0, [2,2,3]) == [[[0,0,0],[0,0,0]], [[0,0,0],[0,0,0]]]);
assert(repeat([1,2,3],3) == [[1,2,3], [1,2,3], [1,2,3]]);
}
test_repeat();
module test_in_list() {
assert(in_list("bar", ["foo", "bar", "baz"]));
assert(!in_list("bee", ["foo", "bar", "baz"]));
assert(in_list("bar", [[2,"foo"], [4,"bar"], [3,"baz"]], idx=1));
assert(in_list("bar", ["foo", "bar", "baz"]));
assert(!in_list("bee", ["foo", "bar", "baz"]));
assert(in_list("bar", [[2,"foo"], [4,"bar"], [3,"baz"]], idx=1));
}
test_in_list();
module test_slice() {
assert(slice([3,4,5,6,7,8,9], 3, 5) == [6,7]);
assert(slice([3,4,5,6,7,8,9], 2, -1) == [5,6,7,8,9]);
assert(slice([3,4,5,6,7,8,9], 1, 1) == []);
assert(slice([3,4,5,6,7,8,9], 6, -1) == [9]);
assert(slice([3,4,5,6,7,8,9], 2, -2) == [5,6,7,8]);
assert(slice([3,4,5,6,7,8,9], 3, 5) == [6,7]);
assert(slice([3,4,5,6,7,8,9], 2, -1) == [5,6,7,8,9]);
assert(slice([3,4,5,6,7,8,9], 1, 1) == []);
assert(slice([3,4,5,6,7,8,9], 6, -1) == [9]);
assert(slice([3,4,5,6,7,8,9], 2, -2) == [5,6,7,8]);
}
test_slice();
module test_select() {
l = [3,4,5,6,7,8,9];
assert(select(l, 5, 6) == [8,9]);
assert(select(l, 5, 8) == [8,9,3,4]);
assert(select(l, 5, 2) == [8,9,3,4,5]);
assert(select(l, -3, -1) == [7,8,9]);
assert(select(l, 3, 3) == [6]);
assert(select(l, 4) == 7);
assert(select(l, -2) == 8);
assert(select(l, [1:3]) == [4,5,6]);
assert(select(l, [1,3]) == [4,6]);
l = [3,4,5,6,7,8,9];
assert(select(l, 5, 6) == [8,9]);
assert(select(l, 5, 8) == [8,9,3,4]);
assert(select(l, 5, 2) == [8,9,3,4,5]);
assert(select(l, -3, -1) == [7,8,9]);
assert(select(l, 3, 3) == [6]);
assert(select(l, 4) == 7);
assert(select(l, -2) == 8);
assert(select(l, [1:3]) == [4,5,6]);
assert(select(l, [1,3]) == [4,6]);
}
test_select();
module test_list_range() {
assert(list_range(4) == [0,1,2,3]);
assert(list_range(n=4, step=2) == [0,2,4,6]);
assert(list_range(n=4, s=3, step=3) == [3,6,9,12]);
assert(list_range(e=3) == [0,1,2,3]);
assert(list_range(e=6, step=2) == [0,2,4,6]);
assert(list_range(s=3, e=5) == [3,4,5]);
assert(list_range(s=3, e=8, step=2) == [3,5,7]);
assert(list_range(s=4, e=8, step=2) == [4,6,8]);
assert(list_range(e=4, n=3) == [0,2,4]);
assert(list_range(n=4, s=[3,4], step=[2,3]) == [[3,4], [5,7], [7,10], [9,13]]);
assert(list_range(4) == [0,1,2,3]);
assert(list_range(n=4, step=2) == [0,2,4,6]);
assert(list_range(n=4, s=3, step=3) == [3,6,9,12]);
assert(list_range(e=3) == [0,1,2,3]);
assert(list_range(e=6, step=2) == [0,2,4,6]);
assert(list_range(s=3, e=5) == [3,4,5]);
assert(list_range(s=3, e=8, step=2) == [3,5,7]);
assert(list_range(s=4, e=8, step=2) == [4,6,8]);
assert(list_range(e=4, n=3) == [0,2,4]);
assert(list_range(n=4, s=[3,4], step=[2,3]) == [[3,4], [5,7], [7,10], [9,13]]);
}
test_list_range();
module test_reverse() {
assert(reverse([3,4,5,6]) == [6,5,4,3]);
assert(reverse([3,4,5,6]) == [6,5,4,3]);
}
test_reverse();
module test_list_rotate() {
assert(list_rotate([1,2,3,4,5],-2) == [4,5,1,2,3]);
assert(list_rotate([1,2,3,4,5],-1) == [5,1,2,3,4]);
assert(list_rotate([1,2,3,4,5],0) == [1,2,3,4,5]);
assert(list_rotate([1,2,3,4,5],1) == [2,3,4,5,1]);
assert(list_rotate([1,2,3,4,5],2) == [3,4,5,1,2]);
assert(list_rotate([1,2,3,4,5],3) == [4,5,1,2,3]);
assert(list_rotate([1,2,3,4,5],4) == [5,1,2,3,4]);
assert(list_rotate([1,2,3,4,5],5) == [1,2,3,4,5]);
assert(list_rotate([1,2,3,4,5],6) == [2,3,4,5,1]);
assert(list_rotate([],3) == []);
assert(list_rotate([1,2,3,4,5],-2) == [4,5,1,2,3]);
assert(list_rotate([1,2,3,4,5],-1) == [5,1,2,3,4]);
assert(list_rotate([1,2,3,4,5],0) == [1,2,3,4,5]);
assert(list_rotate([1,2,3,4,5],1) == [2,3,4,5,1]);
assert(list_rotate([1,2,3,4,5],2) == [3,4,5,1,2]);
assert(list_rotate([1,2,3,4,5],3) == [4,5,1,2,3]);
assert(list_rotate([1,2,3,4,5],4) == [5,1,2,3,4]);
assert(list_rotate([1,2,3,4,5],5) == [1,2,3,4,5]);
assert(list_rotate([1,2,3,4,5],6) == [2,3,4,5,1]);
assert(list_rotate([],3) == []);
}
test_list_rotate();
module test_deduplicate() {
assert(deduplicate([8,3,4,4,4,8,2,3,3,8,8]) == [8,3,4,8,2,3,8]);
assert(deduplicate(closed=true, [8,3,4,4,4,8,2,3,3,8,8]) == [8,3,4,8,2,3]);
assert(deduplicate("Hello") == ["H","e","l","o"]);
assert(deduplicate([[3,4],[7,1.99],[7,2],[1,4]],eps=0.1) == [[3,4],[7,2],[1,4]]);
assert(deduplicate([8,3,4,4,4,8,2,3,3,8,8]) == [8,3,4,8,2,3,8]);
assert(deduplicate(closed=true, [8,3,4,4,4,8,2,3,3,8,8]) == [8,3,4,8,2,3]);
assert(deduplicate("Hello") == ["H","e","l","o"]);
assert(deduplicate([[3,4],[7,1.99],[7,2],[1,4]],eps=0.1) == [[3,4],[7,2],[1,4]]);
}
test_deduplicate();
module test_deduplicate_indexed() {
assert(deduplicate_indexed([8,6,4,6,3], [1,4,3,1,2,2,0,1]) == [1,4,1,2,0,1]);
assert(deduplicate_indexed([8,6,4,6,3], [1,4,3,1,2,2,0,1], closed=true) == [1,4,1,2,0]);
assert(deduplicate_indexed([8,6,4,6,3], [1,4,3,1,2,2,0,1]) == [1,4,1,2,0,1]);
assert(deduplicate_indexed([8,6,4,6,3], [1,4,3,1,2,2,0,1], closed=true) == [1,4,1,2,0]);
}
test_deduplicate_indexed();
module test_list_set() {
assert(list_set([2,3,4,5], 2, 21) == [2,3,21,5]);
assert(list_set([2,3,4,5], [1,3], [81,47]) == [2,81,4,47]);
assert(list_set([2,3,4,5], 2, 21) == [2,3,21,5]);
assert(list_set([2,3,4,5], [1,3], [81,47]) == [2,81,4,47]);
}
test_list_set();
module test_list_remove() {
assert(list_remove([3,6,9,12],1) == [3,9,12]);
assert(list_remove([3,6,9,12],[1,3]) == [3,9]);
assert(list_remove([3,6,9,12],1) == [3,9,12]);
assert(list_remove([3,6,9,12],[1,3]) == [3,9]);
}
test_list_remove();
module test_list_remove_values() {
animals = ["bat", "cat", "rat", "dog", "bat", "rat"];
assert(list_remove_values(animals, "rat") == ["bat","cat","dog","bat","rat"]);
assert(list_remove_values(animals, "bat", all=true) == ["cat","rat","dog","rat"]);
assert(list_remove_values(animals, ["bat","rat"]) == ["cat","dog","bat","rat"]);
assert(list_remove_values(animals, ["bat","rat"], all=true) == ["cat","dog"]);
assert(list_remove_values(animals, ["tucan","rat"], all=true) == ["bat","cat","dog","bat"]);
animals = ["bat", "cat", "rat", "dog", "bat", "rat"];
assert(list_remove_values(animals, "rat") == ["bat","cat","dog","bat","rat"]);
assert(list_remove_values(animals, "bat", all=true) == ["cat","rat","dog","rat"]);
assert(list_remove_values(animals, ["bat","rat"]) == ["cat","dog","bat","rat"]);
assert(list_remove_values(animals, ["bat","rat"], all=true) == ["cat","dog"]);
assert(list_remove_values(animals, ["tucan","rat"], all=true) == ["bat","cat","dog","bat"]);
}
test_list_remove_values();
module test_list_insert() {
assert(list_insert([3,6,9,12],1,5) == [3,5,6,9,12]);
assert(list_insert([3,6,9,12],[1,3],[5,11]) == [3,5,6,9,11,12]);
assert(list_insert([3,6,9,12],1,5) == [3,5,6,9,12]);
assert(list_insert([3,6,9,12],[1,3],[5,11]) == [3,5,6,9,11,12]);
}
test_list_insert();
module test_bselect() {
assert(bselect([3,4,5,6,7], [false,false,false,false,false]) == []);
assert(bselect([3,4,5,6,7], [false,true,true,false,true]) == [4,5,7]);
assert(bselect([3,4,5,6,7], [true,true,true,true,true]) == [3,4,5,6,7]);
assert(bselect([3,4,5,6,7], [false,false,false,false,false]) == []);
assert(bselect([3,4,5,6,7], [false,true,true,false,true]) == [4,5,7]);
assert(bselect([3,4,5,6,7], [true,true,true,true,true]) == [3,4,5,6,7]);
}
test_bselect();
module test_list_bset() {
assert(list_bset([false,true,false,true,false], [3,4]) == [0,3,0,4,0]);
assert(list_bset([false,true,false,true,false], [3,4], dflt=1) == [1,3,1,4,1]);
assert(list_bset([false,true,false,true,false], [3,4]) == [0,3,0,4,0]);
assert(list_bset([false,true,false,true,false], [3,4], dflt=1) == [1,3,1,4,1]);
}
test_list_bset();
module test_list_increasing() {
assert(list_increasing([1,2,3,4]) == true);
assert(list_increasing([1,3,2,4]) == false);
assert(list_increasing([4,3,2,1]) == false);
assert(list_increasing([1,2,3,4]) == true);
assert(list_increasing([1,3,2,4]) == false);
assert(list_increasing([4,3,2,1]) == false);
}
test_list_increasing();
module test_list_decreasing() {
assert(list_decreasing([1,2,3,4]) == false);
assert(list_decreasing([4,2,3,1]) == false);
assert(list_decreasing([4,3,2,1]) == true);
assert(list_decreasing([1,2,3,4]) == false);
assert(list_decreasing([4,2,3,1]) == false);
assert(list_decreasing([4,3,2,1]) == true);
}
test_list_decreasing();
module test_list_shortest() {
assert(list_shortest(["foobar", "bazquxx", "abcd"]) == 4);
assert(list_shortest(["foobar", "bazquxx", "abcd"]) == 4);
}
test_list_shortest();
module test_list_longest() {
assert(list_longest(["foobar", "bazquxx", "abcd"]) == 7);
assert(list_longest(["foobar", "bazquxx", "abcd"]) == 7);
}
test_list_longest();
module test_list_pad() {
assert(list_pad([4,5,6], 5, 8) == [4,5,6,8,8]);
assert(list_pad([4,5,6,7,8], 5, 8) == [4,5,6,7,8]);
assert(list_pad([4,5,6,7,8,9], 5, 8) == [4,5,6,7,8,9]);
assert(list_pad([4,5,6], 5, 8) == [4,5,6,8,8]);
assert(list_pad([4,5,6,7,8], 5, 8) == [4,5,6,7,8]);
assert(list_pad([4,5,6,7,8,9], 5, 8) == [4,5,6,7,8,9]);
}
test_list_pad();
module test_list_trim() {
assert(list_trim([4,5,6], 5) == [4,5,6]);
assert(list_trim([4,5,6,7,8], 5) == [4,5,6,7,8]);
assert(list_trim([3,4,5,6,7,8,9], 5) == [3,4,5,6,7]);
assert(list_trim([4,5,6], 5) == [4,5,6]);
assert(list_trim([4,5,6,7,8], 5) == [4,5,6,7,8]);
assert(list_trim([3,4,5,6,7,8,9], 5) == [3,4,5,6,7]);
}
test_list_trim();
module test_list_fit() {
assert(list_fit([4,5,6], 5, 8) == [4,5,6,8,8]);
assert(list_fit([4,5,6,7,8], 5, 8) == [4,5,6,7,8]);
assert(list_fit([3,4,5,6,7,8,9], 5, 8) == [3,4,5,6,7]);
assert(list_fit([4,5,6], 5, 8) == [4,5,6,8,8]);
assert(list_fit([4,5,6,7,8], 5, 8) == [4,5,6,7,8]);
assert(list_fit([3,4,5,6,7,8,9], 5, 8) == [3,4,5,6,7]);
}
test_list_fit();
module test_idx() {
colors = ["red", "green", "blue", "cyan"];
assert([for (i=idx(colors)) i] == [0,1,2,3]);
assert([for (i=idx(colors,end=-2)) i] == [0,1,2]);
assert([for (i=idx(colors,start=1)) i] == [1,2,3]);
assert([for (i=idx(colors,start=1,end=-2)) i] == [1,2]);
colors = ["red", "green", "blue", "cyan"];
assert([for (i=idx(colors)) i] == [0,1,2,3]);
assert([for (i=idx(colors,end=-2)) i] == [0,1,2]);
assert([for (i=idx(colors,start=1)) i] == [1,2,3]);
assert([for (i=idx(colors,start=1,end=-2)) i] == [1,2]);
}
test_idx();
module test_enumerate() {
assert(enumerate(["a","b","c"]) == [[0,"a"], [1,"b"], [2,"c"]]);
assert(enumerate([[88,"a"],[76,"b"],[21,"c"]], idx=1) == [[0,"a"], [1,"b"], [2,"c"]]);
assert(enumerate([["cat","a",12],["dog","b",10],["log","c",14]], idx=[1:2]) == [[0,"a",12], [1,"b",10], [2,"c",14]]);
assert(enumerate(["a","b","c"]) == [[0,"a"], [1,"b"], [2,"c"]]);
assert(enumerate([[88,"a"],[76,"b"],[21,"c"]], idx=1) == [[0,"a"], [1,"b"], [2,"c"]]);
assert(enumerate([["cat","a",12],["dog","b",10],["log","c",14]], idx=[1:2]) == [[0,"a",12], [1,"b",10], [2,"c",14]]);
}
test_enumerate();
module test_shuffle() {
nums1 = [for (i=list_range(100)) i];
nums2 = shuffle(nums1);
nums3 = shuffle(nums2);
assert(len(nums2)==len(nums1));
assert(len(nums3)==len(nums2));
assert(nums1!=nums2);
assert(nums2!=nums3);
assert(nums1!=nums3);
nums1 = [for (i=list_range(100)) i];
nums2 = shuffle(nums1);
nums3 = shuffle(nums2);
assert(len(nums2)==len(nums1));
assert(len(nums3)==len(nums2));
assert(nums1!=nums2);
assert(nums2!=nums3);
assert(nums1!=nums3);
}
test_shuffle();
module test_sort() {
assert(sort([7,3,9,4,3,1,8]) == [1,3,3,4,7,8,9]);
assert(sort(["cat", "oat", "sat", "bat", "vat", "rat", "pat", "mat", "fat", "hat", "eat"]) == ["bat", "cat", "eat", "fat", "hat", "mat", "oat", "pat", "rat", "sat", "vat"]);
assert(sort(enumerate([[2,3,4],[1,2,3],[2,4,3]]),idx=1)==[[1,[1,2,3]], [0,[2,3,4]], [2,[2,4,3]]]);
assert(sort([7,3,9,4,3,1,8]) == [1,3,3,4,7,8,9]);
assert(sort(["cat", "oat", "sat", "bat", "vat", "rat", "pat", "mat", "fat", "hat", "eat"]) == ["bat", "cat", "eat", "fat", "hat", "mat", "oat", "pat", "rat", "sat", "vat"]);
assert(sort(enumerate([[2,3,4],[1,2,3],[2,4,3]]),idx=1)==[[1,[1,2,3]], [0,[2,3,4]], [2,[2,4,3]]]);
}
test_sort();
module test_sortidx() {
lst1 = ["d","b","e","c"];
assert(sortidx(lst1) == [1,3,0,2]);
lst2 = [
["foo", 88, [0,0,1], false],
["bar", 90, [0,1,0], true],
["baz", 89, [1,0,0], false],
["qux", 23, [1,1,1], true]
];
assert(sortidx(lst2, idx=1) == [3,0,2,1]);
assert(sortidx(lst2, idx=0) == [1,2,0,3]);
assert(sortidx(lst2, idx=[1,3]) == [3,0,2,1]);
lst3 = [[-4, 0, 0], [0, 0, -4], [0, -4, 0], [-4, 0, 0], [0, -4, 0], [0, 0, 4], [0, 0, -4], [0, 4, 0], [4, 0, 0], [0, 0, 4], [0, 4, 0], [4, 0, 0]];
assert(sortidx(lst3)==[0,3,2,4,1,6,5,9,7,10,8,11]);
lst1 = ["d","b","e","c"];
assert(sortidx(lst1) == [1,3,0,2]);
lst2 = [
["foo", 88, [0,0,1], false],
["bar", 90, [0,1,0], true],
["baz", 89, [1,0,0], false],
["qux", 23, [1,1,1], true]
];
assert(sortidx(lst2, idx=1) == [3,0,2,1]);
assert(sortidx(lst2, idx=0) == [1,2,0,3]);
assert(sortidx(lst2, idx=[1,3]) == [3,0,2,1]);
lst3 = [[-4, 0, 0], [0, 0, -4], [0, -4, 0], [-4, 0, 0], [0, -4, 0], [0, 0, 4], [0, 0, -4], [0, 4, 0], [4, 0, 0], [0, 0, 4], [0, 4, 0], [4, 0, 0]];
assert(sortidx(lst3)==[0,3,2,4,1,6,5,9,7,10,8,11]);
}
test_sortidx();
module test_unique() {
assert(unique([]) == []);
assert(unique([8]) == [8]);
assert(unique([7,3,9,4,3,1,8]) == [1,3,4,7,8,9]);
assert(unique([]) == []);
assert(unique([8]) == [8]);
assert(unique([7,3,9,4,3,1,8]) == [1,3,4,7,8,9]);
}
test_unique();
@@ -265,100 +265,100 @@ test_unique();
module test_subindex() {
v = [[1,2,3,4],[5,6,7,8],[9,10,11,12],[13,14,15,16]];
assert(subindex(v,2) == [3, 7, 11, 15]);
assert(subindex(v,[2,1]) == [[3, 2], [7, 6], [11, 10], [15, 14]]);
assert(subindex(v,[1:3]) == [[2, 3, 4], [6, 7, 8], [10, 11, 12], [14, 15, 16]]);
v = [[1,2,3,4],[5,6,7,8],[9,10,11,12],[13,14,15,16]];
assert(subindex(v,2) == [3, 7, 11, 15]);
assert(subindex(v,[2,1]) == [[3, 2], [7, 6], [11, 10], [15, 14]]);
assert(subindex(v,[1:3]) == [[2, 3, 4], [6, 7, 8], [10, 11, 12], [14, 15, 16]]);
}
test_subindex();
module test_pair() {
assert(pair([3,4,5,6]) == [[3,4], [4,5], [5,6]]);
assert(pair("ABCD") == [["A","B"], ["B","C"], ["C","D"]]);
assert(pair([3,4,5,6]) == [[3,4], [4,5], [5,6]]);
assert(pair("ABCD") == [["A","B"], ["B","C"], ["C","D"]]);
}
test_pair();
module test_pair_wrap() {
assert(pair_wrap([3,4,5,6]) == [[3,4], [4,5], [5,6], [6,3]]);
assert(pair_wrap("ABCD") == [["A","B"], ["B","C"], ["C","D"], ["D","A"]]);
assert(pair_wrap([3,4,5,6]) == [[3,4], [4,5], [5,6], [6,3]]);
assert(pair_wrap("ABCD") == [["A","B"], ["B","C"], ["C","D"], ["D","A"]]);
}
test_pair_wrap();
module test_triplet() {
assert(triplet([3,4,5,6,7]) == [[3,4,5], [4,5,6], [5,6,7]]);
assert(triplet("ABCDE") == [["A","B","C"], ["B","C","D"], ["C","D","E"]]);
assert(triplet([3,4,5,6,7]) == [[3,4,5], [4,5,6], [5,6,7]]);
assert(triplet("ABCDE") == [["A","B","C"], ["B","C","D"], ["C","D","E"]]);
}
test_triplet();
module test_triplet_wrap() {
assert(triplet_wrap([3,4,5,6]) == [[3,4,5], [4,5,6], [5,6,3], [6,3,4]]);
assert(triplet_wrap("ABCD") == [["A","B","C"], ["B","C","D"], ["C","D","A"], ["D","A","B"]]);
assert(triplet_wrap([3,4,5,6]) == [[3,4,5], [4,5,6], [5,6,3], [6,3,4]]);
assert(triplet_wrap("ABCD") == [["A","B","C"], ["B","C","D"], ["C","D","A"], ["D","A","B"]]);
}
test_triplet_wrap();
module test_permute() {
assert(permute([3,4,5,6]) == [[3,4],[3,5],[3,6],[4,5],[4,6],[5,6]]);
assert(permute([3,4,5,6],n=3) == [[3,4,5],[3,4,6],[3,5,6],[4,5,6]]);
assert(permute([3,4,5,6]) == [[3,4],[3,5],[3,6],[4,5],[4,6],[5,6]]);
assert(permute([3,4,5,6],n=3) == [[3,4,5],[3,4,6],[3,5,6],[4,5,6]]);
}
test_permute();
module test_repeat_entries() {
list = [0,1,2,3];
assert(repeat_entries(list, 6) == [0,0,1,2,2,3]);
assert(repeat_entries(list, 6, exact=false) == [0,0,1,1,2,2,3,3]);
assert(repeat_entries(list, [1,1,2,1], exact=false) == [0,1,2,2,3]);
list = [0,1,2,3];
assert(repeat_entries(list, 6) == [0,0,1,2,2,3]);
assert(repeat_entries(list, 6, exact=false) == [0,0,1,1,2,2,3,3]);
assert(repeat_entries(list, [1,1,2,1], exact=false) == [0,1,2,2,3]);
}
test_repeat_entries();
module test_zip() {
v1 = [1,2,3,4];
v2 = [5,6,7];
v3 = [8,9,10,11];
assert(zip(v1,v3) == [[1,8],[2,9],[3,10],[4,11]]);
assert(zip([v1,v3]) == [[1,8],[2,9],[3,10],[4,11]]);
assert(zip([v1,v2],fit="short") == [[1,5],[2,6],[3,7]]);
assert(zip([v1,v2],fit="long") == [[1,5],[2,6],[3,7],[4,undef]]);
assert(zip([v1,v2],fit="long", fill=0) == [[1,5],[2,6],[3,7],[4,0]]);
assert(zip([v1,v2,v3],fit="long") == [[1,5,8],[2,6,9],[3,7,10],[4,undef,11]]);
v1 = [1,2,3,4];
v2 = [5,6,7];
v3 = [8,9,10,11];
assert(zip(v1,v3) == [[1,8],[2,9],[3,10],[4,11]]);
assert(zip([v1,v3]) == [[1,8],[2,9],[3,10],[4,11]]);
assert(zip([v1,v2],fit="short") == [[1,5],[2,6],[3,7]]);
assert(zip([v1,v2],fit="long") == [[1,5],[2,6],[3,7],[4,undef]]);
assert(zip([v1,v2],fit="long", fill=0) == [[1,5],[2,6],[3,7],[4,0]]);
assert(zip([v1,v2,v3],fit="long") == [[1,5,8],[2,6,9],[3,7,10],[4,undef,11]]);
}
test_zip();
module test_array_group() {
v = [1,2,3,4,5,6];
assert(array_group(v,2) == [[1,2], [3,4], [5,6]]);
assert(array_group(v,3) == [[1,2,3], [4,5,6]]);
assert(array_group(v,4,0) == [[1,2,3,4], [5,6,0,0]]);
v = [1,2,3,4,5,6];
assert(array_group(v,2) == [[1,2], [3,4], [5,6]]);
assert(array_group(v,3) == [[1,2,3], [4,5,6]]);
assert(array_group(v,4,0) == [[1,2,3,4], [5,6,0,0]]);
}
test_array_group();
module test_flatten() {
assert(flatten([[1,2,3], [4,5,[6,7,8]]]) == [1,2,3,4,5,[6,7,8]]);
assert(flatten([[1,2,3], [4,5,[6,7,8]]]) == [1,2,3,4,5,[6,7,8]]);
}
test_flatten();
module test_array_dim() {
assert(array_dim([[[1,2,3],[4,5,6]],[[7,8,9],[10,11,12]]]) == [2,2,3]);
assert(array_dim([[[1,2,3],[4,5,6]],[[7,8,9],[10,11,12]]], 0) == 2);
assert(array_dim([[[1,2,3],[4,5,6]],[[7,8,9],[10,11,12]]], 2) == 3);
assert(array_dim([[[1,2,3],[4,5,6]],[[7,8,9]]]) == [2,undef,3]);
assert(array_dim([[[1,2,3],[4,5,6]],[[7,8,9],[10,11,12]]]) == [2,2,3]);
assert(array_dim([[[1,2,3],[4,5,6]],[[7,8,9],[10,11,12]]], 0) == 2);
assert(array_dim([[[1,2,3],[4,5,6]],[[7,8,9],[10,11,12]]], 2) == 3);
assert(array_dim([[[1,2,3],[4,5,6]],[[7,8,9]]]) == [2,undef,3]);
}
test_array_dim();
module test_transpose() {
assert(transpose([[1,2,3],[4,5,6],[7,8,9]]) == [[1,4,7],[2,5,8],[3,6,9]]);
assert(transpose([[1,2,3],[4,5,6]]) == [[1,4],[2,5],[3,6]]);
assert(transpose([3,4,5]) == [3,4,5]);
assert(transpose([[1,2,3],[4,5,6],[7,8,9]]) == [[1,4,7],[2,5,8],[3,6,9]]);
assert(transpose([[1,2,3],[4,5,6]]) == [[1,4],[2,5],[3,6]]);
assert(transpose([3,4,5]) == [3,4,5]);
}
test_transpose();
@@ -366,4 +366,4 @@ test_transpose();
cube();
// vim: noexpandtab tabstop=4 shiftwidth=4 softtabstop=4 nowrap
// vim: expandtab tabstop=4 shiftwidth=4 softtabstop=4 nowrap

View File

@@ -2,254 +2,254 @@ include <BOSL2/std.scad>
module test_typeof() {
assert(typeof(undef) == "undef");
assert(typeof(true) == "boolean");
assert(typeof(false) == "boolean");
assert(typeof(-123) == "number");
assert(typeof(0) == "number");
assert(typeof(123) == "number");
assert(typeof("") == "string");
assert(typeof("foo") == "string");
assert(typeof([]) == "list");
assert(typeof(["foo","bar"]) == "list");
assert(typeof([123,849,32]) == "list");
assert(typeof([0:5]) == "range");
assert(typeof([-3:0]) == "range");
assert(typeof([0:1:5]) == "range");
assert(typeof([-3:2:5]) == "range");
assert(typeof([10:-2:-10]) == "range");
assert(typeof(undef) == "undef");
assert(typeof(true) == "boolean");
assert(typeof(false) == "boolean");
assert(typeof(-123) == "number");
assert(typeof(0) == "number");
assert(typeof(123) == "number");
assert(typeof("") == "string");
assert(typeof("foo") == "string");
assert(typeof([]) == "list");
assert(typeof(["foo","bar"]) == "list");
assert(typeof([123,849,32]) == "list");
assert(typeof([0:5]) == "range");
assert(typeof([-3:0]) == "range");
assert(typeof([0:1:5]) == "range");
assert(typeof([-3:2:5]) == "range");
assert(typeof([10:-2:-10]) == "range");
}
test_typeof();
module test_is_type() {
assert(is_type(undef,"undef"));
assert(is_type(true,"boolean"));
assert(is_type(false,"boolean"));
assert(is_type(-123,"number"));
assert(is_type(0,"number"));
assert(is_type(123,"number"));
assert(is_type("","string"));
assert(is_type("foo","string"));
assert(is_type([],"list"));
assert(is_type([1,2,3],"list"));
assert(is_type(["foo","bar"],"list"));
assert(is_type([0:5],"range"));
assert(is_type(undef,"undef"));
assert(is_type(true,"boolean"));
assert(is_type(false,"boolean"));
assert(is_type(-123,"number"));
assert(is_type(0,"number"));
assert(is_type(123,"number"));
assert(is_type("","string"));
assert(is_type("foo","string"));
assert(is_type([],"list"));
assert(is_type([1,2,3],"list"));
assert(is_type(["foo","bar"],"list"));
assert(is_type([0:5],"range"));
assert(is_type(undef,["undef"]));
assert(is_type(true,["boolean"]));
assert(is_type(false,["boolean"]));
assert(is_type(-123,["number"]));
assert(is_type(0,["number"]));
assert(is_type(123,["number"]));
assert(is_type("",["string"]));
assert(is_type("foo",["string"]));
assert(is_type([],["list"]));
assert(is_type([1,2,3],["list"]));
assert(is_type(["foo","bar"],["list"]));
assert(is_type([0:5],["range"]));
assert(is_type(undef,["undef"]));
assert(is_type(true,["boolean"]));
assert(is_type(false,["boolean"]));
assert(is_type(-123,["number"]));
assert(is_type(0,["number"]));
assert(is_type(123,["number"]));
assert(is_type("",["string"]));
assert(is_type("foo",["string"]));
assert(is_type([],["list"]));
assert(is_type([1,2,3],["list"]));
assert(is_type(["foo","bar"],["list"]));
assert(is_type([0:5],["range"]));
assert(is_type(123,["number","string"]));
assert(is_type("foo",["number","string"]));
assert(is_type(123,["number","string"]));
assert(is_type("foo",["number","string"]));
}
test_is_type();
module test_is_def() {
assert(!is_def(undef));
assert(is_def(true));
assert(is_def(false));
assert(is_def(-123));
assert(is_def(0));
assert(is_def(123));
assert(is_def(""));
assert(is_def("foo"));
assert(is_def([]));
assert(is_def([3,4,5]));
assert(is_def(["foo","bar","baz"]));
assert(is_def([0:5]));
assert(!is_def(undef));
assert(is_def(true));
assert(is_def(false));
assert(is_def(-123));
assert(is_def(0));
assert(is_def(123));
assert(is_def(""));
assert(is_def("foo"));
assert(is_def([]));
assert(is_def([3,4,5]));
assert(is_def(["foo","bar","baz"]));
assert(is_def([0:5]));
}
test_is_def();
module test_is_str() {
assert(!is_str(undef));
assert(!is_str(true));
assert(!is_str(false));
assert(!is_str(-123));
assert(!is_str(0));
assert(!is_str(123));
assert(is_str(""));
assert(is_str("foo"));
assert(!is_str([]));
assert(!is_str([3,4,5]));
assert(!is_str(["foo","bar","baz"]));
assert(!is_str([0:5]));
assert(!is_str(undef));
assert(!is_str(true));
assert(!is_str(false));
assert(!is_str(-123));
assert(!is_str(0));
assert(!is_str(123));
assert(is_str(""));
assert(is_str("foo"));
assert(!is_str([]));
assert(!is_str([3,4,5]));
assert(!is_str(["foo","bar","baz"]));
assert(!is_str([0:5]));
}
test_is_str();
module test_is_int() {
assert(is_int(-999));
assert(is_int(-1));
assert(is_int(0));
assert(is_int(1));
assert(is_int(999));
assert(!is_int(-1.1));
assert(!is_int(1.1));
assert(!is_int(-0.1));
assert(!is_int(0.1));
assert(!is_int(-99.1));
assert(!is_int(99.1));
assert(!is_int(undef));
assert(!is_int(false));
assert(!is_int(true));
assert(!is_int("foo"));
assert(!is_int([0,1,2]));
assert(!is_int([0:1:2]));
assert(is_int(-999));
assert(is_int(-1));
assert(is_int(0));
assert(is_int(1));
assert(is_int(999));
assert(!is_int(-1.1));
assert(!is_int(1.1));
assert(!is_int(-0.1));
assert(!is_int(0.1));
assert(!is_int(-99.1));
assert(!is_int(99.1));
assert(!is_int(undef));
assert(!is_int(false));
assert(!is_int(true));
assert(!is_int("foo"));
assert(!is_int([0,1,2]));
assert(!is_int([0:1:2]));
}
test_is_int();
module test_is_integer() {
assert(is_integer(-999));
assert(is_integer(-1));
assert(is_integer(0));
assert(is_integer(1));
assert(is_integer(999));
assert(!is_integer(-1.1));
assert(!is_integer(1.1));
assert(!is_integer(-0.1));
assert(!is_integer(0.1));
assert(!is_integer(-99.1));
assert(!is_integer(99.1));
assert(!is_integer(undef));
assert(!is_integer(false));
assert(!is_integer(true));
assert(!is_integer("foo"));
assert(!is_integer([0,1,2]));
assert(!is_integer([0:1:2]));
assert(is_integer(-999));
assert(is_integer(-1));
assert(is_integer(0));
assert(is_integer(1));
assert(is_integer(999));
assert(!is_integer(-1.1));
assert(!is_integer(1.1));
assert(!is_integer(-0.1));
assert(!is_integer(0.1));
assert(!is_integer(-99.1));
assert(!is_integer(99.1));
assert(!is_integer(undef));
assert(!is_integer(false));
assert(!is_integer(true));
assert(!is_integer("foo"));
assert(!is_integer([0,1,2]));
assert(!is_integer([0:1:2]));
}
test_is_integer();
module test_default() {
assert(default(undef,23) == 23);
assert(default(true,23) == true);
assert(default(false,23) == false);
assert(default(-123,23) == -123);
assert(default(0,23) == 0);
assert(default(123,23) == 123);
assert(default("",23) == "");
assert(default("foo",23) == "foo");
assert(default(undef,23) == 23);
assert(default(true,23) == true);
assert(default(false,23) == false);
assert(default(-123,23) == -123);
assert(default(0,23) == 0);
assert(default(123,23) == 123);
assert(default("",23) == "");
assert(default("foo",23) == "foo");
}
test_default();
module test_first_defined() {
assert(first_defined([undef,undef,true,false,undef]) == true);
assert(first_defined([undef,undef,false,true,undef]) == false);
assert(first_defined([undef,undef,0,1,undef]) == 0);
assert(first_defined([undef,undef,43,44,undef]) == 43);
assert(first_defined([undef,undef,"foo","bar",undef]) == "foo");
assert(first_defined([0,1,2,3,4]) == 0);
assert(first_defined([2,3,4]) == 2);
assert(first_defined([[undef,undef],[undef,true],[false,undef]],recursive=true) == [undef, true]);
assert(first_defined([undef,undef,true,false,undef]) == true);
assert(first_defined([undef,undef,false,true,undef]) == false);
assert(first_defined([undef,undef,0,1,undef]) == 0);
assert(first_defined([undef,undef,43,44,undef]) == 43);
assert(first_defined([undef,undef,"foo","bar",undef]) == "foo");
assert(first_defined([0,1,2,3,4]) == 0);
assert(first_defined([2,3,4]) == 2);
assert(first_defined([[undef,undef],[undef,true],[false,undef]],recursive=true) == [undef, true]);
}
test_first_defined();
module test_num_defined() {
assert(num_defined([undef,undef,true,false,undef]) == 2);
assert(num_defined([9,undef,true,false,undef]) == 3);
assert(num_defined([undef,9,true,false,undef]) == 3);
assert(num_defined(["foo",9,true,false,undef]) == 4);
assert(num_defined([undef,undef,true,false,undef]) == 2);
assert(num_defined([9,undef,true,false,undef]) == 3);
assert(num_defined([undef,9,true,false,undef]) == 3);
assert(num_defined(["foo",9,true,false,undef]) == 4);
}
test_num_defined();
module test_any_defined() {
assert(!any_defined([undef,undef,undef,undef,undef]));
assert(any_defined([3,undef,undef,undef,undef]));
assert(any_defined([undef,3,undef,undef,undef]));
assert(any_defined([undef,undef,3,undef,undef]));
assert(any_defined([undef,undef,undef,3,undef]));
assert(any_defined([undef,undef,undef,undef,3]));
assert(any_defined([3,undef,undef,undef,3]));
assert(any_defined([3,3,3,3,3]));
assert(any_defined(["foo",undef,undef,undef,undef]));
assert(any_defined([undef,"foo",undef,undef,undef]));
assert(any_defined([undef,undef,"foo",undef,undef]));
assert(any_defined([undef,undef,undef,"foo",undef]));
assert(any_defined([undef,undef,undef,undef,"foo"]));
assert(any_defined(["foo",undef,undef,undef,"foo"]));
assert(any_defined(["foo","foo","foo","foo","foo"]));
assert(any_defined([undef,undef,true,false,undef]));
assert(!any_defined([undef,undef,undef,undef,undef]));
assert(any_defined([3,undef,undef,undef,undef]));
assert(any_defined([undef,3,undef,undef,undef]));
assert(any_defined([undef,undef,3,undef,undef]));
assert(any_defined([undef,undef,undef,3,undef]));
assert(any_defined([undef,undef,undef,undef,3]));
assert(any_defined([3,undef,undef,undef,3]));
assert(any_defined([3,3,3,3,3]));
assert(any_defined(["foo",undef,undef,undef,undef]));
assert(any_defined([undef,"foo",undef,undef,undef]));
assert(any_defined([undef,undef,"foo",undef,undef]));
assert(any_defined([undef,undef,undef,"foo",undef]));
assert(any_defined([undef,undef,undef,undef,"foo"]));
assert(any_defined(["foo",undef,undef,undef,"foo"]));
assert(any_defined(["foo","foo","foo","foo","foo"]));
assert(any_defined([undef,undef,true,false,undef]));
}
test_any_defined();
module test_all_defined() {
assert(!all_defined([undef,undef,undef,undef,undef]));
assert(!all_defined([3,undef,undef,undef,undef]));
assert(!all_defined([undef,3,undef,undef,undef]));
assert(!all_defined([undef,undef,3,undef,undef]));
assert(!all_defined([undef,undef,undef,3,undef]));
assert(!all_defined([undef,undef,undef,undef,3]));
assert(!all_defined([3,undef,undef,undef,3]));
assert(all_defined([3,3,3,3,3]));
assert(!all_defined(["foo",undef,undef,undef,undef]));
assert(!all_defined([undef,"foo",undef,undef,undef]));
assert(!all_defined([undef,undef,"foo",undef,undef]));
assert(!all_defined([undef,undef,undef,"foo",undef]));
assert(!all_defined([undef,undef,undef,undef,"foo"]));
assert(!all_defined(["foo",undef,undef,undef,"foo"]));
assert(all_defined(["foo","foo","foo","foo","foo"]));
assert(!all_defined([undef,undef,true,false,undef]));
assert(!all_defined([undef,undef,undef,undef,undef]));
assert(!all_defined([3,undef,undef,undef,undef]));
assert(!all_defined([undef,3,undef,undef,undef]));
assert(!all_defined([undef,undef,3,undef,undef]));
assert(!all_defined([undef,undef,undef,3,undef]));
assert(!all_defined([undef,undef,undef,undef,3]));
assert(!all_defined([3,undef,undef,undef,3]));
assert(all_defined([3,3,3,3,3]));
assert(!all_defined(["foo",undef,undef,undef,undef]));
assert(!all_defined([undef,"foo",undef,undef,undef]));
assert(!all_defined([undef,undef,"foo",undef,undef]));
assert(!all_defined([undef,undef,undef,"foo",undef]));
assert(!all_defined([undef,undef,undef,undef,"foo"]));
assert(!all_defined(["foo",undef,undef,undef,"foo"]));
assert(all_defined(["foo","foo","foo","foo","foo"]));
assert(!all_defined([undef,undef,true,false,undef]));
}
test_all_defined();
module test_get_radius() {
assert(get_radius(r1=100,d1=undef,r=undef,d=undef,dflt=23) == 100);
assert(get_radius(r1=undef,d1=200,r=undef,d=undef,dflt=23) == 100);
assert(get_radius(r1=undef,d1=undef,r=100,d=undef,dflt=23) == 100);
assert(get_radius(r1=undef,d1=undef,r=undef,d=200,dflt=23) == 100);
assert(get_radius(r1=50,d1=undef,r=undef,d=undef,dflt=23) == 50);
assert(get_radius(r1=undef,d1=100,r=undef,d=undef,dflt=23) == 50);
assert(get_radius(r1=undef,d1=undef,r=50,d=undef,dflt=23) == 50);
assert(get_radius(r1=undef,d1=undef,r=undef,d=100,dflt=23) == 50);
assert(get_radius(r1=undef,d1=undef,r=undef,d=undef,dflt=23) == 23);
assert(get_radius(r1=undef,d1=undef,r=undef,d=undef,dflt=undef) == undef);
assert(get_radius(r1=100,d1=undef,r=undef,d=undef,dflt=23) == 100);
assert(get_radius(r1=undef,d1=200,r=undef,d=undef,dflt=23) == 100);
assert(get_radius(r1=undef,d1=undef,r=100,d=undef,dflt=23) == 100);
assert(get_radius(r1=undef,d1=undef,r=undef,d=200,dflt=23) == 100);
assert(get_radius(r1=50,d1=undef,r=undef,d=undef,dflt=23) == 50);
assert(get_radius(r1=undef,d1=100,r=undef,d=undef,dflt=23) == 50);
assert(get_radius(r1=undef,d1=undef,r=50,d=undef,dflt=23) == 50);
assert(get_radius(r1=undef,d1=undef,r=undef,d=100,dflt=23) == 50);
assert(get_radius(r1=undef,d1=undef,r=undef,d=undef,dflt=23) == 23);
assert(get_radius(r1=undef,d1=undef,r=undef,d=undef,dflt=undef) == undef);
}
test_get_radius();
module test_get_height() {
assert(get_height(h=undef, l=undef, height=undef, dflt=undef) == undef);
assert(get_height(h=undef, l=undef, height=undef, dflt=23) == 23);
assert(get_height(h=undef, l=undef, height=50, dflt=23) == 50);
assert(get_height(h=undef, l=50, height=undef, dflt=23) == 50);
assert(get_height(h=50, l=undef, height=undef, dflt=23) == 50);
assert(get_height(h=undef, l=undef, height=75, dflt=23) == 75);
assert(get_height(h=undef, l=75, height=undef, dflt=23) == 75);
assert(get_height(h=75, l=undef, height=undef, dflt=23) == 75);
assert(get_height(h=undef, l=undef, height=undef, dflt=undef) == undef);
assert(get_height(h=undef, l=undef, height=undef, dflt=23) == 23);
assert(get_height(h=undef, l=undef, height=50, dflt=23) == 50);
assert(get_height(h=undef, l=50, height=undef, dflt=23) == 50);
assert(get_height(h=50, l=undef, height=undef, dflt=23) == 50);
assert(get_height(h=undef, l=undef, height=75, dflt=23) == 75);
assert(get_height(h=undef, l=75, height=undef, dflt=23) == 75);
assert(get_height(h=75, l=undef, height=undef, dflt=23) == 75);
}
test_get_height();
module test_scalar_vec3() {
assert(scalar_vec3(undef) == undef);
assert(scalar_vec3(3) == [3,3,3]);
assert(scalar_vec3(3,dflt=1) == [3,1,1]);
assert(scalar_vec3([3]) == [3,0,0]);
assert(scalar_vec3([3,4]) == [3,4,0]);
assert(scalar_vec3([3,4],dflt=1) == [3,4,1]);
assert(scalar_vec3([3],dflt=1) == [3,1,1]);
assert(scalar_vec3([3,4,5]) == [3,4,5]);
assert(scalar_vec3([3,4,5,6]) == [3,4,5]);
assert(scalar_vec3(undef) == undef);
assert(scalar_vec3(3) == [3,3,3]);
assert(scalar_vec3(3,dflt=1) == [3,1,1]);
assert(scalar_vec3([3]) == [3,0,0]);
assert(scalar_vec3([3,4]) == [3,4,0]);
assert(scalar_vec3([3,4],dflt=1) == [3,4,1]);
assert(scalar_vec3([3],dflt=1) == [3,1,1]);
assert(scalar_vec3([3,4,5]) == [3,4,5]);
assert(scalar_vec3([3,4,5,6]) == [3,4,5]);
}
test_scalar_vec3();
// vim: noexpandtab tabstop=4 shiftwidth=4 softtabstop=4 nowrap
// vim: expandtab tabstop=4 shiftwidth=4 softtabstop=4 nowrap

View File

@@ -2,208 +2,208 @@ include <BOSL2/std.scad>
module test_point2d() {
assert(point2d([1,2,3])==[1,2]);
assert(point2d([2,3])==[2,3]);
assert(point2d([1])==[1,0]);
assert(point2d([1,2,3])==[1,2]);
assert(point2d([2,3])==[2,3]);
assert(point2d([1])==[1,0]);
}
test_point2d();
module test_path2d() {
assert(path2d([[1,2], [3,4], [5,6], [7,8]])==[[1,2],[3,4],[5,6],[7,8]]);
assert(path2d([[1,2,3], [2,3,4], [3,4,5], [4,5,6]])==[[1,2],[2,3],[3,4],[4,5]]);
assert(path2d([[1,2,3,4], [2,3,4,5], [3,4,5,6], [4,5,6,7]])==[[1,2],[2,3],[3,4],[4,5]]);
assert(path2d([[1,2], [3,4], [5,6], [7,8]])==[[1,2],[3,4],[5,6],[7,8]]);
assert(path2d([[1,2,3], [2,3,4], [3,4,5], [4,5,6]])==[[1,2],[2,3],[3,4],[4,5]]);
assert(path2d([[1,2,3,4], [2,3,4,5], [3,4,5,6], [4,5,6,7]])==[[1,2],[2,3],[3,4],[4,5]]);
}
test_path2d();
module test_point3d() {
assert(point3d([1,2,3,4,5])==[1,2,3]);
assert(point3d([1,2,3,4])==[1,2,3]);
assert(point3d([1,2,3])==[1,2,3]);
assert(point3d([2,3])==[2,3,0]);
assert(point3d([1])==[1,0,0]);
assert(point3d([1,2,3,4,5])==[1,2,3]);
assert(point3d([1,2,3,4])==[1,2,3]);
assert(point3d([1,2,3])==[1,2,3]);
assert(point3d([2,3])==[2,3,0]);
assert(point3d([1])==[1,0,0]);
}
test_point3d();
module test_path3d() {
assert(path3d([[1,2], [3,4], [5,6], [7,8]])==[[1,2,0],[3,4,0],[5,6,0],[7,8,0]]);
assert(path3d([[1,2,3], [2,3,4], [3,4,5], [4,5,6]])==[[1,2,3],[2,3,4],[3,4,5],[4,5,6]]);
assert(path3d([[1,2,3,4], [2,3,4,5], [3,4,5,6], [4,5,6,7]])==[[1,2,3],[2,3,4],[3,4,5],[4,5,6]]);
assert(path3d([[1,2], [3,4], [5,6], [7,8]])==[[1,2,0],[3,4,0],[5,6,0],[7,8,0]]);
assert(path3d([[1,2,3], [2,3,4], [3,4,5], [4,5,6]])==[[1,2,3],[2,3,4],[3,4,5],[4,5,6]]);
assert(path3d([[1,2,3,4], [2,3,4,5], [3,4,5,6], [4,5,6,7]])==[[1,2,3],[2,3,4],[3,4,5],[4,5,6]]);
}
test_path3d();
module test_point4d() {
assert(point4d([1,2,3,4,5])==[1,2,3,4]);
assert(point4d([1,2,3,4])==[1,2,3,4]);
assert(point4d([1,2,3])==[1,2,3,0]);
assert(point4d([2,3])==[2,3,0,0]);
assert(point4d([1])==[1,0,0,0]);
assert(point4d([1,2,3,4,5])==[1,2,3,4]);
assert(point4d([1,2,3,4])==[1,2,3,4]);
assert(point4d([1,2,3])==[1,2,3,0]);
assert(point4d([2,3])==[2,3,0,0]);
assert(point4d([1])==[1,0,0,0]);
}
test_point4d();
module test_path4d() {
assert(path4d([[1,2], [3,4], [5,6], [7,8]])==[[1,2,0,0],[3,4,0,0],[5,6,0,0],[7,8,0,0]]);
assert(path4d([[1,2,3], [2,3,4], [3,4,5], [4,5,6]])==[[1,2,3,0],[2,3,4,0],[3,4,5,0],[4,5,6,0]]);
assert(path4d([[1,2,3,4], [2,3,4,5], [3,4,5,6], [4,5,6,7]])==[[1,2,3,4],[2,3,4,5],[3,4,5,6],[4,5,6,7]]);
assert(path4d([[1,2,3,4,5], [2,3,4,5,6], [3,4,5,6,7], [4,5,6,7,8]])==[[1,2,3,4],[2,3,4,5],[3,4,5,6],[4,5,6,7]]);
assert(path4d([[1,2], [3,4], [5,6], [7,8]])==[[1,2,0,0],[3,4,0,0],[5,6,0,0],[7,8,0,0]]);
assert(path4d([[1,2,3], [2,3,4], [3,4,5], [4,5,6]])==[[1,2,3,0],[2,3,4,0],[3,4,5,0],[4,5,6,0]]);
assert(path4d([[1,2,3,4], [2,3,4,5], [3,4,5,6], [4,5,6,7]])==[[1,2,3,4],[2,3,4,5],[3,4,5,6],[4,5,6,7]]);
assert(path4d([[1,2,3,4,5], [2,3,4,5,6], [3,4,5,6,7], [4,5,6,7,8]])==[[1,2,3,4],[2,3,4,5],[3,4,5,6],[4,5,6,7]]);
}
test_path4d();
module test_polar_to_xy() {
assert(approx(polar_to_xy(20,45), [20/sqrt(2), 20/sqrt(2)]));
assert(approx(polar_to_xy(20,135), [-20/sqrt(2), 20/sqrt(2)]));
assert(approx(polar_to_xy(20,-135), [-20/sqrt(2), -20/sqrt(2)]));
assert(approx(polar_to_xy(20,-45), [20/sqrt(2), -20/sqrt(2)]));
assert(approx(polar_to_xy(40,30), [40*sqrt(3)/2, 40/2]));
assert(approx(polar_to_xy([40,30]), [40*sqrt(3)/2, 40/2]));
assert(approx(polar_to_xy(20,45), [20/sqrt(2), 20/sqrt(2)]));
assert(approx(polar_to_xy(20,135), [-20/sqrt(2), 20/sqrt(2)]));
assert(approx(polar_to_xy(20,-135), [-20/sqrt(2), -20/sqrt(2)]));
assert(approx(polar_to_xy(20,-45), [20/sqrt(2), -20/sqrt(2)]));
assert(approx(polar_to_xy(40,30), [40*sqrt(3)/2, 40/2]));
assert(approx(polar_to_xy([40,30]), [40*sqrt(3)/2, 40/2]));
}
test_polar_to_xy();
module test_xy_to_polar() {
assert(approx(xy_to_polar([20/sqrt(2), 20/sqrt(2)]),[20,45]));
assert(approx(xy_to_polar([-20/sqrt(2), 20/sqrt(2)]),[20,135]));
assert(approx(xy_to_polar([-20/sqrt(2), -20/sqrt(2)]),[20,-135]));
assert(approx(xy_to_polar([20/sqrt(2), -20/sqrt(2)]),[20,-45]));
assert(approx(xy_to_polar([40*sqrt(3)/2, 40/2]),[40,30]));
assert(approx(xy_to_polar([-40*sqrt(3)/2, 40/2]),[40,150]));
assert(approx(xy_to_polar([-40*sqrt(3)/2, -40/2]),[40,-150]));
assert(approx(xy_to_polar([40*sqrt(3)/2, -40/2]),[40,-30]));
assert(approx(xy_to_polar([20/sqrt(2), 20/sqrt(2)]),[20,45]));
assert(approx(xy_to_polar([-20/sqrt(2), 20/sqrt(2)]),[20,135]));
assert(approx(xy_to_polar([-20/sqrt(2), -20/sqrt(2)]),[20,-135]));
assert(approx(xy_to_polar([20/sqrt(2), -20/sqrt(2)]),[20,-45]));
assert(approx(xy_to_polar([40*sqrt(3)/2, 40/2]),[40,30]));
assert(approx(xy_to_polar([-40*sqrt(3)/2, 40/2]),[40,150]));
assert(approx(xy_to_polar([-40*sqrt(3)/2, -40/2]),[40,-150]));
assert(approx(xy_to_polar([40*sqrt(3)/2, -40/2]),[40,-30]));
}
test_xy_to_polar();
module test_project_plane() {
assert(approx(project_plane([-5,0,-5], [-10,0,-10], [0,0,0], [0,-10,-10]),[0,10*sqrt(2)/2]));
assert(approx(project_plane([0,-5,-5], [-10,0,-10], [0,0,0], [0,-10,-10]),[6.12372, 10.6066],eps=1e-5));
assert(approx(project_plane([-5,0,-5], [-10,0,-10], [0,0,0], [0,-10,-10]),[0,10*sqrt(2)/2]));
assert(approx(project_plane([0,-5,-5], [-10,0,-10], [0,0,0], [0,-10,-10]),[6.12372, 10.6066],eps=1e-5));
}
test_project_plane();
module test_lift_plane() {
assert(approx(lift_plane([0,10*sqrt(2)/2], [-10,0,-10], [0,0,0], [0,-10,-10]),[-5,0,-5]));
assert(approx(lift_plane([6.12372, 10.6066], [-10,0,-10], [0,0,0], [0,-10,-10]),[0,-5,-5],eps=1e-5));
assert(approx(lift_plane([0,10*sqrt(2)/2], [-10,0,-10], [0,0,0], [0,-10,-10]),[-5,0,-5]));
assert(approx(lift_plane([6.12372, 10.6066], [-10,0,-10], [0,0,0], [0,-10,-10]),[0,-5,-5],eps=1e-5));
}
test_lift_plane();
module test_cylindrical_to_xyz() {
assert(approx(cylindrical_to_xyz(100,90,10),[0,100,10]));
assert(approx(cylindrical_to_xyz(100,270,-10),[0,-100,-10]));
assert(approx(cylindrical_to_xyz(100,-90,-10),[0,-100,-10]));
assert(approx(cylindrical_to_xyz(100,180,0),[-100,0,0]));
assert(approx(cylindrical_to_xyz(100,0,0),[100,0,0]));
assert(approx(cylindrical_to_xyz(100,45,10),[100*sqrt(2)/2,100*sqrt(2)/2,10]));
assert(approx(cylindrical_to_xyz([100,90,10]),[0,100,10]));
assert(approx(cylindrical_to_xyz([100,270,-10]),[0,-100,-10]));
assert(approx(cylindrical_to_xyz([100,-90,-10]),[0,-100,-10]));
assert(approx(cylindrical_to_xyz([100,180,0]),[-100,0,0]));
assert(approx(cylindrical_to_xyz([100,0,0]),[100,0,0]));
assert(approx(cylindrical_to_xyz([100,45,10]),[100*sqrt(2)/2,100*sqrt(2)/2,10]));
assert(approx(cylindrical_to_xyz(100,90,10),[0,100,10]));
assert(approx(cylindrical_to_xyz(100,270,-10),[0,-100,-10]));
assert(approx(cylindrical_to_xyz(100,-90,-10),[0,-100,-10]));
assert(approx(cylindrical_to_xyz(100,180,0),[-100,0,0]));
assert(approx(cylindrical_to_xyz(100,0,0),[100,0,0]));
assert(approx(cylindrical_to_xyz(100,45,10),[100*sqrt(2)/2,100*sqrt(2)/2,10]));
assert(approx(cylindrical_to_xyz([100,90,10]),[0,100,10]));
assert(approx(cylindrical_to_xyz([100,270,-10]),[0,-100,-10]));
assert(approx(cylindrical_to_xyz([100,-90,-10]),[0,-100,-10]));
assert(approx(cylindrical_to_xyz([100,180,0]),[-100,0,0]));
assert(approx(cylindrical_to_xyz([100,0,0]),[100,0,0]));
assert(approx(cylindrical_to_xyz([100,45,10]),[100*sqrt(2)/2,100*sqrt(2)/2,10]));
}
test_cylindrical_to_xyz();
module test_xyz_to_cylindrical() {
assert(approx(xyz_to_cylindrical(0,100,10),[100,90,10]));
assert(approx(xyz_to_cylindrical(0,-100,-10),[100,-90,-10]));
assert(approx(xyz_to_cylindrical(-100,0,0),[100,180,0]));
assert(approx(xyz_to_cylindrical(100,0,0),[100,0,0]));
assert(approx(xyz_to_cylindrical(100*sqrt(2)/2,100*sqrt(2)/2,10),[100,45,10]));
assert(approx(xyz_to_cylindrical([0,100,10]),[100,90,10]));
assert(approx(xyz_to_cylindrical([0,-100,-10]),[100,-90,-10]));
assert(approx(xyz_to_cylindrical([-100,0,0]),[100,180,0]));
assert(approx(xyz_to_cylindrical([100,0,0]),[100,0,0]));
assert(approx(xyz_to_cylindrical([100*sqrt(2)/2,100*sqrt(2)/2,10]),[100,45,10]));
assert(approx(xyz_to_cylindrical(0,100,10),[100,90,10]));
assert(approx(xyz_to_cylindrical(0,-100,-10),[100,-90,-10]));
assert(approx(xyz_to_cylindrical(-100,0,0),[100,180,0]));
assert(approx(xyz_to_cylindrical(100,0,0),[100,0,0]));
assert(approx(xyz_to_cylindrical(100*sqrt(2)/2,100*sqrt(2)/2,10),[100,45,10]));
assert(approx(xyz_to_cylindrical([0,100,10]),[100,90,10]));
assert(approx(xyz_to_cylindrical([0,-100,-10]),[100,-90,-10]));
assert(approx(xyz_to_cylindrical([-100,0,0]),[100,180,0]));
assert(approx(xyz_to_cylindrical([100,0,0]),[100,0,0]));
assert(approx(xyz_to_cylindrical([100*sqrt(2)/2,100*sqrt(2)/2,10]),[100,45,10]));
}
test_xyz_to_cylindrical();
module test_spherical_to_xyz() {
assert(approx(spherical_to_xyz(100,90,45),100*[0,sqrt(2)/2,sqrt(2)/2]));
assert(approx(spherical_to_xyz(100,270,45),100*[0,-sqrt(2)/2,sqrt(2)/2]));
assert(approx(spherical_to_xyz(100,-90,45),100*[0,-sqrt(2)/2,sqrt(2)/2]));
assert(approx(spherical_to_xyz(100,90,90),100*[0,1,0]));
assert(approx(spherical_to_xyz(100,-90,90),100*[0,-1,0]));
assert(approx(spherical_to_xyz(100,180,90),100*[-1,0,0]));
assert(approx(spherical_to_xyz(100,0,90),100*[1,0,0]));
assert(approx(spherical_to_xyz(100,0,0),100*[0,0,1]));
assert(approx(spherical_to_xyz(100,0,180),100*[0,0,-1]));
assert(approx(spherical_to_xyz([100,90,45]),100*[0,sqrt(2)/2,sqrt(2)/2]));
assert(approx(spherical_to_xyz([100,270,45]),100*[0,-sqrt(2)/2,sqrt(2)/2]));
assert(approx(spherical_to_xyz([100,-90,45]),100*[0,-sqrt(2)/2,sqrt(2)/2]));
assert(approx(spherical_to_xyz([100,90,90]),100*[0,1,0]));
assert(approx(spherical_to_xyz([100,-90,90]),100*[0,-1,0]));
assert(approx(spherical_to_xyz([100,180,90]),100*[-1,0,0]));
assert(approx(spherical_to_xyz([100,0,90]),100*[1,0,0]));
assert(approx(spherical_to_xyz([100,0,0]),100*[0,0,1]));
assert(approx(spherical_to_xyz([100,0,180]),100*[0,0,-1]));
assert(approx(spherical_to_xyz(100,90,45),100*[0,sqrt(2)/2,sqrt(2)/2]));
assert(approx(spherical_to_xyz(100,270,45),100*[0,-sqrt(2)/2,sqrt(2)/2]));
assert(approx(spherical_to_xyz(100,-90,45),100*[0,-sqrt(2)/2,sqrt(2)/2]));
assert(approx(spherical_to_xyz(100,90,90),100*[0,1,0]));
assert(approx(spherical_to_xyz(100,-90,90),100*[0,-1,0]));
assert(approx(spherical_to_xyz(100,180,90),100*[-1,0,0]));
assert(approx(spherical_to_xyz(100,0,90),100*[1,0,0]));
assert(approx(spherical_to_xyz(100,0,0),100*[0,0,1]));
assert(approx(spherical_to_xyz(100,0,180),100*[0,0,-1]));
assert(approx(spherical_to_xyz([100,90,45]),100*[0,sqrt(2)/2,sqrt(2)/2]));
assert(approx(spherical_to_xyz([100,270,45]),100*[0,-sqrt(2)/2,sqrt(2)/2]));
assert(approx(spherical_to_xyz([100,-90,45]),100*[0,-sqrt(2)/2,sqrt(2)/2]));
assert(approx(spherical_to_xyz([100,90,90]),100*[0,1,0]));
assert(approx(spherical_to_xyz([100,-90,90]),100*[0,-1,0]));
assert(approx(spherical_to_xyz([100,180,90]),100*[-1,0,0]));
assert(approx(spherical_to_xyz([100,0,90]),100*[1,0,0]));
assert(approx(spherical_to_xyz([100,0,0]),100*[0,0,1]));
assert(approx(spherical_to_xyz([100,0,180]),100*[0,0,-1]));
}
test_spherical_to_xyz();
module test_xyz_to_spherical() {
assert(approx(xyz_to_spherical(0, 100*sqrt(2)/2,100*sqrt(2)/2),[100, 90,45]));
assert(approx(xyz_to_spherical(0,-100*sqrt(2)/2,100*sqrt(2)/2),[100,-90,45]));
assert(approx(xyz_to_spherical( 0, 100, 0),[100, 90, 90]));
assert(approx(xyz_to_spherical( 0,-100, 0),[100,-90, 90]));
assert(approx(xyz_to_spherical(-100, 0, 0),[100,180, 90]));
assert(approx(xyz_to_spherical( 100, 0, 0),[100, 0, 90]));
assert(approx(xyz_to_spherical( 0, 0, 100),[100, 0, 0]));
assert(approx(xyz_to_spherical( 0, 0,-100),[100, 0,180]));
assert(approx(xyz_to_spherical([0, 100*sqrt(2)/2,100*sqrt(2)/2]),[100, 90,45]));
assert(approx(xyz_to_spherical([0,-100*sqrt(2)/2,100*sqrt(2)/2]),[100,-90,45]));
assert(approx(xyz_to_spherical([ 0, 100, 0]),[100, 90, 90]));
assert(approx(xyz_to_spherical([ 0,-100, 0]),[100,-90, 90]));
assert(approx(xyz_to_spherical([-100, 0, 0]),[100,180, 90]));
assert(approx(xyz_to_spherical([ 100, 0, 0]),[100, 0, 90]));
assert(approx(xyz_to_spherical([ 0, 0, 100]),[100, 0, 0]));
assert(approx(xyz_to_spherical([ 0, 0,-100]),[100, 0,180]));
assert(approx(xyz_to_spherical(0, 100*sqrt(2)/2,100*sqrt(2)/2),[100, 90,45]));
assert(approx(xyz_to_spherical(0,-100*sqrt(2)/2,100*sqrt(2)/2),[100,-90,45]));
assert(approx(xyz_to_spherical( 0, 100, 0),[100, 90, 90]));
assert(approx(xyz_to_spherical( 0,-100, 0),[100,-90, 90]));
assert(approx(xyz_to_spherical(-100, 0, 0),[100,180, 90]));
assert(approx(xyz_to_spherical( 100, 0, 0),[100, 0, 90]));
assert(approx(xyz_to_spherical( 0, 0, 100),[100, 0, 0]));
assert(approx(xyz_to_spherical( 0, 0,-100),[100, 0,180]));
assert(approx(xyz_to_spherical([0, 100*sqrt(2)/2,100*sqrt(2)/2]),[100, 90,45]));
assert(approx(xyz_to_spherical([0,-100*sqrt(2)/2,100*sqrt(2)/2]),[100,-90,45]));
assert(approx(xyz_to_spherical([ 0, 100, 0]),[100, 90, 90]));
assert(approx(xyz_to_spherical([ 0,-100, 0]),[100,-90, 90]));
assert(approx(xyz_to_spherical([-100, 0, 0]),[100,180, 90]));
assert(approx(xyz_to_spherical([ 100, 0, 0]),[100, 0, 90]));
assert(approx(xyz_to_spherical([ 0, 0, 100]),[100, 0, 0]));
assert(approx(xyz_to_spherical([ 0, 0,-100]),[100, 0,180]));
}
test_xyz_to_spherical();
module test_altaz_to_xyz() {
assert(approx(altaz_to_xyz( 0, 0,100),[ 0,100, 0]));
assert(approx(altaz_to_xyz( 90, 0,100),[ 0, 0, 100]));
assert(approx(altaz_to_xyz(-90, 0,100),[ 0, 0,-100]));
assert(approx(altaz_to_xyz( 0, 90,100),[ 100, 0, 0]));
assert(approx(altaz_to_xyz( 0,-90,100),[-100, 0, 0]));
assert(approx(altaz_to_xyz( 45, 90,100),[100*sqrt(2)/2,0,100*sqrt(2)/2]));
assert(approx(altaz_to_xyz(-45, 90,100),[100*sqrt(2)/2,0,-100*sqrt(2)/2]));
assert(approx(altaz_to_xyz([ 0, 0,100]),[ 0,100, 0]));
assert(approx(altaz_to_xyz([ 90, 0,100]),[ 0, 0, 100]));
assert(approx(altaz_to_xyz([-90, 0,100]),[ 0, 0,-100]));
assert(approx(altaz_to_xyz([ 0, 90,100]),[ 100, 0, 0]));
assert(approx(altaz_to_xyz([ 0,-90,100]),[-100, 0, 0]));
assert(approx(altaz_to_xyz([ 45, 90,100]),[100*sqrt(2)/2,0,100*sqrt(2)/2]));
assert(approx(altaz_to_xyz([-45, 90,100]),[100*sqrt(2)/2,0,-100*sqrt(2)/2]));
assert(approx(altaz_to_xyz( 0, 0,100),[ 0,100, 0]));
assert(approx(altaz_to_xyz( 90, 0,100),[ 0, 0, 100]));
assert(approx(altaz_to_xyz(-90, 0,100),[ 0, 0,-100]));
assert(approx(altaz_to_xyz( 0, 90,100),[ 100, 0, 0]));
assert(approx(altaz_to_xyz( 0,-90,100),[-100, 0, 0]));
assert(approx(altaz_to_xyz( 45, 90,100),[100*sqrt(2)/2,0,100*sqrt(2)/2]));
assert(approx(altaz_to_xyz(-45, 90,100),[100*sqrt(2)/2,0,-100*sqrt(2)/2]));
assert(approx(altaz_to_xyz([ 0, 0,100]),[ 0,100, 0]));
assert(approx(altaz_to_xyz([ 90, 0,100]),[ 0, 0, 100]));
assert(approx(altaz_to_xyz([-90, 0,100]),[ 0, 0,-100]));
assert(approx(altaz_to_xyz([ 0, 90,100]),[ 100, 0, 0]));
assert(approx(altaz_to_xyz([ 0,-90,100]),[-100, 0, 0]));
assert(approx(altaz_to_xyz([ 45, 90,100]),[100*sqrt(2)/2,0,100*sqrt(2)/2]));
assert(approx(altaz_to_xyz([-45, 90,100]),[100*sqrt(2)/2,0,-100*sqrt(2)/2]));
}
test_altaz_to_xyz();
module test_xyz_to_altaz() {
assert(approx(xyz_to_altaz( 0,100, 0),[ 0, 0,100]));
assert(approx(xyz_to_altaz( 0, 0, 100),[ 90, 0,100]));
assert(approx(xyz_to_altaz( 0, 0,-100),[-90, 0,100]));
assert(approx(xyz_to_altaz( 100, 0, 0),[ 0, 90,100]));
assert(approx(xyz_to_altaz(-100, 0, 0),[ 0,-90,100]));
assert(approx(xyz_to_altaz(100*sqrt(2)/2,0,100*sqrt(2)/2),[ 45, 90,100]));
assert(approx(xyz_to_altaz(100*sqrt(2)/2,0,-100*sqrt(2)/2),[-45, 90,100]));
assert(approx(xyz_to_altaz([ 0,100, 0]),[ 0, 0,100]));
assert(approx(xyz_to_altaz([ 0, 0, 100]),[ 90, 0,100]));
assert(approx(xyz_to_altaz([ 0, 0,-100]),[-90, 0,100]));
assert(approx(xyz_to_altaz([ 100, 0, 0]),[ 0, 90,100]));
assert(approx(xyz_to_altaz([-100, 0, 0]),[ 0,-90,100]));
assert(approx(xyz_to_altaz([100*sqrt(2)/2,0,100*sqrt(2)/2]),[ 45, 90,100]));
assert(approx(xyz_to_altaz([100*sqrt(2)/2,0,-100*sqrt(2)/2]),[-45, 90,100]));
assert(approx(xyz_to_altaz( 0,100, 0),[ 0, 0,100]));
assert(approx(xyz_to_altaz( 0, 0, 100),[ 90, 0,100]));
assert(approx(xyz_to_altaz( 0, 0,-100),[-90, 0,100]));
assert(approx(xyz_to_altaz( 100, 0, 0),[ 0, 90,100]));
assert(approx(xyz_to_altaz(-100, 0, 0),[ 0,-90,100]));
assert(approx(xyz_to_altaz(100*sqrt(2)/2,0,100*sqrt(2)/2),[ 45, 90,100]));
assert(approx(xyz_to_altaz(100*sqrt(2)/2,0,-100*sqrt(2)/2),[-45, 90,100]));
assert(approx(xyz_to_altaz([ 0,100, 0]),[ 0, 0,100]));
assert(approx(xyz_to_altaz([ 0, 0, 100]),[ 90, 0,100]));
assert(approx(xyz_to_altaz([ 0, 0,-100]),[-90, 0,100]));
assert(approx(xyz_to_altaz([ 100, 0, 0]),[ 0, 90,100]));
assert(approx(xyz_to_altaz([-100, 0, 0]),[ 0,-90,100]));
assert(approx(xyz_to_altaz([100*sqrt(2)/2,0,100*sqrt(2)/2]),[ 45, 90,100]));
assert(approx(xyz_to_altaz([100*sqrt(2)/2,0,-100*sqrt(2)/2]),[-45, 90,100]));
}
test_xyz_to_altaz();
// vim: noexpandtab tabstop=4 shiftwidth=4 softtabstop=4 nowrap
// vim: expandtab tabstop=4 shiftwidth=4 softtabstop=4 nowrap

View File

@@ -3,12 +3,12 @@ include <BOSL2/cubetruss.scad>
module test_cubetruss_dist() {
assert(cubetruss_dist(5,1,size=30,strut=3) == 138);
assert(cubetruss_dist(3,2,size=30,strut=3) == 87);
assert(cubetruss_dist(5,1,size=20,strut=2) == 92);
assert(cubetruss_dist(3,2,size=20,strut=2) == 58);
assert(cubetruss_dist(5,1,size=30,strut=3) == 138);
assert(cubetruss_dist(3,2,size=30,strut=3) == 87);
assert(cubetruss_dist(5,1,size=20,strut=2) == 92);
assert(cubetruss_dist(3,2,size=20,strut=2) == 58);
}
test_cubetruss_dist();
// vim: noexpandtab tabstop=4 shiftwidth=4 softtabstop=4 nowrap
// vim: expandtab tabstop=4 shiftwidth=4 softtabstop=4 nowrap

View File

@@ -2,103 +2,103 @@ include <BOSL2/std.scad>
module test_is_edge_array() {
assert(is_edge_array([[0,0,0,0],[0,0,0,0],[0,0,0,0]]));
assert(is_edge_array([[1,1,1,1],[1,1,1,1],[1,1,1,1]]));
assert(!is_edge_array([[1,1,1],[1,1,1],[1,1,1]]));
assert(!is_edge_array([[1,1,1,1,1],[1,1,1,1,1],[1,1,1,1,1]]));
assert(!is_edge_array([[1,1,1,1],[1,1,1,1]]));
assert(!is_edge_array([1,1,1,1]));
assert(!is_edge_array("foo"));
assert(!is_edge_array(42));
assert(!is_edge_array(true));
assert(is_edge_array(edges(["X","Y"])));
assert(is_edge_array([[0,0,0,0],[0,0,0,0],[0,0,0,0]]));
assert(is_edge_array([[1,1,1,1],[1,1,1,1],[1,1,1,1]]));
assert(!is_edge_array([[1,1,1],[1,1,1],[1,1,1]]));
assert(!is_edge_array([[1,1,1,1,1],[1,1,1,1,1],[1,1,1,1,1]]));
assert(!is_edge_array([[1,1,1,1],[1,1,1,1]]));
assert(!is_edge_array([1,1,1,1]));
assert(!is_edge_array("foo"));
assert(!is_edge_array(42));
assert(!is_edge_array(true));
assert(is_edge_array(edges(["X","Y"])));
}
test_is_edge_array();
module test__edge_set() {
// Edge set pass through
assert(_edge_set([[1,1,1,1],[0,1,0,1],[0,0,0,0]]) == [[1,1,1,1],[0,1,0,1],[0,0,0,0]]);
// Edge set pass through
assert(_edge_set([[1,1,1,1],[0,1,0,1],[0,0,0,0]]) == [[1,1,1,1],[0,1,0,1],[0,0,0,0]]);
// Vectors towards corners
assert(_edge_set([-1,-1,-1]) == [[1,0,0,0],[1,0,0,0],[1,0,0,0]]);
assert(_edge_set([-1,-1, 1]) == [[0,0,1,0],[0,0,1,0],[1,0,0,0]]);
assert(_edge_set([-1, 1,-1]) == [[0,1,0,0],[1,0,0,0],[0,0,1,0]]);
assert(_edge_set([-1, 1, 1]) == [[0,0,0,1],[0,0,1,0],[0,0,1,0]]);
assert(_edge_set([ 1,-1,-1]) == [[1,0,0,0],[0,1,0,0],[0,1,0,0]]);
assert(_edge_set([ 1,-1, 1]) == [[0,0,1,0],[0,0,0,1],[0,1,0,0]]);
assert(_edge_set([ 1, 1,-1]) == [[0,1,0,0],[0,1,0,0],[0,0,0,1]]);
assert(_edge_set([ 1, 1, 1]) == [[0,0,0,1],[0,0,0,1],[0,0,0,1]]);
// Vectors towards corners
assert(_edge_set([-1,-1,-1]) == [[1,0,0,0],[1,0,0,0],[1,0,0,0]]);
assert(_edge_set([-1,-1, 1]) == [[0,0,1,0],[0,0,1,0],[1,0,0,0]]);
assert(_edge_set([-1, 1,-1]) == [[0,1,0,0],[1,0,0,0],[0,0,1,0]]);
assert(_edge_set([-1, 1, 1]) == [[0,0,0,1],[0,0,1,0],[0,0,1,0]]);
assert(_edge_set([ 1,-1,-1]) == [[1,0,0,0],[0,1,0,0],[0,1,0,0]]);
assert(_edge_set([ 1,-1, 1]) == [[0,0,1,0],[0,0,0,1],[0,1,0,0]]);
assert(_edge_set([ 1, 1,-1]) == [[0,1,0,0],[0,1,0,0],[0,0,0,1]]);
assert(_edge_set([ 1, 1, 1]) == [[0,0,0,1],[0,0,0,1],[0,0,0,1]]);
// Vectors towards edges
assert(_edge_set([ 0,-1,-1]) == [[1,0,0,0],[0,0,0,0],[0,0,0,0]]);
assert(_edge_set([ 0, 1,-1]) == [[0,1,0,0],[0,0,0,0],[0,0,0,0]]);
assert(_edge_set([ 0,-1, 1]) == [[0,0,1,0],[0,0,0,0],[0,0,0,0]]);
assert(_edge_set([ 0, 1, 1]) == [[0,0,0,1],[0,0,0,0],[0,0,0,0]]);
assert(_edge_set([-1, 0,-1]) == [[0,0,0,0],[1,0,0,0],[0,0,0,0]]);
assert(_edge_set([ 1, 0,-1]) == [[0,0,0,0],[0,1,0,0],[0,0,0,0]]);
assert(_edge_set([-1, 0, 1]) == [[0,0,0,0],[0,0,1,0],[0,0,0,0]]);
assert(_edge_set([ 1, 0, 1]) == [[0,0,0,0],[0,0,0,1],[0,0,0,0]]);
assert(_edge_set([-1,-1, 0]) == [[0,0,0,0],[0,0,0,0],[1,0,0,0]]);
assert(_edge_set([ 1,-1, 0]) == [[0,0,0,0],[0,0,0,0],[0,1,0,0]]);
assert(_edge_set([-1, 1, 0]) == [[0,0,0,0],[0,0,0,0],[0,0,1,0]]);
assert(_edge_set([ 1, 1, 0]) == [[0,0,0,0],[0,0,0,0],[0,0,0,1]]);
// Vectors towards edges
assert(_edge_set([ 0,-1,-1]) == [[1,0,0,0],[0,0,0,0],[0,0,0,0]]);
assert(_edge_set([ 0, 1,-1]) == [[0,1,0,0],[0,0,0,0],[0,0,0,0]]);
assert(_edge_set([ 0,-1, 1]) == [[0,0,1,0],[0,0,0,0],[0,0,0,0]]);
assert(_edge_set([ 0, 1, 1]) == [[0,0,0,1],[0,0,0,0],[0,0,0,0]]);
assert(_edge_set([-1, 0,-1]) == [[0,0,0,0],[1,0,0,0],[0,0,0,0]]);
assert(_edge_set([ 1, 0,-1]) == [[0,0,0,0],[0,1,0,0],[0,0,0,0]]);
assert(_edge_set([-1, 0, 1]) == [[0,0,0,0],[0,0,1,0],[0,0,0,0]]);
assert(_edge_set([ 1, 0, 1]) == [[0,0,0,0],[0,0,0,1],[0,0,0,0]]);
assert(_edge_set([-1,-1, 0]) == [[0,0,0,0],[0,0,0,0],[1,0,0,0]]);
assert(_edge_set([ 1,-1, 0]) == [[0,0,0,0],[0,0,0,0],[0,1,0,0]]);
assert(_edge_set([-1, 1, 0]) == [[0,0,0,0],[0,0,0,0],[0,0,1,0]]);
assert(_edge_set([ 1, 1, 0]) == [[0,0,0,0],[0,0,0,0],[0,0,0,1]]);
// Vectors towards faces
assert(_edge_set([ 0, 0,-1]) == [[1,1,0,0],[1,1,0,0],[0,0,0,0]]);
assert(_edge_set([ 0, 0, 1]) == [[0,0,1,1],[0,0,1,1],[0,0,0,0]]);
assert(_edge_set([ 0,-1, 0]) == [[1,0,1,0],[0,0,0,0],[1,1,0,0]]);
assert(_edge_set([ 0, 1, 0]) == [[0,1,0,1],[0,0,0,0],[0,0,1,1]]);
assert(_edge_set([-1, 0, 0]) == [[0,0,0,0],[1,0,1,0],[1,0,1,0]]);
assert(_edge_set([ 1, 0, 0]) == [[0,0,0,0],[0,1,0,1],[0,1,0,1]]);
// Vectors towards faces
assert(_edge_set([ 0, 0,-1]) == [[1,1,0,0],[1,1,0,0],[0,0,0,0]]);
assert(_edge_set([ 0, 0, 1]) == [[0,0,1,1],[0,0,1,1],[0,0,0,0]]);
assert(_edge_set([ 0,-1, 0]) == [[1,0,1,0],[0,0,0,0],[1,1,0,0]]);
assert(_edge_set([ 0, 1, 0]) == [[0,1,0,1],[0,0,0,0],[0,0,1,1]]);
assert(_edge_set([-1, 0, 0]) == [[0,0,0,0],[1,0,1,0],[1,0,1,0]]);
assert(_edge_set([ 1, 0, 0]) == [[0,0,0,0],[0,1,0,1],[0,1,0,1]]);
// Named edge sets
assert(_edge_set("X") == [[1,1,1,1],[0,0,0,0],[0,0,0,0]]);
assert(_edge_set("Y") == [[0,0,0,0],[1,1,1,1],[0,0,0,0]]);
assert(_edge_set("Z") == [[0,0,0,0],[0,0,0,0],[1,1,1,1]]);
assert(_edge_set("NONE") == [[0,0,0,0],[0,0,0,0],[0,0,0,0]]);
assert(_edge_set("ALL") == [[1,1,1,1],[1,1,1,1],[1,1,1,1]]);
// Named edge sets
assert(_edge_set("X") == [[1,1,1,1],[0,0,0,0],[0,0,0,0]]);
assert(_edge_set("Y") == [[0,0,0,0],[1,1,1,1],[0,0,0,0]]);
assert(_edge_set("Z") == [[0,0,0,0],[0,0,0,0],[1,1,1,1]]);
assert(_edge_set("NONE") == [[0,0,0,0],[0,0,0,0],[0,0,0,0]]);
assert(_edge_set("ALL") == [[1,1,1,1],[1,1,1,1],[1,1,1,1]]);
}
test__edge_set();
module test_normalize_edges() {
assert(normalize_edges([[-2,-2,-2,-2],[-2,-2,-2,-2],[-2,-2,-2,-2]]) == [[0,0,0,0],[0,0,0,0],[0,0,0,0]]);
assert(normalize_edges([[-1,-1,-1,-1],[-1,-1,-1,-1],[-1,-1,-1,-1]]) == [[0,0,0,0],[0,0,0,0],[0,0,0,0]]);
assert(normalize_edges([[0,0,0,0],[0,0,0,0],[0,0,0,0]]) == [[0,0,0,0],[0,0,0,0],[0,0,0,0]]);
assert(normalize_edges([[1,1,1,1],[1,1,1,1],[1,1,1,1]]) == [[1,1,1,1],[1,1,1,1],[1,1,1,1]]);
assert(normalize_edges([[2,2,2,2],[2,2,2,2],[2,2,2,2]]) == [[1,1,1,1],[1,1,1,1],[1,1,1,1]]);
assert(normalize_edges([[-2,-2,-2,-2],[-2,-2,-2,-2],[-2,-2,-2,-2]]) == [[0,0,0,0],[0,0,0,0],[0,0,0,0]]);
assert(normalize_edges([[-1,-1,-1,-1],[-1,-1,-1,-1],[-1,-1,-1,-1]]) == [[0,0,0,0],[0,0,0,0],[0,0,0,0]]);
assert(normalize_edges([[0,0,0,0],[0,0,0,0],[0,0,0,0]]) == [[0,0,0,0],[0,0,0,0],[0,0,0,0]]);
assert(normalize_edges([[1,1,1,1],[1,1,1,1],[1,1,1,1]]) == [[1,1,1,1],[1,1,1,1],[1,1,1,1]]);
assert(normalize_edges([[2,2,2,2],[2,2,2,2],[2,2,2,2]]) == [[1,1,1,1],[1,1,1,1],[1,1,1,1]]);
}
test_normalize_edges();
module test_edges() {
assert(edges("X")==[[1,1,1,1],[0,0,0,0],[0,0,0,0]]);
assert(edges("Y")==[[0,0,0,0],[1,1,1,1],[0,0,0,0]]);
assert(edges("Z")==[[0,0,0,0],[0,0,0,0],[1,1,1,1]]);
assert(edges(["X"])==[[1,1,1,1],[0,0,0,0],[0,0,0,0]]);
assert(edges(["Y"])==[[0,0,0,0],[1,1,1,1],[0,0,0,0]]);
assert(edges(["Z"])==[[0,0,0,0],[0,0,0,0],[1,1,1,1]]);
assert(edges(["X","Y"])==[[1,1,1,1],[1,1,1,1],[0,0,0,0]]);
assert(edges(["X","Z"])==[[1,1,1,1],[0,0,0,0],[1,1,1,1]]);
assert(edges(["Y","Z"])==[[0,0,0,0],[1,1,1,1],[1,1,1,1]]);
assert(edges("ALL",except="X")==[[0,0,0,0],[1,1,1,1],[1,1,1,1]]);
assert(edges("ALL",except="Y")==[[1,1,1,1],[0,0,0,0],[1,1,1,1]]);
assert(edges("ALL",except="Z")==[[1,1,1,1],[1,1,1,1],[0,0,0,0]]);
assert(edges(["Y","Z"],except=[FRONT+RIGHT,FRONT+LEFT])==[[0,0,0,0],[1,1,1,1],[0,0,1,1]]);
assert(edges("X")==[[1,1,1,1],[0,0,0,0],[0,0,0,0]]);
assert(edges("Y")==[[0,0,0,0],[1,1,1,1],[0,0,0,0]]);
assert(edges("Z")==[[0,0,0,0],[0,0,0,0],[1,1,1,1]]);
assert(edges(["X"])==[[1,1,1,1],[0,0,0,0],[0,0,0,0]]);
assert(edges(["Y"])==[[0,0,0,0],[1,1,1,1],[0,0,0,0]]);
assert(edges(["Z"])==[[0,0,0,0],[0,0,0,0],[1,1,1,1]]);
assert(edges(["X","Y"])==[[1,1,1,1],[1,1,1,1],[0,0,0,0]]);
assert(edges(["X","Z"])==[[1,1,1,1],[0,0,0,0],[1,1,1,1]]);
assert(edges(["Y","Z"])==[[0,0,0,0],[1,1,1,1],[1,1,1,1]]);
assert(edges("ALL",except="X")==[[0,0,0,0],[1,1,1,1],[1,1,1,1]]);
assert(edges("ALL",except="Y")==[[1,1,1,1],[0,0,0,0],[1,1,1,1]]);
assert(edges("ALL",except="Z")==[[1,1,1,1],[1,1,1,1],[0,0,0,0]]);
assert(edges(["Y","Z"],except=[FRONT+RIGHT,FRONT+LEFT])==[[0,0,0,0],[1,1,1,1],[0,0,1,1]]);
}
test_edges();
module test_corner_edge_count() {
edges = edges([TOP,FRONT+RIGHT]);
assert(corner_edge_count(edges,TOP+FRONT+RIGHT) == 3);
assert(corner_edge_count(edges,TOP+FRONT+LEFT) == 2);
assert(corner_edge_count(edges,BOTTOM+FRONT+RIGHT) == 1);
assert(corner_edge_count(edges,BOTTOM+FRONT+LEFT) == 0);
edges = edges([TOP,FRONT+RIGHT]);
assert(corner_edge_count(edges,TOP+FRONT+RIGHT) == 3);
assert(corner_edge_count(edges,TOP+FRONT+LEFT) == 2);
assert(corner_edge_count(edges,BOTTOM+FRONT+RIGHT) == 1);
assert(corner_edge_count(edges,BOTTOM+FRONT+LEFT) == 0);
}
test_corner_edge_count();
// vim: noexpandtab tabstop=4 shiftwidth=4 softtabstop=4 nowrap
// vim: expandtab tabstop=4 shiftwidth=4 softtabstop=4 nowrap

View File

@@ -8,4 +8,4 @@ module test_deprecate() {}
module test_deprecate_argument() {}
// vim: noexpandtab tabstop=4 shiftwidth=4 softtabstop=4 nowrap
// vim: expandtab tabstop=4 shiftwidth=4 softtabstop=4 nowrap

File diff suppressed because it is too large Load Diff

View File

@@ -3,377 +3,377 @@ include <BOSL2/std.scad>
// Simple Calculations
module test_quant() {
assert(quant(-4,3) == -3);
assert(quant(-3,3) == -3);
assert(quant(-2,3) == -3);
assert(quant(-1,3) == 0);
assert(quant(0,3) == 0);
assert(quant(1,3) == 0);
assert(quant(2,3) == 3);
assert(quant(3,3) == 3);
assert(quant(4,3) == 3);
assert(quant(7,3) == 6);
assert(quant([12,13,13.1,14,14.1,15,16],4) == [12,12,12,16,16,16,16]);
assert(quant([9,10,10.4,10.5,11,12],3) == [9,9,9,12,12,12]);
assert(quant([[9,10,10.4],[10.5,11,12]],3) == [[9,9,9],[12,12,12]]);
assert(quant(-4,3) == -3);
assert(quant(-3,3) == -3);
assert(quant(-2,3) == -3);
assert(quant(-1,3) == 0);
assert(quant(0,3) == 0);
assert(quant(1,3) == 0);
assert(quant(2,3) == 3);
assert(quant(3,3) == 3);
assert(quant(4,3) == 3);
assert(quant(7,3) == 6);
assert(quant([12,13,13.1,14,14.1,15,16],4) == [12,12,12,16,16,16,16]);
assert(quant([9,10,10.4,10.5,11,12],3) == [9,9,9,12,12,12]);
assert(quant([[9,10,10.4],[10.5,11,12]],3) == [[9,9,9],[12,12,12]]);
}
test_quant();
module test_quantdn() {
assert(quantdn(-4,3) == -6);
assert(quantdn(-3,3) == -3);
assert(quantdn(-2,3) == -3);
assert(quantdn(-1,3) == -3);
assert(quantdn(0,3) == 0);
assert(quantdn(1,3) == 0);
assert(quantdn(2,3) == 0);
assert(quantdn(3,3) == 3);
assert(quantdn(4,3) == 3);
assert(quantdn(7,3) == 6);
assert(quantdn([12,13,13.1,14,14.1,15,16],4) == [12,12,12,12,12,12,16]);
assert(quantdn([9,10,10.4,10.5,11,12],3) == [9,9,9,9,9,12]);
assert(quantdn([[9,10,10.4],[10.5,11,12]],3) == [[9,9,9],[9,9,12]]);
assert(quantdn(-4,3) == -6);
assert(quantdn(-3,3) == -3);
assert(quantdn(-2,3) == -3);
assert(quantdn(-1,3) == -3);
assert(quantdn(0,3) == 0);
assert(quantdn(1,3) == 0);
assert(quantdn(2,3) == 0);
assert(quantdn(3,3) == 3);
assert(quantdn(4,3) == 3);
assert(quantdn(7,3) == 6);
assert(quantdn([12,13,13.1,14,14.1,15,16],4) == [12,12,12,12,12,12,16]);
assert(quantdn([9,10,10.4,10.5,11,12],3) == [9,9,9,9,9,12]);
assert(quantdn([[9,10,10.4],[10.5,11,12]],3) == [[9,9,9],[9,9,12]]);
}
test_quantdn();
module test_quantup() {
assert(quantup(-4,3) == -3);
assert(quantup(-3,3) == -3);
assert(quantup(-2,3) == 0);
assert(quantup(-1,3) == 0);
assert(quantup(0,3) == 0);
assert(quantup(1,3) == 3);
assert(quantup(2,3) == 3);
assert(quantup(3,3) == 3);
assert(quantup(4,3) == 6);
assert(quantup(7,3) == 9);
assert(quantup([12,13,13.1,14,14.1,15,16],4) == [12,16,16,16,16,16,16]);
assert(quantup([9,10,10.4,10.5,11,12],3) == [9,12,12,12,12,12]);
assert(quantup([[9,10,10.4],[10.5,11,12]],3) == [[9,12,12],[12,12,12]]);
assert(quantup(-4,3) == -3);
assert(quantup(-3,3) == -3);
assert(quantup(-2,3) == 0);
assert(quantup(-1,3) == 0);
assert(quantup(0,3) == 0);
assert(quantup(1,3) == 3);
assert(quantup(2,3) == 3);
assert(quantup(3,3) == 3);
assert(quantup(4,3) == 6);
assert(quantup(7,3) == 9);
assert(quantup([12,13,13.1,14,14.1,15,16],4) == [12,16,16,16,16,16,16]);
assert(quantup([9,10,10.4,10.5,11,12],3) == [9,12,12,12,12,12]);
assert(quantup([[9,10,10.4],[10.5,11,12]],3) == [[9,12,12],[12,12,12]]);
}
test_quantup();
module test_constrain() {
assert(constrain(-2,-1,1) == -1);
assert(constrain(-1.75,-1,1) == -1);
assert(constrain(-1,-1,1) == -1);
assert(constrain(-0.75,-1,1) == -0.75);
assert(constrain(0,-1,1) == 0);
assert(constrain(0.75,-1,1) == 0.75);
assert(constrain(1,-1,1) == 1);
assert(constrain(1.75,-1,1) == 1);
assert(constrain(2,-1,1) == 1);
assert(constrain(-2,-1,1) == -1);
assert(constrain(-1.75,-1,1) == -1);
assert(constrain(-1,-1,1) == -1);
assert(constrain(-0.75,-1,1) == -0.75);
assert(constrain(0,-1,1) == 0);
assert(constrain(0.75,-1,1) == 0.75);
assert(constrain(1,-1,1) == 1);
assert(constrain(1.75,-1,1) == 1);
assert(constrain(2,-1,1) == 1);
}
test_constrain();
module test_approx() {
assert(approx(PI, 3.141592653589793236) == true);
assert(approx(PI, 3.1415926) == false);
assert(approx(PI, 3.1415926, eps=1e-6) == true);
assert(approx(-PI, -3.141592653589793236) == true);
assert(approx(-PI, -3.1415926) == false);
assert(approx(-PI, -3.1415926, eps=1e-6) == true);
assert(approx(1/3, 0.3333333333) == true);
assert(approx(-1/3, -0.3333333333) == true);
assert(approx(10*[cos(30),sin(30)], 10*[sqrt(3)/2, 1/2]) == true);
assert(approx(PI, 3.141592653589793236) == true);
assert(approx(PI, 3.1415926) == false);
assert(approx(PI, 3.1415926, eps=1e-6) == true);
assert(approx(-PI, -3.141592653589793236) == true);
assert(approx(-PI, -3.1415926) == false);
assert(approx(-PI, -3.1415926, eps=1e-6) == true);
assert(approx(1/3, 0.3333333333) == true);
assert(approx(-1/3, -0.3333333333) == true);
assert(approx(10*[cos(30),sin(30)], 10*[sqrt(3)/2, 1/2]) == true);
}
test_approx();
module test_min_index() {
vals = rands(-100,100,100);
minval = min(vals);
minidx = min_index(vals);
assert(vals[minidx] == minval);
assert(min_index([3,4,5,6]) == 0);
assert(min_index([4,3,5,6]) == 1);
assert(min_index([4,5,3,6]) == 2);
assert(min_index([4,5,6,3]) == 3);
assert(min_index([6,5,4,3]) == 3);
assert(min_index([6,3,4,5]) == 1);
assert(min_index([-56,72,-874,5]) == 2);
vals = rands(-100,100,100);
minval = min(vals);
minidx = min_index(vals);
assert(vals[minidx] == minval);
assert(min_index([3,4,5,6]) == 0);
assert(min_index([4,3,5,6]) == 1);
assert(min_index([4,5,3,6]) == 2);
assert(min_index([4,5,6,3]) == 3);
assert(min_index([6,5,4,3]) == 3);
assert(min_index([6,3,4,5]) == 1);
assert(min_index([-56,72,-874,5]) == 2);
}
test_min_index();
module test_max_index() {
vals = rands(-100,100,100);
maxval = max(vals);
maxidx = max_index(vals);
assert(vals[maxidx] == maxval);
assert(max_index([3,4,5,6]) == 3);
assert(max_index([3,4,6,5]) == 2);
assert(max_index([3,6,4,5]) == 1);
assert(max_index([6,3,4,5]) == 0);
assert(max_index([5,6,4,3]) == 1);
assert(max_index([-56,72,-874,5]) == 1);
vals = rands(-100,100,100);
maxval = max(vals);
maxidx = max_index(vals);
assert(vals[maxidx] == maxval);
assert(max_index([3,4,5,6]) == 3);
assert(max_index([3,4,6,5]) == 2);
assert(max_index([3,6,4,5]) == 1);
assert(max_index([6,3,4,5]) == 0);
assert(max_index([5,6,4,3]) == 1);
assert(max_index([-56,72,-874,5]) == 1);
}
test_max_index();
module test_posmod() {
assert(posmod(-5,3) == 1);
assert(posmod(-4,3) == 2);
assert(posmod(-3,3) == 0);
assert(posmod(-2,3) == 1);
assert(posmod(-1,3) == 2);
assert(posmod(0,3) == 0);
assert(posmod(1,3) == 1);
assert(posmod(2,3) == 2);
assert(posmod(3,3) == 0);
assert(posmod(-5,3) == 1);
assert(posmod(-4,3) == 2);
assert(posmod(-3,3) == 0);
assert(posmod(-2,3) == 1);
assert(posmod(-1,3) == 2);
assert(posmod(0,3) == 0);
assert(posmod(1,3) == 1);
assert(posmod(2,3) == 2);
assert(posmod(3,3) == 0);
}
test_posmod();
module test_modang() {
assert(modang(-700) == 20);
assert(modang(-270) == 90);
assert(modang(-120) == -120);
assert(modang(120) == 120);
assert(modang(270) == -90);
assert(modang(700) == -20);
assert(modang(-700) == 20);
assert(modang(-270) == 90);
assert(modang(-120) == -120);
assert(modang(120) == 120);
assert(modang(270) == -90);
assert(modang(700) == -20);
}
test_modang();
module test_modrange() {
assert(modrange(-5,5,3) == [1,2]);
assert(modrange(-1,4,3) == [2,0,1]);
assert(modrange(1,8,10,step=2) == [1,3,5,7]);
assert(modrange(5,12,10,step=2) == [5,7,9,1]);
assert(modrange(-5,5,3) == [1,2]);
assert(modrange(-1,4,3) == [2,0,1]);
assert(modrange(1,8,10,step=2) == [1,3,5,7]);
assert(modrange(5,12,10,step=2) == [5,7,9,1]);
}
test_modrange();
module test_sqr() {
assert(sqr(-3) == 9);
assert(sqr(0) == 0);
assert(sqr(1) == 1);
assert(sqr(2) == 4);
assert(sqr(3) == 9);
assert(sqr(16) == 256);
assert(sqr(-3) == 9);
assert(sqr(0) == 0);
assert(sqr(1) == 1);
assert(sqr(2) == 4);
assert(sqr(3) == 9);
assert(sqr(16) == 256);
}
test_sqr();
module test_log2() {
assert(log2(0.125) == -3);
assert(log2(16) == 4);
assert(log2(256) == 8);
assert(log2(0.125) == -3);
assert(log2(16) == 4);
assert(log2(256) == 8);
}
test_log2();
module test_rand_int() {
nums = rand_int(-100,100,1000,seed=2134);
assert(len(nums)==1000);
for (num = nums) {
assert(num>=-100);
assert(num<=100);
assert(num==floor(num));
}
nums = rand_int(-100,100,1000,seed=2134);
assert(len(nums)==1000);
for (num = nums) {
assert(num>=-100);
assert(num<=100);
assert(num==floor(num));
}
}
test_rand_int();
module test_gaussian_rands() {
nums1 = gaussian_rands(0,10,1000,seed=2132);
nums2 = gaussian_rands(0,10,1000,seed=2130);
nums3 = gaussian_rands(0,10,1000,seed=2132);
assert(len(nums1)==1000);
assert(len(nums2)==1000);
assert(len(nums3)==1000);
assert(nums1==nums3);
assert(nums1!=nums2);
nums1 = gaussian_rands(0,10,1000,seed=2132);
nums2 = gaussian_rands(0,10,1000,seed=2130);
nums3 = gaussian_rands(0,10,1000,seed=2132);
assert(len(nums1)==1000);
assert(len(nums2)==1000);
assert(len(nums3)==1000);
assert(nums1==nums3);
assert(nums1!=nums2);
}
test_gaussian_rands();
module test_log_rands() {
nums1 = log_rands(0,100,10,1000,seed=2189);
nums2 = log_rands(0,100,10,1000,seed=2310);
nums3 = log_rands(0,100,10,1000,seed=2189);
assert(len(nums1)==1000);
assert(len(nums2)==1000);
assert(len(nums3)==1000);
assert(nums1==nums3);
assert(nums1!=nums2);
nums1 = log_rands(0,100,10,1000,seed=2189);
nums2 = log_rands(0,100,10,1000,seed=2310);
nums3 = log_rands(0,100,10,1000,seed=2189);
assert(len(nums1)==1000);
assert(len(nums2)==1000);
assert(len(nums3)==1000);
assert(nums1==nums3);
assert(nums1!=nums2);
}
test_log_rands();
module test_segs() {
assert(segs(50,$fn=8) == 8);
assert(segs(50,$fa=2,$fs=2) == 158);
assert(segs(50,$fn=8) == 8);
assert(segs(50,$fa=2,$fs=2) == 158);
}
test_segs();
module test_lerp() {
assert(lerp(-20,20,0) == -20);
assert(lerp(-20,20,0.25) == -10);
assert(lerp(-20,20,0.5) == 0);
assert(lerp(-20,20,0.75) == 10);
assert(lerp(-20,20,1) == 20);
assert(lerp(-20,20,[0,0.25,0.5,0.75,1]) == [-20,-10,0,10,20]);
assert(lerp(-20,20,[0:0.25:1]) == [-20,-10,0,10,20]);
assert(lerp([10,10],[30,-10],0.5) == [20,0]);
assert(lerp(-20,20,0) == -20);
assert(lerp(-20,20,0.25) == -10);
assert(lerp(-20,20,0.5) == 0);
assert(lerp(-20,20,0.75) == 10);
assert(lerp(-20,20,1) == 20);
assert(lerp(-20,20,[0,0.25,0.5,0.75,1]) == [-20,-10,0,10,20]);
assert(lerp(-20,20,[0:0.25:1]) == [-20,-10,0,10,20]);
assert(lerp([10,10],[30,-10],0.5) == [20,0]);
}
test_lerp();
module test_hypot() {
assert(hypot(20,30) == norm([20,30]));
assert(hypot(20,30) == norm([20,30]));
}
test_hypot();
module test_sinh() {
assert(abs(sinh(-2)+3.6268604078) < EPSILON);
assert(abs(sinh(-1)+1.1752011936) < EPSILON);
assert(abs(sinh(0)) < EPSILON);
assert(abs(sinh(1)-1.1752011936) < EPSILON);
assert(abs(sinh(2)-3.6268604078) < EPSILON);
assert(abs(sinh(-2)+3.6268604078) < EPSILON);
assert(abs(sinh(-1)+1.1752011936) < EPSILON);
assert(abs(sinh(0)) < EPSILON);
assert(abs(sinh(1)-1.1752011936) < EPSILON);
assert(abs(sinh(2)-3.6268604078) < EPSILON);
}
test_sinh();
module test_cosh() {
assert(abs(cosh(-2)-3.7621956911) < EPSILON);
assert(abs(cosh(-1)-1.5430806348) < EPSILON);
assert(abs(cosh(0)-1) < EPSILON);
assert(abs(cosh(1)-1.5430806348) < EPSILON);
assert(abs(cosh(2)-3.7621956911) < EPSILON);
assert(abs(cosh(-2)-3.7621956911) < EPSILON);
assert(abs(cosh(-1)-1.5430806348) < EPSILON);
assert(abs(cosh(0)-1) < EPSILON);
assert(abs(cosh(1)-1.5430806348) < EPSILON);
assert(abs(cosh(2)-3.7621956911) < EPSILON);
}
test_cosh();
module test_tanh() {
assert(abs(tanh(-2)+0.9640275801) < EPSILON);
assert(abs(tanh(-1)+0.761594156) < EPSILON);
assert(abs(tanh(0)) < EPSILON);
assert(abs(tanh(1)-0.761594156) < EPSILON);
assert(abs(tanh(2)-0.9640275801) < EPSILON);
assert(abs(tanh(-2)+0.9640275801) < EPSILON);
assert(abs(tanh(-1)+0.761594156) < EPSILON);
assert(abs(tanh(0)) < EPSILON);
assert(abs(tanh(1)-0.761594156) < EPSILON);
assert(abs(tanh(2)-0.9640275801) < EPSILON);
}
test_tanh();
module test_asinh() {
assert(abs(asinh(sinh(-2))+2) < EPSILON);
assert(abs(asinh(sinh(-1))+1) < EPSILON);
assert(abs(asinh(sinh(0))) < EPSILON);
assert(abs(asinh(sinh(1))-1) < EPSILON);
assert(abs(asinh(sinh(2))-2) < EPSILON);
assert(abs(asinh(sinh(-2))+2) < EPSILON);
assert(abs(asinh(sinh(-1))+1) < EPSILON);
assert(abs(asinh(sinh(0))) < EPSILON);
assert(abs(asinh(sinh(1))-1) < EPSILON);
assert(abs(asinh(sinh(2))-2) < EPSILON);
}
test_asinh();
module test_acosh() {
assert(abs(acosh(cosh(-2))-2) < EPSILON);
assert(abs(acosh(cosh(-1))-1) < EPSILON);
assert(abs(acosh(cosh(0))) < EPSILON);
assert(abs(acosh(cosh(1))-1) < EPSILON);
assert(abs(acosh(cosh(2))-2) < EPSILON);
assert(abs(acosh(cosh(-2))-2) < EPSILON);
assert(abs(acosh(cosh(-1))-1) < EPSILON);
assert(abs(acosh(cosh(0))) < EPSILON);
assert(abs(acosh(cosh(1))-1) < EPSILON);
assert(abs(acosh(cosh(2))-2) < EPSILON);
}
test_acosh();
module test_atanh() {
assert(abs(atanh(tanh(-2))+2) < EPSILON);
assert(abs(atanh(tanh(-1))+1) < EPSILON);
assert(abs(atanh(tanh(0))) < EPSILON);
assert(abs(atanh(tanh(1))-1) < EPSILON);
assert(abs(atanh(tanh(2))-2) < EPSILON);
assert(abs(atanh(tanh(-2))+2) < EPSILON);
assert(abs(atanh(tanh(-1))+1) < EPSILON);
assert(abs(atanh(tanh(0))) < EPSILON);
assert(abs(atanh(tanh(1))-1) < EPSILON);
assert(abs(atanh(tanh(2))-2) < EPSILON);
}
test_atanh();
module test_sum() {
assert(sum([]) == 0);
assert(sum([],dflt=undef) == undef);
assert(sum([1,2,3]) == 6);
assert(sum([-2,-1,0,1,2]) == 0);
assert(sum([[1,2,3], [3,4,5], [5,6,7]]) == [9,12,15]);
assert(sum([]) == 0);
assert(sum([],dflt=undef) == undef);
assert(sum([1,2,3]) == 6);
assert(sum([-2,-1,0,1,2]) == 0);
assert(sum([[1,2,3], [3,4,5], [5,6,7]]) == [9,12,15]);
}
test_sum();
module test_cumsum() {
assert(cumsum([]) == []);
assert(cumsum([1,1,1]) == [1,2,3]);
assert(cumsum([2,2,2]) == [2,4,6]);
assert(cumsum([1,2,3]) == [1,3,6]);
assert(cumsum([-2,-1,0,1,2]) == [-2,-3,-3,-2,0]);
assert(cumsum([[1,2,3], [3,4,5], [5,6,7]]) == [[1,2,3],[4,6,8],[9,12,15]]);
assert(cumsum([]) == []);
assert(cumsum([1,1,1]) == [1,2,3]);
assert(cumsum([2,2,2]) == [2,4,6]);
assert(cumsum([1,2,3]) == [1,3,6]);
assert(cumsum([-2,-1,0,1,2]) == [-2,-3,-3,-2,0]);
assert(cumsum([[1,2,3], [3,4,5], [5,6,7]]) == [[1,2,3],[4,6,8],[9,12,15]]);
}
test_cumsum();
module test_sum_of_squares() {
assert(sum_of_squares([1,2,3]) == 14);
assert(sum_of_squares([1,2,4]) == 21);
assert(sum_of_squares([-3,-2,-1]) == 14);
assert(sum_of_squares([1,2,3]) == 14);
assert(sum_of_squares([1,2,4]) == 21);
assert(sum_of_squares([-3,-2,-1]) == 14);
}
test_sum_of_squares();
module test_sum_of_sines() {
assert(sum_of_sines(0, [[3,4,0],[2,2,0]]) == 0);
assert(sum_of_sines(45, [[3,4,0],[2,2,0]]) == 2);
assert(sum_of_sines(90, [[3,4,0],[2,2,0]]) == 0);
assert(sum_of_sines(135, [[3,4,0],[2,2,0]]) == -2);
assert(sum_of_sines(180, [[3,4,0],[2,2,0]]) == 0);
assert(sum_of_sines(0, [[3,4,0],[2,2,0]]) == 0);
assert(sum_of_sines(45, [[3,4,0],[2,2,0]]) == 2);
assert(sum_of_sines(90, [[3,4,0],[2,2,0]]) == 0);
assert(sum_of_sines(135, [[3,4,0],[2,2,0]]) == -2);
assert(sum_of_sines(180, [[3,4,0],[2,2,0]]) == 0);
}
test_sum_of_sines();
module test_deltas() {
assert(deltas([2,5,9,17]) == [3,4,8]);
assert(deltas([[1,2,3], [3,6,8], [4,8,11]]) == [[2,4,5], [1,2,3]]);
assert(deltas([2,5,9,17]) == [3,4,8]);
assert(deltas([[1,2,3], [3,6,8], [4,8,11]]) == [[2,4,5], [1,2,3]]);
}
test_deltas();
module test_product() {
assert(product([2,3,4]) == 24);
assert(product([[1,2,3], [3,4,5], [5,6,7]]) == [15, 48, 105]);
m1 = [[2,3,4],[4,5,6],[6,7,8]];
m2 = [[4,1,2],[3,7,2],[8,7,4]];
m3 = [[3,7,8],[9,2,4],[5,8,3]];
assert(product([m1,m2,m3]) == m1*m2*m3);
assert(product([2,3,4]) == 24);
assert(product([[1,2,3], [3,4,5], [5,6,7]]) == [15, 48, 105]);
m1 = [[2,3,4],[4,5,6],[6,7,8]];
m2 = [[4,1,2],[3,7,2],[8,7,4]];
m3 = [[3,7,8],[9,2,4],[5,8,3]];
assert(product([m1,m2,m3]) == m1*m2*m3);
}
test_product();
module test_mean() {
assert(mean([2,3,4]) == 3);
assert(mean([[1,2,3], [3,4,5], [5,6,7]]) == [3,4,5]);
assert(mean([2,3,4]) == 3);
assert(mean([[1,2,3], [3,4,5], [5,6,7]]) == [3,4,5]);
}
test_mean();
module test_det2() {
assert(det2([[6,-2], [1,8]]) == 50);
assert(det2([[4,7], [3,2]]) == -13);
assert(det2([[4,3], [3,4]]) == 7);
assert(det2([[6,-2], [1,8]]) == 50);
assert(det2([[4,7], [3,2]]) == -13);
assert(det2([[4,3], [3,4]]) == 7);
}
test_det2();
module test_det3() {
M = [ [6,4,-2], [1,-2,8], [1,5,7] ];
assert(det3(M) == -334);
M = [ [6,4,-2], [1,-2,8], [1,5,7] ];
assert(det3(M) == -334);
}
test_det3();
module test_determinant() {
M = [ [6,4,-2,9], [1,-2,8,3], [1,5,7,6], [4,2,5,1] ];
assert(determinant(M) == 2267);
M = [ [6,4,-2,9], [1,-2,8,3], [1,5,7,6], [4,2,5,1] ];
assert(determinant(M) == 2267);
}
test_determinant();
@@ -382,167 +382,167 @@ test_determinant();
module test_compare_vals() {
assert(compare_vals(-10,0) < 0);
assert(compare_vals(10,0) > 0);
assert(compare_vals(10,10) == 0);
assert(compare_vals(-10,0) < 0);
assert(compare_vals(10,0) > 0);
assert(compare_vals(10,10) == 0);
assert(compare_vals("abc","abcd") < 0);
assert(compare_vals("abcd","abc") > 0);
assert(compare_vals("abcd","abcd") == 0);
assert(compare_vals("abc","abcd") < 0);
assert(compare_vals("abcd","abc") > 0);
assert(compare_vals("abcd","abcd") == 0);
assert(compare_vals(false,false) == 0);
assert(compare_vals(true,false) > 0);
assert(compare_vals(false,true) < 0);
assert(compare_vals(true,true) == 0);
assert(compare_vals(false,false) == 0);
assert(compare_vals(true,false) > 0);
assert(compare_vals(false,true) < 0);
assert(compare_vals(true,true) == 0);
assert(compare_vals([2,3,4], [2,3,4,5]) < 0);
assert(compare_vals([2,3,4,5], [2,3,4,5]) == 0);
assert(compare_vals([2,3,4,5], [2,3,4]) > 0);
assert(compare_vals([2,3,4,5], [2,3,5,5]) < 0);
assert(compare_vals([[2,3,4,5]], [[2,3,5,5]]) < 0);
assert(compare_vals([2,3,4], [2,3,4,5]) < 0);
assert(compare_vals([2,3,4,5], [2,3,4,5]) == 0);
assert(compare_vals([2,3,4,5], [2,3,4]) > 0);
assert(compare_vals([2,3,4,5], [2,3,5,5]) < 0);
assert(compare_vals([[2,3,4,5]], [[2,3,5,5]]) < 0);
assert(compare_vals([[2,3,4],[3,4,5]], [[2,3,4], [3,4,5]]) == 0);
assert(compare_vals([[2,3,4],[3,4,5]], [[2,3,4,5], [3,4,5]]) < 0);
assert(compare_vals([[2,3,4],[3,4,5]], [[2,3,4], [3,4,5,6]]) < 0);
assert(compare_vals([[2,3,4,5],[3,4,5]], [[2,3,4], [3,4,5]]) > 0);
assert(compare_vals([[2,3,4],[3,4,5,6]], [[2,3,4], [3,4,5]]) > 0);
assert(compare_vals([[2,3,4],[3,5,5]], [[2,3,4], [3,4,5]]) > 0);
assert(compare_vals([[2,3,4],[3,4,5]], [[2,3,4], [3,5,5]]) < 0);
assert(compare_vals([[2,3,4],[3,4,5]], [[2,3,4], [3,4,5]]) == 0);
assert(compare_vals([[2,3,4],[3,4,5]], [[2,3,4,5], [3,4,5]]) < 0);
assert(compare_vals([[2,3,4],[3,4,5]], [[2,3,4], [3,4,5,6]]) < 0);
assert(compare_vals([[2,3,4,5],[3,4,5]], [[2,3,4], [3,4,5]]) > 0);
assert(compare_vals([[2,3,4],[3,4,5,6]], [[2,3,4], [3,4,5]]) > 0);
assert(compare_vals([[2,3,4],[3,5,5]], [[2,3,4], [3,4,5]]) > 0);
assert(compare_vals([[2,3,4],[3,4,5]], [[2,3,4], [3,5,5]]) < 0);
assert(compare_vals(undef, undef) == 0);
assert(compare_vals(undef, true) < 0);
assert(compare_vals(undef, 0) < 0);
assert(compare_vals(undef, "foo") < 0);
assert(compare_vals(undef, [2,3,4]) < 0);
assert(compare_vals(undef, [0:3]) < 0);
assert(compare_vals(undef, undef) == 0);
assert(compare_vals(undef, true) < 0);
assert(compare_vals(undef, 0) < 0);
assert(compare_vals(undef, "foo") < 0);
assert(compare_vals(undef, [2,3,4]) < 0);
assert(compare_vals(undef, [0:3]) < 0);
assert(compare_vals(true, undef) > 0);
assert(compare_vals(true, true) == 0);
assert(compare_vals(true, 0) < 0);
assert(compare_vals(true, "foo") < 0);
assert(compare_vals(true, [2,3,4]) < 0);
assert(compare_vals(true, [0:3]) < 0);
assert(compare_vals(true, undef) > 0);
assert(compare_vals(true, true) == 0);
assert(compare_vals(true, 0) < 0);
assert(compare_vals(true, "foo") < 0);
assert(compare_vals(true, [2,3,4]) < 0);
assert(compare_vals(true, [0:3]) < 0);
assert(compare_vals(0, undef) > 0);
assert(compare_vals(0, true) > 0);
assert(compare_vals(0, 0) == 0);
assert(compare_vals(0, "foo") < 0);
assert(compare_vals(0, [2,3,4]) < 0);
assert(compare_vals(0, [0:3]) < 0);
assert(compare_vals(0, undef) > 0);
assert(compare_vals(0, true) > 0);
assert(compare_vals(0, 0) == 0);
assert(compare_vals(0, "foo") < 0);
assert(compare_vals(0, [2,3,4]) < 0);
assert(compare_vals(0, [0:3]) < 0);
assert(compare_vals(1, undef) > 0);
assert(compare_vals(1, true) > 0);
assert(compare_vals(1, 1) == 0);
assert(compare_vals(1, "foo") < 0);
assert(compare_vals(1, [2,3,4]) < 0);
assert(compare_vals(1, [0:3]) < 0);
assert(compare_vals(1, undef) > 0);
assert(compare_vals(1, true) > 0);
assert(compare_vals(1, 1) == 0);
assert(compare_vals(1, "foo") < 0);
assert(compare_vals(1, [2,3,4]) < 0);
assert(compare_vals(1, [0:3]) < 0);
assert(compare_vals("foo", undef) > 0);
assert(compare_vals("foo", true) > 0);
assert(compare_vals("foo", 1) > 0);
assert(compare_vals("foo", "foo") == 0);
assert(compare_vals("foo", [2,3,4]) < 0);
assert(compare_vals("foo", [0:3]) < 0);
assert(compare_vals("foo", undef) > 0);
assert(compare_vals("foo", true) > 0);
assert(compare_vals("foo", 1) > 0);
assert(compare_vals("foo", "foo") == 0);
assert(compare_vals("foo", [2,3,4]) < 0);
assert(compare_vals("foo", [0:3]) < 0);
assert(compare_vals([2,3,4], undef) > 0);
assert(compare_vals([2,3,4], true) > 0);
assert(compare_vals([2,3,4], 1) > 0);
assert(compare_vals([2,3,4], "foo") > 0);
assert(compare_vals([2,3,4], [2,3,4]) == 0);
assert(compare_vals([2,3,4], [0:3]) < 0);
assert(compare_vals([2,3,4], undef) > 0);
assert(compare_vals([2,3,4], true) > 0);
assert(compare_vals([2,3,4], 1) > 0);
assert(compare_vals([2,3,4], "foo") > 0);
assert(compare_vals([2,3,4], [2,3,4]) == 0);
assert(compare_vals([2,3,4], [0:3]) < 0);
assert(compare_vals([0:3], undef) > 0);
assert(compare_vals([0:3], true) > 0);
assert(compare_vals([0:3], 1) > 0);
assert(compare_vals([0:3], "foo") > 0);
assert(compare_vals([0:3], [2,3,4]) > 0);
assert(compare_vals([0:3], [0:3]) == 0);
assert(compare_vals([0:3], undef) > 0);
assert(compare_vals([0:3], true) > 0);
assert(compare_vals([0:3], 1) > 0);
assert(compare_vals([0:3], "foo") > 0);
assert(compare_vals([0:3], [2,3,4]) > 0);
assert(compare_vals([0:3], [0:3]) == 0);
}
test_compare_vals();
module test_compare_lists() {
assert(compare_lists([2,3,4], [2,3,4,5]) < 0);
assert(compare_lists([2,3,4,5], [2,3,4,5]) == 0);
assert(compare_lists([2,3,4,5], [2,3,4]) > 0);
assert(compare_lists([2,3,4,5], [2,3,5,5]) < 0);
assert(compare_lists([2,3,4], [2,3,4,5]) < 0);
assert(compare_lists([2,3,4,5], [2,3,4,5]) == 0);
assert(compare_lists([2,3,4,5], [2,3,4]) > 0);
assert(compare_lists([2,3,4,5], [2,3,5,5]) < 0);
assert(compare_lists([[2,3,4],[3,4,5]], [[2,3,4], [3,4,5]]) == 0);
assert(compare_lists([[2,3,4],[3,4,5]], [[2,3,4,5], [3,4,5]]) < 0);
assert(compare_lists([[2,3,4],[3,4,5]], [[2,3,4], [3,4,5,6]]) < 0);
assert(compare_lists([[2,3,4,5],[3,4,5]], [[2,3,4], [3,4,5]]) > 0);
assert(compare_lists([[2,3,4],[3,4,5,6]], [[2,3,4], [3,4,5]]) > 0);
assert(compare_lists([[2,3,4],[3,5,5]], [[2,3,4], [3,4,5]]) > 0);
assert(compare_lists([[2,3,4],[3,4,5]], [[2,3,4], [3,5,5]]) < 0);
assert(compare_lists([[2,3,4],[3,4,5]], [[2,3,4], [3,4,5]]) == 0);
assert(compare_lists([[2,3,4],[3,4,5]], [[2,3,4,5], [3,4,5]]) < 0);
assert(compare_lists([[2,3,4],[3,4,5]], [[2,3,4], [3,4,5,6]]) < 0);
assert(compare_lists([[2,3,4,5],[3,4,5]], [[2,3,4], [3,4,5]]) > 0);
assert(compare_lists([[2,3,4],[3,4,5,6]], [[2,3,4], [3,4,5]]) > 0);
assert(compare_lists([[2,3,4],[3,5,5]], [[2,3,4], [3,4,5]]) > 0);
assert(compare_lists([[2,3,4],[3,4,5]], [[2,3,4], [3,5,5]]) < 0);
assert(compare_lists("cat", "bat") > 0);
assert(compare_lists(["cat"], ["bat"]) > 0);
assert(compare_lists("cat", "bat") > 0);
assert(compare_lists(["cat"], ["bat"]) > 0);
}
test_compare_lists();
module test_any() {
assert(any([0,false,undef]) == false);
assert(any([1,false,undef]) == true);
assert(any([1,5,true]) == true);
assert(any([[0,0], [0,0]]) == false);
assert(any([[0,0], [1,0]]) == true);
assert(any([0,false,undef]) == false);
assert(any([1,false,undef]) == true);
assert(any([1,5,true]) == true);
assert(any([[0,0], [0,0]]) == false);
assert(any([[0,0], [1,0]]) == true);
}
test_any();
module test_all() {
assert(all([0,false,undef]) == false);
assert(all([1,false,undef]) == false);
assert(all([1,5,true]) == true);
assert(all([[0,0], [0,0]]) == false);
assert(all([[0,0], [1,0]]) == false);
assert(all([[1,1], [1,1]]) == true);
assert(all([0,false,undef]) == false);
assert(all([1,false,undef]) == false);
assert(all([1,5,true]) == true);
assert(all([[0,0], [0,0]]) == false);
assert(all([[0,0], [1,0]]) == false);
assert(all([[1,1], [1,1]]) == true);
}
test_all();
module test_count_true() {
assert(count_true([0,false,undef]) == 0);
assert(count_true([1,false,undef]) == 1);
assert(count_true([1,5,false]) == 2);
assert(count_true([1,5,true]) == 3);
assert(count_true([[0,0], [0,0]]) == 0);
assert(count_true([[0,0], [1,0]]) == 1);
assert(count_true([[1,1], [1,1]]) == 4);
assert(count_true([[1,1], [1,1]], nmax=3) == 3);
assert(count_true([0,false,undef]) == 0);
assert(count_true([1,false,undef]) == 1);
assert(count_true([1,5,false]) == 2);
assert(count_true([1,5,true]) == 3);
assert(count_true([[0,0], [0,0]]) == 0);
assert(count_true([[0,0], [1,0]]) == 1);
assert(count_true([[1,1], [1,1]]) == 4);
assert(count_true([[1,1], [1,1]], nmax=3) == 3);
}
test_count_true();
module test_factorial() {
assert(factorial(1) == 1);
assert(factorial(2) == 2);
assert(factorial(3) == 6);
assert(factorial(4) == 24);
assert(factorial(5) == 120);
assert(factorial(6) == 720);
assert(factorial(7) == 5040);
assert(factorial(8) == 40320);
assert(factorial(1) == 1);
assert(factorial(2) == 2);
assert(factorial(3) == 6);
assert(factorial(4) == 24);
assert(factorial(5) == 120);
assert(factorial(6) == 720);
assert(factorial(7) == 5040);
assert(factorial(8) == 40320);
}
test_factorial();
module test_gcd() {
assert(gcd(15,25) == 5);
assert(gcd(15,27) == 3);
assert(gcd(270,405) == 135);
assert(gcd(15,25) == 5);
assert(gcd(15,27) == 3);
assert(gcd(270,405) == 135);
}
test_gcd();
module test_lcm() {
assert(lcm(15,25) == 75);
assert(lcm(15,27) == 135);
assert(lcm(270,405) == 810);
assert(lcm(15,25) == 75);
assert(lcm(15,27) == 135);
assert(lcm(270,405) == 810);
}
test_lcm();
// vim: noexpandtab tabstop=4 shiftwidth=4 softtabstop=4 nowrap
// vim: expandtab tabstop=4 shiftwidth=4 softtabstop=4 nowrap

View File

@@ -2,27 +2,27 @@ include <BOSL2/std.scad>
module test_square() {
assert(square(100, center=true) == [[50,-50],[-50,-50],[-50,50],[50,50]]);
assert(square(100, center=false) == [[100,0],[0,0],[0,100],[100,100]]);
assert(square(100, anchor=FWD+LEFT) == [[100,0],[0,0],[0,100],[100,100]]);
assert(square(100, anchor=BACK+RIGHT) == [[0,-100],[-100,-100],[-100,0],[0,0]]);
assert(square(100, center=true) == [[50,-50],[-50,-50],[-50,50],[50,50]]);
assert(square(100, center=false) == [[100,0],[0,0],[0,100],[100,100]]);
assert(square(100, anchor=FWD+LEFT) == [[100,0],[0,0],[0,100],[100,100]]);
assert(square(100, anchor=BACK+RIGHT) == [[0,-100],[-100,-100],[-100,0],[0,0]]);
}
test_square();
module test_circle() {
for (pt = circle(d=200)) {
assert(approx(norm(pt),100));
}
for (pt = circle(r=100)) {
assert(approx(norm(pt),100));
}
assert(polygon_is_clockwise(circle(d=200)));
assert(polygon_is_clockwise(circle(r=100)));
assert(len(circle(d=100,$fn=6)) == 6);
assert(len(circle(d=100,$fn=36)) == 36);
for (pt = circle(d=200)) {
assert(approx(norm(pt),100));
}
for (pt = circle(r=100)) {
assert(approx(norm(pt),100));
}
assert(polygon_is_clockwise(circle(d=200)));
assert(polygon_is_clockwise(circle(r=100)));
assert(len(circle(d=100,$fn=6)) == 6);
assert(len(circle(d=100,$fn=36)) == 36);
}
test_circle();
// vim: noexpandtab tabstop=4 shiftwidth=4 softtabstop=4 nowrap
// vim: expandtab tabstop=4 shiftwidth=4 softtabstop=4 nowrap

View File

@@ -3,283 +3,283 @@ include <BOSL2/strings.scad>
function rec_cmp(a,b,eps=1e-9) =
typeof(a)!=typeof(b)? false :
is_num(a)? approx(a,b,eps=eps) :
is_list(a)? len(a)==len(b) && all([for (i=idx(a)) rec_cmp(a[i],b[i],eps=eps)]) :
a == b;
typeof(a)!=typeof(b)? false :
is_num(a)? approx(a,b,eps=eps) :
is_list(a)? len(a)==len(b) && all([for (i=idx(a)) rec_cmp(a[i],b[i],eps=eps)]) :
a == b;
module verify_f(actual,expected) {
if (!rec_cmp(actual,expected)) {
echo(str("Expected: ",fmt_float(expected,10)));
echo(str(" : ",expected));
echo(str("Actual : ",fmt_float(actual,10)));
echo(str(" : ",actual));
echo(str("Delta : ",fmt_float(expected-actual,10)));
echo(str(" : ",expected-actual));
assert(approx(expected,actual));
}
if (!rec_cmp(actual,expected)) {
echo(str("Expected: ",fmt_float(expected,10)));
echo(str(" : ",expected));
echo(str("Actual : ",fmt_float(actual,10)));
echo(str(" : ",actual));
echo(str("Delta : ",fmt_float(expected-actual,10)));
echo(str(" : ",expected-actual));
assert(approx(expected,actual));
}
}
module test_Quat() {
verify_f(Quat(UP,0),[0,0,0,1]);
verify_f(Quat(FWD,0),[0,0,0,1]);
verify_f(Quat(LEFT,0),[0,0,0,1]);
verify_f(Quat(UP,45),[0,0,0.3826834324,0.9238795325]);
verify_f(Quat(LEFT,45),[-0.3826834324, 0, 0, 0.9238795325]);
verify_f(Quat(BACK,45),[0,0.3826834323,0,0.9238795325]);
verify_f(Quat(FWD+RIGHT,30),[0.1830127019, -0.1830127019, 0, 0.9659258263]);
verify_f(Quat(UP,0),[0,0,0,1]);
verify_f(Quat(FWD,0),[0,0,0,1]);
verify_f(Quat(LEFT,0),[0,0,0,1]);
verify_f(Quat(UP,45),[0,0,0.3826834324,0.9238795325]);
verify_f(Quat(LEFT,45),[-0.3826834324, 0, 0, 0.9238795325]);
verify_f(Quat(BACK,45),[0,0.3826834323,0,0.9238795325]);
verify_f(Quat(FWD+RIGHT,30),[0.1830127019, -0.1830127019, 0, 0.9659258263]);
}
test_Quat();
module test_QuatX() {
verify_f(QuatX(0),[0,0,0,1]);
verify_f(QuatX(35),[0.3007057995,0,0,0.9537169507]);
verify_f(QuatX(45),[0.3826834324,0,0,0.9238795325]);
verify_f(QuatX(0),[0,0,0,1]);
verify_f(QuatX(35),[0.3007057995,0,0,0.9537169507]);
verify_f(QuatX(45),[0.3826834324,0,0,0.9238795325]);
}
test_QuatX();
module test_QuatY() {
verify_f(QuatY(0),[0,0,0,1]);
verify_f(QuatY(35),[0,0.3007057995,0,0.9537169507]);
verify_f(QuatY(45),[0,0.3826834323,0,0.9238795325]);
verify_f(QuatY(0),[0,0,0,1]);
verify_f(QuatY(35),[0,0.3007057995,0,0.9537169507]);
verify_f(QuatY(45),[0,0.3826834323,0,0.9238795325]);
}
test_QuatY();
module test_QuatZ() {
verify_f(QuatZ(0),[0,0,0,1]);
verify_f(QuatZ(36),[0,0,0.3090169944,0.9510565163]);
verify_f(QuatZ(45),[0,0,0.3826834324,0.9238795325]);
verify_f(QuatZ(0),[0,0,0,1]);
verify_f(QuatZ(36),[0,0,0.3090169944,0.9510565163]);
verify_f(QuatZ(45),[0,0,0.3826834324,0.9238795325]);
}
test_QuatZ();
module test_QuatXYZ() {
verify_f(QuatXYZ([0,0,0]), [0,0,0,1]);
verify_f(QuatXYZ([30,0,0]), [0.2588190451, 0, 0, 0.9659258263]);
verify_f(QuatXYZ([90,0,0]), [0.7071067812, 0, 0, 0.7071067812]);
verify_f(QuatXYZ([-270,0,0]), [-0.7071067812, 0, 0, -0.7071067812]);
verify_f(QuatXYZ([180,0,0]), [1,0,0,0]);
verify_f(QuatXYZ([270,0,0]), [0.7071067812, 0, 0, -0.7071067812]);
verify_f(QuatXYZ([-90,0,0]), [-0.7071067812, 0, 0, 0.7071067812]);
verify_f(QuatXYZ([360,0,0]), [0,0,0,-1]);
verify_f(QuatXYZ([0,0,0]), [0,0,0,1]);
verify_f(QuatXYZ([30,0,0]), [0.2588190451, 0, 0, 0.9659258263]);
verify_f(QuatXYZ([90,0,0]), [0.7071067812, 0, 0, 0.7071067812]);
verify_f(QuatXYZ([-270,0,0]), [-0.7071067812, 0, 0, -0.7071067812]);
verify_f(QuatXYZ([180,0,0]), [1,0,0,0]);
verify_f(QuatXYZ([270,0,0]), [0.7071067812, 0, 0, -0.7071067812]);
verify_f(QuatXYZ([-90,0,0]), [-0.7071067812, 0, 0, 0.7071067812]);
verify_f(QuatXYZ([360,0,0]), [0,0,0,-1]);
verify_f(QuatXYZ([0,0,0]), [0,0,0,1]);
verify_f(QuatXYZ([0,30,0]), [0, 0.2588190451, 0, 0.9659258263]);
verify_f(QuatXYZ([0,90,0]), [0, 0.7071067812, 0, 0.7071067812]);
verify_f(QuatXYZ([0,-270,0]), [0, -0.7071067812, 0, -0.7071067812]);
verify_f(QuatXYZ([0,180,0]), [0,1,0,0]);
verify_f(QuatXYZ([0,270,0]), [0, 0.7071067812, 0, -0.7071067812]);
verify_f(QuatXYZ([0,-90,0]), [0, -0.7071067812, 0, 0.7071067812]);
verify_f(QuatXYZ([0,360,0]), [0,0,0,-1]);
verify_f(QuatXYZ([0,0,0]), [0,0,0,1]);
verify_f(QuatXYZ([0,30,0]), [0, 0.2588190451, 0, 0.9659258263]);
verify_f(QuatXYZ([0,90,0]), [0, 0.7071067812, 0, 0.7071067812]);
verify_f(QuatXYZ([0,-270,0]), [0, -0.7071067812, 0, -0.7071067812]);
verify_f(QuatXYZ([0,180,0]), [0,1,0,0]);
verify_f(QuatXYZ([0,270,0]), [0, 0.7071067812, 0, -0.7071067812]);
verify_f(QuatXYZ([0,-90,0]), [0, -0.7071067812, 0, 0.7071067812]);
verify_f(QuatXYZ([0,360,0]), [0,0,0,-1]);
verify_f(QuatXYZ([0,0,0]), [0,0,0,1]);
verify_f(QuatXYZ([0,0,30]), [0, 0, 0.2588190451, 0.9659258263]);
verify_f(QuatXYZ([0,0,90]), [0, 0, 0.7071067812, 0.7071067812]);
verify_f(QuatXYZ([0,0,-270]), [0, 0, -0.7071067812, -0.7071067812]);
verify_f(QuatXYZ([0,0,180]), [0,0,1,0]);
verify_f(QuatXYZ([0,0,270]), [0, 0, 0.7071067812, -0.7071067812]);
verify_f(QuatXYZ([0,0,-90]), [0, 0, -0.7071067812, 0.7071067812]);
verify_f(QuatXYZ([0,0,360]), [0,0,0,-1]);
verify_f(QuatXYZ([0,0,0]), [0,0,0,1]);
verify_f(QuatXYZ([0,0,30]), [0, 0, 0.2588190451, 0.9659258263]);
verify_f(QuatXYZ([0,0,90]), [0, 0, 0.7071067812, 0.7071067812]);
verify_f(QuatXYZ([0,0,-270]), [0, 0, -0.7071067812, -0.7071067812]);
verify_f(QuatXYZ([0,0,180]), [0,0,1,0]);
verify_f(QuatXYZ([0,0,270]), [0, 0, 0.7071067812, -0.7071067812]);
verify_f(QuatXYZ([0,0,-90]), [0, 0, -0.7071067812, 0.7071067812]);
verify_f(QuatXYZ([0,0,360]), [0,0,0,-1]);
verify_f(QuatXYZ([30,30,30]), [0.1767766953, 0.3061862178, 0.1767766953, 0.9185586535]);
verify_f(QuatXYZ([12,34,56]), [-0.04824789229, 0.3036636044, 0.4195145429, 0.8540890495]);
verify_f(QuatXYZ([30,30,30]), [0.1767766953, 0.3061862178, 0.1767766953, 0.9185586535]);
verify_f(QuatXYZ([12,34,56]), [-0.04824789229, 0.3036636044, 0.4195145429, 0.8540890495]);
}
test_QuatXYZ();
module test_Q_Ident() {
verify_f(Q_Ident(), [0,0,0,1]);
verify_f(Q_Ident(), [0,0,0,1]);
}
test_Q_Ident();
module test_Q_Add_S() {
verify_f(Q_Add_S([0,0,0,1],3),[0,0,0,4]);
verify_f(Q_Add_S([0,0,1,0],3),[0,0,1,3]);
verify_f(Q_Add_S([0,1,0,0],3),[0,1,0,3]);
verify_f(Q_Add_S([1,0,0,0],3),[1,0,0,3]);
verify_f(Q_Add_S(Quat(LEFT+FWD,23),1),[-0.1409744184, -0.1409744184, 0, 1.979924705]);
verify_f(Q_Add_S([0,0,0,1],3),[0,0,0,4]);
verify_f(Q_Add_S([0,0,1,0],3),[0,0,1,3]);
verify_f(Q_Add_S([0,1,0,0],3),[0,1,0,3]);
verify_f(Q_Add_S([1,0,0,0],3),[1,0,0,3]);
verify_f(Q_Add_S(Quat(LEFT+FWD,23),1),[-0.1409744184, -0.1409744184, 0, 1.979924705]);
}
test_Q_Add_S();
module test_Q_Sub_S() {
verify_f(Q_Sub_S([0,0,0,1],3),[0,0,0,-2]);
verify_f(Q_Sub_S([0,0,1,0],3),[0,0,1,-3]);
verify_f(Q_Sub_S([0,1,0,0],3),[0,1,0,-3]);
verify_f(Q_Sub_S([1,0,0,0],3),[1,0,0,-3]);
verify_f(Q_Sub_S(Quat(LEFT+FWD,23),1),[-0.1409744184, -0.1409744184, 0, -0.02007529538]);
verify_f(Q_Sub_S([0,0,0,1],3),[0,0,0,-2]);
verify_f(Q_Sub_S([0,0,1,0],3),[0,0,1,-3]);
verify_f(Q_Sub_S([0,1,0,0],3),[0,1,0,-3]);
verify_f(Q_Sub_S([1,0,0,0],3),[1,0,0,-3]);
verify_f(Q_Sub_S(Quat(LEFT+FWD,23),1),[-0.1409744184, -0.1409744184, 0, -0.02007529538]);
}
test_Q_Sub_S();
module test_Q_Mul_S() {
verify_f(Q_Mul_S([0,0,0,1],3),[0,0,0,3]);
verify_f(Q_Mul_S([0,0,1,0],3),[0,0,3,0]);
verify_f(Q_Mul_S([0,1,0,0],3),[0,3,0,0]);
verify_f(Q_Mul_S([1,0,0,0],3),[3,0,0,0]);
verify_f(Q_Mul_S([1,0,0,1],3),[3,0,0,3]);
verify_f(Q_Mul_S(Quat(LEFT+FWD,23),4),[-0.5638976735, -0.5638976735, 0, 3.919698818]);
verify_f(Q_Mul_S([0,0,0,1],3),[0,0,0,3]);
verify_f(Q_Mul_S([0,0,1,0],3),[0,0,3,0]);
verify_f(Q_Mul_S([0,1,0,0],3),[0,3,0,0]);
verify_f(Q_Mul_S([1,0,0,0],3),[3,0,0,0]);
verify_f(Q_Mul_S([1,0,0,1],3),[3,0,0,3]);
verify_f(Q_Mul_S(Quat(LEFT+FWD,23),4),[-0.5638976735, -0.5638976735, 0, 3.919698818]);
}
test_Q_Mul_S();
module test_Q_Div_S() {
verify_f(Q_Div_S([0,0,0,1],3),[0,0,0,1/3]);
verify_f(Q_Div_S([0,0,1,0],3),[0,0,1/3,0]);
verify_f(Q_Div_S([0,1,0,0],3),[0,1/3,0,0]);
verify_f(Q_Div_S([1,0,0,0],3),[1/3,0,0,0]);
verify_f(Q_Div_S([1,0,0,1],3),[1/3,0,0,1/3]);
verify_f(Q_Div_S(Quat(LEFT+FWD,23),4),[-0.03524360459, -0.03524360459, 0, 0.2449811762]);
verify_f(Q_Div_S([0,0,0,1],3),[0,0,0,1/3]);
verify_f(Q_Div_S([0,0,1,0],3),[0,0,1/3,0]);
verify_f(Q_Div_S([0,1,0,0],3),[0,1/3,0,0]);
verify_f(Q_Div_S([1,0,0,0],3),[1/3,0,0,0]);
verify_f(Q_Div_S([1,0,0,1],3),[1/3,0,0,1/3]);
verify_f(Q_Div_S(Quat(LEFT+FWD,23),4),[-0.03524360459, -0.03524360459, 0, 0.2449811762]);
}
test_Q_Div_S();
module test_Q_Add() {
verify_f(Q_Add([2,3,4,5],[-1,-1,-1,-1]),[1,2,3,4]);
verify_f(Q_Add([2,3,4,5],[-3,-3,-3,-3]),[-1,0,1,2]);
verify_f(Q_Add([2,3,4,5],[0,0,0,0]),[2,3,4,5]);
verify_f(Q_Add([2,3,4,5],[1,1,1,1]),[3,4,5,6]);
verify_f(Q_Add([2,3,4,5],[1,0,0,0]),[3,3,4,5]);
verify_f(Q_Add([2,3,4,5],[0,1,0,0]),[2,4,4,5]);
verify_f(Q_Add([2,3,4,5],[0,0,1,0]),[2,3,5,5]);
verify_f(Q_Add([2,3,4,5],[0,0,0,1]),[2,3,4,6]);
verify_f(Q_Add([2,3,4,5],[2,1,2,1]),[4,4,6,6]);
verify_f(Q_Add([2,3,4,5],[1,2,1,2]),[3,5,5,7]);
verify_f(Q_Add([2,3,4,5],[-1,-1,-1,-1]),[1,2,3,4]);
verify_f(Q_Add([2,3,4,5],[-3,-3,-3,-3]),[-1,0,1,2]);
verify_f(Q_Add([2,3,4,5],[0,0,0,0]),[2,3,4,5]);
verify_f(Q_Add([2,3,4,5],[1,1,1,1]),[3,4,5,6]);
verify_f(Q_Add([2,3,4,5],[1,0,0,0]),[3,3,4,5]);
verify_f(Q_Add([2,3,4,5],[0,1,0,0]),[2,4,4,5]);
verify_f(Q_Add([2,3,4,5],[0,0,1,0]),[2,3,5,5]);
verify_f(Q_Add([2,3,4,5],[0,0,0,1]),[2,3,4,6]);
verify_f(Q_Add([2,3,4,5],[2,1,2,1]),[4,4,6,6]);
verify_f(Q_Add([2,3,4,5],[1,2,1,2]),[3,5,5,7]);
}
test_Q_Add();
module test_Q_Sub() {
verify_f(Q_Sub([2,3,4,5],[-1,-1,-1,-1]),[3,4,5,6]);
verify_f(Q_Sub([2,3,4,5],[-3,-3,-3,-3]),[5,6,7,8]);
verify_f(Q_Sub([2,3,4,5],[0,0,0,0]),[2,3,4,5]);
verify_f(Q_Sub([2,3,4,5],[1,1,1,1]),[1,2,3,4]);
verify_f(Q_Sub([2,3,4,5],[1,0,0,0]),[1,3,4,5]);
verify_f(Q_Sub([2,3,4,5],[0,1,0,0]),[2,2,4,5]);
verify_f(Q_Sub([2,3,4,5],[0,0,1,0]),[2,3,3,5]);
verify_f(Q_Sub([2,3,4,5],[0,0,0,1]),[2,3,4,4]);
verify_f(Q_Sub([2,3,4,5],[2,1,2,1]),[0,2,2,4]);
verify_f(Q_Sub([2,3,4,5],[1,2,1,2]),[1,1,3,3]);
verify_f(Q_Sub([2,3,4,5],[-1,-1,-1,-1]),[3,4,5,6]);
verify_f(Q_Sub([2,3,4,5],[-3,-3,-3,-3]),[5,6,7,8]);
verify_f(Q_Sub([2,3,4,5],[0,0,0,0]),[2,3,4,5]);
verify_f(Q_Sub([2,3,4,5],[1,1,1,1]),[1,2,3,4]);
verify_f(Q_Sub([2,3,4,5],[1,0,0,0]),[1,3,4,5]);
verify_f(Q_Sub([2,3,4,5],[0,1,0,0]),[2,2,4,5]);
verify_f(Q_Sub([2,3,4,5],[0,0,1,0]),[2,3,3,5]);
verify_f(Q_Sub([2,3,4,5],[0,0,0,1]),[2,3,4,4]);
verify_f(Q_Sub([2,3,4,5],[2,1,2,1]),[0,2,2,4]);
verify_f(Q_Sub([2,3,4,5],[1,2,1,2]),[1,1,3,3]);
}
test_Q_Sub();
module test_Q_Mul() {
verify_f(Q_Mul(QuatZ(30),QuatX(57)),[0.4608999698, 0.1234977747, 0.2274546059, 0.8488721457]);
verify_f(Q_Mul(QuatY(30),QuatZ(23)),[0.05160021841, 0.2536231763, 0.1925746368, 0.94653458]);
verify_f(Q_Mul(QuatZ(30),QuatX(57)),[0.4608999698, 0.1234977747, 0.2274546059, 0.8488721457]);
verify_f(Q_Mul(QuatY(30),QuatZ(23)),[0.05160021841, 0.2536231763, 0.1925746368, 0.94653458]);
}
test_Q_Mul();
module test_Q_Dot() {
verify_f(Q_Dot(QuatZ(30),QuatX(57)),0.8488721457);
verify_f(Q_Dot(QuatY(30),QuatZ(23)),0.94653458);
verify_f(Q_Dot(QuatZ(30),QuatX(57)),0.8488721457);
verify_f(Q_Dot(QuatY(30),QuatZ(23)),0.94653458);
}
test_Q_Dot();
module test_Q_Neg() {
verify_f(Q_Neg([1,0,0,1]),[-1,0,0,-1]);
verify_f(Q_Neg([0,1,1,0]),[0,-1,-1,0]);
verify_f(Q_Neg(QuatXYZ([23,45,67])),[0.0533818345,-0.4143703268,-0.4360652669,-0.7970537592]);
verify_f(Q_Neg([1,0,0,1]),[-1,0,0,-1]);
verify_f(Q_Neg([0,1,1,0]),[0,-1,-1,0]);
verify_f(Q_Neg(QuatXYZ([23,45,67])),[0.0533818345,-0.4143703268,-0.4360652669,-0.7970537592]);
}
test_Q_Neg();
module test_Q_Conj() {
verify_f(Q_Conj([1,0,0,1]),[-1,0,0,1]);
verify_f(Q_Conj([0,1,1,0]),[0,-1,-1,0]);
verify_f(Q_Conj(QuatXYZ([23,45,67])),[0.0533818345, -0.4143703268, -0.4360652669, 0.7970537592]);
verify_f(Q_Conj([1,0,0,1]),[-1,0,0,1]);
verify_f(Q_Conj([0,1,1,0]),[0,-1,-1,0]);
verify_f(Q_Conj(QuatXYZ([23,45,67])),[0.0533818345, -0.4143703268, -0.4360652669, 0.7970537592]);
}
test_Q_Conj();
module test_Q_Norm() {
verify_f(Q_Norm([1,0,0,1]),1.414213562);
verify_f(Q_Norm([0,1,1,0]),1.414213562);
verify_f(Q_Norm(QuatXYZ([23,45,67])),1);
verify_f(Q_Norm([1,0,0,1]),1.414213562);
verify_f(Q_Norm([0,1,1,0]),1.414213562);
verify_f(Q_Norm(QuatXYZ([23,45,67])),1);
}
test_Q_Norm();
module test_Q_Normalize() {
verify_f(Q_Normalize([1,0,0,1]),[0.7071067812, 0, 0, 0.7071067812]);
verify_f(Q_Normalize([0,1,1,0]),[0, 0.7071067812, 0.7071067812, 0]);
verify_f(Q_Normalize(QuatXYZ([23,45,67])),[-0.0533818345, 0.4143703268, 0.4360652669, 0.7970537592]);
verify_f(Q_Normalize([1,0,0,1]),[0.7071067812, 0, 0, 0.7071067812]);
verify_f(Q_Normalize([0,1,1,0]),[0, 0.7071067812, 0.7071067812, 0]);
verify_f(Q_Normalize(QuatXYZ([23,45,67])),[-0.0533818345, 0.4143703268, 0.4360652669, 0.7970537592]);
}
test_Q_Normalize();
module test_Q_Dist() {
verify_f(Q_Dist(QuatXYZ([23,45,67]),QuatXYZ([23,45,67])),0);
verify_f(Q_Dist(QuatXYZ([23,45,67]),QuatXYZ([12,34,56])),0.1257349854);
verify_f(Q_Dist(QuatXYZ([23,45,67]),QuatXYZ([23,45,67])),0);
verify_f(Q_Dist(QuatXYZ([23,45,67]),QuatXYZ([12,34,56])),0.1257349854);
}
test_Q_Dist();
module test_Q_Slerp() {
verify_f(Q_Slerp(QuatX(45),QuatY(30),0.0),QuatX(45));
verify_f(Q_Slerp(QuatX(45),QuatY(30),0.5),[0.1967063121, 0.1330377423, 0, 0.9713946602]);
verify_f(Q_Slerp(QuatX(45),QuatY(30),1.0),QuatY(30));
verify_f(Q_Slerp(QuatX(45),QuatY(30),0.0),QuatX(45));
verify_f(Q_Slerp(QuatX(45),QuatY(30),0.5),[0.1967063121, 0.1330377423, 0, 0.9713946602]);
verify_f(Q_Slerp(QuatX(45),QuatY(30),1.0),QuatY(30));
}
test_Q_Slerp();
module test_Q_Matrix3() {
verify_f(Q_Matrix3(QuatZ(37)),rot(37,planar=true));
verify_f(Q_Matrix3(QuatZ(-49)),rot(-49,planar=true));
verify_f(Q_Matrix3(QuatZ(37)),rot(37,planar=true));
verify_f(Q_Matrix3(QuatZ(-49)),rot(-49,planar=true));
}
test_Q_Matrix3();
module test_Q_Matrix4() {
verify_f(Q_Matrix4(QuatZ(37)),rot(37));
verify_f(Q_Matrix4(QuatZ(-49)),rot(-49));
verify_f(Q_Matrix4(QuatX(37)),rot([37,0,0]));
verify_f(Q_Matrix4(QuatY(37)),rot([0,37,0]));
verify_f(Q_Matrix4(QuatXYZ([12,34,56])),rot([12,34,56]));
verify_f(Q_Matrix4(QuatZ(37)),rot(37));
verify_f(Q_Matrix4(QuatZ(-49)),rot(-49));
verify_f(Q_Matrix4(QuatX(37)),rot([37,0,0]));
verify_f(Q_Matrix4(QuatY(37)),rot([0,37,0]));
verify_f(Q_Matrix4(QuatXYZ([12,34,56])),rot([12,34,56]));
}
test_Q_Matrix4();
module test_Q_Axis() {
verify_f(Q_Axis(QuatX(37)),RIGHT);
verify_f(Q_Axis(QuatX(-37)),LEFT);
verify_f(Q_Axis(QuatY(37)),BACK);
verify_f(Q_Axis(QuatY(-37)),FWD);
verify_f(Q_Axis(QuatZ(37)),UP);
verify_f(Q_Axis(QuatZ(-37)),DOWN);
verify_f(Q_Axis(QuatX(37)),RIGHT);
verify_f(Q_Axis(QuatX(-37)),LEFT);
verify_f(Q_Axis(QuatY(37)),BACK);
verify_f(Q_Axis(QuatY(-37)),FWD);
verify_f(Q_Axis(QuatZ(37)),UP);
verify_f(Q_Axis(QuatZ(-37)),DOWN);
}
test_Q_Axis();
module test_Q_Angle() {
verify_f(Q_Angle(QuatX(0)),0);
verify_f(Q_Angle(QuatY(0)),0);
verify_f(Q_Angle(QuatZ(0)),0);
verify_f(Q_Angle(QuatX(37)),37);
verify_f(Q_Angle(QuatX(-37)),37);
verify_f(Q_Angle(QuatY(37)),37);
verify_f(Q_Angle(QuatY(-37)),37);
verify_f(Q_Angle(QuatZ(37)),37);
verify_f(Q_Angle(QuatZ(-37)),37);
verify_f(Q_Angle(QuatX(0)),0);
verify_f(Q_Angle(QuatY(0)),0);
verify_f(Q_Angle(QuatZ(0)),0);
verify_f(Q_Angle(QuatX(37)),37);
verify_f(Q_Angle(QuatX(-37)),37);
verify_f(Q_Angle(QuatY(37)),37);
verify_f(Q_Angle(QuatY(-37)),37);
verify_f(Q_Angle(QuatZ(37)),37);
verify_f(Q_Angle(QuatZ(-37)),37);
}
test_Q_Angle();
module test_Qrot() {
verify_f(Qrot(QuatXYZ([12,34,56])),rot([12,34,56]));
verify_f(Qrot(QuatXYZ([12,34,56]),p=[2,3,4]),rot([12,34,56],p=[2,3,4]));
verify_f(Qrot(QuatXYZ([12,34,56]),p=[[2,3,4],[4,9,6]]),rot([12,34,56],p=[[2,3,4],[4,9,6]]));
verify_f(Qrot(QuatXYZ([12,34,56])),rot([12,34,56]));
verify_f(Qrot(QuatXYZ([12,34,56]),p=[2,3,4]),rot([12,34,56],p=[2,3,4]));
verify_f(Qrot(QuatXYZ([12,34,56]),p=[[2,3,4],[4,9,6]]),rot([12,34,56],p=[[2,3,4],[4,9,6]]));
}
test_Qrot();
// vim: noexpandtab tabstop=4 shiftwidth=4 softtabstop=4 nowrap
// vim: expandtab tabstop=4 shiftwidth=4 softtabstop=4 nowrap

View File

@@ -3,75 +3,75 @@ include <BOSL2/queues.scad>
module test_queue_init() {
assert(queue_init()==[]);
assert(queue_init()==[]);
}
test_queue_init();
module test_queue_empty() {
assert(queue_empty([]));
assert(!queue_empty([3]));
assert(!queue_empty([2,4,8]));
assert(queue_empty([]));
assert(!queue_empty([3]));
assert(!queue_empty([2,4,8]));
}
test_queue_empty();
module test_queue_size() {
assert(queue_size([]) == 0);
assert(queue_size([3]) == 1);
assert(queue_size([2,4,8]) == 3);
assert(queue_size([]) == 0);
assert(queue_size([3]) == 1);
assert(queue_size([2,4,8]) == 3);
}
test_queue_size();
module test_queue_head() {
assert(queue_head([]) == undef);
assert(queue_head([3,5,7,9]) == 3);
assert(queue_head([3,5,7,9], 3) == [3,5,7]);
assert(queue_head([]) == undef);
assert(queue_head([3,5,7,9]) == 3);
assert(queue_head([3,5,7,9], 3) == [3,5,7]);
}
test_queue_head();
module test_queue_tail() {
assert(queue_tail([]) == undef);
assert(queue_tail([3,5,7,9]) == 9);
assert(queue_tail([3,5,7,9], 3) == [5,7,9]);
assert(queue_tail([]) == undef);
assert(queue_tail([3,5,7,9]) == 9);
assert(queue_tail([3,5,7,9], 3) == [5,7,9]);
}
test_queue_tail();
module test_queue_peek() {
q = [8,5,4,3,2,3,7];
assert(queue_peek(q,0) == 8);
assert(queue_peek(q,2) == 4);
assert(queue_peek(q,2,1) == [4]);
assert(queue_peek(q,2,3) == [4,3,2]);
q = [8,5,4,3,2,3,7];
assert(queue_peek(q,0) == 8);
assert(queue_peek(q,2) == 4);
assert(queue_peek(q,2,1) == [4]);
assert(queue_peek(q,2,3) == [4,3,2]);
}
test_queue_peek();
module test_queue_add() {
q1 = queue_init();
q2 = queue_add(q1, "Foo");
assert(q2==["Foo"]);
q3 = queue_add(q2, "Bar");
assert(q3==["Foo","Bar"]);
q4 = queue_add(q3, "Baz");
assert(q4==["Foo","Bar","Baz"]);
q1 = queue_init();
q2 = queue_add(q1, "Foo");
assert(q2==["Foo"]);
q3 = queue_add(q2, "Bar");
assert(q3==["Foo","Bar"]);
q4 = queue_add(q3, "Baz");
assert(q4==["Foo","Bar","Baz"]);
}
test_queue_add();
module test_queue_pop() {
q = ["Foo", "Bar", "Baz", "Qux"];
q1 = queue_pop(q);
assert(q1 == ["Bar", "Baz", "Qux"]);
q2 = queue_pop(q,2);
assert(q2 == ["Baz", "Qux"]);
q3 = queue_pop(q,3);
assert(q3 == ["Qux"]);
q = ["Foo", "Bar", "Baz", "Qux"];
q1 = queue_pop(q);
assert(q1 == ["Bar", "Baz", "Qux"]);
q2 = queue_pop(q,2);
assert(q2 == ["Baz", "Qux"]);
q3 = queue_pop(q,3);
assert(q3 == ["Qux"]);
}
test_queue_pop();
// vim: noexpandtab tabstop=4 shiftwidth=4 softtabstop=4 nowrap
// vim: expandtab tabstop=4 shiftwidth=4 softtabstop=4 nowrap

View File

@@ -3,17 +3,17 @@ include <BOSL2/skin.scad>
module test_skin() {
profiles = [
[[-100,-100,0], [0,100,0], [100,-100,0]],
[[-100,-100,100], [-100,100,100], [100,100,100], [100,-100,100]],
];
vnf1 = skin(profiles, caps=false, method="distance");
assert(vnf1 == [[[-100,-100,0],[-100,100,100],[-100,-100,100],[0,100,0],[100,100,100],[100,-100,0],[100,-100,100]],[[0,1,2],[0,3,1],[3,4,1],[3,5,4],[5,6,4],[5,2,6],[5,0,2]]]);
vnf2 = skin(profiles, caps=true, method="distance");
assert(vnf2 == [[[-100,-100,0],[-100,100,100],[-100,-100,100],[0,100,0],[100,100,100],[100,-100,0],[100,-100,100],[100,-100,0],[0,100,0],[-100,-100,0],[-100,-100,100],[-100,100,100],[100,100,100],[100,-100,100]],[[0,1,2],[0,3,1],[3,4,1],[3,5,4],[5,6,4],[5,2,6],[5,0,2],[7,8,9],[10,11,12],[12,13,10]]]);
vnf_polyhedron(vnf2);
profiles = [
[[-100,-100,0], [0,100,0], [100,-100,0]],
[[-100,-100,100], [-100,100,100], [100,100,100], [100,-100,100]],
];
vnf1 = skin(profiles, caps=false, method="distance");
assert(vnf1 == [[[-100,-100,0],[-100,100,100],[-100,-100,100],[0,100,0],[100,100,100],[100,-100,0],[100,-100,100]],[[0,1,2],[0,3,1],[3,4,1],[3,5,4],[5,6,4],[5,2,6],[5,0,2]]]);
vnf2 = skin(profiles, caps=true, method="distance");
assert(vnf2 == [[[-100,-100,0],[-100,100,100],[-100,-100,100],[0,100,0],[100,100,100],[100,-100,0],[100,-100,100],[100,-100,0],[0,100,0],[-100,-100,0],[-100,-100,100],[-100,100,100],[100,100,100],[100,-100,100]],[[0,1,2],[0,3,1],[3,4,1],[3,5,4],[5,6,4],[5,2,6],[5,0,2],[7,8,9],[10,11,12],[12,13,10]]]);
vnf_polyhedron(vnf2);
}
test_skin();
// vim: noexpandtab tabstop=4 shiftwidth=4 softtabstop=4 nowrap
// vim: expandtab tabstop=4 shiftwidth=4 softtabstop=4 nowrap

View File

@@ -3,77 +3,77 @@ include <BOSL2/stacks.scad>
module test_stack_init() {
assert(stack_init()==[]);
assert(stack_init()==[]);
}
test_stack_init();
module test_stack_empty() {
assert(stack_empty([]));
assert(!stack_empty([3]));
assert(!stack_empty([2,4,8]));
assert(stack_empty([]));
assert(!stack_empty([3]));
assert(!stack_empty([2,4,8]));
}
test_stack_empty();
module test_stack_depth() {
assert(stack_depth([]) == 0);
assert(stack_depth([3]) == 1);
assert(stack_depth([2,4,8]) == 3);
assert(stack_depth([]) == 0);
assert(stack_depth([3]) == 1);
assert(stack_depth([2,4,8]) == 3);
}
test_stack_depth();
module test_stack_top() {
assert(stack_top([]) == undef);
assert(stack_top([3,5,7,9]) == 9);
assert(stack_top([3,5,7,9], 3) == [5,7,9]);
assert(stack_top([]) == undef);
assert(stack_top([3,5,7,9]) == 9);
assert(stack_top([3,5,7,9], 3) == [5,7,9]);
}
test_stack_top();
module test_stack_peek() {
s = [8,5,4,3,2,3,7];
assert(stack_peek(s,0) == 7);
assert(stack_peek(s,2) == 2);
assert(stack_peek(s,2,1) == [2]);
assert(stack_peek(s,2,3) == [2,3,7]);
s = [8,5,4,3,2,3,7];
assert(stack_peek(s,0) == 7);
assert(stack_peek(s,2) == 2);
assert(stack_peek(s,2,1) == [2]);
assert(stack_peek(s,2,3) == [2,3,7]);
}
test_stack_peek();
module test_stack_push() {
s1 = stack_init();
s2 = stack_push(s1, "Foo");
assert(s2==["Foo"]);
s3 = stack_push(s2, "Bar");
assert(s3==["Foo","Bar"]);
s4 = stack_push(s3, "Baz");
assert(s4==["Foo","Bar","Baz"]);
s1 = stack_init();
s2 = stack_push(s1, "Foo");
assert(s2==["Foo"]);
s3 = stack_push(s2, "Bar");
assert(s3==["Foo","Bar"]);
s4 = stack_push(s3, "Baz");
assert(s4==["Foo","Bar","Baz"]);
}
test_stack_push();
module test_stack_pop() {
s = ["Foo", "Bar", "Baz", "Qux"];
s1 = stack_pop(s);
assert(s1 == ["Foo", "Bar", "Baz"]);
s2 = stack_pop(s,2);
assert(s2 == ["Foo", "Bar"]);
s3 = stack_pop(s,3);
assert(s3 == ["Foo"]);
s = ["Foo", "Bar", "Baz", "Qux"];
s1 = stack_pop(s);
assert(s1 == ["Foo", "Bar", "Baz"]);
s2 = stack_pop(s,2);
assert(s2 == ["Foo", "Bar"]);
s3 = stack_pop(s,3);
assert(s3 == ["Foo"]);
}
test_stack_pop();
module test_stack_rotate() {
s = ["Foo", "Bar", "Baz", "Qux", "Quux"];
s1 = stack_rotate(s,4);
assert(s1 == ["Foo", "Baz", "Qux", "Quux", "Bar"]);
s2 = stack_rotate(s,-4);
assert(s2 == ["Foo", "Quux", "Bar", "Baz", "Qux"]);
s = ["Foo", "Bar", "Baz", "Qux", "Quux"];
s1 = stack_rotate(s,4);
assert(s1 == ["Foo", "Baz", "Qux", "Quux", "Bar"]);
s2 = stack_rotate(s,-4);
assert(s2 == ["Foo", "Quux", "Bar", "Baz", "Qux"]);
}
test_stack_rotate();
// vim: noexpandtab tabstop=4 shiftwidth=4 softtabstop=4 nowrap
// vim: expandtab tabstop=4 shiftwidth=4 softtabstop=4 nowrap

View File

@@ -3,57 +3,57 @@ include <BOSL2/structs.scad>
module test_struct_set() {
st = struct_set([], "Foo", 42);
assert(st == [["Foo",42]]);
st2 = struct_set(st, "Bar", 28);
assert(st2 == [["Foo",42],["Bar",28]]);
st3 = struct_set(st2, "Foo", 91);
assert(st3 == [["Foo",91],["Bar",28]]);
st = struct_set([], "Foo", 42);
assert(st == [["Foo",42]]);
st2 = struct_set(st, "Bar", 28);
assert(st2 == [["Foo",42],["Bar",28]]);
st3 = struct_set(st2, "Foo", 91);
assert(st3 == [["Foo",91],["Bar",28]]);
}
test_struct_set();
module test_struct_remove() {
st = [["Foo",91],["Bar",28],["Baz",9]];
assert(struct_remove(st, "Foo") == [["Bar",28],["Baz",9]]);
assert(struct_remove(st, "Bar") == [["Foo",91],["Baz",9]]);
assert(struct_remove(st, "Baz") == [["Foo",91],["Bar",28]]);
st = [["Foo",91],["Bar",28],["Baz",9]];
assert(struct_remove(st, "Foo") == [["Bar",28],["Baz",9]]);
assert(struct_remove(st, "Bar") == [["Foo",91],["Baz",9]]);
assert(struct_remove(st, "Baz") == [["Foo",91],["Bar",28]]);
}
test_struct_remove();
module test_struct_val() {
st = [["Foo",91],["Bar",28],["Baz",9]];
assert(struct_val(st,"Foo") == 91);
assert(struct_val(st,"Bar") == 28);
assert(struct_val(st,"Baz") == 9);
st = [["Foo",91],["Bar",28],["Baz",9]];
assert(struct_val(st,"Foo") == 91);
assert(struct_val(st,"Bar") == 28);
assert(struct_val(st,"Baz") == 9);
}
test_struct_val();
module test_struct_keys() {
assert(struct_keys([["Foo",3],["Bar",2],["Baz",1]]) == ["Foo","Bar","Baz"]);
assert(struct_keys([["Zee",1],["Why",2],["Exx",3]]) == ["Zee","Why","Exx"]);
assert(struct_keys([["Foo",3],["Bar",2],["Baz",1]]) == ["Foo","Bar","Baz"]);
assert(struct_keys([["Zee",1],["Why",2],["Exx",3]]) == ["Zee","Why","Exx"]);
}
test_struct_keys();
module test_struct_echo() {
// Can't yet test echo output
// Can't yet test echo output
}
test_struct_echo();
module test_is_struct() {
assert(is_struct([["Foo",1],["Bar",2],["Baz",3]]));
assert(!is_struct([["Foo"],["Bar"],["Baz"]]));
assert(!is_struct(["Foo","Bar","Baz"]));
assert(!is_struct([3,4,5]));
assert(!is_struct(3));
assert(!is_struct(true));
assert(!is_struct("foo"));
assert(is_struct([["Foo",1],["Bar",2],["Baz",3]]));
assert(!is_struct([["Foo"],["Bar"],["Baz"]]));
assert(!is_struct(["Foo","Bar","Baz"]));
assert(!is_struct([3,4,5]));
assert(!is_struct(3));
assert(!is_struct(true));
assert(!is_struct("foo"));
}
test_is_struct();
// vim: noexpandtab tabstop=4 shiftwidth=4 softtabstop=4 nowrap
// vim: expandtab tabstop=4 shiftwidth=4 softtabstop=4 nowrap

View File

@@ -1,159 +1,159 @@
include <BOSL2/std.scad>
module test(got,expect,extra_info) {
if (
is_undef(expect) != is_undef(got) ||
expect*0 != got*0 ||
(is_vnf(expect) && !all([for (i=idx(expect[0])) approx(got[0][i],expect[0][i])]) && got[1]!=expect[1]) ||
(is_matrix(expect) && !all([for (i=idx(expect)) approx(got[i],expect[i])])) ||
(got!=expect && !approx(got, expect))
) {
fmt = is_int(expect)? "{:.14i}" :
is_num(expect)? "{:.14g}" :
is_vector(expect)? "{:.14g}" :
"{}";
echofmt(str("Expected: ",fmt),[expect]);
echofmt(str("But Got : ",fmt),[got]);
if (expect*0 == got*0) {
echofmt(str("Delta is: ",fmt),[expect-got]);
}
if (!is_undef(extra_info)) {
echo(str("Extra Info: ",extra_info));
}
assert(false, "TEST FAILED!");
}
if (
is_undef(expect) != is_undef(got) ||
expect*0 != got*0 ||
(is_vnf(expect) && !all([for (i=idx(expect[0])) approx(got[0][i],expect[0][i])]) && got[1]!=expect[1]) ||
(is_matrix(expect) && !all([for (i=idx(expect)) approx(got[i],expect[i])])) ||
(got!=expect && !approx(got, expect))
) {
fmt = is_int(expect)? "{:.14i}" :
is_num(expect)? "{:.14g}" :
is_vector(expect)? "{:.14g}" :
"{}";
echofmt(str("Expected: ",fmt),[expect]);
echofmt(str("But Got : ",fmt),[got]);
if (expect*0 == got*0) {
echofmt(str("Delta is: ",fmt),[expect-got]);
}
if (!is_undef(extra_info)) {
echo(str("Extra Info: ",extra_info));
}
assert(false, "TEST FAILED!");
}
}
module test_rot() {
pts2d = 50 * [for (x=[-1,0,1],y=[-1,0,1]) [x,y]];
pts3d = 50 * [for (x=[-1,0,1],y=[-1,0,1],z=[-1,0,1]) [x,y,z]];
vecs2d = [
for (x=[-1,0,1], y=[-1,0,1]) if(x!=0||y!=0) [x,y],
polar_to_xy(1, -75),
polar_to_xy(1, 75)
];
vecs3d = [
LEFT, RIGHT, FRONT, BACK, DOWN, UP,
spherical_to_xyz(1, -30, 45),
spherical_to_xyz(1, 0, 45),
spherical_to_xyz(1, 30, 45),
spherical_to_xyz(2, 30, 45),
spherical_to_xyz(1, -30, 135),
spherical_to_xyz(2, -30, 135),
spherical_to_xyz(1, 0, 135),
spherical_to_xyz(1, 30, 135),
spherical_to_xyz(1, -30, 75),
spherical_to_xyz(1, 45, 45),
];
angs = [-180, -90, -45, 0, 30, 45, 90];
for (a = [-360*3:360:360*3]) {
test(rot(a), affine3d_identity(), extra_info=str("rot(",a,") != identity"));
test(rot(a,p=pts2d), pts2d, extra_info=str("rot(",a,",p=...), 2D"));
test(rot(a,p=pts3d), pts3d, extra_info=str("rot(",a,",p=...), 3D"));
}
test(rot(90), [[0,-1,0,0],[1,0,0,0],[0,0,1,0],[0,0,0,1]])
for (a=angs) {
test(rot(a), affine3d_zrot(a), extra_info=str("Z angle (only) = ",a));
test(rot([a,0,0]), affine3d_xrot(a), extra_info=str("X angle = ",a));
test(rot([0,a,0]), affine3d_yrot(a), extra_info=str("Y angle = ",a));
test(rot([0,0,a]), affine3d_zrot(a), extra_info=str("Z angle = ",a));
pts2d = 50 * [for (x=[-1,0,1],y=[-1,0,1]) [x,y]];
pts3d = 50 * [for (x=[-1,0,1],y=[-1,0,1],z=[-1,0,1]) [x,y,z]];
vecs2d = [
for (x=[-1,0,1], y=[-1,0,1]) if(x!=0||y!=0) [x,y],
polar_to_xy(1, -75),
polar_to_xy(1, 75)
];
vecs3d = [
LEFT, RIGHT, FRONT, BACK, DOWN, UP,
spherical_to_xyz(1, -30, 45),
spherical_to_xyz(1, 0, 45),
spherical_to_xyz(1, 30, 45),
spherical_to_xyz(2, 30, 45),
spherical_to_xyz(1, -30, 135),
spherical_to_xyz(2, -30, 135),
spherical_to_xyz(1, 0, 135),
spherical_to_xyz(1, 30, 135),
spherical_to_xyz(1, -30, 75),
spherical_to_xyz(1, 45, 45),
];
angs = [-180, -90, -45, 0, 30, 45, 90];
for (a = [-360*3:360:360*3]) {
test(rot(a), affine3d_identity(), extra_info=str("rot(",a,") != identity"));
test(rot(a,p=pts2d), pts2d, extra_info=str("rot(",a,",p=...), 2D"));
test(rot(a,p=pts3d), pts3d, extra_info=str("rot(",a,",p=...), 3D"));
}
test(rot(90), [[0,-1,0,0],[1,0,0,0],[0,0,1,0],[0,0,0,1]])
for (a=angs) {
test(rot(a), affine3d_zrot(a), extra_info=str("Z angle (only) = ",a));
test(rot([a,0,0]), affine3d_xrot(a), extra_info=str("X angle = ",a));
test(rot([0,a,0]), affine3d_yrot(a), extra_info=str("Y angle = ",a));
test(rot([0,0,a]), affine3d_zrot(a), extra_info=str("Z angle = ",a));
test(rot(a,p=pts2d), apply(affine3d_zrot(a),pts2d), extra_info=str("Z angle (only) = ",a, ", p=..., 2D"));
test(rot([0,0,a],p=pts2d), apply(affine3d_zrot(a),pts2d), extra_info=str("Z angle = ",a, ", p=..., 2D"));
test(rot(a,p=pts2d), apply(affine3d_zrot(a),pts2d), extra_info=str("Z angle (only) = ",a, ", p=..., 2D"));
test(rot([0,0,a],p=pts2d), apply(affine3d_zrot(a),pts2d), extra_info=str("Z angle = ",a, ", p=..., 2D"));
test(rot(a,p=pts3d), apply(affine3d_zrot(a),pts3d), extra_info=str("Z angle (only) = ",a, ", p=..., 3D"));
test(rot([a,0,0],p=pts3d), apply(affine3d_xrot(a),pts3d), extra_info=str("X angle = ",a, ", p=..., 3D"));
test(rot([0,a,0],p=pts3d), apply(affine3d_yrot(a),pts3d), extra_info=str("Y angle = ",a, ", p=..., 3D"));
test(rot([0,0,a],p=pts3d), apply(affine3d_zrot(a),pts3d), extra_info=str("Z angle = ",a, ", p=..., 3D"));
}
for (xa=angs, ya=angs, za=angs) {
test(
rot([xa,ya,za]),
affine3d_chain([
affine3d_xrot(xa),
affine3d_yrot(ya),
affine3d_zrot(za)
]),
extra_info=str("[X,Y,Z] = ",[xa,ya,za])
);
test(
rot([xa,ya,za],p=pts3d),
apply(
affine3d_chain([
affine3d_xrot(xa),
affine3d_yrot(ya),
affine3d_zrot(za)
]),
pts3d
),
extra_info=str("[X,Y,Z] = ",[xa,ya,za], ", p=...")
);
}
for (vec1 = vecs3d) {
for (ang = angs) {
test(
rot(a=ang, v=vec1),
affine3d_rot_by_axis(vec1,ang),
extra_info=str("a = ",ang,", v = ", vec1)
);
test(
rot(a=ang, v=vec1, p=pts3d),
apply(affine3d_rot_by_axis(vec1,ang), pts3d),
extra_info=str("a = ",ang,", v = ", vec1, ", p=...")
);
}
}
for (vec1 = vecs2d) {
for (vec2 = vecs2d) {
test(
rot(from=vec1, to=vec2, p=pts2d, planar=true),
apply(affine2d_zrot(vang(vec2)-vang(vec1)), pts2d),
extra_info=str(
"from = ", vec1, ", ",
"to = ", vec2, ", ",
"planar = ", true, ", ",
"p=..., 2D"
)
);
}
}
for (vec1 = vecs3d) {
for (vec2 = vecs3d) {
for (a = angs) {
test(
rot(from=vec1, to=vec2, a=a),
affine3d_chain([
affine3d_zrot(a),
affine3d_rot_from_to(vec1,vec2)
]),
extra_info=str(
"from = ", vec1, ", ",
"to = ", vec2, ", ",
"a = ", a
)
);
test(
rot(from=vec1, to=vec2, a=a, p=pts3d),
apply(
affine3d_chain([
affine3d_zrot(a),
affine3d_rot_from_to(vec1,vec2)
]),
pts3d
),
extra_info=str(
"from = ", vec1, ", ",
"to = ", vec2, ", ",
"a = ", a, ", ",
"p=..., 3D"
)
);
}
}
}
test(rot(a,p=pts3d), apply(affine3d_zrot(a),pts3d), extra_info=str("Z angle (only) = ",a, ", p=..., 3D"));
test(rot([a,0,0],p=pts3d), apply(affine3d_xrot(a),pts3d), extra_info=str("X angle = ",a, ", p=..., 3D"));
test(rot([0,a,0],p=pts3d), apply(affine3d_yrot(a),pts3d), extra_info=str("Y angle = ",a, ", p=..., 3D"));
test(rot([0,0,a],p=pts3d), apply(affine3d_zrot(a),pts3d), extra_info=str("Z angle = ",a, ", p=..., 3D"));
}
for (xa=angs, ya=angs, za=angs) {
test(
rot([xa,ya,za]),
affine3d_chain([
affine3d_xrot(xa),
affine3d_yrot(ya),
affine3d_zrot(za)
]),
extra_info=str("[X,Y,Z] = ",[xa,ya,za])
);
test(
rot([xa,ya,za],p=pts3d),
apply(
affine3d_chain([
affine3d_xrot(xa),
affine3d_yrot(ya),
affine3d_zrot(za)
]),
pts3d
),
extra_info=str("[X,Y,Z] = ",[xa,ya,za], ", p=...")
);
}
for (vec1 = vecs3d) {
for (ang = angs) {
test(
rot(a=ang, v=vec1),
affine3d_rot_by_axis(vec1,ang),
extra_info=str("a = ",ang,", v = ", vec1)
);
test(
rot(a=ang, v=vec1, p=pts3d),
apply(affine3d_rot_by_axis(vec1,ang), pts3d),
extra_info=str("a = ",ang,", v = ", vec1, ", p=...")
);
}
}
for (vec1 = vecs2d) {
for (vec2 = vecs2d) {
test(
rot(from=vec1, to=vec2, p=pts2d, planar=true),
apply(affine2d_zrot(vang(vec2)-vang(vec1)), pts2d),
extra_info=str(
"from = ", vec1, ", ",
"to = ", vec2, ", ",
"planar = ", true, ", ",
"p=..., 2D"
)
);
}
}
for (vec1 = vecs3d) {
for (vec2 = vecs3d) {
for (a = angs) {
test(
rot(from=vec1, to=vec2, a=a),
affine3d_chain([
affine3d_zrot(a),
affine3d_rot_from_to(vec1,vec2)
]),
extra_info=str(
"from = ", vec1, ", ",
"to = ", vec2, ", ",
"a = ", a
)
);
test(
rot(from=vec1, to=vec2, a=a, p=pts3d),
apply(
affine3d_chain([
affine3d_zrot(a),
affine3d_rot_from_to(vec1,vec2)
]),
pts3d
),
extra_info=str(
"from = ", vec1, ", ",
"to = ", vec2, ", ",
"a = ", a, ", ",
"p=..., 3D"
)
);
}
}
}
}
test_rot();
// vim: noexpandtab tabstop=4 shiftwidth=4 softtabstop=4 nowrap
// vim: expandtab tabstop=4 shiftwidth=4 softtabstop=4 nowrap

View File

@@ -2,121 +2,121 @@ include <BOSL2/std.scad>
module test_is_vector() {
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);
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);
}
test_is_vector();
module test_add_scalar() {
assert(add_scalar([1,2,3],3) == [4,5,6]);
assert(add_scalar([[1,2,3],[3,4,5]],3) == [[4,5,6],[6,7,8]]);
assert(add_scalar([1,2,3],3) == [4,5,6]);
assert(add_scalar([[1,2,3],[3,4,5]],3) == [[4,5,6],[6,7,8]]);
}
test_add_scalar();
module test_vmul() {
assert(vmul([3,4,5], [8,7,6]) == [24,28,30]);
assert(vmul([1,2,3], [4,5,6]) == [4,10,18]);
assert(vmul([3,4,5], [8,7,6]) == [24,28,30]);
assert(vmul([1,2,3], [4,5,6]) == [4,10,18]);
}
test_vmul();
module test_vdiv() {
assert(vdiv([24,28,30], [8,7,6]) == [3, 4, 5]);
assert(vdiv([24,28,30], [8,7,6]) == [3, 4, 5]);
}
test_vdiv();
module test_vabs() {
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]);
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]);
}
test_vabs();
include <BOSL2/strings.scad>
module test_vang() {
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]));
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]));
}
test_vang();
module test_unit() {
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);
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);
}
test_unit();
module test_vector_angle() {
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);
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);
}
test_vector_angle();
module test_vector_axis() {
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);
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);
}
test_vector_axis();
@@ -124,4 +124,4 @@ test_vector_axis();
cube();
// vim: noexpandtab tabstop=4 shiftwidth=4 softtabstop=4 nowrap
// vim: expandtab tabstop=4 shiftwidth=4 softtabstop=4 nowrap

View File

@@ -2,116 +2,116 @@ include <BOSL2/std.scad>
module test_bosl_version() {
assert(is_vector(bosl_version())); // Returned value is a vector.
assert(len(bosl_version())==3); // of three numbers.
assert(bosl_version()[0]==2); // The major version is 2.
for (v=bosl_version()) {
assert(floor(v)==v); // All version parts are integers.
}
assert(is_vector(bosl_version())); // Returned value is a vector.
assert(len(bosl_version())==3); // of three numbers.
assert(bosl_version()[0]==2); // The major version is 2.
for (v=bosl_version()) {
assert(floor(v)==v); // All version parts are integers.
}
}
test_bosl_version();
module test_bosl_version_num() {
assert(is_num(bosl_version_num()));
v = bosl_version();
assert(bosl_version_num() == v[0]+v[1]/100+v[2]/1000000);
assert(is_num(bosl_version_num()));
v = bosl_version();
assert(bosl_version_num() == v[0]+v[1]/100+v[2]/1000000);
}
test_bosl_version_num();
module test_bosl_version_str() {
assert(is_string(bosl_version_str()));
v = bosl_version();
assert(bosl_version_str() == str(v[0],".",v[1],".",v[2]));
assert(is_string(bosl_version_str()));
v = bosl_version();
assert(bosl_version_str() == str(v[0],".",v[1],".",v[2]));
}
test_bosl_version_str();
module test_bosl_required() {
bosl_required(2.000001);
bosl_required("2.0.1");
bosl_required([2,0,1]);
bosl_required(2.000001);
bosl_required("2.0.1");
bosl_required([2,0,1]);
}
test_bosl_required();
module test_version_to_list() {
assert(is_list(version_to_list(2.010001)));
assert(is_list(version_to_list("2.1.1")));
assert(is_list(version_to_list([2,1,1])));
assert(version_to_list(2.010001)==[2,1,1]);
assert(version_to_list("2.1.1")==[2,1,1]);
assert(version_to_list([2,1,1])==[2,1,1]);
assert(version_to_list(2.010035)==[2,1,35]);
assert(version_to_list(2.345678)==[2,34,5678]);
assert(version_to_list("2.34.5678")==[2,34,5678]);
assert(version_to_list([2,34,5678])==[2,34,5678]);
assert(version_to_list([2,34,56,78])==[2,34,56]);
assert(is_list(version_to_list(2.010001)));
assert(is_list(version_to_list("2.1.1")));
assert(is_list(version_to_list([2,1,1])));
assert(version_to_list(2.010001)==[2,1,1]);
assert(version_to_list("2.1.1")==[2,1,1]);
assert(version_to_list([2,1,1])==[2,1,1]);
assert(version_to_list(2.010035)==[2,1,35]);
assert(version_to_list(2.345678)==[2,34,5678]);
assert(version_to_list("2.34.5678")==[2,34,5678]);
assert(version_to_list([2,34,5678])==[2,34,5678]);
assert(version_to_list([2,34,56,78])==[2,34,56]);
}
test_version_to_list();
module test_version_to_str() {
assert(is_string(version_to_str(2.010001)));
assert(is_string(version_to_str("2.1.1")));
assert(is_string(version_to_str([2,1,1])));
assert(version_to_str(2.010001)=="2.1.1");
assert(version_to_str("2.1.1")=="2.1.1");
assert(version_to_str([2,1,1])=="2.1.1");
assert(version_to_str(2.345678)=="2.34.5678");
assert(version_to_str("2.34.5678")=="2.34.5678");
assert(version_to_str([2,34,5678])=="2.34.5678");
assert(version_to_str([2,34,56,78])=="2.34.56");
assert(is_string(version_to_str(2.010001)));
assert(is_string(version_to_str("2.1.1")));
assert(is_string(version_to_str([2,1,1])));
assert(version_to_str(2.010001)=="2.1.1");
assert(version_to_str("2.1.1")=="2.1.1");
assert(version_to_str([2,1,1])=="2.1.1");
assert(version_to_str(2.345678)=="2.34.5678");
assert(version_to_str("2.34.5678")=="2.34.5678");
assert(version_to_str([2,34,5678])=="2.34.5678");
assert(version_to_str([2,34,56,78])=="2.34.56");
}
test_version_to_str();
module test_version_to_num() {
assert(is_num(version_to_num(2.010001)));
assert(is_num(version_to_num("2.1.1")));
assert(is_num(version_to_num([2,1,1])));
assert(version_to_num(2.010001)==2.010001);
assert(version_to_num("2.1.1")==2.010001);
assert(version_to_num([2,1,1])==2.010001);
assert(version_to_num(2.345678)==2.345678);
assert(version_to_num("2.34.5678")==2.345678);
assert(version_to_num([2,34,5678])==2.345678);
assert(version_to_num([2,34,56,78])==2.340056);
assert(is_num(version_to_num(2.010001)));
assert(is_num(version_to_num("2.1.1")));
assert(is_num(version_to_num([2,1,1])));
assert(version_to_num(2.010001)==2.010001);
assert(version_to_num("2.1.1")==2.010001);
assert(version_to_num([2,1,1])==2.010001);
assert(version_to_num(2.345678)==2.345678);
assert(version_to_num("2.34.5678")==2.345678);
assert(version_to_num([2,34,5678])==2.345678);
assert(version_to_num([2,34,56,78])==2.340056);
}
test_version_to_num();
module test_version_cmp() {
function diversify(x) = [
version_to_num(x),
version_to_str(x),
version_to_list(x)
];
function diversify(x) = [
version_to_num(x),
version_to_str(x),
version_to_list(x)
];
module testvercmp(x,y,z) {
for (a = diversify(y)) {
for (b = diversify(x)) {
assert(version_cmp(a,b)>0);
}
for (b = diversify(y)) {
assert(version_cmp(a,b)==0);
}
for (b = diversify(z)) {
assert(version_cmp(a,b)<0);
}
}
}
module testvercmp(x,y,z) {
for (a = diversify(y)) {
for (b = diversify(x)) {
assert(version_cmp(a,b)>0);
}
for (b = diversify(y)) {
assert(version_cmp(a,b)==0);
}
for (b = diversify(z)) {
assert(version_cmp(a,b)<0);
}
}
}
testvercmp([2,1,33],[2,1,34],[2,1,35]);
testvercmp([2,2,1],[2,2,34],[2,2,67]);
testvercmp([2,2,34],[2,3,34],[2,4,34]);
testvercmp([2,3,34],[3,3,34],[4,3,34]);
testvercmp([2,3,34],[3,1,1],[4,1,1]);
testvercmp([2,1,1],[3,3,34],[4,1,1]);
testvercmp([2,1,1],[3,1,1],[4,3,34]);
testvercmp([2,1,33],[2,1,34],[2,1,35]);
testvercmp([2,2,1],[2,2,34],[2,2,67]);
testvercmp([2,2,34],[2,3,34],[2,4,34]);
testvercmp([2,3,34],[3,3,34],[4,3,34]);
testvercmp([2,3,34],[3,1,1],[4,1,1]);
testvercmp([2,1,1],[3,3,34],[4,1,1]);
testvercmp([2,1,1],[3,1,1],[4,3,34]);
}
test_version_cmp();
// vim: noexpandtab tabstop=4 shiftwidth=4 softtabstop=4 nowrap
// vim: expandtab tabstop=4 shiftwidth=4 softtabstop=4 nowrap

View File

@@ -3,101 +3,101 @@ include <BOSL2/vnf.scad>
module test_is_vnf() {
assert(is_vnf([[],[]]));
assert(!is_vnf([]));
assert(is_vnf([[[-1,-1,-1],[1,-1,-1],[0,1,-1],[0,0,1]],[[0,1,2],[0,3,1],[1,3,2],[2,3,0]]]));
assert(is_vnf([[],[]]));
assert(!is_vnf([]));
assert(is_vnf([[[-1,-1,-1],[1,-1,-1],[0,1,-1],[0,0,1]],[[0,1,2],[0,3,1],[1,3,2],[2,3,0]]]));
}
test_is_vnf();
module test_is_vnf_list() {
assert(is_vnf_list([]));
assert(!is_vnf_list([[],[]]));
assert(is_vnf_list([[[],[]]]));
assert(!is_vnf_list([[[-1,-1,-1],[1,-1,-1],[0,1,-1],[0,0,1]],[[0,1,2],[0,3,1],[1,3,2],[2,3,0]]]));
assert(is_vnf_list([[[[-1,-1,-1],[1,-1,-1],[0,1,-1],[0,0,1]],[[0,1,2],[0,3,1],[1,3,2],[2,3,0]]]]));
assert(is_vnf_list([]));
assert(!is_vnf_list([[],[]]));
assert(is_vnf_list([[[],[]]]));
assert(!is_vnf_list([[[-1,-1,-1],[1,-1,-1],[0,1,-1],[0,0,1]],[[0,1,2],[0,3,1],[1,3,2],[2,3,0]]]));
assert(is_vnf_list([[[[-1,-1,-1],[1,-1,-1],[0,1,-1],[0,0,1]],[[0,1,2],[0,3,1],[1,3,2],[2,3,0]]]]));
}
test_is_vnf_list();
module test_vnf_vertices() {
vnf = [[[-1,-1,-1],[1,-1,-1],[0,1,-1],[0,0,1]],[[0,1,2],[0,3,1],[1,3,2],[2,3,0]]];
assert(vnf_vertices(vnf) == vnf[0]);
vnf = [[[-1,-1,-1],[1,-1,-1],[0,1,-1],[0,0,1]],[[0,1,2],[0,3,1],[1,3,2],[2,3,0]]];
assert(vnf_vertices(vnf) == vnf[0]);
}
test_vnf_vertices();
module test_vnf_faces() {
vnf = [[[-1,-1,-1],[1,-1,-1],[0,1,-1],[0,0,1]],[[0,1,2],[0,3,1],[1,3,2],[2,3,0]]];
assert(vnf_faces(vnf) == vnf[1]);
vnf = [[[-1,-1,-1],[1,-1,-1],[0,1,-1],[0,0,1]],[[0,1,2],[0,3,1],[1,3,2],[2,3,0]]];
assert(vnf_faces(vnf) == vnf[1]);
}
test_vnf_faces();
module test_vnf_get_vertex() {
vnf = [[[-1,-1,-1],[1,-1,-1],[0,1,-1],[0,0,1]],[[0,1,2],[0,3,1],[1,3,2],[2,3,0]]];
assert(vnf_get_vertex(vnf,[0,1,-1]) == [2,vnf]);
assert(vnf_get_vertex(vnf,[0,1,2]) == [4,[concat(vnf[0],[[0,1,2]]),vnf[1]]]);
vnf = [[[-1,-1,-1],[1,-1,-1],[0,1,-1],[0,0,1]],[[0,1,2],[0,3,1],[1,3,2],[2,3,0]]];
assert(vnf_get_vertex(vnf,[0,1,-1]) == [2,vnf]);
assert(vnf_get_vertex(vnf,[0,1,2]) == [4,[concat(vnf[0],[[0,1,2]]),vnf[1]]]);
}
test_vnf_get_vertex();
module test_vnf_add_face() {
verts = [[-1,-1,-1],[1,-1,-1],[0,1,-1],[0,0,1]];
faces = [[0,1,2],[0,3,1],[1,3,2],[2,3,0]];
vnf1 = vnf_add_face(pts=select(verts,faces[0]));
vnf2 = vnf_add_face(vnf1, pts=select(verts,faces[1]));
vnf3 = vnf_add_face(vnf2, pts=select(verts,faces[2]));
vnf4 = vnf_add_face(vnf3, pts=select(verts,faces[3]));
assert(vnf1 == [select(verts,0,2),select(faces,[0])]);
assert(vnf2 == [verts,select(faces,[0:1])]);
assert(vnf3 == [verts,select(faces,[0:2])]);
assert(vnf4 == [verts,faces]);
verts = [[-1,-1,-1],[1,-1,-1],[0,1,-1],[0,0,1]];
faces = [[0,1,2],[0,3,1],[1,3,2],[2,3,0]];
vnf1 = vnf_add_face(pts=select(verts,faces[0]));
vnf2 = vnf_add_face(vnf1, pts=select(verts,faces[1]));
vnf3 = vnf_add_face(vnf2, pts=select(verts,faces[2]));
vnf4 = vnf_add_face(vnf3, pts=select(verts,faces[3]));
assert(vnf1 == [select(verts,0,2),select(faces,[0])]);
assert(vnf2 == [verts,select(faces,[0:1])]);
assert(vnf3 == [verts,select(faces,[0:2])]);
assert(vnf4 == [verts,faces]);
}
test_vnf_add_face();
module test_vnf_add_faces() {
verts = [[-1,-1,-1],[1,-1,-1],[0,1,-1],[0,0,1]];
faces = [[0,1,2],[0,3,1],[1,3,2],[2,3,0]];
assert(vnf_add_faces(faces=[for (face=faces) select(verts,face)]) == [verts,faces]);
verts = [[-1,-1,-1],[1,-1,-1],[0,1,-1],[0,0,1]];
faces = [[0,1,2],[0,3,1],[1,3,2],[2,3,0]];
assert(vnf_add_faces(faces=[for (face=faces) select(verts,face)]) == [verts,faces]);
}
test_vnf_add_faces();
module test_vnf_merge() {
vnf1 = vnf_add_face(pts=[[-1,-1,-1],[1,-1,-1],[0,1,-1]]);
vnf2 = vnf_add_face(pts=[[1,1,1],[-1,1,1],[0,1,-1]]);
assert(vnf_merge([vnf1,vnf2]) == [[[-1,-1,-1],[1,-1,-1],[0,1,-1],[1,1,1],[-1,1,1],[0,1,-1]],[[0,1,2],[3,4,5]]]);
vnf1 = vnf_add_face(pts=[[-1,-1,-1],[1,-1,-1],[0,1,-1]]);
vnf2 = vnf_add_face(pts=[[1,1,1],[-1,1,1],[0,1,-1]]);
assert(vnf_merge([vnf1,vnf2]) == [[[-1,-1,-1],[1,-1,-1],[0,1,-1],[1,1,1],[-1,1,1],[0,1,-1]],[[0,1,2],[3,4,5]]]);
}
test_vnf_merge();
module test_vnf_triangulate() {
vnf = [[[-1,-1,0],[1,-1,0],[1,1,0],[-1,1,0]],[[0,1,2,3]]];
assert(vnf_triangulate(vnf) == [[[-1,-1,0],[1,-1,0],[1,1,0],[-1,1,0]], [[0,1,2],[2,3,0]]]);
vnf = [[[-1,-1,0],[1,-1,0],[1,1,0],[-1,1,0]],[[0,1,2,3]]];
assert(vnf_triangulate(vnf) == [[[-1,-1,0],[1,-1,0],[1,1,0],[-1,1,0]], [[0,1,2],[2,3,0]]]);
}
test_vnf_triangulate();
module test_vnf_vertex_array() {
vnf1 = vnf_vertex_array(
points=[for (h=[0:100:100]) [[100,-50,h],[-100,-50,h],[0,100,h]]],
col_wrap=true, caps=true
);
vnf2 = vnf_vertex_array(
points=[for (h=[0:100:100]) [[100,-50,h],[-100,-50,h],[0,100,h]]],
col_wrap=true, caps=true, style="alt"
);
vnf3 = vnf_vertex_array(
points=[for (h=[0:100:100]) [[100,-50,h],[-100,-50,h],[0,100,h]]],
col_wrap=true, caps=true, style="quincunx"
);
assert(vnf1 == [[[100,-50,0],[-100,-50,0],[0,100,0],[100,-50,100],[-100,-50,100],[0,100,100]],[[0,4,3],[0,1,4],[1,5,4],[1,2,5],[2,3,5],[2,0,3],[2,1,0],[3,4,5]]]);
assert(vnf2 == [[[100,-50,0],[-100,-50,0],[0,100,0],[100,-50,100],[-100,-50,100],[0,100,100]],[[0,1,3],[3,1,4],[1,2,4],[4,2,5],[2,0,5],[5,0,3],[2,1,0],[3,4,5]]]);
assert(vnf3 == [[[100,-50,0],[-100,-50,0],[0,100,0],[100,-50,100],[-100,-50,100],[0,100,100],[0,-50,50],[-50,25,50],[50,25,50]],[[0,6,3],[3,6,4],[4,6,1],[1,6,0],[1,7,4],[4,7,5],[5,7,2],[2,7,1],[2,8,5],[5,8,3],[3,8,0],[0,8,2],[2,1,0],[3,4,5]]]);
vnf1 = vnf_vertex_array(
points=[for (h=[0:100:100]) [[100,-50,h],[-100,-50,h],[0,100,h]]],
col_wrap=true, caps=true
);
vnf2 = vnf_vertex_array(
points=[for (h=[0:100:100]) [[100,-50,h],[-100,-50,h],[0,100,h]]],
col_wrap=true, caps=true, style="alt"
);
vnf3 = vnf_vertex_array(
points=[for (h=[0:100:100]) [[100,-50,h],[-100,-50,h],[0,100,h]]],
col_wrap=true, caps=true, style="quincunx"
);
assert(vnf1 == [[[100,-50,0],[-100,-50,0],[0,100,0],[100,-50,100],[-100,-50,100],[0,100,100]],[[0,4,3],[0,1,4],[1,5,4],[1,2,5],[2,3,5],[2,0,3],[2,1,0],[3,4,5]]]);
assert(vnf2 == [[[100,-50,0],[-100,-50,0],[0,100,0],[100,-50,100],[-100,-50,100],[0,100,100]],[[0,1,3],[3,1,4],[1,2,4],[4,2,5],[2,0,5],[5,0,3],[2,1,0],[3,4,5]]]);
assert(vnf3 == [[[100,-50,0],[-100,-50,0],[0,100,0],[100,-50,100],[-100,-50,100],[0,100,100],[0,-50,50],[-50,25,50],[50,25,50]],[[0,6,3],[3,6,4],[4,6,1],[1,6,0],[1,7,4],[4,7,5],[5,7,2],[2,7,1],[2,8,5],[5,8,3],[3,8,0],[0,8,2],[2,1,0],[3,4,5]]]);
}
test_vnf_vertex_array();
// vim: noexpandtab tabstop=4 shiftwidth=4 softtabstop=4 nowrap
// vim: expandtab tabstop=4 shiftwidth=4 softtabstop=4 nowrap