diff options
-rw-r--r-- | src/CGALEvaluator.cc | 10 | ||||
-rw-r--r-- | src/cgaladv.cc | 2 | ||||
-rw-r--r-- | testdata/scad/features/resize-tests.scad | 31 |
3 files changed, 29 insertions, 14 deletions
diff --git a/src/CGALEvaluator.cc b/src/CGALEvaluator.cc index 8e1b5eb..adaec4a 100644 --- a/src/CGALEvaluator.cc +++ b/src/CGALEvaluator.cc @@ -215,20 +215,24 @@ CGAL_Nef_polyhedron CGALEvaluator::applyResize(const CgaladvNode &node) bbox_size.push_back( bb.xmax()-bb.xmin() ); bbox_size.push_back( bb.ymax()-bb.ymin() ); bbox_size.push_back( bb.zmax()-bb.zmin() ); + int newsizemax_index = 0; for (int i=0;i<3;i++) { if (node.newsize[i]) { if (bbox_size[i]==NT3(0)) { - PRINT("WARNING: Cannot resize in direction normal to flat object"); + PRINT("WARNING: Resize in direction normal to flat object is not implemented"); return N; } else { scale[i] = NT3(node.newsize[i]) / bbox_size[i]; } + if ( node.newsize[i] > node.newsize[newsizemax_index] ) + newsizemax_index = i; } } - NT3 autoscale = std::max( scale[0], std::max( scale[1], scale[2] )); + NT3 autoscale = NT3( node.newsize[ newsizemax_index ] ) / bbox_size[ newsizemax_index ]; for (int i=0;i<3;i++) { - if (node.autosize[i]) scale[i] = autoscale; + if (node.autosize[i] && node.newsize[i]==0) + scale[i] = autoscale; } Eigen::Matrix4d t; diff --git a/src/cgaladv.cc b/src/cgaladv.cc index ee3d657..8fd030a 100644 --- a/src/cgaladv.cc +++ b/src/cgaladv.cc @@ -98,7 +98,7 @@ AbstractNode *CgaladvModule::instantiate(const Context *ctx, const ModuleInstant if ( va.size() >= 3 ) node->autosize[2] = va[2].toBool(); } else if ( autosize.type() == Value::BOOL ) { - node->autosize << true, true, true; + node->autosize << autosize.toBool(),autosize.toBool(),autosize.toBool(); } } diff --git a/testdata/scad/features/resize-tests.scad b/testdata/scad/features/resize-tests.scad index 659848b..3150e86 100644 --- a/testdata/scad/features/resize-tests.scad +++ b/testdata/scad/features/resize-tests.scad @@ -4,6 +4,7 @@ // and should be inscribed in gold row in 'top' view // back row (green) = should be all cubes auto-scaled up // back top (purple) = uses 'auto' feature +// lime green = 'auto' feature where we 'shrink' // pink = recursive resize, negative, <1, wrong syntax, etc $fn=8; @@ -60,22 +61,32 @@ translate([10,90,0]) resize([5,6,7],auto=true) cube(); color("purple"){ translate([10, 0, 10]) cube(); -translate([10,10,10]) resize([5,0,0],auto=[true,true,false]) cube(); +translate([10,10,10]) resize([5,0,0],auto=[true,true,false]) cube(); translate([10,20,10]) resize([6,0,0],auto=[true,true,true]) cube(); translate([13.5,33.5,10]) resize([7,0,0],auto=[true,false,false]) sphere(); translate([10,40,10]) resize([6,0,0],auto=[true,false,true]) cube(); translate([10,50,10]) resize([7,0,7],auto=[false,true,true]) cube(); -translate([13.5,63.5,10]) resize([7,0,0],auto=[false,true,false]) sphere(); translate([10,70,10]) resize([8,0,0],auto=[false,false,false]) cube(); +translate([13.5,63.5,10]) resize([7,0,0],auto=[false,true,false]) sphere(); +translate([10,70,10]) resize([8,0,0],auto=[false,false,false]) cube(); translate([10,80,10]) resize([9,0,0],auto=[false,false,true]) cube(); translate([10,90,10]) resize([0,0,7],auto=[true,true,false]) cube(); } color("pink"){ -translate([10,0,-10]) resize([4,4,4]) resize([5000,100,1000]) cube(); -translate([10,10,-10]) resize([-5,0,0]) cube(); -translate([10,20,-10]) resize([-5,0,0],auto=3) cube(); -translate([10,30,-10]) resize(-5,0,0,auto=3) cube(); -translate([10,40,-10]) resize(5,0,0) cube(); -translate([10,50,-10]) resize([0.5,0,7]) cube([0.5,1,1000]); -translate([10,60,-10]) resize([0,0,0.5]) cube([6,6,10000000000]); -}
\ No newline at end of file +translate([0 , 0,-10]) resize([4,4,4]) resize([5000,100,1000]) cube(); +translate([10,0,-10]) resize([-5,0,0]) cube(); +translate([20,0,-10]) resize([-5,0,0],auto=3) cube(); +translate([30,0,-10]) resize(-5,0,0,auto=3) cube(); +translate([40,0,-10]) resize(5,0,0) cube(); +translate([50,0,-10]) resize([0.5,0,7]) cube([0.5,1,1000]); +translate([60,0,-10]) resize([0,0,0.5]) cube([6,6,10000000000]); +} + +color("lime"){ +translate([20,0,0]) resize([5,0,0],auto=[true,true,false]) cube(9); +translate([30,0,0]) resize([6,0,0],auto=[true,true,true]) cube(9); +translate([40,0,0]) resize([6,0,0],auto=[true,false,true]) cube(9); +translate([50,0,0]) resize([5,0,20],auto=[false,true,true]) cube(9); +translate([60,0,0]) resize([0,0,7],auto=[false,false,true]) cube(9); +translate([70,0,0]) resize([6,0,0],auto=[true,true,false]) cube(9); +} |