tri_delaunay.scad
1 /** 2 * tri_circumcenter.scad 3 * 4 * @copyright Justin Lin, 2021 5 * @license https://opensource.org/licenses/lgpl-3.0.html 6 * 7 * @see https://openhome.cc/eGossip/OpenSCAD/lib3x-tri_delaunay.html 8 * 9 **/ 10 11 use <_impl/_tri_delaunay_impl.scad> 12 use <../matrix/m_transpose.scad> 13 14 use <tri_delaunay_shapes.scad> 15 use <tri_delaunay_indices.scad> 16 use <tri_delaunay_voronoi.scad> 17 18 // ret: "TRI_SHAPES", "TRI_INDICES", "VORONOI_CELLS", "DELAUNAY" 19 function tri_delaunay(points, ret = "TRI_INDICES") = 20 let( 21 _indices_hash = function(indices) indices[3], 22 transposed = m_transpose(points), 23 xs = transposed[0], 24 ys = transposed[1], 25 max_x = max(xs), 26 min_x = min(xs), 27 max_y = max(ys), 28 min_y = min(ys), 29 center = [max_x + min_x, max_y + min_y] / 2, 30 width = (max_x - min_x) * 2, 31 height = (max_y - min_y) * 2, 32 leng_pts = len(points), 33 d = _tri_delaunay( 34 delaunay_init(center, width, height, leng_pts, _indices_hash), 35 points, 36 leng_pts, 37 _indices_hash 38 ) 39 ) 40 ret == "TRI_INDICES" ? tri_delaunay_indices(d) : 41 ret == "TRI_SHAPES" ? tri_delaunay_shapes(d) : 42 ret == "VORONOI_CELLS" ? tri_delaunay_voronoi(d) : 43 d; // "DELAUNAY": [coords(list), triangles(hashmap), circles(hashmap)]