1
0
mirror of https://github.com/JustinSDK/dotSCAD.git synced 2025-01-17 14:18:13 +01:00
dotSCAD/test/test_golden_spiral_extrude.scad

68 lines
172 KiB
OpenSCAD
Raw Normal View History

2022-06-06 13:11:46 +08:00
use <unittest.scad>
use <shape_circle.scad>
include <golden_spiral_extrude.scad>
2017-07-01 07:44:40 +08:00
2020-01-27 13:45:04 +08:00
module test_golden_spiral_extrude(sections, triangles) {
if(triangles == "SOLID") {
// ==== test_golden_spiral_extrude_solid ====
2021-03-23 17:06:39 +08:00
expected = [[[0, 0, -10], [0, 0, 10], [0, 4, 10], [0, 4, -10]], [[-0.0500815, -0.120907, -9.93122], [0.056353, 0.136048, 9.98684], [1.58082, 3.81643, 9.93122], [1.47438, 3.55947, -9.98684]], [[-0.183996, -0.183996, -9.86074], [0.207717, 0.207717, 9.97153], [3.01242, 3.01242, 9.86074], [2.62071, 2.62071, -9.97153]], [[-0.358464, -0.14848, -9.78859], [0.406012, 0.168176, 9.95408], [4.05398, 1.67921, 9.78859], [3.28951, 1.36256, -9.95408]], [[-0.514215, 0, -9.7148], [0.584352, 0, 9.93451], [4.51422, 0, 9.7148], [3.41565, 0, -9.93451]], [[-0.656515, -0.111605, -9.63941], [0.643795, -0.534101, 9.91285], [4.36285, -1.7425, 9.63941], [3.06254, -1.32, -9.91285]], [[-0.807332, -0.139981, -9.56243], [0.514109, -1.10006, 9.88911], [3.66143, -3.38673, 9.56243], [2.33999, -2.42665, -9.88911]], [[-0.931363, -0.0944707, -9.48391], [0.183672, -1.62919, 9.86331], [2.45807, -4.75963, 9.48391], [1.34304, -3.22492, -9.86331]], [[-1.00091, 0.00280938, -9.40387], [-0.334042, -2.04961, 9.83548], [0.855015, -5.70915, 9.40387], [0.188144, -3.65673, -9.83548]], [[-1, 0.12101, -9.32234], [-1, -2.29542, 9.80563], [-1, -6.12101, 9.32234], [-1, -3.70458, -9.80563]], [[-1.34387, 0.271245, -9.23936], [-1.86518, -2.34953, 9.77379], [-2.60703, -6.0791, 9.23936], [-2.08573, -3.45832, -9.77379]], [[-1.63065, 0.477481, -9.15495], [-2.75003, -2.22495, 9.73997], [-4.19619, -5.71628, 9.15495], [-3.0768, -3.01385, -9.73997]], [[-1.85281, 0.723673, -9.06915], [-3.6169, -1.91647, 9.70421], [-5.70289, -5.03837, 9.06915], [-3.9388, -2.39822, -9.70421]], [[-2.0068, 0.993202, -8.98199], [-4.42697, -1.42697, 9.66652], [-7.06427, -4.06427, 8.98199], [-4.6441, -1.6441, -9.66652]], [[-2.09287, 1.26977, -8.8935], [-5.14199, -0.767589, 9.62693], [-8.22183, -2.82547, 8.8935], [-5.17271, -0.788113, -9.62693]], [[-2.11486, 1.53821, -8.80371], [-5.72606, 0.0424011, 9.58546], [-9.12394, -1.36505, 8.80371], [-5.51273, 0.130765, -9.58546]], [[-2.07967, 1.78524, -8.71266], [-6.14737, 0.976124, 9.54214], [-9.72818, 0.263857, 8.71266], [-5.66048, 1.07297, -9.54214]], [[-1.99674, 2, -8.62037], [-6.37979, 2, 9.49698], [-10.0033, 2, 8.62037], [-5.62021, 2, -9.49698]], [[-1.86607, 2.46943, -8.52688], [-6.4481, 3.02579, 9.45002], [-10.0173, 3.45916, 8.52688], [-5.43524, 2.9028, -9.45002]], [[-1.68377, 2.90797, -8.43223], [-6.38824, 4.06751, 9.40128], [-9.85129, 4.92108, 8.43223], [-5.14683, 3.76154, -9.40128]], [[-1.45527, 3.31041, -8.33643], [-6.19742, 5.10887, 9.35078], [-9.50499, 6.36327, 8.33643], [-4.76284, 4.56481, -9.35078]], [[-1.18645, 3.67238, -8.23954], [-5.875, 6.13312, 9.29855], [-8.98084, 7.76319, 8.23954], [-4.2923, 5.30245, -9.29855]], [[-0.883544, 3.99037, -8.14158], [-5.42249, 7.12337, 9.24462], [-8.2842, 9.09867, 8.14158], [-3.74526, 5.96566, -9.24462]], [[-0.552981, 4.26174, -8.04258], [-4.84358, 8.06289, 9.18901], [-7.42319, 10.3482, 8.04258], [-3.13259, 6.54708, -9.18901]], [[-0.201311, 4.48477, -7.94257], [-4.14418, 8.93534, 9.13175], [-6.40865, 11.4914, 7.94257], [-2.46578, 7.04083, -9.13175]], [[0.16494, 4.65854, -7.8416], [-3.33227, 9.72513, 9.07287], [-5.25398, 12.5092, 7.8416], [-1.75676, 7.44261, -9.07287]], [[0.539359, 4.78302, -7.73969], [-2.41791, 10.4176, 9.01239], [-3.97493, 13.3843, 7.73969], [-1.01766, 7.74966, -9.01239]], [[0.915757, 4.85891, -7.63687], [-1.41305, 10.9995, 8.95034], [-2.58944, 14.1013, 7.63687], [-0.260624, 7.96078, -8.95034]], [[1.28825, 4.88768, -7.53319], [-0.331392, 11.4588, 8.88675], [-1.1173, 14.6474, 7.53319], [0.502341, 8.07624, -8.88675]], [[1.65134, 4.87143, -7.42867], [0.81182, 11.7855, 8.82165], [0.420068, 15.0119, 7.42867], [1.25959, 8.0978, -8.82165]], [[2, 4.81288, -7.32334], [2, 11.9714, 8.75506], [2, 15.1871, 7.32334], [2, 8.02856, -8.75506]], [[2.57805, 4.71354, -7.21725], [3.12723, 12.0418, 8.68701], [3.36493, 15.2138, 7.21725], [2.81576, 7.8855, -8.68701]], [[3.14158, 4.57387, -7.11042], [4.2647, 12.0253, 8.61754], [4.73352, 15.1357, 7.11042], [3.6104, 7.68433, -8.61754]], [[3.68796, 4.39542, -7.00289], [5.40557, 11.9208, 8.54666], [6.09759, 14.9527, 7.00289], [4.37998, 7.42736, -8.54666]], [[4.21472, 4.1
2020-01-27 13:45:04 +08:00
2017-07-01 07:44:40 +08:00
for(i = [0:len(expected) - 1]) {
2019-06-12 07:36:15 +08:00
assertEqualPoints(expected[i], sections[i]);
2017-07-01 07:44:40 +08:00
}
2020-01-27 13:45:04 +08:00
}
else {
// ==== test_golden_spiral_extrude_solid ====
2021-03-23 17:06:39 +08:00
expected = [[[8, 0, 0], [7.59808, 0, 1.5], [6.5, 0, 2.59808], [5, 0, 3], [3.5, 0, 2.59808], [2.40192, 0, 1.5], [2, 0, 0], [2.40192, 0, -1.5], [3.5, 0, -2.59808], [5, 0, -3], [6.5, 0, -2.59808], [7.59808, 0, -1.5], [7, 0, 0], [6.73205, 0, 1], [6, 0, 1.73205], [5, 0, 2], [4, 0, 1.73205], [3.26795, 0, 1], [3, 0, 0], [3.26795, 0, -1], [4, 0, -1.73205], [5, 0, -2], [6, 0, -1.73205], [6.73205, 0, -1]], [[7.96888, 1.58511, 0], [7.55825, 1.50343, 1.5625], [6.4364, 1.28028, 2.70633], [4.90393, 0.975452, 3.125], [3.37145, 0.670623, 2.70633], [2.2496, 0.447473, 1.5625], [1.83897, 0.365794, 0], [2.2496, 0.447473, -1.5625], [3.37145, 0.670623, -2.70633], [4.90393, 0.975452, -3.125], [6.4364, 1.28028, -2.70633], [7.55825, 1.50343, -1.5625], [6.94723, 1.38189, 0], [6.67348, 1.32744, 1.04167], [5.92558, 1.17867, 1.80422], [4.90393, 0.975452, 2.08333], [3.88228, 0.772233, 1.80422], [3.13437, 0.623466, 1.04167], [2.86062, 0.569013, 0], [3.13437, 0.623466, -1.04167], [3.88228, 0.772233, -1.80422], [4.90393, 0.975452, -2.08333], [5.92558, 1.17867, -1.80422], [6.67348, 1.32744, -1.04167]], [[7.62201, 3.15714, 0], [7.21973, 2.99051, 1.625], [6.1207, 2.53528, 2.81458], [4.6194, 1.91342, 3.25], [3.11809, 1.29156, 2.81458], [2.01906, 0.836323, 1.625], [1.61679, 0.669696, 0], [2.01906, 0.836323, -1.625], [3.11809, 1.29156, -2.81458], [4.6194, 1.91342, -3.25], [6.1207, 2.53528, -2.81458], [7.21973, 2.99051, -1.625], [6.62114, 2.74256, 0], [6.35295, 2.63148, 1.08333], [5.62027, 2.32799, 1.87639], [4.6194, 1.91342, 2.16667], [3.61853, 1.49884, 1.87639], [2.88584, 1.19535, 1.08333], [2.61766, 1.08427, 0], [2.88584, 1.19535, -1.08333], [3.61853, 1.49884, -1.87639], [4.6194, 1.91342, -2.16667], [5.62027, 2.32799, -1.87639], [6.35295, 2.63148, -1.08333]], [[6.96356, 4.6529, 0], [6.5876, 4.40169, 1.6875], [5.56045, 3.71538, 2.92284], [4.15735, 2.77785, 3.375], [2.75424, 1.84033, 2.92284], [1.7271, 1.15401, 1.6875], [1.35114, 0.902802, 0], [1.7271, 1.15401, -1.6875], [2.75424, 1.84033, -2.92284], [4.15735, 2.77785, -3.375], [5.56045, 3.71538, -2.92284], [6.5876, 4.40169, -1.6875], [6.02815, 4.02788, 0], [5.77751, 3.86041, 1.125], [5.09275, 3.40287, 1.94856], [4.15735, 2.77785, 2.25], [3.22194, 2.15283, 1.94856], [2.53718, 1.69529, 1.125], [2.28654, 1.52782, 0], [2.53718, 1.69529, -1.125], [3.22194, 2.15283, -1.94856], [4.15735, 2.77785, -2.25], [5.09275, 3.40287, -1.94856], [5.77751, 3.86041, -1.125]], [[6.01041, 6.01041, 0], [5.67884, 5.67884, 1.75], [4.77297, 4.77297, 3.03109], [3.53553, 3.53553, 3.5], [2.2981, 2.2981, 3.03109], [1.39223, 1.39223, 1.75], [1.06066, 1.06066, 0], [1.39223, 1.39223, -1.75], [2.2981, 2.2981, -3.03109], [3.53553, 3.53553, -3.5], [4.77297, 4.77297, -3.03109], [5.67884, 5.67884, -1.75], [5.18545, 5.18545, 0], [4.9644, 4.9644, 1.16667], [4.36049, 4.36049, 2.02073], [3.53553, 3.53553, 2.33333], [2.71058, 2.71058, 2.02073], [2.10666, 2.10666, 1.16667], [1.88562, 1.88562, 0], [2.10666, 2.10666, -1.16667], [2.71058, 2.71058, -2.02073], [3.53553, 3.53553, -2.33333], [4.36049, 4.36049, -2.02073], [4.9644, 4.9644, -1.16667]], [[4.79179, 7.17143, 0], [4.52198, 6.76762, 1.8125], [3.78482, 5.66439, 3.13934], [2.77785, 4.15735, 3.625], [1.77088, 2.65031, 3.13934], [1.03373, 1.54708, 1.8125], [0.763909, 1.14327, 0], [1.03373, 1.54708, -1.8125], [1.77088, 2.65031, -3.13934], [2.77785, 4.15735, -3.625], [3.78482, 5.66439, -3.13934], [4.52198, 6.76762, -1.8125], [4.12048, 6.16673, 0], [3.9406, 5.89753, 1.20833], [3.44917, 5.16204, 2.09289], [2.77785, 4.15735, 2.41667], [2.10654, 3.15266, 2.09289], [1.6151, 2.41717, 1.20833], [1.43522, 2.14796, 0], [1.6151, 2.41717, -1.20833], [2.10654, 3.15266, -2.09289], [2.77785, 4.15735, -2.41667], [3.44917, 5.16204, -2.09289], [3.9406, 5.89753, -1.20833]], [[3.34848, 8.08395, 0], [3.15622, 7.61978, 1.875], [2.63095, 6.35167, 3.2476], [1.91342, 4.6194, 3.75], [1.19589, 2.88712, 3.2476], [0.670616, 1.61901, 1.875], [0.478354, 1.15485, 0], [0.670616, 1.61901, -1.875], [1.19589, 2.88712, -3.2476], [1.91342, 4.6194, -3.75], [2.63095, 6.35167, -3.2476], [3.15622, 7.61978, -1.875], [2.87013, 6.9291, 0],
2020-01-27 13:45:04 +08:00
for(i = [0:len(expected) - 1]) {
assertEqualPoints(expected[i], sections[i]);
}
}
}
2017-07-01 07:44:40 +08:00
2020-01-27 13:45:04 +08:00
module test_golden_spiral_extrude_solid() {
echo("==== test_golden_spiral_extrude_solid ====");
2017-07-01 07:44:40 +08:00
shape_pts = [
[2, -10],
[2, 10],
[-2, 10],
[-2, -10]
];
golden_spiral_extrude(
shape_pts,
from = 3,
to = 10,
point_distance = 1,
rt_dir = "CLK",
twist = 180,
scale = 0.1
);
}
module test_golden_spiral_extrude_hollow() {
echo("==== test_golden_spiral_extrude_hollow ====");
$fn = 12;
shape_pts = concat(
2020-03-17 14:23:18 +08:00
shape_circle(radius = 3),
shape_circle(radius = 2)
2017-07-01 07:44:40 +08:00
);
golden_spiral_extrude(
shape_pts,
from = 5,
to = 10,
point_distance = 1,
scale = 10,
triangles = "HOLLOW"
);
}
test_golden_spiral_extrude_solid();
test_golden_spiral_extrude_hollow();