From e4dd4da8182ce2a06a7709ab015dd0e541becd1a Mon Sep 17 00:00:00 2001 From: Marius Kintel Date: Mon, 19 May 2014 11:49:41 -0400 Subject: [PATCH] #791 Handle twist=0 as no twist --- src/linearextrude.cc | 14 ++++++----- ...near_extrude-scale-zero-tests-expected.csg | 24 +++++++++---------- .../dumptest/use-tests-expected.csg | 4 ++-- 3 files changed, 22 insertions(+), 20 deletions(-) diff --git a/src/linearextrude.cc b/src/linearextrude.cc index d2d798be..235c45ea 100644 --- a/src/linearextrude.cc +++ b/src/linearextrude.cc @@ -110,13 +110,15 @@ AbstractNode *LinearExtrudeModule::instantiate(const Context *ctx, const ModuleI if (twist.type() == Value::NUMBER) { node->twist = twist.toDouble(); - if (slices.type() == Value::NUMBER) { - node->slices = (int)slices.toDouble(); - } else { - node->slices = (int)fmax(2, fabs(Calc::get_fragments_from_r(node->height, - node->fn, node->fs, node->fa) * node->twist / 360)); + if (node->twist != 0.0) { + if (slices.type() == Value::NUMBER) { + node->slices = (int)slices.toDouble(); + } else { + node->slices = (int)fmax(2, fabs(Calc::get_fragments_from_r(node->height, + node->fn, node->fs, node->fa) * node->twist / 360)); + } + node->has_twist = true; } - node->has_twist = true; } if (node->filename.empty()) { diff --git a/tests/regression/dumptest/linear_extrude-scale-zero-tests-expected.csg b/tests/regression/dumptest/linear_extrude-scale-zero-tests-expected.csg index e4d24305..b1148d4f 100644 --- a/tests/regression/dumptest/linear_extrude-scale-zero-tests-expected.csg +++ b/tests/regression/dumptest/linear_extrude-scale-zero-tests-expected.csg @@ -2,7 +2,7 @@ group() { multmatrix([[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]]) { group() { multmatrix([[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]]) { - linear_extrude(height = 3, center = false, convexity = 1, twist = 0, slices = 20, scale = [0, 1], $fn = 0, $fa = 12, $fs = 2) { + linear_extrude(height = 3, center = false, convexity = 1, scale = [0, 1], $fn = 0, $fa = 12, $fs = 2) { difference() { square(size = [2, 2], center = true); square(size = [1, 1], center = true); @@ -10,7 +10,7 @@ group() { } } multmatrix([[1, 0, 0, 4], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]]) { - linear_extrude(height = 3, center = false, convexity = 1, twist = 0, slices = 20, scale = [0, 1], $fn = 0, $fa = 12, $fs = 2) { + linear_extrude(height = 3, center = false, convexity = 1, scale = [0, 1], $fn = 0, $fa = 12, $fs = 2) { multmatrix([[1, 0, 0, 1], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]]) { square(size = [1, 1], center = true); } @@ -20,7 +20,7 @@ group() { } } multmatrix([[1, 0, 0, 8], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]]) { - linear_extrude(height = 3, center = false, convexity = 1, twist = 0, slices = 20, scale = [0, 1], $fn = 0, $fa = 12, $fs = 2) { + linear_extrude(height = 3, center = false, convexity = 1, scale = [0, 1], $fn = 0, $fa = 12, $fs = 2) { multmatrix([[1, 0, 0, 0.5], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]]) { square(size = [1, 1], center = false); } @@ -30,7 +30,7 @@ group() { } } multmatrix([[1, 0, 0, 12], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]]) { - linear_extrude(height = 3, center = false, convexity = 1, twist = 0, slices = 20, scale = [0, 1], $fn = 0, $fa = 12, $fs = 2) { + linear_extrude(height = 3, center = false, convexity = 1, scale = [0, 1], $fn = 0, $fa = 12, $fs = 2) { difference() { square(size = [2, 2], center = true); multmatrix([[1, 0, 0, -0.5], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]]) { @@ -44,7 +44,7 @@ group() { multmatrix([[1, 0, 0, 0], [0, 1, 0, 3], [0, 0, 1, 0], [0, 0, 0, 1]]) { group() { multmatrix([[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]]) { - linear_extrude(height = 3, center = false, convexity = 1, twist = 0, slices = 20, scale = [1, 0], $fn = 0, $fa = 12, $fs = 2) { + linear_extrude(height = 3, center = false, convexity = 1, scale = [1, 0], $fn = 0, $fa = 12, $fs = 2) { difference() { square(size = [2, 2], center = true); square(size = [1, 1], center = true); @@ -52,7 +52,7 @@ group() { } } multmatrix([[1, 0, 0, 4], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]]) { - linear_extrude(height = 3, center = false, convexity = 1, twist = 0, slices = 20, scale = [1, 0], $fn = 0, $fa = 12, $fs = 2) { + linear_extrude(height = 3, center = false, convexity = 1, scale = [1, 0], $fn = 0, $fa = 12, $fs = 2) { multmatrix([[1, 0, 0, 1], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]]) { square(size = [1, 1], center = true); } @@ -62,7 +62,7 @@ group() { } } multmatrix([[1, 0, 0, 8], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]]) { - linear_extrude(height = 3, center = false, convexity = 1, twist = 0, slices = 20, scale = [1, 0], $fn = 0, $fa = 12, $fs = 2) { + linear_extrude(height = 3, center = false, convexity = 1, scale = [1, 0], $fn = 0, $fa = 12, $fs = 2) { multmatrix([[1, 0, 0, 0.5], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]]) { square(size = [1, 1], center = false); } @@ -72,7 +72,7 @@ group() { } } multmatrix([[1, 0, 0, 12], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]]) { - linear_extrude(height = 3, center = false, convexity = 1, twist = 0, slices = 20, scale = [1, 0], $fn = 0, $fa = 12, $fs = 2) { + linear_extrude(height = 3, center = false, convexity = 1, scale = [1, 0], $fn = 0, $fa = 12, $fs = 2) { difference() { square(size = [2, 2], center = true); multmatrix([[1, 0, 0, -0.5], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]]) { @@ -86,7 +86,7 @@ group() { multmatrix([[1, 0, 0, 0], [0, 1, 0, 6], [0, 0, 1, 0], [0, 0, 0, 1]]) { group() { multmatrix([[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]]) { - linear_extrude(height = 3, center = false, convexity = 1, twist = 0, slices = 20, scale = [0, 0], $fn = 0, $fa = 12, $fs = 2) { + linear_extrude(height = 3, center = false, convexity = 1, scale = [0, 0], $fn = 0, $fa = 12, $fs = 2) { difference() { square(size = [2, 2], center = true); square(size = [1, 1], center = true); @@ -94,7 +94,7 @@ group() { } } multmatrix([[1, 0, 0, 4], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]]) { - linear_extrude(height = 3, center = false, convexity = 1, twist = 0, slices = 20, scale = [0, 0], $fn = 0, $fa = 12, $fs = 2) { + linear_extrude(height = 3, center = false, convexity = 1, scale = [0, 0], $fn = 0, $fa = 12, $fs = 2) { multmatrix([[1, 0, 0, 1], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]]) { square(size = [1, 1], center = true); } @@ -104,7 +104,7 @@ group() { } } multmatrix([[1, 0, 0, 8], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]]) { - linear_extrude(height = 3, center = false, convexity = 1, twist = 0, slices = 20, scale = [0, 0], $fn = 0, $fa = 12, $fs = 2) { + linear_extrude(height = 3, center = false, convexity = 1, scale = [0, 0], $fn = 0, $fa = 12, $fs = 2) { multmatrix([[1, 0, 0, 0.5], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]]) { square(size = [1, 1], center = false); } @@ -114,7 +114,7 @@ group() { } } multmatrix([[1, 0, 0, 12], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]]) { - linear_extrude(height = 3, center = false, convexity = 1, twist = 0, slices = 20, scale = [0, 0], $fn = 0, $fa = 12, $fs = 2) { + linear_extrude(height = 3, center = false, convexity = 1, scale = [0, 0], $fn = 0, $fa = 12, $fs = 2) { difference() { square(size = [2, 2], center = true); multmatrix([[1, 0, 0, -0.5], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]]) { diff --git a/tests/regression/dumptest/use-tests-expected.csg b/tests/regression/dumptest/use-tests-expected.csg index c47fa742..1535abe7 100644 --- a/tests/regression/dumptest/use-tests-expected.csg +++ b/tests/regression/dumptest/use-tests-expected.csg @@ -40,10 +40,10 @@ group() { group() { multmatrix([[0, 0, 1, 0], [0, 1, 0, 0], [-1, 0, 0, 0], [0, 0, 0, 1]]) { union() { - linear_extrude(height = 1.5, center = true, convexity = 1, twist = 0, slices = 2, scale = [1, 1], $fn = 0, $fa = 12, $fs = 2) { + linear_extrude(height = 1.5, center = true, convexity = 1, scale = [1, 1], $fn = 0, $fa = 12, $fs = 2) { circle($fn = 30, $fa = 12, $fs = 2, r = 0.3); } - linear_extrude(height = 1.5, center = true, convexity = 1, twist = 0, slices = 2, scale = [1, 1], $fn = 0, $fa = 12, $fs = 2) { + linear_extrude(height = 1.5, center = true, convexity = 1, scale = [1, 1], $fn = 0, $fa = 12, $fs = 2) { projection(cut = false, convexity = 0) { multmatrix([[0, 0, -1, 0], [0, 1, 0, 0], [1, 0, 0, 0], [0, 0, 0, 1]]) { multmatrix([[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0.31819805153], [0, 0, 0, 1]]) {