Merge pull request #336 from revarbat/revarbat_dev

Various fixes to get example generation working.
This commit is contained in:
Revar Desmera 2020-12-14 18:33:20 -08:00 committed by GitHub
commit 03823f990c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 158 additions and 146 deletions

View file

@ -1020,7 +1020,7 @@ function projection_on_plane(plane, points) =
: points,
plane = normalize_plane(plane),
n = point3d(plane)
)
)
[for(pi=p) pi - (pi*n - plane[3])*n];
@ -1069,7 +1069,7 @@ function closest_point_on_plane(plane, point) =
let( plane = normalize_plane(plane),
n = point3d(plane),
d = n*point - plane[3] // distance from plane
)
)
point - n*d;
@ -1113,7 +1113,7 @@ function plane_line_angle(plane, line) =
normal = plane_normal(plane),
sin_angle = linedir*normal,
cos_angle = norm(cross(linedir,normal))
)
)
atan2(sin_angle,cos_angle);
@ -1369,7 +1369,7 @@ function circle_2tangents(pt1, pt2, pt3, r, d, tangents=false) =
a = vector_angle(v1, v2),
hyp = r / sin(a/2),
cp = pt2 + hyp * vmid
)
)
!tangents ? [cp, n] :
let(
x = hyp * cos(a/2),
@ -1377,7 +1377,7 @@ function circle_2tangents(pt1, pt2, pt3, r, d, tangents=false) =
tp2 = pt2 + x * v2,
dang1 = vector_angle(tp1-cp,pt2-cp),
dang2 = vector_angle(tp2-cp,pt2-cp)
)
)
[cp, n, tp1, tp2, dang1, dang2];
module circle_2tangents(pt1, pt2, pt3, r, d, h, center=false) {
@ -1678,14 +1678,23 @@ function furthest_point(pt, points) =
function polygon_area(poly, signed=false) =
assert(is_path(poly), "Invalid polygon." )
len(poly)<3 ? 0 :
let( cpoly = close_path(simplify_path(poly)) )
len(poly[0])==2
? sum([for(i=[1:1:len(poly)-2]) cross(poly[i]-poly[0],poly[i+1]-poly[0]) ])/2
: let( plane = plane_from_points(poly) )
plane==undef? undef :
let( n = unit(plane_normal(plane)),
total = sum([for(i=[1:1:len(poly)-1]) cross(poly[i]-poly[0],poly[i+1]-poly[0])*n ])/2
)
signed ? total : abs(total);
? sum([for(i=[1:1:len(poly)-2]) cross(poly[i]-poly[0],poly[i+1]-poly[0]) ])/2
: let( plane = plane_from_points(poly) )
plane==undef? undef :
let(
n = unit(plane_normal(plane)),
total = sum([
for(i=[1:1:len(cpoly)-2])
let(
v1 = cpoly[i] - cpoly[0],
v2 = cpoly[i+1] - cpoly[0]
)
cross(v1,v2) * n
])/2
)
signed ? total : abs(total);
// Function: is_convex_polygon()
@ -2082,9 +2091,8 @@ function _split_polygon_at_z(poly, z) =
// polys = A list of 3D polygons to split.
// xs = A list of scalar X values to split at.
function split_polygons_at_each_x(polys, xs, _i=0) =
assert( is_consistent(polys) && is_path(poly[0],dim=3) ,
"The input list should contains only 3D polygons." )
assert( is_finite(xs), "The split value list should contain only numbers." )
assert( [for (poly=polys) if (!is_path(poly,3)) 1] == [], "Expects list of 3D paths.")
assert( is_vector(xs), "The split value list should contain only numbers." )
_i>=len(xs)? polys :
split_polygons_at_each_x(
[
@ -2103,9 +2111,8 @@ function split_polygons_at_each_x(polys, xs, _i=0) =
// polys = A list of 3D polygons to split.
// ys = A list of scalar Y values to split at.
function split_polygons_at_each_y(polys, ys, _i=0) =
// assert( is_consistent(polys) && is_path(polys[0],dim=3) , // not all polygons should have the same length!!!
// "The input list should contains only 3D polygons." )
assert( is_finite(ys) || is_vector(ys), "The split value list should contain only numbers." ) //***
assert( [for (poly=polys) if (!is_path(poly,3)) 1] == [], "Expects list of 3D paths.")
assert( is_vector(ys), "The split value list should contain only numbers." )
_i>=len(ys)? polys :
split_polygons_at_each_y(
[
@ -2124,9 +2131,8 @@ function split_polygons_at_each_y(polys, ys, _i=0) =
// polys = A list of 3D polygons to split.
// zs = A list of scalar Z values to split at.
function split_polygons_at_each_z(polys, zs, _i=0) =
assert( is_consistent(polys) && is_path(poly[0],dim=3) ,
"The input list should contains only 3D polygons." )
assert( is_finite(zs), "The split value list should contain only numbers." )
assert( [for (poly=polys) if (!is_path(poly,3)) 1] == [], "Expects list of 3D paths.")
assert( is_vector(zs), "The split value list should contain only numbers." )
_i>=len(zs)? polys :
split_polygons_at_each_z(
[

View file

@ -8,7 +8,7 @@
//////////////////////////////////////////////////////////////////////
BOSL_VERSION = [2,0,479];
BOSL_VERSION = [2,0,480];
// Section: BOSL Library Version Functions

View file

@ -672,8 +672,11 @@ function vnf_validate(vnf, show_warns=true, check_isects=false) =
],
nonplanars = unique([
for (face = faces) let(
faceverts = [for (k=face) varr[k]]
) if (!coplanar(faceverts)) [
faceverts = [for (k=face) varr[k]],
area = polygon_area(faceverts)
)
if (is_num(area) && abs(area) > EPSILON)
if (!coplanar(faceverts)) [
"ERROR",
"NONPLANAR",
"Face vertices are not coplanar",
@ -712,9 +715,12 @@ function vnf_validate(vnf, show_warns=true, check_isects=false) =
if (v!=edge[0] && v!=edge[1]) let(
a = varr[edge[0]],
b = varr[v],
c = varr[edge[1]],
c = varr[edge[1]]
)
if (a != b && b != c && a != c) let(
pt = segment_closest_point([a,c],b)
) if (pt == b) [
)
if (pt == b) [
"ERROR",
"T_JUNCTION",
"Vertex is mid-edge on another Face",