1
0
mirror of https://github.com/JustinSDK/dotSCAD.git synced 2025-01-17 22:28:16 +01:00

refactored

This commit is contained in:
Justin Lin 2017-05-14 12:59:40 +08:00
parent 5ebf3e18e4
commit 89a7c5fbbc
3 changed files with 25 additions and 27 deletions

View File

@ -1,7 +1,7 @@
function __half_trapezium(radius, h, round_r) = function __half_trapezium(radius, h, round_r) =
let( let(
is_vt = __is_vector(radius), is_vt = __is_vector(radius),
r1 = is_vt ? radius[0] : radiusm, r1 = is_vt ? radius[0] : radius,
r2 = is_vt ? radius[1] : radius, r2 = is_vt ? radius[1] : radius,
frags = __frags(round_r), frags = __frags(round_r),
b_ang = atan2(h, r1 - r2), b_ang = atan2(h, r1 - r2),

View File

@ -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
);

View File

@ -15,33 +15,17 @@
include <__private__/__is_vector.scad>; include <__private__/__is_vector.scad>;
include <__private__/__frags.scad>; include <__private__/__frags.scad>;
include <__private__/__pie_for_rounding.scad>; include <__private__/__pie_for_rounding.scad>;
include <__private__/__half_trapezium.scad>;
include <__private__/__trapezium.scad>;
function shape_square(size, corner_r = 0) = function shape_square(size, corner_r = 0) =
let( let(
corner_frags = __frags(corner_r) / 4,
x = __is_vector(size) ? size[0] : size, x = __is_vector(size) ? size[0] : size,
y = __is_vector(size) ? size[1] : size, y = __is_vector(size) ? size[1] : size
half_x = x / 2, )
half_y = y / 2, __trapezium(
half_w = half_x - corner_r, radius = x,
half_h = half_y - corner_r, h = y,
right_side = [ round_r = corner_r
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;