mirror of
https://github.com/BelfrySCAD/BOSL2.git
synced 2024-12-29 16:29:40 +00:00
Added reverse_polygon() and improved ccw_polygon() and clockwise_polygon()
This commit is contained in:
parent
2b95e67cda
commit
bb92d788ef
3 changed files with 26 additions and 6 deletions
|
@ -1230,7 +1230,7 @@ function polygon_is_clockwise(path) =
|
|||
// Description:
|
||||
// Given a polygon path, returns the clockwise winding version of that path.
|
||||
function clockwise_polygon(path) =
|
||||
polygon_is_clockwise(path)? path : reverse(path);
|
||||
polygon_is_clockwise(path)? path : reverse_polygon(path);
|
||||
|
||||
|
||||
// Function: ccw_polygon()
|
||||
|
@ -1239,7 +1239,16 @@ function clockwise_polygon(path) =
|
|||
// Description:
|
||||
// Given a polygon path, returns the counter-clockwise winding version of that path.
|
||||
function ccw_polygon(path) =
|
||||
polygon_is_clockwise(path)? reverse(path) : path;
|
||||
polygon_is_clockwise(path)? reverse_polygon(path) : path;
|
||||
|
||||
|
||||
// Function: reverse_polygon()
|
||||
// Usage:
|
||||
// reverse_polygon(poly)
|
||||
// Description:
|
||||
// Reverses a polygon's winding direction, while still using the same start point.
|
||||
function reverse_polygon(poly) =
|
||||
let(lp=len(poly)) [for (i=idx(poly)) poly[(lp-i)%lp]];
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -655,20 +655,31 @@ test_polygon_is_clockwise();
|
|||
|
||||
module test_clockwise_polygon() {
|
||||
path = circle(d=100);
|
||||
rpath = concat([path[0]], reverse(select(path,1,-1)));
|
||||
assert(clockwise_polygon(path) == path);
|
||||
assert(clockwise_polygon(reverse(path)) == path);
|
||||
assert(clockwise_polygon(rpath) == path);
|
||||
}
|
||||
test_clockwise_polygon();
|
||||
|
||||
|
||||
module test_ccw_polygon() {
|
||||
path = circle(d=100);
|
||||
assert(ccw_polygon(path) == reverse(path));
|
||||
assert(ccw_polygon(reverse(path)) == reverse(path));
|
||||
rpath = concat([path[0]], reverse(select(path,1,-1)));
|
||||
assert(ccw_polygon(path) == rpath);
|
||||
assert(ccw_polygon(rpath) == rpath);
|
||||
}
|
||||
test_ccw_polygon();
|
||||
|
||||
|
||||
module test_reverse_polygon() {
|
||||
path = circle(d=100);
|
||||
rpath = concat([path[0]], reverse(select(path,1,-1)));
|
||||
assert(reverse_polygon(path) == rpath);
|
||||
assert(reverse_polygon(rpath) == path);
|
||||
}
|
||||
test_reverse_polygon();
|
||||
|
||||
|
||||
module test_is_region() {
|
||||
assert(is_region([circle(d=10),square(10)]));
|
||||
assert(is_region([circle(d=10),square(10),circle(d=50)]));
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
BOSL_VERSION = [2,0,41];
|
||||
BOSL_VERSION = [2,0,42];
|
||||
|
||||
|
||||
// Section: BOSL Library Version Functions
|
||||
|
|
Loading…
Reference in a new issue