1
0
mirror of https://github.com/JustinSDK/dotSCAD.git synced 2025-08-24 23:25:51 +02:00

should sort by xy

This commit is contained in:
Justin Lin
2020-02-26 13:43:39 +08:00
parent 0b920df2cb
commit 2448fe26d9
2 changed files with 14 additions and 2 deletions

View File

@@ -1,5 +1,18 @@
use <util/slice.scad>;
function _convex_hull_lt_than_by_xy(p1, p2) =
p1[0] < p2[0] || (p1[0] == p2[0] && p1[1] < p2[1]);
function _convex_hull_sort_by_xy(lt) =
let(leng = len(lt))
leng <= 1 ? lt :
let(
pivot = lt[0],
before = [for(j = 1; j < leng; j = j + 1) if(_convex_hull_lt_than_by_xy(lt[j], pivot)) lt[j]],
after = [for(j = 1; j < leng; j = j + 1) if(!_convex_hull_lt_than_by_xy(lt[j], pivot)) lt[j]]
)
concat(_convex_hull_sort_by_xy(before), [pivot], _convex_hull_sort_by_xy(after));
// oa->ob ct_clk : greater than 0
function _convex_hull_impl_dir(o, a, b) =
let(

View File

@@ -1,9 +1,8 @@
use <experimental/_impl/_convex_hull_impl.scad>;
use <util/sort.scad>;
function convex_hull(points) =
let(
sorted = sort(points, by = "x"),
sorted = _convex_hull_sort_by_xy(points),
leng = len(sorted),
lwr_ch = _convex_hull_lower_chain(sorted, leng, [], 0, 0),
leng_lwr_ch = len(lwr_ch),