1
0
mirror of https://github.com/JustinSDK/dotSCAD.git synced 2025-08-11 17:24:20 +02:00

avoid name collision

This commit is contained in:
Justin Lin
2020-02-25 08:13:01 +08:00
parent 25ace9564a
commit 06c7490f3a
2 changed files with 14 additions and 14 deletions

View File

@@ -1,7 +1,7 @@
use <util/slice.scad>; use <util/slice.scad>;
// oa->ob ct_clk : greater than 0 // oa->ob ct_clk : greater than 0
function _dir(o, a, b) = function _convex_hull_impl_dir(o, a, b) =
let( let(
ox = o[0], ox = o[0],
oy = o[1], oy = o[1],
@@ -12,15 +12,15 @@ function _dir(o, a, b) =
) )
(ax - ox) * (by - oy) - (ay - oy) * (bx - ox); (ax - ox) * (by - oy) - (ay - oy) * (bx - ox);
function _lower_m(chain, p, m) = function _convex_hull_convex_hull_lower_m(chain, p, m) =
(m >= 2 && _dir(chain[m - 2], chain[m - 1], p) <= 0) ? _lower_m(chain, p, m - 1) : m; (m >= 2 && _convex_hull_impl_dir(chain[m - 2], chain[m - 1], p) <= 0) ? _convex_hull_convex_hull_lower_m(chain, p, m - 1) : m;
function lower_chain(points, leng, chain, m, i) = function _convex_hull_lower_chain(points, leng, chain, m, i) =
i == leng ? chain : i == leng ? chain :
let( let(
current_m = _lower_m(chain, points[i], m) current_m = _convex_hull_convex_hull_lower_m(chain, points[i], m)
) )
lower_chain( _convex_hull_lower_chain(
points, points,
leng, leng,
concat(slice(chain, 0, current_m), [points[i]]), concat(slice(chain, 0, current_m), [points[i]]),
@@ -28,16 +28,16 @@ function lower_chain(points, leng, chain, m, i) =
i + 1 i + 1
); );
function _upper_m(chain, p, m, t) = function _convex_hull_upper_m(chain, p, m, t) =
(m >= t && _dir(chain[m - 2], chain[m - 1], p) <= 0) ? (m >= t && _convex_hull_impl_dir(chain[m - 2], chain[m - 1], p) <= 0) ?
_upper_m(chain, p, m - 1, t) : m; _convex_hull_upper_m(chain, p, m - 1, t) : m;
function _upper_chain(points, chain, m, t, i) = function _convex_hull_upper_chain(points, chain, m, t, i) =
i < 0 ? chain : i < 0 ? chain :
let( let(
current_m = _upper_m(chain, points[i], m, t) current_m = _convex_hull_upper_m(chain, points[i], m, t)
) )
_upper_chain( _convex_hull_upper_chain(
points, points,
concat(slice(chain, 0, current_m), [points[i]]), concat(slice(chain, 0, current_m), [points[i]]),
current_m + 1, current_m + 1,

View File

@@ -5,8 +5,8 @@ function convex_hull(points) =
let( let(
sorted = sort(points, by = "x"), sorted = sort(points, by = "x"),
leng = len(sorted), leng = len(sorted),
lwr_ch = lower_chain(sorted, leng, [], 0, 0), lwr_ch = _convex_hull_lower_chain(sorted, leng, [], 0, 0),
leng_lwr_ch = len(lwr_ch), leng_lwr_ch = len(lwr_ch),
chain = _upper_chain(sorted, lwr_ch, leng_lwr_ch, leng_lwr_ch + 1, leng - 2) chain = _convex_hull_upper_chain(sorted, lwr_ch, leng_lwr_ch, leng_lwr_ch + 1, leng - 2)
) )
[for(i = [0:len(chain) - 2]) chain[i]]; [for(i = [0:len(chain) - 2]) chain[i]];