mirror of
https://github.com/BelfrySCAD/BOSL2.git
synced 2025-01-01 09:49:45 +00:00
Various fixes to get example generation working.
This commit is contained in:
parent
ea88aa8ac2
commit
35e6fdb1aa
3 changed files with 158 additions and 146 deletions
|
@ -1678,12 +1678,21 @@ function furthest_point(pt, points) =
|
||||||
function polygon_area(poly, signed=false) =
|
function polygon_area(poly, signed=false) =
|
||||||
assert(is_path(poly), "Invalid polygon." )
|
assert(is_path(poly), "Invalid polygon." )
|
||||||
len(poly)<3 ? 0 :
|
len(poly)<3 ? 0 :
|
||||||
|
let( cpoly = close_path(simplify_path(poly)) )
|
||||||
len(poly[0])==2
|
len(poly[0])==2
|
||||||
? sum([for(i=[1:1:len(poly)-2]) cross(poly[i]-poly[0],poly[i+1]-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) )
|
: let( plane = plane_from_points(poly) )
|
||||||
plane==undef? undef :
|
plane==undef? undef :
|
||||||
let( n = unit(plane_normal(plane)),
|
let(
|
||||||
total = sum([for(i=[1:1:len(poly)-1]) cross(poly[i]-poly[0],poly[i+1]-poly[0])*n ])/2
|
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);
|
signed ? total : abs(total);
|
||||||
|
|
||||||
|
@ -2082,9 +2091,8 @@ function _split_polygon_at_z(poly, z) =
|
||||||
// polys = A list of 3D polygons to split.
|
// polys = A list of 3D polygons to split.
|
||||||
// xs = A list of scalar X values to split at.
|
// xs = A list of scalar X values to split at.
|
||||||
function split_polygons_at_each_x(polys, xs, _i=0) =
|
function split_polygons_at_each_x(polys, xs, _i=0) =
|
||||||
assert( is_consistent(polys) && is_path(poly[0],dim=3) ,
|
assert( [for (poly=polys) if (!is_path(poly,3)) 1] == [], "Expects list of 3D paths.")
|
||||||
"The input list should contains only 3D polygons." )
|
assert( is_vector(xs), "The split value list should contain only numbers." )
|
||||||
assert( is_finite(xs), "The split value list should contain only numbers." )
|
|
||||||
_i>=len(xs)? polys :
|
_i>=len(xs)? polys :
|
||||||
split_polygons_at_each_x(
|
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.
|
// polys = A list of 3D polygons to split.
|
||||||
// ys = A list of scalar Y values to split at.
|
// ys = A list of scalar Y values to split at.
|
||||||
function split_polygons_at_each_y(polys, ys, _i=0) =
|
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!!!
|
assert( [for (poly=polys) if (!is_path(poly,3)) 1] == [], "Expects list of 3D paths.")
|
||||||
// "The input list should contains only 3D polygons." )
|
assert( is_vector(ys), "The split value list should contain only numbers." )
|
||||||
assert( is_finite(ys) || is_vector(ys), "The split value list should contain only numbers." ) //***
|
|
||||||
_i>=len(ys)? polys :
|
_i>=len(ys)? polys :
|
||||||
split_polygons_at_each_y(
|
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.
|
// polys = A list of 3D polygons to split.
|
||||||
// zs = A list of scalar Z values to split at.
|
// zs = A list of scalar Z values to split at.
|
||||||
function split_polygons_at_each_z(polys, zs, _i=0) =
|
function split_polygons_at_each_z(polys, zs, _i=0) =
|
||||||
assert( is_consistent(polys) && is_path(poly[0],dim=3) ,
|
assert( [for (poly=polys) if (!is_path(poly,3)) 1] == [], "Expects list of 3D paths.")
|
||||||
"The input list should contains only 3D polygons." )
|
assert( is_vector(zs), "The split value list should contain only numbers." )
|
||||||
assert( is_finite(zs), "The split value list should contain only numbers." )
|
|
||||||
_i>=len(zs)? polys :
|
_i>=len(zs)? polys :
|
||||||
split_polygons_at_each_z(
|
split_polygons_at_each_z(
|
||||||
[
|
[
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
//////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|
||||||
BOSL_VERSION = [2,0,479];
|
BOSL_VERSION = [2,0,480];
|
||||||
|
|
||||||
|
|
||||||
// Section: BOSL Library Version Functions
|
// Section: BOSL Library Version Functions
|
||||||
|
|
14
vnf.scad
14
vnf.scad
|
@ -672,8 +672,11 @@ function vnf_validate(vnf, show_warns=true, check_isects=false) =
|
||||||
],
|
],
|
||||||
nonplanars = unique([
|
nonplanars = unique([
|
||||||
for (face = faces) let(
|
for (face = faces) let(
|
||||||
faceverts = [for (k=face) varr[k]]
|
faceverts = [for (k=face) varr[k]],
|
||||||
) if (!coplanar(faceverts)) [
|
area = polygon_area(faceverts)
|
||||||
|
)
|
||||||
|
if (is_num(area) && abs(area) > EPSILON)
|
||||||
|
if (!coplanar(faceverts)) [
|
||||||
"ERROR",
|
"ERROR",
|
||||||
"NONPLANAR",
|
"NONPLANAR",
|
||||||
"Face vertices are not coplanar",
|
"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(
|
if (v!=edge[0] && v!=edge[1]) let(
|
||||||
a = varr[edge[0]],
|
a = varr[edge[0]],
|
||||||
b = varr[v],
|
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)
|
pt = segment_closest_point([a,c],b)
|
||||||
) if (pt == b) [
|
)
|
||||||
|
if (pt == b) [
|
||||||
"ERROR",
|
"ERROR",
|
||||||
"T_JUNCTION",
|
"T_JUNCTION",
|
||||||
"Vertex is mid-edge on another Face",
|
"Vertex is mid-edge on another Face",
|
||||||
|
|
Loading…
Reference in a new issue