mirror of
https://github.com/revarbat/BOSL2.git
synced 2025-08-13 13:24:19 +02:00
Added resample_path() tests.
This commit is contained in:
@@ -173,29 +173,77 @@ test_subdivide_long_segments();
|
||||
|
||||
module test_resample_path(){
|
||||
path = xscale(2,circle($fn=250, r=10));
|
||||
sampled = resample_path(path, 16);
|
||||
assert_approx(sampled,
|
||||
[[20, 0], [17.1657142861, -5.13020769642],
|
||||
[11.8890531315, -8.04075246881], [6.03095737128,
|
||||
-9.53380030092], [1.72917236085e-14, -9.99921044204],
|
||||
[-6.03095737128, -9.53380030092], [-11.8890531315,
|
||||
-8.04075246881], [-17.1657142861, -5.13020769642], [-20,
|
||||
-3.19176120946e-14], [-17.1657142861, 5.13020769642],
|
||||
[-11.8890531315, 8.04075246881], [-6.03095737128,
|
||||
9.53380030092], [-4.20219414821e-14, 9.99921044204],
|
||||
[6.03095737128, 9.53380030092], [11.8890531315,
|
||||
8.04075246881], [17.1657142861, 5.13020769642]]);
|
||||
assert_approx(
|
||||
resample_path(path, 16), [
|
||||
[20, 0],
|
||||
[17.1657142861, -5.13020769642],
|
||||
[11.8890531315, -8.04075246881],
|
||||
[6.03095737128, -9.53380030092],
|
||||
[1.72917236085e-14, -9.99921044204],
|
||||
[-6.03095737128, -9.53380030092],
|
||||
[-11.8890531315, -8.04075246881],
|
||||
[-17.1657142861, -5.13020769642],
|
||||
[-20, -3.19176120946e-14],
|
||||
[-17.1657142861, 5.13020769642],
|
||||
[-11.8890531315, 8.04075246881],
|
||||
[-6.03095737128, 9.53380030092],
|
||||
[-4.20219414821e-14, 9.99921044204],
|
||||
[6.03095737128, 9.53380030092],
|
||||
[11.8890531315, 8.04075246881],
|
||||
[17.1657142861, 5.13020769642]
|
||||
]
|
||||
);
|
||||
path2 = square(20);
|
||||
assert_approx(resample_path(path2, spacing=6),
|
||||
[[20, 0], [13.8461538462, 0], [7.69230769231, 0], [1.53846153846, 0],
|
||||
[0, 4.61538461538], [0, 10.7692307692], [0, 16.9230769231], [3.07692307692, 20],
|
||||
[9.23076923077, 20], [15.3846153846, 20], [20, 18.4615384615], [20, 12.3076923077], [20, 6.15384615385]]);
|
||||
assert_equal(resample_path(path2, spacing=6,closed=false),[[20, 0], [14, 0], [8, 0], [2, 0], [0, 4], [0, 10], [0, 16], [2, 20], [8, 20], [14, 20], [20, 20]]);
|
||||
assert_approx(resample_path(path, spacing=17),
|
||||
[[20, 0], [8.01443073309, -9.16170407964],
|
||||
[-8.01443073309, -9.16170407964], [-20,
|
||||
-1.59309060367e-14], [-8.01443073309, 9.16170407964],
|
||||
[8.01443073309, 9.16170407964]]);
|
||||
assert_approx(
|
||||
resample_path(path2, spacing=6), [
|
||||
[20, 0], [13.8461538462, 0], [7.69230769231, 0],
|
||||
[1.53846153846, 0], [0, 4.61538461538],
|
||||
[0, 10.7692307692], [0, 16.9230769231],
|
||||
[3.07692307692, 20], [9.23076923077, 20],
|
||||
[15.3846153846, 20], [20, 18.4615384615],
|
||||
[20, 12.3076923077], [20, 6.15384615385]
|
||||
]
|
||||
);
|
||||
assert_equal(
|
||||
resample_path(path2, spacing=6,closed=false), [
|
||||
[20, 0], [14, 0], [ 8, 0], [ 2, 0],
|
||||
[ 0, 4], [ 0,10], [ 0,16], [ 2,20],
|
||||
[ 8,20], [14,20], [20,20]
|
||||
]
|
||||
);
|
||||
assert_equal(
|
||||
resample_path(path2, n=7, keep_corners=90, closed=true), [
|
||||
[20,0],[10,0],[0,0],[0,10],[0,20],[20,20],[20,10]
|
||||
]
|
||||
);
|
||||
assert_equal(
|
||||
resample_path(path2, n=7, keep_corners=90, closed=false), [
|
||||
[20,0],[10,0],[0,0],[0,10],[0,20],[10,20],[20,20]
|
||||
]
|
||||
);
|
||||
assert_approx(
|
||||
resample_path(path2, spacing=6, keep_corners=90, closed=false), [
|
||||
[20, 0], [13.3333333333, 0], [6.66666666667,0],
|
||||
[ 0, 0], [ 0,6.66666666667], [0,13.3333333333],
|
||||
[ 0,20], [ 6.66666666667,20], [13.3333333333,20],
|
||||
[20,20]
|
||||
]
|
||||
);
|
||||
assert_approx(
|
||||
resample_path(path2, spacing=6, keep_corners=90), [
|
||||
[20, 0], [13.3333333333, 0], [ 6.66666666667, 0],
|
||||
[ 0, 0], [ 0, 6.66666666667], [ 0,13.3333333333],
|
||||
[ 0,20], [ 6.66666666667,20], [13.3333333333,20],
|
||||
[20,20], [20,13.3333333333], [20, 6.66666666667]
|
||||
]
|
||||
);
|
||||
assert_approx(
|
||||
resample_path(path, spacing=17), [
|
||||
[20, 0], [8.01443073309, -9.16170407964],
|
||||
[-8.01443073309, -9.16170407964], [-20, -1.59309060367e-14],
|
||||
[-8.01443073309, 9.16170407964], [8.01443073309, 9.16170407964]
|
||||
]
|
||||
);
|
||||
}
|
||||
test_resample_path();
|
||||
|
||||
|
Reference in New Issue
Block a user