mirror of
https://github.com/BelfrySCAD/BOSL2.git
synced 2025-02-19 10:09:39 +00:00
Remove casual quantizing from vnf_add_faces()
This commit is contained in:
parent
7cba0b60f9
commit
f65228f0af
2 changed files with 20 additions and 25 deletions
|
@ -8,7 +8,7 @@
|
||||||
//////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|
||||||
BOSL_VERSION = [2,0,206];
|
BOSL_VERSION = [2,0,207];
|
||||||
|
|
||||||
|
|
||||||
// Section: BOSL Library Version Functions
|
// Section: BOSL Library Version Functions
|
||||||
|
|
43
vnf.scad
43
vnf.scad
|
@ -57,7 +57,7 @@ function vnf_quantize(vnf,q=pow(2,-12)) =
|
||||||
|
|
||||||
// Function: vnf_get_vertex()
|
// Function: vnf_get_vertex()
|
||||||
// Usage:
|
// Usage:
|
||||||
// vvnf = vnf_get_vertex(vnf, p, [eps]);
|
// vvnf = vnf_get_vertex(vnf, p);
|
||||||
// Description:
|
// Description:
|
||||||
// Finds the index number of the given vertex point `p` in the given VNF structure `vnf`. If said
|
// Finds the index number of the given vertex point `p` in the given VNF structure `vnf`. If said
|
||||||
// point does not already exist in the VNF vertex list, it is added. Returns: `[INDEX, VNF]` where
|
// point does not already exist in the VNF vertex list, it is added. Returns: `[INDEX, VNF]` where
|
||||||
|
@ -66,19 +66,16 @@ function vnf_quantize(vnf,q=pow(2,-12)) =
|
||||||
// Arguments:
|
// Arguments:
|
||||||
// vnf = The VNF structue to get the point index from.
|
// vnf = The VNF structue to get the point index from.
|
||||||
// p = The point, or list of points to get the index of.
|
// p = The point, or list of points to get the index of.
|
||||||
// eps = Maximum variance when comparing points. Default: 2^-30
|
|
||||||
// Example:
|
// Example:
|
||||||
// vnf1 = vnf_get_vertex(p=[3,5,8]); // Returns: [0, [[[3,5,8]],[]]]
|
// vnf1 = vnf_get_vertex(p=[3,5,8]); // Returns: [0, [[[3,5,8]],[]]]
|
||||||
// vnf2 = vnf_get_vertex(vnf1, p=[3,2,1]); // Returns: [1, [[[3,5,8],[3,2,1]],[]]]
|
// vnf2 = vnf_get_vertex(vnf1, p=[3,2,1]); // Returns: [1, [[[3,5,8],[3,2,1]],[]]]
|
||||||
// vnf3 = vnf_get_vertex(vnf2, p=[3,5,8]); // Returns: [0, [[[3,5,8],[3,2,1]],[]]]
|
// vnf3 = vnf_get_vertex(vnf2, p=[3,5,8]); // Returns: [0, [[[3,5,8],[3,2,1]],[]]]
|
||||||
// vnf4 = vnf_get_vertex(vnf3, p=[[1,3,2],[3,2,1]]); // Returns: [[1,2], [[[3,5,8],[3,2,1],[1,3,2]],[]]]
|
// vnf4 = vnf_get_vertex(vnf3, p=[[1,3,2],[3,2,1]]); // Returns: [[1,2], [[[3,5,8],[3,2,1],[1,3,2]],[]]]
|
||||||
function vnf_get_vertex(vnf=EMPTY_VNF, p, eps=pow(2,-30)) =
|
function vnf_get_vertex(vnf=EMPTY_VNF, p) =
|
||||||
is_path(p)? _vnf_get_vertices(vnf, p, eps=eps) :
|
is_path(p)? _vnf_get_vertices(vnf, p) :
|
||||||
assert(is_vnf(vnf))
|
assert(is_vnf(vnf))
|
||||||
assert(is_vector(p))
|
assert(is_vector(p))
|
||||||
let(
|
let(
|
||||||
quantum = pow(2,floor(log2(eps))),
|
|
||||||
p = quant(p,quantum),
|
|
||||||
v = search([p], vnf[0])[0]
|
v = search([p], vnf[0])[0]
|
||||||
) [
|
) [
|
||||||
v != []? v : len(vnf[0]),
|
v != []? v : len(vnf[0]),
|
||||||
|
@ -90,11 +87,11 @@ function vnf_get_vertex(vnf=EMPTY_VNF, p, eps=pow(2,-30)) =
|
||||||
|
|
||||||
|
|
||||||
// Internal use only
|
// Internal use only
|
||||||
function _vnf_get_vertices(vnf=EMPTY_VNF, pts, eps=pow(2,-30), _i=0, _idxs=[]) =
|
function _vnf_get_vertices(vnf=EMPTY_VNF, pts, _i=0, _idxs=[]) =
|
||||||
_i>=len(pts)? [_idxs, vnf] :
|
_i>=len(pts)? [_idxs, vnf] :
|
||||||
let(
|
let(
|
||||||
vvnf = vnf_get_vertex(vnf, pts[_i], eps=eps)
|
vvnf = vnf_get_vertex(vnf, pts[_i])
|
||||||
) _vnf_get_vertices(vvnf[1], pts, eps=eps, _i=_i+1, _idxs=concat(_idxs,[vvnf[0]]));
|
) _vnf_get_vertices(vvnf[1], pts, _i=_i+1, _idxs=concat(_idxs,[vvnf[0]]));
|
||||||
|
|
||||||
|
|
||||||
// Function: vnf_add_face()
|
// Function: vnf_add_face()
|
||||||
|
@ -107,13 +104,12 @@ function _vnf_get_vertices(vnf=EMPTY_VNF, pts, eps=pow(2,-30), _i=0, _idxs=[]) =
|
||||||
// Arguments:
|
// Arguments:
|
||||||
// vnf = The VNF structure to add a face to.
|
// vnf = The VNF structure to add a face to.
|
||||||
// pts = The vertex points for the face.
|
// pts = The vertex points for the face.
|
||||||
// eps = Maximum variance when comparing points. Default: `EPSILON` (1e-9)
|
function vnf_add_face(vnf=EMPTY_VNF, pts) =
|
||||||
function vnf_add_face(vnf=EMPTY_VNF, pts, eps=pow(2,-30)) =
|
|
||||||
assert(is_vnf(vnf))
|
assert(is_vnf(vnf))
|
||||||
assert(is_path(pts))
|
assert(is_path(pts))
|
||||||
let(
|
let(
|
||||||
vvnf = vnf_get_vertex(vnf, pts, eps=eps),
|
vvnf = vnf_get_vertex(vnf, pts),
|
||||||
face = deduplicate(vvnf[0], closed=true, eps=eps),
|
face = deduplicate(vvnf[0], closed=true),
|
||||||
vnf2 = vvnf[1]
|
vnf2 = vvnf[1]
|
||||||
) [
|
) [
|
||||||
vnf_vertices(vnf2),
|
vnf_vertices(vnf2),
|
||||||
|
@ -123,7 +119,7 @@ function vnf_add_face(vnf=EMPTY_VNF, pts, eps=pow(2,-30)) =
|
||||||
|
|
||||||
// Function: vnf_add_faces()
|
// Function: vnf_add_faces()
|
||||||
// Usage:
|
// Usage:
|
||||||
// vnf_add_faces(vnf, faces, [eps]);
|
// vnf_add_faces(vnf, faces);
|
||||||
// Description:
|
// Description:
|
||||||
// Given a VNF structure and a list of faces, where each face is given as a list of vertex points,
|
// Given a VNF structure and a list of faces, where each face is given as a list of vertex points,
|
||||||
// adds the faces to the VNF structure. Returns the modified VNF structure `[VERTICES, FACES]`.
|
// adds the faces to the VNF structure. Returns the modified VNF structure `[VERTICES, FACES]`.
|
||||||
|
@ -132,10 +128,9 @@ function vnf_add_face(vnf=EMPTY_VNF, pts, eps=pow(2,-30)) =
|
||||||
// Arguments:
|
// Arguments:
|
||||||
// vnf = The VNF structure to add a face to.
|
// vnf = The VNF structure to add a face to.
|
||||||
// faces = The list of faces, where each face is given as a list of vertex points.
|
// faces = The list of faces, where each face is given as a list of vertex points.
|
||||||
// eps = Maximum variance when comparing points. Default: `EPSILON` (1e-9)
|
function vnf_add_faces(vnf=EMPTY_VNF, faces, _i=0) =
|
||||||
function vnf_add_faces(vnf=EMPTY_VNF, faces, eps=pow(2,-30), _i=0) =
|
|
||||||
(assert(is_vnf(vnf)) assert(is_list(faces)) _i>=len(faces))? vnf :
|
(assert(is_vnf(vnf)) assert(is_list(faces)) _i>=len(faces))? vnf :
|
||||||
vnf_add_faces(vnf_add_face(vnf, faces[_i], eps=eps), faces, eps=eps, _i=_i+1);
|
vnf_add_faces(vnf_add_face(vnf, faces[_i]), faces, _i=_i+1);
|
||||||
|
|
||||||
|
|
||||||
// Function: vnf_merge()
|
// Function: vnf_merge()
|
||||||
|
@ -155,10 +150,10 @@ function vnf_merge(vnfs=[],_i=0,_acc=EMPTY_VNF) =
|
||||||
|
|
||||||
// Function: vnf_compact()
|
// Function: vnf_compact()
|
||||||
// Usage:
|
// Usage:
|
||||||
// cvnf = vnf_compact(vnf, [eps]);
|
// cvnf = vnf_compact(vnf);
|
||||||
// Description:
|
// Description:
|
||||||
// Takes a VNF and consolidates all duplicate vertices, and drops unreferenced vertices.
|
// Takes a VNF and consolidates all duplicate vertices, and drops unreferenced vertices.
|
||||||
function vnf_compact(vnf,eps=pow(2,-30)) =
|
function vnf_compact(vnf) =
|
||||||
let(
|
let(
|
||||||
verts = vnf[0],
|
verts = vnf[0],
|
||||||
faces = [
|
faces = [
|
||||||
|
@ -166,7 +161,7 @@ function vnf_compact(vnf,eps=pow(2,-30)) =
|
||||||
for (i=face) verts[i]
|
for (i=face) verts[i]
|
||||||
]
|
]
|
||||||
]
|
]
|
||||||
) vnf_add_faces(faces=faces,eps=eps);
|
) vnf_add_faces(faces=faces);
|
||||||
|
|
||||||
|
|
||||||
// Function: vnf_triangulate()
|
// Function: vnf_triangulate()
|
||||||
|
@ -427,9 +422,9 @@ module vnf_polyhedron(vnf, convexity=2) {
|
||||||
// path3d(regular_ngon(n=5, d=100),100)
|
// path3d(regular_ngon(n=5, d=100),100)
|
||||||
// ], slices=0, caps=false);
|
// ], slices=0, caps=false);
|
||||||
// vnf_validate(vnf,size=2);
|
// vnf_validate(vnf,size=2);
|
||||||
function vnf_validate(vnf, show_warns=true, check_isects=false, eps=pow(2,-30)) =
|
function vnf_validate(vnf, show_warns=true, check_isects=false) =
|
||||||
let(
|
let(
|
||||||
vnf = vnf_compact(vnf,eps=eps),
|
vnf = vnf_compact(vnf),
|
||||||
edges = sort([
|
edges = sort([
|
||||||
for (face=vnf[1], edge=pair_wrap(face))
|
for (face=vnf[1], edge=pair_wrap(face))
|
||||||
edge[0]<edge[1]? edge : [edge[1],edge[0]]
|
edge[0]<edge[1]? edge : [edge[1],edge[0]]
|
||||||
|
@ -450,7 +445,7 @@ function vnf_validate(vnf, show_warns=true, check_isects=false, eps=pow(2,-30))
|
||||||
for (face = vnf[1]) let(
|
for (face = vnf[1]) let(
|
||||||
verts = [for (k=face) vnf[0][k]],
|
verts = [for (k=face) vnf[0][k]],
|
||||||
area = abs(polygon_area(verts))
|
area = abs(polygon_area(verts))
|
||||||
) if (area < eps) [
|
) if (area < EPSILON) [
|
||||||
"WARNING",
|
"WARNING",
|
||||||
"NULL_FACE",
|
"NULL_FACE",
|
||||||
str("Face has zero area: ",fmt_float(area,15)),
|
str("Face has zero area: ",fmt_float(area,15)),
|
||||||
|
@ -461,7 +456,7 @@ function vnf_validate(vnf, show_warns=true, check_isects=false, eps=pow(2,-30))
|
||||||
nonplanars = unique([
|
nonplanars = unique([
|
||||||
for (face = vnf[1]) let(
|
for (face = vnf[1]) let(
|
||||||
verts = [for (k=face) vnf[0][k]]
|
verts = [for (k=face) vnf[0][k]]
|
||||||
) if (!points_are_coplanar(verts,eps=eps)) [
|
) if (!points_are_coplanar(verts)) [
|
||||||
"ERROR",
|
"ERROR",
|
||||||
"NONPLANAR",
|
"NONPLANAR",
|
||||||
"Face vertices are not coplanar",
|
"Face vertices are not coplanar",
|
||||||
|
|
Loading…
Reference in a new issue