Merge pull request #273 from revarbat/revarbat_dev

hull, quaternion, and edges regressions.
This commit is contained in:
Revar Desmera 2020-09-22 20:39:43 -07:00 committed by GitHub
commit c50dddc3eb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 226 additions and 3 deletions

View file

@ -160,6 +160,25 @@ module test_is_nan() {
test_is_nan();
module test_is_finite() {
assert(!is_finite(undef));
assert(!is_finite(true));
assert(!is_finite(false));
assert(is_finite(-5));
assert(is_finite(0));
assert(is_finite(5));
assert(!is_finite(INF));
assert(!is_finite(-INF));
assert(!is_finite(""));
assert(!is_finite("foo"));
assert(!is_finite([]));
assert(!is_finite([3,4,5]));
assert(!is_finite([3:1:5]));
assert(!is_finite(NAN));
}
test_is_finite();
module test_is_range() {
assert(!is_range(undef));
assert(!is_range(true));

View file

@ -100,5 +100,111 @@ module test_corner_edge_count() {
test_corner_edge_count();
module test_corner_edges() {
edges = edges([TOP,FRONT+RIGHT]);
assert_equal(corner_edges(edges,TOP+FRONT+RIGHT), [1,1,1]);
assert_equal(corner_edges(edges,TOP+FRONT+LEFT), [1,1,0]);
assert_equal(corner_edges(edges,BOTTOM+FRONT+RIGHT), [0,0,1]);
assert_equal(corner_edges(edges,BOTTOM+FRONT+LEFT), [0,0,0]);
}
test_corner_edges();
module test_corners() {
assert_equal(corners(BOT + FRONT + LEFT ), [1,0,0,0,0,0,0,0]);
assert_equal(corners(BOT + FRONT + RIGHT), [0,1,0,0,0,0,0,0]);
assert_equal(corners(BOT + BACK + LEFT ), [0,0,1,0,0,0,0,0]);
assert_equal(corners(BOT + BACK + RIGHT), [0,0,0,1,0,0,0,0]);
assert_equal(corners(TOP + FRONT + LEFT ), [0,0,0,0,1,0,0,0]);
assert_equal(corners(TOP + FRONT + RIGHT), [0,0,0,0,0,1,0,0]);
assert_equal(corners(TOP + BACK + LEFT ), [0,0,0,0,0,0,1,0]);
assert_equal(corners(TOP + BACK + RIGHT), [0,0,0,0,0,0,0,1]);
assert_equal(corners(BOT + FRONT), [1,1,0,0,0,0,0,0]);
assert_equal(corners(BOT + BACK ), [0,0,1,1,0,0,0,0]);
assert_equal(corners(TOP + FRONT), [0,0,0,0,1,1,0,0]);
assert_equal(corners(TOP + BACK ), [0,0,0,0,0,0,1,1]);
assert_equal(corners(BOT + LEFT ), [1,0,1,0,0,0,0,0]);
assert_equal(corners(BOT + RIGHT), [0,1,0,1,0,0,0,0]);
assert_equal(corners(TOP + LEFT ), [0,0,0,0,1,0,1,0]);
assert_equal(corners(TOP + RIGHT), [0,0,0,0,0,1,0,1]);
assert_equal(corners(FRONT + LEFT ), [1,0,0,0,1,0,0,0]);
assert_equal(corners(FRONT + RIGHT), [0,1,0,0,0,1,0,0]);
assert_equal(corners(BACK + LEFT ), [0,0,1,0,0,0,1,0]);
assert_equal(corners(BACK + RIGHT), [0,0,0,1,0,0,0,1]);
assert_equal(corners(LEFT), [1,0,1,0,1,0,1,0]);
assert_equal(corners(RIGHT), [0,1,0,1,0,1,0,1]);
assert_equal(corners(FRONT), [1,1,0,0,1,1,0,0]);
assert_equal(corners(BACK), [0,0,1,1,0,0,1,1]);
assert_equal(corners(BOT), [1,1,1,1,0,0,0,0]);
assert_equal(corners(TOP), [0,0,0,0,1,1,1,1]);
assert_equal(corners([BOT + FRONT + LEFT ]), [1,0,0,0,0,0,0,0]);
assert_equal(corners([BOT + FRONT + RIGHT]), [0,1,0,0,0,0,0,0]);
assert_equal(corners([BOT + BACK + LEFT ]), [0,0,1,0,0,0,0,0]);
assert_equal(corners([BOT + BACK + RIGHT]), [0,0,0,1,0,0,0,0]);
assert_equal(corners([TOP + FRONT + LEFT ]), [0,0,0,0,1,0,0,0]);
assert_equal(corners([TOP + FRONT + RIGHT]), [0,0,0,0,0,1,0,0]);
assert_equal(corners([TOP + BACK + LEFT ]), [0,0,0,0,0,0,1,0]);
assert_equal(corners([TOP + BACK + RIGHT]), [0,0,0,0,0,0,0,1]);
assert_equal(corners([BOT + FRONT]), [1,1,0,0,0,0,0,0]);
assert_equal(corners([BOT + BACK ]), [0,0,1,1,0,0,0,0]);
assert_equal(corners([TOP + FRONT]), [0,0,0,0,1,1,0,0]);
assert_equal(corners([TOP + BACK ]), [0,0,0,0,0,0,1,1]);
assert_equal(corners([BOT + LEFT ]), [1,0,1,0,0,0,0,0]);
assert_equal(corners([BOT + RIGHT]), [0,1,0,1,0,0,0,0]);
assert_equal(corners([TOP + LEFT ]), [0,0,0,0,1,0,1,0]);
assert_equal(corners([TOP + RIGHT]), [0,0,0,0,0,1,0,1]);
assert_equal(corners([FRONT + LEFT ]), [1,0,0,0,1,0,0,0]);
assert_equal(corners([FRONT + RIGHT]), [0,1,0,0,0,1,0,0]);
assert_equal(corners([BACK + LEFT ]), [0,0,1,0,0,0,1,0]);
assert_equal(corners([BACK + RIGHT]), [0,0,0,1,0,0,0,1]);
assert_equal(corners([LEFT]), [1,0,1,0,1,0,1,0]);
assert_equal(corners([RIGHT]), [0,1,0,1,0,1,0,1]);
assert_equal(corners([FRONT]), [1,1,0,0,1,1,0,0]);
assert_equal(corners([BACK]), [0,0,1,1,0,0,1,1]);
assert_equal(corners([BOT]), [1,1,1,1,0,0,0,0]);
assert_equal(corners([TOP]), [0,0,0,0,1,1,1,1]);
assert_equal(corners([TOP,FRONT+RIGHT]), [0,1,0,0,1,1,1,1]);
}
test_corners();
module test_is_corner_array() {
edges = edges([TOP,FRONT+RIGHT]);
corners = corners([TOP,FRONT+RIGHT]);
assert(!is_corner_array(undef));
assert(!is_corner_array(true));
assert(!is_corner_array(false));
assert(!is_corner_array(INF));
assert(!is_corner_array(-INF));
assert(!is_corner_array(NAN));
assert(!is_corner_array(-4));
assert(!is_corner_array(0));
assert(!is_corner_array(4));
assert(!is_corner_array("foo"));
assert(!is_corner_array([]));
assert(!is_corner_array([4,5,6]));
assert(!is_corner_array([2:3:9]));
assert(!is_corner_array(edges));
assert(is_corner_array(corners));
}
test_is_corner_array();
module test_normalize_corners() {
assert_equal(normalize_corners([-2,-2,-2,-2,-2,-2,-2,-2]), [0,0,0,0,0,0,0,0]);
assert_equal(normalize_corners([-1,-1,-1,-1,-1,-1,-1,-1]), [0,0,0,0,0,0,0,0]);
assert_equal(normalize_corners([0,0,0,0,0,0,0,0]), [0,0,0,0,0,0,0,0]);
assert_equal(normalize_corners([1,1,1,1,1,1,1,1]), [1,1,1,1,1,1,1,1]);
assert_equal(normalize_corners([2,2,2,2,2,2,2,2]), [1,1,1,1,1,1,1,1]);
}
test_normalize_corners();
// vim: expandtab tabstop=4 shiftwidth=4 softtabstop=4 nowrap

View file

@ -660,6 +660,20 @@ module test_tri_functions() {
*test_tri_functions();
module test_hyp_opp_to_adj() nil(); // Covered in test_tri_functions()
module test_hyp_ang_to_adj() nil(); // Covered in test_tri_functions()
module test_opp_ang_to_adj() nil(); // Covered in test_tri_functions()
module test_hyp_adj_to_opp() nil(); // Covered in test_tri_functions()
module test_hyp_ang_to_opp() nil(); // Covered in test_tri_functions()
module test_adj_ang_to_opp() nil(); // Covered in test_tri_functions()
module test_adj_opp_to_hyp() nil(); // Covered in test_tri_functions()
module test_adj_ang_to_hyp() nil(); // Covered in test_tri_functions()
module test_opp_ang_to_hyp() nil(); // Covered in test_tri_functions()
module test_hyp_adj_to_ang() nil(); // Covered in test_tri_functions()
module test_hyp_opp_to_ang() nil(); // Covered in test_tri_functions()
module test_adj_opp_to_ang() nil(); // Covered in test_tri_functions()
module test_triangle_area() {
assert(abs(triangle_area([0,0], [0,10], [10,0]) + 50) < EPSILON);
assert(abs(triangle_area([0,0], [0,10], [0,15])) < EPSILON);

View file

@ -98,3 +98,87 @@ module test_hull() {
*/
}
test_hull();
module test_hull2d_path() {
assert_equal(hull([[3,4],[5,5]]), [0,1]);
assert_equal(hull([[3,4,1],[5,5,3]]), [0,1]);
test_collinear_2d = let(u = unit([5,3])) [ for(i = [9,2,3,4,5,7,12,15,13]) i * u ];
assert_equal(hull(test_collinear_2d), [7,1]);
test_collinear_3d = let(u = unit([5,3,2])) [ for(i = [9,2,3,4,5,7,12,15,13]) i * u ];
assert_equal(hull(test_collinear_3d), [7,1]);
rand10_2d = [[1.55356, -1.98965], [4.23157, -0.947788], [-4.06193, -1.55463],
[1.23889, -3.73133], [-1.02637, -4.0155], [4.26806, -4.61909],
[3.59556, -3.1574], [-2.77776, -4.21857], [-3.66253,-4.34458], [1.82324, 0.102025]];
assert_equal(sort(hull(rand10_2d)), [1,2,5,8,9]);
rand75_2d = [[-3.14743, -3.28139], [0.15343, -0.370249], [0.082565, 3.95939], [-2.56925, -3.16262], [-1.59463, 4.20893],
[-4.90744, -1.21374], [-1.0819, -1.93703], [-3.72723, -3.0744], [-3.34339, 1.53535], [3.15803, -0.307388], [4.23289,
4.46259], [1.73624, 1.38918], [3.72087, -1.55028], [1.2604, 2.30502], [-0.966431, 1.673], [-3.26866, -0.531443], [1.52605,
0.991804], [-1.26305, 1.0737], [-4.31943, 4.11932], [0.488101, 0.0425981], [1.0233, -0.723037], [-4.73406, 2.14568],
[-4.75915, 3.83262], [4.90999, -2.76668], [1.91971, -3.8604], [4.38594, -0.761767], [-0.352984, 1.55291], [2.02714,
-0.340099], [1.76052, 2.09196], [-1.27485, -4.39477], [4.36364, 3.84964], [0.593612, -4.00028], [3.06833, -3.67117],
[4.26834, -4.21213], [4.60226, -0.120432], [-2.45646, 2.60327], [-4.79461, 3.83724], [-3.29755, 0.760159], [0.218423,
4.1687], [-0.115829, -2.06242], [-3.96188, 3.21568], [4.3018, -2.5299], [-4.41694, 4.75173], [-3.8393, 2.82212], [-1.14268,
1.80751], [2.05805, 1.68593], [-3.0159, -2.91139], [-1.44828, -1.93564], [-0.265887, 0.519893], [-0.457361, -0.610096],
[-0.426359, -2.37315], [-3.1018, 2.31141], [0.179141, -3.56242], [-0.491786, 0.813055], [-3.28502, -1.18933], [0.0914813,
2.16122], [4.5777, 4.83972], [-1.07096, 2.74992], [-0.698689, 3.9032], [-1.21809, -1.54434], [3.14457, 4.92302], [-4.63176,
2.81952], [4.84414, 4.63699], [2.4259, -0.747268], [-1.52088, -4.58305], [1.6961, -3.73678], [-0.483003, -3.67283],
[-3.72746, -0.284265], [2.07629, 1.99902], [-3.12698, -0.96353], [4.02254, 3.41521], [-0.963391, -3.2143], [0.315255,
0.593049], [1.57006, 1.80436], [4.60957, -2.86325]];
assert_equal(sort(hull(rand75_2d)),[5,7,23,33,36,42,56,60,62,64]);
rand10_2d_rot = rot([22,44,12], p=path3d(rand10_2d));
assert_equal(sort(hull(rand10_2d_rot)), [1,2,5,8,9]);
rand75_2d_rot = rot([122,-44,32], p=path3d(rand75_2d));
assert_equal(sort(hull(rand75_2d_rot)), [5,7,23,33,36,42,56,60,62,64]);
}
test_hull2d_path();
module test_hull3d_faces() {
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)
];
assert_equal(hull(testpoints_on_sphere), [[8, 4, 0], [0, 4, 1], [4, 8, 5], [8, 2, 5], [2, 3, 5], [0, 1, 6], [3, 2, 7], [1, 4, 9], [4, 5, 9],
[5, 3, 9], [8, 0, 10], [2, 8, 10], [0, 6, 10], [6, 7, 10], [7, 2, 10], [6, 1, 11], [3, 7, 11], [7, 6, 11], [1, 9, 11], [9, 3, 11]]);
rand10_3d = [[14.0893, -15.2751, 21.0843], [-14.1564, 17.5751, 3.32094], [17.4966, 12.1717, 18.0607], [24.5489, 9.64591, 10.4738], [-12.0233, -24.4368, 13.1614],
[6.24019, -18.4135, 24.9554], [11.9438, -15.9724, -22.6454], [11.6147, 7.56059, 7.5667], [-19.7491, 9.42769, 15.3419], [-10.3726, 16.3559, 3.38503]];
assert_equal(hull(rand10_3d),[[3, 6, 0], [1, 3, 2], [3, 0, 2], [6, 1, 4], [0, 6, 5], [6, 4, 5], [2, 0, 5], [1, 2, 8], [2, 5, 8], [4, 1, 8], [5, 4, 8], [6, 3, 9], [3, 1, 9], [1, 6, 9]]);
rand25_3d = [[-20.5261, 14.5058, -11.6349], [16.4625, 20.1316, 12.9816], [-14.0268, 5.58802, 17.686], [-5.47944, 16.2501,
5.3086], [20.2168, -11.8466, 12.4598], [14.4633, -15.1479, 4.82151], [12.7897, 5.25704, 19.6205], [11.2456,
18.2794, -3.47074], [-1.87665, 22.9852, 1.99367], [-15.6052, -2.11009, 14.0096], [-10.7389, -14.569,
5.6121], [24.5965, 17.9039, 20.8313], [-13.7054, 13.3362, 1.50374], [10.1111, -23.1494, 19.9305], [14.154,
19.6682, -0.170182], [-22.6438, 22.7429, -0.776773], [-9.75056, 17.8896, -8.04152], [23.1746, 20.5475,
22.6957], [-10.5356, -4.32407, -7.0911], [2.20779, -8.30749, 6.87185], [23.2643, 2.64462, -19.0087],
[24.4055, 24.4504, 23.4777], [-3.84086, -6.98473, -10.2889], [0.178043, -16.07, 16.8081], [-8.86482,
-12.8256, 14.7418], [11.1759, -11.5614, -11.643], [7.16751, 13.9344, -19.1675], [2.26602, -10.5374,
0.125718], [-13.9053, 11.1143, -21.9289], [24.9018, -23.5307, -21.4684], [-13.6609, -19.6495, -8.91583],
[-16.5393, -22.4105, -6.91617], [-4.11378, -3.14362, -5.6881], [7.50883, -17.5284, -0.0615319], [-7.41739,
0.0721313, -7.47111], [22.6975, -7.99655, 14.0555], [-13.3644, 9.26993, 20.858], [-13.6889, 16.7462,
-14.5836], [16.5137, 3.90703, -5.49396], [-6.75614, -11.1444, -24.5309], [22.9868, 10.0028, 12.2866],
[-4.81079, -0.967785, -10.4726], [-0.949023, 23.1441, -2.08208], [16.1256, -8.2295, -24.0113], [6.45274,
-7.21416, 23.1409], [22.8274, 1.07038, 19.1756], [-10.6256, -10.0112, -6.12274], [6.29254, -7.81875,
-24.4037], [22.8538, 8.78163, -6.82567], [-1.96142, 19.1728, -1.726]];
assert_equal(hull(rand25_3d),[[21, 29, 11], [29, 21, 20], [21, 14, 20], [20, 14, 26], [15, 0, 28], [13, 29, 31], [0, 15,
31], [15, 9, 31], [9, 24, 31], [24, 13, 31], [28, 0, 31], [11, 29, 35], [29, 13, 35], [15,
21, 36], [9, 15, 36], [24, 9, 36], [13, 24, 36], [15, 28, 37], [28, 26, 37], [28, 31, 39],
[31, 29, 39], [14, 21, 42], [21, 15, 42], [26, 14, 42], [15, 37, 42], [37, 26, 42], [29, 20,
43], [39, 29, 43], [20, 26, 43], [26, 28, 43], [21, 13, 44], [13, 36, 44], [36, 21, 44],
[21, 11, 45], [11, 35, 45], [13, 21, 45], [35, 13, 45], [28, 39, 47], [39, 43, 47], [43, 28, 47]]);
}
test_hull3d_faces();
// vim: expandtab tabstop=4 shiftwidth=4 softtabstop=4 nowrap

View file

@ -23,13 +23,13 @@ module verify_f(actual,expected) {
}
module test_is_quat() {
module test_Q_is_quat() {
verify_f(Q_is_quat([0]),false);
verify_f(Q_is_quat([0,0,0,0]),false);
verify_f(Q_is_quat([1,0,2,0]),true);
verify_f(Q_is_quat([1,0,2,0,0]),false);
}
test_is_quat();
test_Q_is_quat();
module test_Quat() {

View file

@ -8,7 +8,7 @@
//////////////////////////////////////////////////////////////////////
BOSL_VERSION = [2,0,425];
BOSL_VERSION = [2,0,426];
// Section: BOSL Library Version Functions