From b7966c80a57308d6ecc29360da8ff7f602563bea Mon Sep 17 00:00:00 2001 From: Justin Lin Date: Mon, 27 Jan 2020 16:14:00 +0800 Subject: [PATCH] refactor deps --- src/_impl/_shape_path_extend_impl.scad | 57 ++++++++++++++++++++++++++ src/shape_path_extend.scad | 57 +------------------------- test/test_shape_path_extend.scad | 9 ++-- 3 files changed, 63 insertions(+), 60 deletions(-) create mode 100644 src/_impl/_shape_path_extend_impl.scad diff --git a/src/_impl/_shape_path_extend_impl.scad b/src/_impl/_shape_path_extend_impl.scad new file mode 100644 index 00000000..138b2f9d --- /dev/null +++ b/src/_impl/_shape_path_extend_impl.scad @@ -0,0 +1,57 @@ +use <__comm__/__to3d.scad>; +use <__comm__/__polytransversals.scad>; +use ; + +function _shape_path_extend_az(p1, p2) = + let( + x1 = p1[0], + y1 = p1[1], + x2 = p2[0], + y2 = p2[1] + ) -90 + atan2((y2 - y1), (x2 - x1)); + +function _shape_path_first_stroke(stroke_pts, path_pts) = + let( + p1 = path_pts[0], + p2 = path_pts[1], + a = _shape_path_extend_az(p1, p2) + ) + [ + for(p = stroke_pts) + rotate_p(p, a) + p1 + ]; + +function _shape_path_extend_stroke(stroke_pts, p1, p2, scale_step, i) = + let( + leng = norm(__to3d(p2) - __to3d(p1)), + a = _shape_path_extend_az(p1, p2) + ) + [ + for(p = stroke_pts) + rotate_p(p * (1 + scale_step * i) + [0, leng], a) + p1 + ]; + +function _shape_path_extend_inner(stroke_pts, path_pts, leng_path_pts, scale_step) = + [ + for(i = 1; i < leng_path_pts; i = i + 1) + _shape_path_extend_stroke( + stroke_pts, + path_pts[i - 1], + path_pts[i ], + scale_step, + i + ) + ]; + +function _shape_path_extend_impl(stroke_pts, path_pts, scale, closed) = + let( + leng_path_pts = len(path_pts), + scale_step = (scale - 1) / (leng_path_pts - 1), + strokes = _shape_path_extend_inner(stroke_pts, path_pts, leng_path_pts, scale_step) + ) + closed && path_pts[0] == path_pts[leng_path_pts - 1] ? + __polytransversals(concat(strokes, [strokes[0]])) : + __polytransversals( + concat([_shape_path_first_stroke(stroke_pts, path_pts)], strokes) + ); + diff --git a/src/shape_path_extend.scad b/src/shape_path_extend.scad index 0eac7f2e..22a500de 100644 --- a/src/shape_path_extend.scad +++ b/src/shape_path_extend.scad @@ -8,60 +8,7 @@ * **/ -include <__comm__/__to3d.scad>; -include <__comm__/__polytransversals.scad>; -include ; - -function _shape_path_extend_az(p1, p2) = - let( - x1 = p1[0], - y1 = p1[1], - x2 = p2[0], - y2 = p2[1] - ) -90 + atan2((y2 - y1), (x2 - x1)); - -function _shape_path_first_stroke(stroke_pts, path_pts) = - let( - p1 = path_pts[0], - p2 = path_pts[1], - a = _shape_path_extend_az(p1, p2) - ) - [ - for(p = stroke_pts) - rotate_p(p, a) + p1 - ]; - -function _shape_path_extend_stroke(stroke_pts, p1, p2, scale_step, i) = - let( - leng = norm(__to3d(p2) - __to3d(p1)), - a = _shape_path_extend_az(p1, p2) - ) - [ - for(p = stroke_pts) - rotate_p(p * (1 + scale_step * i) + [0, leng], a) + p1 - ]; - -function _shape_path_extend_inner(stroke_pts, path_pts, leng_path_pts, scale_step) = - [ - for(i = 1; i < leng_path_pts; i = i + 1) - _shape_path_extend_stroke( - stroke_pts, - path_pts[i - 1], - path_pts[i ], - scale_step, - i - ) - ]; +use <_impl/_shape_path_extend_impl.scad>; function shape_path_extend(stroke_pts, path_pts, scale = 1.0, closed = false) = - let( - leng_path_pts = len(path_pts), - scale_step = (scale - 1) / (leng_path_pts - 1), - strokes = _shape_path_extend_inner(stroke_pts, path_pts, leng_path_pts, scale_step) - ) - closed && path_pts[0] == path_pts[leng_path_pts - 1] ? - __polytransversals(concat(strokes, [strokes[0]])) : - __polytransversals( - concat([_shape_path_first_stroke(stroke_pts, path_pts)], strokes) - ); - + _shape_path_extend_impl(stroke_pts, path_pts, scale, closed); \ No newline at end of file diff --git a/test/test_shape_path_extend.scad b/test/test_shape_path_extend.scad index 3e6aac0f..35f1248b 100644 --- a/test/test_shape_path_extend.scad +++ b/test/test_shape_path_extend.scad @@ -1,9 +1,8 @@ -include ; +use ; -include ; -include ; -include ; -include ; +use ; +use ; +use ; module test_shape_path_extend_stroke1() { echo("==== test_shape_path_extend_stroke1 ====");