mirror of
https://github.com/JustinSDK/dotSCAD.git
synced 2025-08-06 14:56:47 +02:00
refactor: use sort
This commit is contained in:
@@ -1,18 +1,4 @@
|
|||||||
function _cmp(a, b) =
|
use <../util/sort.scad>;
|
||||||
a.x != b.x ? a.x < b.x :
|
|
||||||
a.y != b.y ? a.y < b.y :
|
|
||||||
a.z < b.z;
|
|
||||||
|
|
||||||
function _convex_hull_sort_by_xyz(pts) =
|
|
||||||
let(leng = len(pts))
|
|
||||||
leng <= 1 ? pts :
|
|
||||||
leng == 2 ? (_cmp(pts[1], pts[0]) ? [pts[1], pts[0]] : pts) :
|
|
||||||
let(
|
|
||||||
pivot = pts[0],
|
|
||||||
before = [for(j = 1; j < leng; j = j + 1) if(_cmp(pts[j], pivot)) pts[j]],
|
|
||||||
after = [for(j = 1; j < leng; j = j + 1) if(!_cmp(pts[j], pivot)) pts[j]]
|
|
||||||
)
|
|
||||||
[each _convex_hull_sort_by_xyz(before), pivot, each _convex_hull_sort_by_xyz(after)];
|
|
||||||
|
|
||||||
function normal(pts, f) = cross(pts[f[1]] - pts[f[0]], pts[f[2]] - pts[f[0]]);
|
function normal(pts, f) = cross(pts[f[1]] - pts[f[0]], pts[f[2]] - pts[f[0]]);
|
||||||
|
|
||||||
@@ -83,7 +69,7 @@ function _all_faces(v0, v1, v2, v3, pts, pts_leng, vis, cur_faces, i = 0) =
|
|||||||
|
|
||||||
function _convex_hull3(pts) =
|
function _convex_hull3(pts) =
|
||||||
let(
|
let(
|
||||||
sorted = _convex_hull_sort_by_xyz(pts),
|
sorted = sort(pts, by = function(p1, p2) p1 < p2 ? -1 : 1),
|
||||||
leng = len(sorted),
|
leng = len(sorted),
|
||||||
v0 = 0,
|
v0 = 0,
|
||||||
v1 = _fst_v1(sorted, leng, v0 + 1),
|
v1 = _fst_v1(sorted, leng, v0 + 1),
|
||||||
|
Reference in New Issue
Block a user