diff --git a/src/__private__/__half_trapezium.scad b/src/__private__/__half_trapezium.scad index 28c352c0..234a3ab9 100644 --- a/src/__private__/__half_trapezium.scad +++ b/src/__private__/__half_trapezium.scad @@ -1,7 +1,7 @@ function __half_trapezium(radius, h, round_r) = let( is_vt = __is_vector(radius), - r1 = is_vt ? radius[0] : radiusm, + r1 = is_vt ? radius[0] : radius, r2 = is_vt ? radius[1] : radius, frags = __frags(round_r), b_ang = atan2(h, r1 - r2), diff --git a/src/__private__/__trapezium.scad b/src/__private__/__trapezium.scad new file mode 100644 index 00000000..e48cf14b --- /dev/null +++ b/src/__private__/__trapezium.scad @@ -0,0 +1,14 @@ +function __trapezium(radius, h, round_r) = + let( + r_half_trapezium = __half_trapezium(radius, h, round_r), + to = len(r_half_trapezium) - 1, + l_half_trapezium = [ + for(i = [0:to]) + let(pt = r_half_trapezium[to - i]) + [-pt[0], pt[1]] + ] + ) + concat( + r_half_trapezium, + l_half_trapezium + ); \ No newline at end of file diff --git a/src/shape_square.scad b/src/shape_square.scad index e83eb596..c0269ca5 100644 --- a/src/shape_square.scad +++ b/src/shape_square.scad @@ -15,33 +15,17 @@ include <__private__/__is_vector.scad>; include <__private__/__frags.scad>; include <__private__/__pie_for_rounding.scad>; +include <__private__/__half_trapezium.scad>; +include <__private__/__trapezium.scad>; function shape_square(size, corner_r = 0) = let( - corner_frags = __frags(corner_r) / 4, x = __is_vector(size) ? size[0] : size, - y = __is_vector(size) ? size[1] : size, - half_x = x / 2, - half_y = y / 2, - half_w = half_x - corner_r, - half_h = half_y - corner_r, - right_side = [ - for(pt = __pie_for_rounding(corner_r, -90, 0, corner_frags)) - [pt[0] + half_w - corner_r, pt[1] - half_h + corner_r] - ], - top_side = [ - for(pt = __pie_for_rounding(corner_r, 0, 90, corner_frags)) - [pt[0] + half_w - corner_r, pt[1] + half_h - corner_r] - ], - left_side = [ - for(pt = __pie_for_rounding(corner_r, 90, 180, corner_frags)) - [pt[0] - half_w + corner_r, pt[1] + half_h - corner_r] - ], - bottom_side = [ - for(pt = __pie_for_rounding(corner_r, 180, 270, corner_frags)) - [pt[0] - half_w + corner_r, pt[1] - half_h + corner_r] - ], - shape_pts = concat( - right_side, top_side, left_side, bottom_side - ) - ) shape_pts; \ No newline at end of file + y = __is_vector(size) ? size[1] : size + ) + __trapezium( + radius = x, + h = y, + round_r = corner_r + ); + \ No newline at end of file