summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordon bright <hugh.m.bright@gmail.com>2013-03-11 22:23:53 (GMT)
committerdon bright <hugh.m.bright@gmail.com>2013-03-11 22:23:53 (GMT)
commitfc257c93835470181f73d27e1867057d24a43c1e (patch)
tree034944062417cf742d17594cfc72337a1f8b9916 /src
parent1726c26518cdc03cc1aff0438ccf4cdc93806eca (diff)
make resize of flat objects fail in the direction normal to the flat.
also fail on resize to negative size. update tests
Diffstat (limited to 'src')
-rw-r--r--src/CGALEvaluator.cc52
-rw-r--r--src/CGAL_Nef_polyhedron_DxfData.cc4
-rw-r--r--src/cgaladv.cc10
3 files changed, 26 insertions, 40 deletions
diff --git a/src/CGALEvaluator.cc b/src/CGALEvaluator.cc
index 8e72fff..406614f 100644
--- a/src/CGALEvaluator.cc
+++ b/src/CGALEvaluator.cc
@@ -179,23 +179,19 @@ CGAL_Nef_polyhedron CGALEvaluator::applyHull(const CgaladvNode &node)
return N;
}
-/* resize([x,y,z],auto=[x,y,z]|bool)
- This will resize the child object to x,y,z.
- If any of x,y,z is 0, then that dimension is left as-is in the child node.
- If any of x,y,z is 0 and their corresponding 'auto' is true, then
- they are auto-scaled up to match the ratio of the other dimensions (the max)
-
- Example -
- resize([0,2]) cube() will make a cube([1,2,1])
- resize([0,2],auto=[true,false,false]) cube() will make a cube([2,2,1])
- resize([0,2],auto=true) cube() will make a cube([2,2,2])
- resize([0,0,3]) cube() will make a cube([1,1,3])
-*/
CGAL_Nef_polyhedron CGALEvaluator::applyResize(const CgaladvNode &node)
{
- // Based on resize() in Giles Bathgate's RapCAD (but not exactly)
+ // Based on resize() in Giles Bathgate's RapCAD (but not exactly)
CGAL_Nef_polyhedron N;
N = applyToChildren(node, CGE_UNION);
+
+ for (int i=0;i<3;i++) {
+ if (node.newsize[i]<0) {
+ PRINT("WARNING: Cannot resize to sizes less than 0.");
+ return N;
+ }
+ }
+
CGAL_Iso_cuboid_3 bb;
if ( N.dim == 2 ) {
@@ -212,25 +208,21 @@ CGAL_Nef_polyhedron CGALEvaluator::applyResize(const CgaladvNode &node)
scale << 1,1,1;
bbox_size << bb.xmax()-bb.xmin(), bb.ymax()-bb.ymin(), bb.zmax()-bb.zmin();
for (int i=0;i<3;i++) {
- if (bbox_size[i]==NT(0)) bbox_size[i]=NT(1);
- if (node.newsize[i]) scale[i] = NT(node.newsize[i]) / bbox_size[i];
+ if (node.newsize[i]) {
+ if (bbox_size[i]==NT(0)) {
+ PRINT("WARNING: Cannot resize in direction normal to flat object");
+ return N;
+ }
+ else {
+ scale[i] = NT(node.newsize[i]) / bbox_size[i];
+ }
+ }
}
NT autoscale = scale.maxCoeff();
- for (int i=0;i<3;i++)
- if (node.autosize[i])
- scale[i] = autoscale;
- for (int i=0;i<3;i++)
- if (scale[i]<NT(0)) {
- PRINT("WARNING: Cannot resize to a new size less than 0.");
- return N;
- }
- std::cout << autoscale << " autoscale\n";
- std::cout << node.autosize[0] << ",";
- std::cout << node.autosize[1] << ",";
- std::cout << node.autosize[2] << " node autosize \n";
- std::cout << scale[0] << ",";
- std::cout << scale[1] << ",";
- std::cout << scale[2] << " scalev \n";
+ for (int i=0;i<3;i++) {
+ if (node.autosize[i]) scale[i] = autoscale;
+ }
+
Eigen::Matrix4d t;
t << CGAL::to_double(scale[0]), 0, 0, 0,
0, CGAL::to_double(scale[1]), 0, 0,
diff --git a/src/CGAL_Nef_polyhedron_DxfData.cc b/src/CGAL_Nef_polyhedron_DxfData.cc
index 8539e0e..f7ff7f3 100644
--- a/src/CGAL_Nef_polyhedron_DxfData.cc
+++ b/src/CGAL_Nef_polyhedron_DxfData.cc
@@ -96,10 +96,6 @@ std::string CGAL_Nef_polyhedron::dump() const
void CGAL_Nef_polyhedron::transform( const Transform3d &matrix )
{
- std::cout << matrix(0,0) << "," << matrix(1,0) << "," << matrix(2,0) << "," << matrix(3,0) << "\n";
- std::cout << matrix(0,1) << "," << matrix(1,1) << "," << matrix(2,1) << "," << matrix(3,1) << "\n";
- std::cout << matrix(0,2) << "," << matrix(1,2) << "," << matrix(2,2) << "," << matrix(3,2) << "\n";
- std::cout << matrix(0,3) << "," << matrix(1,3) << "," << matrix(2,3) << "," << matrix(3,3) << "\n";
if (!this->isNull()) {
if (this->dim == 2) {
// Unfortunately CGAL provides no transform method for CGAL_Nef_polyhedron2
diff --git a/src/cgaladv.cc b/src/cgaladv.cc
index fb0bfaf..a4cb5ec 100644
--- a/src/cgaladv.cc
+++ b/src/cgaladv.cc
@@ -97,8 +97,6 @@ AbstractNode *CgaladvModule::evaluate(const Context *ctx, const ModuleInstantiat
if ( va.size() >= 1 ) node->autosize[0] = va[0].toBool();
if ( va.size() >= 2 ) node->autosize[1] = va[1].toBool();
if ( va.size() >= 3 ) node->autosize[2] = va[2].toBool();
- std::cout << "adv.cc: " << va << "\n";
- std::cout << "adv.cc as: " << node->autosize << "\n";
}
else if ( autosize.type() == Value::BOOL ) {
node->autosize << true, true, true;
@@ -167,10 +165,10 @@ std::string CgaladvNode::toString() const
break;
case RESIZE:
stream << "(newsize = ["
- << this->newsize[0] << ","
- << this->newsize[1] << ","
- << this->newsize[2] << "]"
- << ", auto = " << this->autosize << ")";
+ << this->newsize[0] << "," << this->newsize[1] << "," << this->newsize[2] << "]"
+ << ", auto = ["
+ << this->autosize[0] << "," << this->autosize[1] << "," << this->autosize[2] << "]"
+ << ")";
break;
default:
assert(false);
contact: Jan Huwald // Impressum