1
0
mirror of https://github.com/JustinSDK/dotSCAD.git synced 2025-08-09 08:16:50 +02:00

refactor deps

This commit is contained in:
Justin Lin
2020-01-27 16:14:00 +08:00
parent fa18ee0b91
commit b7966c80a5
3 changed files with 63 additions and 60 deletions

View File

@@ -0,0 +1,57 @@
use <__comm__/__to3d.scad>;
use <__comm__/__polytransversals.scad>;
use <rotate_p.scad>;
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)
);

View File

@@ -8,60 +8,7 @@
* *
**/ **/
include <__comm__/__to3d.scad>; use <_impl/_shape_path_extend_impl.scad>;
include <__comm__/__polytransversals.scad>;
include <util/__comm__/__reverse.scad>;
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(stroke_pts, path_pts, scale = 1.0, closed = false) = function shape_path_extend(stroke_pts, path_pts, scale = 1.0, closed = false) =
let( _shape_path_extend_impl(stroke_pts, path_pts, scale, closed);
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)
);

View File

@@ -1,9 +1,8 @@
include <unittest.scad>; use <unittest.scad>;
include <rotate_p.scad>; use <shape_path_extend.scad>;
include <shape_path_extend.scad>; use <circle_path.scad>;
include <circle_path.scad>; use <archimedean_spiral.scad>;
include <archimedean_spiral.scad>;
module test_shape_path_extend_stroke1() { module test_shape_path_extend_stroke1() {
echo("==== test_shape_path_extend_stroke1 ===="); echo("==== test_shape_path_extend_stroke1 ====");