diff --git a/src/__private__/__nearest_multiple_of_4.scad b/src/__private__/__nearest_multiple_of_4.scad new file mode 100644 index 00000000..a9ca9724 --- /dev/null +++ b/src/__private__/__nearest_multiple_of_4.scad @@ -0,0 +1,5 @@ +function __multiple_of_4(n) = + let( + remain = n % 4 + ) + (remain / 4) > 0.5 ? n - remain + 4 : n - remain; diff --git a/src/line2d.scad b/src/line2d.scad index a6dbed0a..c6782caa 100644 --- a/src/line2d.scad +++ b/src/line2d.scad @@ -11,6 +11,7 @@ **/ include <__private__/__frags.scad>; +include <__private__/__nearest_multiple_of_4.scad>; module line2d(p1, p2, width, p1Style = "CAP_SQUARE", p2Style = "CAP_SQUARE") { half_width = 0.5 * width; @@ -23,10 +24,7 @@ module line2d(p1, p2, width, p1Style = "CAP_SQUARE", p2Style = "CAP_SQUARE") { translate([0, -width / 2]) square([leng, width]); - frags = __frags(half_width); - - remain = frags % 4; - end_frags = (remain / 4) > 0.5 ? frags - remain + 4 : frags - remain; + frags = __nearest_multiple_of_4(__frags(half_width)); module square_end(point) { translate(point) @@ -37,7 +35,7 @@ module line2d(p1, p2, width, p1Style = "CAP_SQUARE", p2Style = "CAP_SQUARE") { module round_end(point) { translate(point) rotate(atan_angle) - circle(half_width, center = true, $fn = end_frags); + circle(half_width, center = true, $fn = frags); } if(p1Style == "CAP_SQUARE") {