mirror of
https://github.com/JustinSDK/dotSCAD.git
synced 2025-01-17 14:18:13 +01:00
added test_polyline2d
This commit is contained in:
parent
fc65f4bc48
commit
b770833521
@ -1,6 +1,7 @@
|
||||
// 2D
|
||||
include <test_rounded_square.scad>;
|
||||
include <test_line2d.scad>;
|
||||
include <test_polyline2d.scad>;
|
||||
|
||||
// 2D Shape
|
||||
include <test_shape_arc.scad>;
|
||||
|
120
test/test_polyline2d.scad
Normal file
120
test/test_polyline2d.scad
Normal file
@ -0,0 +1,120 @@
|
||||
include <unittest.scad>;
|
||||
include <line2d.scad>;
|
||||
|
||||
module test_polyline2d() {
|
||||
|
||||
$fn = 24;
|
||||
points = [[1, 2], [-5, -4], [-5, 3], [5, 5]];
|
||||
line_width = 1;
|
||||
leng_points = len(points);
|
||||
|
||||
module assertCorrectSegment(index, point1, point2, width) {
|
||||
assertEqualPoint(points[index - 1], point1);
|
||||
assertEqualPoint(points[index], point2);
|
||||
assertEqual(line_width, width);
|
||||
}
|
||||
|
||||
module assertCorrectCaps(startStyle, endStyle, index, p1Style, p2Style) {
|
||||
function correctMiddleCaps(p1Style, p2Style) =
|
||||
p1Style == "CAP_BUTT" && p2Style == "CAP_ROUND";
|
||||
|
||||
if(index == 1 && (p1Style != startStyle || p2Style != "CAP_ROUND")) {
|
||||
fail(
|
||||
"Wrong start caps",
|
||||
str(
|
||||
"expected: [", startStyle, ", \"CAP_ROUND\"]",
|
||||
", but: ", [p1Style, p2Style]
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
if((1 < index && index < leng_points - 1) && !correctMiddleCaps(p1Style, p2Style)) {
|
||||
|
||||
fail(
|
||||
"Wrong middle caps",
|
||||
str(
|
||||
"expected: [\"CAP_BUTT\", \"CAP_ROUND\"]",
|
||||
", but: ", [p1Style, p2Style]
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
if(index == leng_points - 1 && (p1Style != "CAP_BUTT" || p2Style != endStyle)) {
|
||||
fail(
|
||||
"Wrong end caps",
|
||||
str(
|
||||
"expected: [\"CAP_BUTT\, ", endStyle, "]",
|
||||
", but: ", [p1Style, p2Style]
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// testcases
|
||||
|
||||
module test_polyline2d_cap_square() {
|
||||
echo("==== test_polyline2d_cap_square ====");
|
||||
|
||||
include <polyline2d.scad>;
|
||||
|
||||
module test_line_segment(index, point1, point2, width, p1Style, p2Style) {
|
||||
|
||||
assertCorrectSegment(index, point1, point2, width);
|
||||
assertCorrectCaps(
|
||||
"CAP_SQUARE", "CAP_SQUARE",
|
||||
index, p1Style, p2Style
|
||||
);
|
||||
}
|
||||
|
||||
polyline2d(points = points, width = line_width);
|
||||
}
|
||||
|
||||
module test_polyline2d_cap_end_round() {
|
||||
echo("==== test_polyline2d_cap_end_round ====");
|
||||
|
||||
include <polyline2d.scad>;
|
||||
|
||||
module test_line_segment(index, point1, point2, width, p1Style, p2Style) {
|
||||
|
||||
assertCorrectSegment(index, point1, point2, width);
|
||||
assertCorrectCaps(
|
||||
"CAP_SQUARE", "CAP_ROUND",
|
||||
index, p1Style, p2Style
|
||||
);
|
||||
}
|
||||
|
||||
polyline2d(
|
||||
points = points,
|
||||
width = line_width,
|
||||
endingStyle = "CAP_ROUND"
|
||||
);
|
||||
}
|
||||
|
||||
module test_polyline2d_cap_round() {
|
||||
echo("==== test_polyline2d_cap_round ====");
|
||||
|
||||
include <polyline2d.scad>;
|
||||
|
||||
module test_line_segment(index, point1, point2, width, p1Style, p2Style) {
|
||||
|
||||
assertCorrectSegment(index, point1, point2, width);
|
||||
assertCorrectCaps(
|
||||
"CAP_ROUND", "CAP_ROUND",
|
||||
index, p1Style, p2Style
|
||||
);
|
||||
}
|
||||
|
||||
polyline2d(
|
||||
points = points,
|
||||
width = line_width,
|
||||
startingStyle = "CAP_ROUND",
|
||||
endingStyle = "CAP_ROUND"
|
||||
);
|
||||
}
|
||||
|
||||
test_polyline2d_cap_square();
|
||||
test_polyline2d_cap_end_round();
|
||||
test_polyline2d_cap_round();
|
||||
}
|
||||
|
||||
test_polyline2d();
|
Loading…
x
Reference in New Issue
Block a user