mirror of
https://github.com/revarbat/BOSL2.git
synced 2025-08-25 22:01:06 +02:00
add region centroid capability and consolidate into one centroid
function for polygons, regions and VNFs. Fix bug with anchors for linear_sweep (due to centerpoint issues) Fix intersection anchors for vnfs when anchor vector intersects in a path instead of a single point.
This commit is contained in:
@@ -46,7 +46,7 @@ test_is_polygon_convex();
|
||||
test_polygon_shift();
|
||||
test_reindex_polygon();
|
||||
test_align_polygon();
|
||||
test_polygon_centroid();
|
||||
test_centroid();
|
||||
test_point_in_polygon();
|
||||
test_is_polygon_clockwise();
|
||||
test_clockwise_polygon();
|
||||
@@ -819,15 +819,31 @@ module test_noncollinear_triple() {
|
||||
*test_noncollinear_triple();
|
||||
|
||||
|
||||
module test_polygon_centroid() {
|
||||
module test_centroid() {
|
||||
// polygons
|
||||
$fn = 24;
|
||||
assert_approx(polygon_centroid(circle(d=100)), [0,0]);
|
||||
assert_approx(polygon_centroid(rect([40,60],rounding=10,anchor=LEFT)), [20,0]);
|
||||
assert_approx(polygon_centroid(rect([40,60],rounding=10,anchor=FWD)), [0,30]);
|
||||
assert_approx(centroid(circle(d=100)), [0,0]);
|
||||
assert_approx(centroid(rect([40,60],rounding=10,anchor=LEFT)), [20,0]);
|
||||
assert_approx(centroid(rect([40,60],rounding=10,anchor=FWD)), [0,30]);
|
||||
poly = move([1,2.5,3.1],p=rot([12,49,24], p=path3d(circle(10,$fn=33))));
|
||||
assert_approx(polygon_centroid(poly), [1,2.5,3.1]);
|
||||
assert_approx(centroid(poly), [1,2.5,3.1]);
|
||||
|
||||
// regions
|
||||
R = [square(10), move([5,4],circle(r=3,$fn=32)), right(15,square(7)), move([18,3],circle(r=2,$fn=5))];
|
||||
assert_approx(centroid(R), [9.82836532809, 4.76313546433]);
|
||||
|
||||
// VNFs
|
||||
assert_approx(centroid(cube(100, center=false)), [50,50,50]);
|
||||
assert_approx(centroid(cube(100, center=true)), [0,0,0]);
|
||||
assert_approx(centroid(cube(100, anchor=ALLPOS)), [-50,-50,-50]);
|
||||
assert_approx(centroid(cube(100, anchor=BOT)), [0,0,50]);
|
||||
assert_approx(centroid(cube(100, anchor=TOP)), [0,0,-50]);
|
||||
assert_approx(centroid(sphere(d=100, anchor=CENTER, $fn=36)), [0,0,0]);
|
||||
assert_approx(centroid(sphere(d=100, anchor=BOT, $fn=36)), [0,0,50]);
|
||||
ellipse = xscale(2, p=circle($fn=24, r=3));
|
||||
assert_approx(centroid(path_sweep(pentagon(r=1), path3d(ellipse), closed=true)),[0,0,0]);
|
||||
}
|
||||
*test_polygon_centroid();
|
||||
*test_centroid();
|
||||
|
||||
|
||||
|
||||
|
@@ -78,7 +78,7 @@ module test_exclusive_or() {
|
||||
assert(are_regions_equal(exclusive_or(R9,R8),[[[-5, -5], [-13, -5], [-13, 5], [-5, 5], [-5, 3], [-3, 3], [-3, -3], [-5, -3]], [[-3, -5], [-5, -5], [-5, -13], [5, -13], [5, -5], [3, -5], [3, -3], [-3, -3]], [[-5, 5], [-3, 5], [-3, 3], [3, 3], [3, 5], [5, 5], [5, 13], [-5, 13]], [[3, -3], [3, 3], [5, 3], [5, 5], [13, 5], [13, -5], [5, -5], [5, -3]]],either_winding=true));
|
||||
|
||||
p = turtle(["move",100,"left",144], repeat=4);
|
||||
p2 = move(-polygon_centroid(p),p);
|
||||
p2 = move(-centroid(p),p);
|
||||
p3 = polygon_parts(p2);
|
||||
p4 = exclusive_or(p3,square(51,center=true));
|
||||
|
||||
|
@@ -43,18 +43,6 @@ module test_vnf_from_polygons() {
|
||||
test_vnf_from_polygons();
|
||||
|
||||
|
||||
module test_vnf_centroid() {
|
||||
assert_approx(vnf_centroid(cube(100, center=false)), [50,50,50]);
|
||||
assert_approx(vnf_centroid(cube(100, center=true)), [0,0,0]);
|
||||
assert_approx(vnf_centroid(cube(100, anchor=ALLPOS)), [-50,-50,-50]);
|
||||
assert_approx(vnf_centroid(cube(100, anchor=BOT)), [0,0,50]);
|
||||
assert_approx(vnf_centroid(cube(100, anchor=TOP)), [0,0,-50]);
|
||||
assert_approx(vnf_centroid(sphere(d=100, anchor=CENTER, $fn=36)), [0,0,0]);
|
||||
assert_approx(vnf_centroid(sphere(d=100, anchor=BOT, $fn=36)), [0,0,50]);
|
||||
ellipse = xscale(2, p=circle($fn=24, r=3));
|
||||
assert_approx(vnf_centroid(path_sweep(pentagon(r=1), path3d(ellipse), closed=true)),[0,0,0]);}
|
||||
test_vnf_centroid();
|
||||
|
||||
|
||||
module test_vnf_volume() {
|
||||
assert_approx(vnf_volume(cube(100, center=false)), 1000000);
|
||||
|
Reference in New Issue
Block a user