2020-01-27 15:28:39 +08:00
|
|
|
use <unittest.scad>;
|
|
|
|
use <polyline2d.scad>;
|
2017-05-26 14:24:06 +08:00
|
|
|
|
|
|
|
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);
|
2019-06-11 14:32:21 +08:00
|
|
|
assertEqualNum(line_width, width);
|
2017-05-26 14:24:06 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
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 ====");
|
|
|
|
|
2020-01-24 14:36:42 +08:00
|
|
|
module test_polyline2d_line_segment(index, point1, point2, width, p1Style, p2Style) {
|
2017-05-26 14:24:06 +08:00
|
|
|
|
|
|
|
assertCorrectSegment(index, point1, point2, width);
|
|
|
|
assertCorrectCaps(
|
|
|
|
"CAP_SQUARE", "CAP_SQUARE",
|
|
|
|
index, p1Style, p2Style
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
polyline2d(points = points, width = line_width);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
test_polyline2d_cap_square();
|
|
|
|
}
|
|
|
|
|
|
|
|
test_polyline2d();
|