Added reverse_polygon() and improved ccw_polygon() and clockwise_polygon()

This commit is contained in:
Revar Desmera 2019-11-17 18:19:55 -08:00
parent 2b95e67cda
commit bb92d788ef
3 changed files with 26 additions and 6 deletions

View file

@ -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]];

View file

@ -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)]));

View file

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