mirror of
https://github.com/revarbat/BOSL2.git
synced 2025-01-16 13:50:23 +01:00
moved some functions around and renamed
This commit is contained in:
parent
9b7c3acfd7
commit
60c3a99e90
50
paths.scad
50
paths.scad
@ -125,6 +125,56 @@ function path_merge_collinear(path, closed=false, eps=EPSILON) =
|
||||
) [for (i=indices) path[i]];
|
||||
|
||||
|
||||
// Function: are_polygons_equal()
|
||||
// Usage:
|
||||
// b = are_polygons_equal(poly1, poly2, [eps])
|
||||
// Description:
|
||||
// Returns true if poly1 and poly2 are the same polongs
|
||||
// within given epsilon tolerance.
|
||||
// Arguments:
|
||||
// poly1 = first polygon
|
||||
// poly2 = second polygon
|
||||
// eps = tolerance for comparison
|
||||
// Example(NORENDER):
|
||||
// are_polygons_equal(pentagon(r=4),
|
||||
// rot(360/5, p=pentagon(r=4))); // returns true
|
||||
// are_polygons_equal(pentagon(r=4),
|
||||
// rot(90, p=pentagon(r=4))); // returns false
|
||||
function are_polygons_equal(poly1, poly2, eps=EPSILON) =
|
||||
let(
|
||||
poly1 = cleanup_path(poly1),
|
||||
poly2 = cleanup_path(poly2),
|
||||
l1 = len(poly1),
|
||||
l2 = len(poly2)
|
||||
) l1 != l2 ? false :
|
||||
let( maybes = find_first_match(poly1[0], poly2, eps=eps, all=true) )
|
||||
maybes == []? false :
|
||||
[for (i=maybes) if (_are_polygons_equal(poly1, poly2, eps, i)) 1] != [];
|
||||
|
||||
function _are_polygons_equal(poly1, poly2, eps, st) =
|
||||
max([for(d=poly1-select(poly2,st,st-1)) d*d])<eps*eps;
|
||||
|
||||
|
||||
// Function: is_polygon_in_list()
|
||||
// Topics: Polygons, Comparators
|
||||
// See Also: are_polygons_equal(), are_regions_equal()
|
||||
// Usage:
|
||||
// bool = is_polygon_in_list(poly, polys);
|
||||
// Description:
|
||||
// Returns true if one of the polygons in `polys` is equivalent to the polygon `poly`.
|
||||
// Arguments:
|
||||
// poly = The polygon to search for.
|
||||
// polys = The list of polygons to look for the polygon in.
|
||||
function is_polygon_in_list(poly, polys) =
|
||||
__is_polygon_in_list(poly, polys, 0);
|
||||
|
||||
function __is_polygon_in_list(poly, polys, i) =
|
||||
i >= len(polys)? false :
|
||||
are_polygons_equal(poly, polys[i])? true :
|
||||
__is_polygon_in_list(poly, polys, i+1);
|
||||
|
||||
|
||||
|
||||
// Section: Path length calculation
|
||||
|
||||
|
||||
|
77
regions.scad
77
regions.scad
@ -170,74 +170,9 @@ function is_region_simple(region, eps=EPSILON) =
|
||||
] ==[];
|
||||
|
||||
|
||||
|
||||
function approx_sign(x) = approx(x,0) ? 0 : sign(x);
|
||||
|
||||
|
||||
function do_segments_intersect(s1,s2) =
|
||||
let(
|
||||
a1=cross(s1[1]-s1[0], s2[0]-s1[1]),
|
||||
a2=cross(s1[1]-s1[0], s2[1]-s1[1]),
|
||||
a3=cross(s2[1]-s2[0], s1[0]-s2[1]),
|
||||
a4=cross(s2[1]-s2[0], s1[1]-s2[1])
|
||||
)
|
||||
approx_sign(a1)!=approx_sign(a2) && approx_sign(a3)!=approx_sign(a4);
|
||||
|
||||
// note that parallel intersecting lines seem to have all the a's equal approx to zero
|
||||
|
||||
|
||||
// Function: polygons_equal()
|
||||
// Function: are_regions_equal()
|
||||
// Usage:
|
||||
// b = polygons_equal(poly1, poly2, [eps])
|
||||
// Description:
|
||||
// Returns true if poly1 and poly2 are the same polongs
|
||||
// within given epsilon tolerance.
|
||||
// Arguments:
|
||||
// poly1 = first polygon
|
||||
// poly2 = second polygon
|
||||
// eps = tolerance for comparison
|
||||
// Example(NORENDER):
|
||||
// polygons_equal(pentagon(r=4),
|
||||
// rot(360/5, p=pentagon(r=4))); // returns true
|
||||
// polygons_equal(pentagon(r=4),
|
||||
// rot(90, p=pentagon(r=4))); // returns false
|
||||
function polygons_equal(poly1, poly2, eps=EPSILON) =
|
||||
let(
|
||||
poly1 = cleanup_path(poly1),
|
||||
poly2 = cleanup_path(poly2),
|
||||
l1 = len(poly1),
|
||||
l2 = len(poly2)
|
||||
) l1 != l2 ? false :
|
||||
let( maybes = find_first_match(poly1[0], poly2, eps=eps, all=true) )
|
||||
maybes == []? false :
|
||||
[for (i=maybes) if (__polygons_equal(poly1, poly2, eps, i)) 1] != [];
|
||||
|
||||
function __polygons_equal(poly1, poly2, eps, st) =
|
||||
max([for(d=poly1-select(poly2,st,st-1)) d*d])<eps*eps;
|
||||
|
||||
|
||||
// Function: is_polygon_in_list()
|
||||
// Topics: Polygons, Comparators
|
||||
// See Also: polygons_equal(), regions_equal()
|
||||
// Usage:
|
||||
// bool = is_polygon_in_list(poly, polys);
|
||||
// Description:
|
||||
// Returns true if one of the polygons in `polys` is equivalent to the polygon `poly`.
|
||||
// Arguments:
|
||||
// poly = The polygon to search for.
|
||||
// polys = The list of polygons to look for the polygon in.
|
||||
function is_polygon_in_list(poly, polys) =
|
||||
__is_polygon_in_list(poly, polys, 0);
|
||||
|
||||
function __is_polygon_in_list(poly, polys, i) =
|
||||
i >= len(polys)? false :
|
||||
polygons_equal(poly, polys[i])? true :
|
||||
__is_polygon_in_list(poly, polys, i+1);
|
||||
|
||||
|
||||
// Function: regions_equal()
|
||||
// Usage:
|
||||
// b = regions_equal(region1, region2, [eps])
|
||||
// b = are_regions_equal(region1, region2, [eps])
|
||||
// Description:
|
||||
// Returns true if the components of region1 and region2 are the same polygons (in any order)
|
||||
// within given epsilon tolerance.
|
||||
@ -245,15 +180,15 @@ function __is_polygon_in_list(poly, polys, i) =
|
||||
// region1 = first region
|
||||
// region2 = second region
|
||||
// eps = tolerance for comparison
|
||||
function regions_equal(region1, region2) =
|
||||
function are_regions_equal(region1, region2) =
|
||||
assert(is_region(region1) && is_region(region2))
|
||||
len(region1) != len(region2)? false :
|
||||
__regions_equal(region1, region2, 0);
|
||||
__are_regions_equal(region1, region2, 0);
|
||||
|
||||
function __regions_equal(region1, region2, i) =
|
||||
function __are_regions_equal(region1, region2, i) =
|
||||
i >= len(region1)? true :
|
||||
!is_polygon_in_list(region1[i], region2)? false :
|
||||
__regions_equal(region1, region2, i+1);
|
||||
__are_regions_equal(region1, region2, i+1);
|
||||
|
||||
|
||||
/// Internal Function: _path_region_intersections()
|
||||
|
@ -910,8 +910,8 @@ function path_sweep(shape, path, method="incremental", normal, closed=false, twi
|
||||
: let( rshape = is_path(shape) ? [path3d(shape)]
|
||||
: [for(s=shape) path3d(s)]
|
||||
)
|
||||
regions_equal(apply(transform_list[0], rshape),
|
||||
apply(transform_list[L], rshape)),
|
||||
are_regions_equal(apply(transform_list[0], rshape),
|
||||
apply(transform_list[L], rshape)),
|
||||
dummy = ends_match ? 0 : echo("WARNING: ***** The points do not match when closing the model *****")
|
||||
)
|
||||
transforms ? transform_list : sweep(is_path(shape)?clockwise_polygon(shape):shape, transform_list, closed=false, caps=fullcaps,style=style);
|
||||
|
4
vnf.scad
4
vnf.scad
@ -10,13 +10,15 @@
|
||||
|
||||
|
||||
// Section: Creating Polyhedrons with VNF Structures
|
||||
|
||||
// VNF stands for "Vertices'N'Faces". VNF structures are 2-item lists, `[VERTICES,FACES]` where the
|
||||
// first item is a list of vertex points, and the second is a list of face indices into the vertex
|
||||
// list. Each VNF is self contained, with face indices referring only to its own vertex list.
|
||||
// You can construct a `polyhedron()` in parts by describing each part in a self-contained VNF, then
|
||||
// merge the various VNFs to get the completed polyhedron vertex list and faces.
|
||||
|
||||
// Constant: EMPTY_VNF
|
||||
// Description:
|
||||
// The empty VNF data structure. Equal to `[[],[]]`.
|
||||
EMPTY_VNF = [[],[]]; // The standard empty VNF with no vertices or faces.
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user