1
0
mirror of https://github.com/JustinSDK/dotSCAD.git synced 2025-08-11 17:24:20 +02:00
This commit is contained in:
Justin Lin
2020-05-20 17:18:38 +08:00
parent e82ed21ddc
commit 1e1a5b4c73
3 changed files with 19 additions and 19 deletions

View File

@@ -1,6 +1,6 @@
use <util/has.scad>; use <util/has.scad>;
function _px_contour_corner_value(pts, x, y) = function _vx_contour_corner_value(pts, x, y) =
let( let(
c1 = has(pts, [x, y - 1], sorted = true) || has(pts, [x - 1, y - 1], sorted = true) ? 1 : 0, c1 = has(pts, [x, y - 1], sorted = true) || has(pts, [x - 1, y - 1], sorted = true) ? 1 : 0,
c2 = has(pts, [x - 1, y], sorted = true) || has(pts, [x - 1, y + 1], sorted = true) ? 2 : 0, c2 = has(pts, [x - 1, y], sorted = true) || has(pts, [x - 1, y + 1], sorted = true) ? 2 : 0,
@@ -9,27 +9,27 @@ function _px_contour_corner_value(pts, x, y) =
) )
c1 + c2 + c3 + c4; c1 + c2 + c3 + c4;
_px_contour_dir_table = [ _vx_contour_dir_table = [
[4, 0], [6, 0], [7, 0], // RIGHT [4, 0], [6, 0], [7, 0], // RIGHT
[8, 1], [12, 1], [14, 1], // DOWN [8, 1], [12, 1], [14, 1], // DOWN
[2, 2], [3, 2], [11, 2], // UP [2, 2], [3, 2], [11, 2], // UP
[1, 3], [9, 3], [13, 3] // LEFT [1, 3], [9, 3], [13, 3] // LEFT
]; ];
function _px_contour_dir(cr_value) = function _vx_contour_dir(cr_value) =
lookup(cr_value, _px_contour_dir_table); lookup(cr_value, _vx_contour_dir_table);
_px_contour_nxt_offset = [ _vx_contour_nxt_offset = [
[1, 0], // RIGHT [1, 0], // RIGHT
[0, -1], // DOWN [0, -1], // DOWN
[0, 1], // UP [0, 1], // UP
[-1, 0] // LEFT [-1, 0] // LEFT
]; ];
function _px_contour_travel(pts, p, fst) = function _vx_contour_travel(pts, p, fst) =
let( let(
dir_i = _px_contour_dir(_px_contour_corner_value(pts, p[0], p[1])), dir_i = _vx_contour_dir(_vx_contour_corner_value(pts, p[0], p[1])),
nxt_p = p + _px_contour_nxt_offset[dir_i] nxt_p = p + _vx_contour_nxt_offset[dir_i]
) )
nxt_p == fst ? [p] : nxt_p == fst ? [p] :
concat( concat(
[p], _px_contour_travel(pts, nxt_p, fst) [p], _vx_contour_travel(pts, nxt_p, fst)
); );

View File

@@ -1,27 +1,27 @@
use <pixel/px_circle.scad>; use <voxel/vx_circle.scad>;
use <pixel/px_polyline.scad>; use <voxel/vx_polyline.scad>;
use <shape_pentagram.scad>; use <shape_pentagram.scad>;
use <hull_polyline2d.scad>; use <hull_polyline2d.scad>;
use <experimental/px_contour.scad>; use <experimental/vx_contour.scad>;
pts = px_circle(10, true); pts = vx_circle(10, true);
for(p = pts) { for(p = pts) {
translate(p) translate(p)
square(1, center = true); square(1, center = true);
} }
#hull_polyline2d(px_contour(pts), width = .1); #hull_polyline2d(vx_contour(pts), width = .1);
pentagram = [ pentagram = [
for(pt = shape_pentagram(15)) for(pt = shape_pentagram(15))
[round(pt[0]), round(pt[1])] [round(pt[0]), round(pt[1])]
]; ];
pts2 = px_polyline(concat(pentagram, [pentagram[0]])); pts2 = vx_polyline(concat(pentagram, [pentagram[0]]));
translate([30, 0]) { translate([30, 0]) {
for(pt = pts2) { for(pt = pts2) {
translate(pt) translate(pt)
linear_extrude(1, scale = 0.5) linear_extrude(1, scale = 0.5)
square(1, center = true); square(1, center = true);
} }
#hull_polyline2d(px_contour(pts2), width = .1); #hull_polyline2d(vx_contour(pts2), width = .1);
} }

View File

@@ -1,10 +1,10 @@
use <experimental/_impl/_px_contour_impl.scad>; use <experimental/_impl/_vx_contour_impl.scad>;
use <util/sort.scad>; use <util/sort.scad>;
function px_contour(points) = function vx_contour(points) =
let( let(
// always start from the left-bottom pt // always start from the left-bottom pt
sortedXY = sort(points, by = "vt"), sortedXY = sort(points, by = "vt"),
fst = sortedXY[0] + [-1, -1] fst = sortedXY[0] + [-1, -1]
) )
_px_contour_travel(sortedXY, fst, fst); _vx_contour_travel(sortedXY, fst, fst);