1
0
mirror of https://github.com/JustinSDK/dotSCAD.git synced 2025-08-27 16:30:29 +02:00
This commit is contained in:
Justin Lin
2020-03-20 07:25:08 +08:00
parent eaaea18771
commit f8f498ffaa
3 changed files with 15 additions and 15 deletions

View File

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

View File

@@ -2,14 +2,14 @@ use <pixel/px_circle.scad>;
use <pixel/px_polyline.scad>;
use <shape_pentagram.scad>;
use <hull_polyline2d.scad>;
use <experimental/px_surround.scad>;
use <experimental/px_contour.scad>;
pts = px_circle(10, true);
for(p = pts) {
translate(p)
square(1, center = true);
}
#hull_polyline2d(px_surround(pts), width = .1);
#hull_polyline2d(px_contour(pts), width = .1);
pentagram = [
@@ -23,5 +23,5 @@ translate([30, 0]) {
linear_extrude(1, scale = 0.5)
square(1, center = true);
}
#hull_polyline2d(px_surround(pts2), width = .1);
#hull_polyline2d(px_contour(pts2), width = .1);
}

View File

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