mirror of
https://github.com/JustinSDK/dotSCAD.git
synced 2025-01-16 13:50:05 +01:00
35 lines
5.7 KiB
OpenSCAD
35 lines
5.7 KiB
OpenSCAD
use <unittest.scad>
|
|
use <bspline_curve.scad>
|
|
|
|
module test_bspline_curve() {
|
|
echo("==== test_bspline_curve ====");
|
|
|
|
points = [
|
|
[-10, 0],
|
|
[-5, 5],
|
|
[ 5, -5],
|
|
[ 10, 0]
|
|
];
|
|
|
|
expected = [[-7.5, 2.5], [-7.399, 2.597], [-7.296, 2.688], [-7.191, 2.773], [-7.084, 2.852], [-6.975, 2.925], [-6.864, 2.992], [-6.751, 3.053], [-6.636, 3.108], [-6.519, 3.157], [-6.4, 3.2], [-6.279, 3.237], [-6.156, 3.268], [-6.031, 3.293], [-5.904, 3.312], [-5.775, 3.325], [-5.644, 3.332], [-5.511, 3.333], [-5.376, 3.328], [-5.239, 3.317], [-5.1, 3.3], [-4.959, 3.277], [-4.816, 3.248], [-4.671, 3.213], [-4.524, 3.172], [-4.375, 3.125], [-4.224, 3.072], [-4.071, 3.013], [-3.916, 2.948], [-3.759, 2.877], [-3.6, 2.8], [-3.439, 2.717], [-3.276, 2.628], [-3.111, 2.533], [-2.944, 2.432], [-2.775, 2.325], [-2.604, 2.212], [-2.431, 2.093], [-2.256, 1.968], [-2.079, 1.837], [-1.9, 1.7], [-1.719, 1.557], [-1.536, 1.408], [-1.351, 1.253], [-1.164, 1.092], [-0.975, 0.925], [-0.784, 0.752], [-0.591, 0.573], [-0.396, 0.388], [-0.199, 0.197], [3.9968e-15, -3.9968e-15], [0.199, -0.197], [0.396, -0.388], [0.591, -0.573], [0.784, -0.752], [0.975, -0.925], [1.164, -1.092], [1.351, -1.253], [1.536, -1.408], [1.719, -1.557], [1.9, -1.7], [2.079, -1.837], [2.256, -1.968], [2.431, -2.093], [2.604, -2.212], [2.775, -2.325], [2.944, -2.432], [3.111, -2.533], [3.276, -2.628], [3.439, -2.717], [3.6, -2.8], [3.759, -2.877], [3.916, -2.948], [4.071, -3.013], [4.224, -3.072], [4.375, -3.125], [4.524, -3.172], [4.671, -3.213], [4.816, -3.248], [4.959, -3.277], [5.1, -3.3], [5.239, -3.317], [5.376, -3.328], [5.511, -3.333], [5.644, -3.332], [5.775, -3.325], [5.904, -3.312], [6.031, -3.293], [6.156, -3.268], [6.279, -3.237], [6.4, -3.2], [6.519, -3.157], [6.636, -3.108], [6.751, -3.053], [6.864, -2.992], [6.975, -2.925], [7.084, -2.852], [7.191, -2.773], [7.296, -2.688], [7.399, -2.597]];
|
|
actual = bspline_curve(0.01, 2, points);
|
|
|
|
assertEqualPoints(expected, actual, 0.0005);
|
|
|
|
// a non-uniform B-spline curve
|
|
knots = [0, 1/8, 1/4, 1/2, 3/4, 4/5, 1];
|
|
|
|
expected2 = [[-8.33333, 1.66667], [-8.19933, 1.79667], [-8.064, 1.92], [-7.92733, 2.03667], [-7.78933, 2.14667], [-7.65, 2.25], [-7.50933, 2.34667], [-7.36733, 2.43667], [-7.224, 2.52], [-7.07933, 2.59667], [-6.93333, 2.66667], [-6.786, 2.73], [-6.63733, 2.78667], [-6.48733, 2.83667], [-6.336, 2.88], [-6.18333, 2.91667], [-6.02933, 2.94667], [-5.874, 2.97], [-5.71733, 2.98667], [-5.55933, 2.99667], [-5.4, 3], [-5.23933, 2.99667], [-5.07733, 2.98667], [-4.914, 2.97], [-4.74933, 2.94667], [-4.58333, 2.91667], [-4.416, 2.88], [-4.24733, 2.83667], [-4.07733, 2.78667], [-3.906, 2.73], [-3.73333, 2.66667], [-3.55933, 2.59667], [-3.384, 2.52], [-3.20733, 2.43667], [-3.02933, 2.34667], [-2.85, 2.25], [-2.66933, 2.14667], [-2.48733, 2.03667], [-2.304, 1.92], [-2.11933, 1.79667], [-1.93333, 1.66667], [-1.746, 1.53], [-1.55733, 1.38667], [-1.36733, 1.23667], [-1.176, 1.08], [-0.983333, 0.916667], [-0.789333, 0.746667], [-0.594, 0.57], [-0.397333, 0.386667], [-0.199333, 0.196667], [3.9968e-15, -3.9968e-15], [0.199667, -0.196333], [0.398667, -0.385333], [0.597, -0.567], [0.794667, -0.741333], [0.991667, -0.908333], [1.188, -1.068], [1.38367, -1.22033], [1.57867, -1.36533], [1.773, -1.503], [1.96667, -1.63333], [2.15967, -1.75633], [2.352, -1.872], [2.54367, -1.98033], [2.73467, -2.08133], [2.925, -2.175], [3.11467, -2.26133], [3.30367, -2.34033], [3.492, -2.412], [3.67967, -2.47633], [3.86667, -2.53333], [4.053, -2.583], [4.23867, -2.62533], [4.42367, -2.66033], [4.608, -2.688], [4.79167, -2.70833], [4.97467, -2.72133], [5.157, -2.727], [5.33867, -2.72533], [5.51967, -2.71633], [5.7, -2.7], [5.87967, -2.67633], [6.05867, -2.64533], [6.237, -2.607], [6.41467, -2.56133], [6.59167, -2.50833], [6.768, -2.448], [6.94367, -2.38033], [7.11867, -2.30533], [7.293, -2.223], [7.46667, -2.13333], [7.63967, -2.03633], [7.812, -1.932], [7.98367, -1.82033], [8.15467, -1.70133], [8.325, -1.575], [8.49467, -1.44133], [8.66367, -1.30033], [8.832, -1.152], [8.99967, -0.996333]];
|
|
actual2 = bspline_curve(0.01, 2, points, knots);
|
|
|
|
assertEqualPoints(expected2, actual2, 0.0005);
|
|
|
|
knots3 = [0, 0, 0, 1, 2, 2, 2];
|
|
|
|
expected3 = [[-10, 0], [-9.8, 0.196], [-9.6, 0.384], [-9.4, 0.564], [-9.2, 0.736], [-9, 0.9], [-8.8, 1.056], [-8.6, 1.204], [-8.4, 1.344], [-8.2, 1.476], [-8, 1.6], [-7.8, 1.716], [-7.6, 1.824], [-7.4, 1.924], [-7.2, 2.016], [-7, 2.1], [-6.8, 2.176], [-6.6, 2.244], [-6.4, 2.304], [-6.2, 2.356], [-6, 2.4], [-5.8, 2.436], [-5.6, 2.464], [-5.4, 2.484], [-5.2, 2.496], [-5, 2.5], [-4.8, 2.496], [-4.6, 2.484], [-4.4, 2.464], [-4.2, 2.436], [-4, 2.4], [-3.8, 2.356], [-3.6, 2.304], [-3.4, 2.244], [-3.2, 2.176], [-3, 2.1], [-2.8, 2.016], [-2.6, 1.924], [-2.4, 1.824], [-2.2, 1.716], [-2, 1.6], [-1.8, 1.476], [-1.6, 1.344], [-1.4, 1.204], [-1.2, 1.056], [-1, 0.9], [-0.8, 0.736], [-0.6, 0.564], [-0.4, 0.384], [-0.2, 0.196], [3.9968e-15, -3.9968e-15], [0.2, -0.196], [0.4, -0.384], [0.6, -0.564], [0.8, -0.736], [1, -0.9], [1.2, -1.056], [1.4, -1.204], [1.6, -1.344], [1.8, -1.476], [2, -1.6], [2.2, -1.716], [2.4, -1.824], [2.6, -1.924], [2.8, -2.016], [3, -2.1], [3.2, -2.176], [3.4, -2.244], [3.6, -2.304], [3.8, -2.356], [4, -2.4], [4.2, -2.436], [4.4, -2.464], [4.6, -2.484], [4.8, -2.496], [5, -2.5], [5.2, -2.496], [5.4, -2.484], [5.6, -2.464], [5.8, -2.436], [6, -2.4], [6.2, -2.356], [6.4, -2.304], [6.6, -2.244], [6.8, -2.176], [7, -2.1], [7.2, -2.016], [7.4, -1.924], [7.6, -1.824], [7.8, -1.716], [8, -1.6], [8.2, -1.476], [8.4, -1.344], [8.6, -1.204], [8.8, -1.056], [9, -0.9], [9.2, -0.736], [9.4, -0.564], [9.6, -0.384], [9.8, -0.196]];
|
|
actual3 = bspline_curve(0.01, 2, points, knots3);
|
|
|
|
assertEqualPoints(expected3, actual3, 0.0005);
|
|
}
|
|
|
|
test_bspline_curve(); |