T
Trygon
Thu, Aug 6, 2015 7:41 AM
Question 1
Is it acceptable to omit the curly braces after if and for statements if
there is only one child object?
Question 2
Should union() always be specified or is it OK to rely on implicit union
operations?
// example 1
if(true) cube(20);
// example 2
difference(){
translate([0,0,0]) {cube(30,center=true);cube(30);}
sphere(r=18);
// example 3 - combining 1 & 2
if(true) translate([10,0,0]) {cube(30,center=true);cube(30);}
--
View this message in context: http://forum.openscad.org/Syntax-Query-tp13457.html
Sent from the OpenSCAD mailing list archive at Nabble.com.
Question 1
Is it acceptable to omit the curly braces after if and for statements if
there is only one child object?
Question 2
Should union() always be specified or is it OK to rely on implicit union
operations?
// example 1
if(true) cube(20);
// example 2
difference(){
translate([0,0,0]) {cube(30,center=true);cube(30);}
sphere(r=18);
// example 3 - combining 1 & 2
if(true) translate([10,0,0]) {cube(30,center=true);cube(30);}
--
View this message in context: http://forum.openscad.org/Syntax-Query-tp13457.html
Sent from the OpenSCAD mailing list archive at Nabble.com.
M
MichaelAtOz
Thu, Aug 6, 2015 9:15 AM
Q1. Yes. Note it is often good to use round braces in the if expression, as
you have. e.g.
if (thisBooleanVariable) cube(); // in this exact case without () you get an
error
else sphere();
Q2.
implicit union() is only on the top level of the main program or a module
AFAIK.
using {} without a union(), in your ex. 2&3, can be problematic if it
contains geometry.
I think {} turns into group{} (not documented), I find it is inconsistent.
Don't use it.
Unless specifically shown otherwise above, my contribution is in the Public Domain; To the extent possible under law, I have waived all copyright and related or neighbouring rights to this work. This work is published globally via the internet. :) Inclusion of works of previous authors is not included in the above.
View this message in context: http://forum.openscad.org/Syntax-Query-tp13457p13458.html
Sent from the OpenSCAD mailing list archive at Nabble.com.
Q1. Yes. Note it is often good to use round braces in the if expression, as
you have. e.g.
if (thisBooleanVariable) cube(); // in this exact case without () you get an
error
else sphere();
Q2.
implicit union() is only on the top level of the main program or a module
AFAIK.
using {} without a union(), in your ex. 2&3, can be problematic if it
contains geometry.
I think {} turns into group{} (not documented), I find it is inconsistent.
Don't use it.
-----
Unless specifically shown otherwise above, my contribution is in the Public Domain; To the extent possible under law, I have waived all copyright and related or neighbouring rights to this work. This work is published globally via the internet. :) Inclusion of works of previous authors is not included in the above.
The TPP is no simple “trade agreement.” Fight it! http://www.ourfairdeal.org/
--
View this message in context: http://forum.openscad.org/Syntax-Query-tp13457p13458.html
Sent from the OpenSCAD mailing list archive at Nabble.com.
B
bobc
Thu, Aug 6, 2015 12:28 PM
Q1) round braces around the "if" expression are not just a good idea, they
are mandatory! :)
Q2) a statement such as translate () {...} used to create a group is fine,
but will perform implicit union. I normally use group() in that sort of
case, but group() and union() are equivalent.
"{A; B;}" does not become "group() {A;B;}" , it becomes "A; B;". Probably
not what is desired.
viz
difference ()
{
{ cube(); sphere(); }
cube();
}
=> CSG Tree
group() {
difference() {
cube(size = [1, 1, 1], center = false);
sphere($fn = 0, $fa = 12, $fs = 2, r = 1);
cube(size = [1, 1, 1], center = false);
}
}
There is another quirk in the syntax I noticed:
cube () { cube(); }
compiles and renders without error/warning, but the second cube is ignored.
--
View this message in context: http://forum.openscad.org/Syntax-Query-tp13457p13459.html
Sent from the OpenSCAD mailing list archive at Nabble.com.
Q1) round braces around the "if" expression are not just a good idea, they
are mandatory! :)
Q2) a statement such as translate () {...} used to create a group is fine,
but *will* perform implicit union. I normally use group() in that sort of
case, but group() and union() are equivalent.
"{A; B;}" does not become "group() {A;B;}" , it becomes "A; B;". Probably
not what is desired.
viz
difference ()
{
{ cube(); sphere(); }
cube();
}
=> CSG Tree
group() {
difference() {
cube(size = [1, 1, 1], center = false);
sphere($fn = 0, $fa = 12, $fs = 2, r = 1);
cube(size = [1, 1, 1], center = false);
}
}
There is another quirk in the syntax I noticed:
cube () { cube(); }
compiles and renders without error/warning, but the second cube is ignored.
--
View this message in context: http://forum.openscad.org/Syntax-Query-tp13457p13459.html
Sent from the OpenSCAD mailing list archive at Nabble.com.
JL
Jean-Paul Louis
Thu, Aug 6, 2015 4:00 PM
Bob,
Please do not confuse a beginner. You did not respond to his Q1.
He asked about the “{}” around a single statement after an if() definition,
and you responded about the “()” of the test itself.
Just my humble $0.02,
Jean-Paul
AC9GH
On Aug 6, 2015, at 8:28 AM, bobc bobcousins42@googlemail.com wrote:
Q1) round braces around the "if" expression are not just a good idea, they
are mandatory! :)
Q2) a statement such as translate () {...} used to create a group is fine,
but will perform implicit union. I normally use group() in that sort of
case, but group() and union() are equivalent.
"{A; B;}" does not become "group() {A;B;}" , it becomes "A; B;". Probably
not what is desired.
viz
difference ()
{
{ cube(); sphere(); }
cube();
}
=> CSG Tree
group() {
difference() {
cube(size = [1, 1, 1], center = false);
sphere($fn = 0, $fa = 12, $fs = 2, r = 1);
cube(size = [1, 1, 1], center = false);
}
}
There is another quirk in the syntax I noticed:
cube () { cube(); }
compiles and renders without error/warning, but the second cube is ignored.
--
View this message in context: http://forum.openscad.org/Syntax-Query-tp13457p13459.html
Sent from the OpenSCAD mailing list archive at Nabble.com.
OpenSCAD mailing list
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Bob,
Please do not confuse a beginner. You did not respond to his Q1.
He asked about the “{}” around a single statement after an if() definition,
and you responded about the “()” of the test itself.
Just my humble $0.02,
Jean-Paul
AC9GH
> On Aug 6, 2015, at 8:28 AM, bobc <bobcousins42@googlemail.com> wrote:
>
> Q1) round braces around the "if" expression are not just a good idea, they
> are mandatory! :)
>
> Q2) a statement such as translate () {...} used to create a group is fine,
> but *will* perform implicit union. I normally use group() in that sort of
> case, but group() and union() are equivalent.
>
> "{A; B;}" does not become "group() {A;B;}" , it becomes "A; B;". Probably
> not what is desired.
>
> viz
>
> difference ()
> {
> { cube(); sphere(); }
> cube();
> }
> => CSG Tree
> group() {
> difference() {
> cube(size = [1, 1, 1], center = false);
> sphere($fn = 0, $fa = 12, $fs = 2, r = 1);
> cube(size = [1, 1, 1], center = false);
> }
> }
>
> There is another quirk in the syntax I noticed:
>
> cube () { cube(); }
>
> compiles and renders without error/warning, but the second cube is ignored.
>
>
>
>
> --
> View this message in context: http://forum.openscad.org/Syntax-Query-tp13457p13459.html
> Sent from the OpenSCAD mailing list archive at Nabble.com.
>
> _______________________________________________
> OpenSCAD mailing list
> Discuss@lists.openscad.org
> http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
B
bobc
Thu, Aug 6, 2015 4:38 PM
Sorry, yes you are right! I was responding to Michael's comment, he confused
me talking about round braces.
For the OP, I believe that
if (1) cube ();
if (1) { cube (); }
if (1) group () { cube(); }
if (1) union () { cube(); }
are all identical in function.
--
View this message in context: http://forum.openscad.org/Syntax-Query-tp13457p13462.html
Sent from the OpenSCAD mailing list archive at Nabble.com.
Sorry, yes you are right! I was responding to Michael's comment, he confused
me talking about round braces.
For the OP, I believe that
if (1) cube ();
if (1) { cube (); }
if (1) group () { cube(); }
if (1) union () { cube(); }
are all identical in function.
--
View this message in context: http://forum.openscad.org/Syntax-Query-tp13457p13462.html
Sent from the OpenSCAD mailing list archive at Nabble.com.
T
Trygon
Thu, Aug 6, 2015 6:32 PM
OK thanks, in summary instead of writing:
if() {translate() union{cube();cube();}}
it can simply be written as:
if() translate() {cube();cube();}
I hope that the above is correct...
The only item I am now unsure of is group(), which does not appear to be
documented, but OpenSCAD clearly recognises. Is it a deprecated boolean
operator?
--
View this message in context: http://forum.openscad.org/Syntax-Query-tp13457p13463.html
Sent from the OpenSCAD mailing list archive at Nabble.com.
OK thanks, in summary instead of writing:
if() {translate() union{cube();cube();}}
it can simply be written as:
if() translate() {cube();cube();}
I hope that the above is correct...
The only item I am now unsure of is group(), which does not appear to be
documented, but OpenSCAD clearly recognises. Is it a deprecated boolean
operator?
--
View this message in context: http://forum.openscad.org/Syntax-Query-tp13457p13463.html
Sent from the OpenSCAD mailing list archive at Nabble.com.
R
runsun
Thu, Aug 6, 2015 7:25 PM
The only item I am now unsure of is group(), which does not appear to be
documented, but OpenSCAD clearly recognises. Is it a deprecated boolean
operator?
Go to menu [View][Show CSG tree], where openscad display how shapes are
organized internally, you'll see lots of group() but no union(). Obviously
it's an internal thing.
$ Runsun Pan, PhD
$ -- libs: doctest , faces ( git ), offliner ( git );
tips: hash( 1 , 2 ), sweep , var
$ -- Linux Mint 17.1 Rebecca x64 + OpenSCAD 2015.03.15/2015.04.01.nightly
--
View this message in context: http://forum.openscad.org/Syntax-Query-tp13457p13464.html
Sent from the OpenSCAD mailing list archive at Nabble.com.
Trygon wrote
> The only item I am now unsure of is group(), which does not appear to be
> documented, but OpenSCAD clearly recognises. Is it a deprecated boolean
> operator?
Go to menu [View][Show CSG tree], where openscad display how shapes are
organized internally, you'll see lots of group() but no union(). Obviously
it's an internal thing.
-----
$ Runsun Pan, PhD
$ -- libs: doctest , faces ( git ), offliner ( git );
tips: hash( 1 , 2 ), sweep , var
$ -- Linux Mint 17.1 Rebecca x64 + OpenSCAD 2015.03.15/2015.04.01.nightly
--
View this message in context: http://forum.openscad.org/Syntax-Query-tp13457p13464.html
Sent from the OpenSCAD mailing list archive at Nabble.com.
M
MichaelAtOz
Thu, Aug 6, 2015 9:15 PM
Sorry, yes you are right! I was responding to Michael's comment, he
confused me talking about round braces.
For the OP, I believe that
if (1) cube ();
if (1) { cube (); }
if (1) group () { cube(); }
if (1) union () { cube(); }
are all identical in function.
The reason I said to avoid plain { } is the code below (cut down example),
with the commented out union() does not produce the same geometry as with
the uncommented union(). Both for F5 & F6. I came across this yesterday
morning, so it was fresh in my mind.
intersection() {
cube();
//union()
{
sphere();
cylinder(r=0.5,h=5,true);
}
}
Unless specifically shown otherwise above, my contribution is in the Public Domain; To the extent possible under law, I have waived all copyright and related or neighbouring rights to this work. This work is published globally via the internet. :) Inclusion of works of previous authors is not included in the above.
View this message in context: http://forum.openscad.org/Syntax-Query-tp13457p13465.html
Sent from the OpenSCAD mailing list archive at Nabble.com.
bobc wrote
> Sorry, yes you are right! I was responding to Michael's comment, he
> confused me talking about round braces.
>
> For the OP, I believe that
>
> if (1) cube ();
> if (1) { cube (); }
> if (1) group () { cube(); }
> if (1) union () { cube(); }
>
> are all identical in function.
The reason I said to avoid plain { } is the code below (cut down example),
with the commented out union() does not produce the same geometry as with
the uncommented union(). Both for F5 & F6. I came across this yesterday
morning, so it was fresh in my mind.
intersection() {
cube();
//union()
{
sphere();
cylinder(r=0.5,h=5,true);
}
}
-----
Unless specifically shown otherwise above, my contribution is in the Public Domain; To the extent possible under law, I have waived all copyright and related or neighbouring rights to this work. This work is published globally via the internet. :) Inclusion of works of previous authors is not included in the above.
The TPP is no simple “trade agreement.” Fight it! http://www.ourfairdeal.org/
--
View this message in context: http://forum.openscad.org/Syntax-Query-tp13457p13465.html
Sent from the OpenSCAD mailing list archive at Nabble.com.
BC
Bob Cousins
Thu, Aug 6, 2015 9:47 PM
Yes, that seems like a bug, if not an unexpected feature. the "{..}" gets
flattened in the CSG tree:
group() {
intersection() {
cube(size = [1, 1, 1], center = false);
sphere($fn = 0, $fa = 12, $fs = 2, r = 1);
cylinder($fn = 0, $fa = 12, $fs = 2, h = 1, r1 = 0.5, r2 = 0.5, center
= false);
}
}
There is no implicit union generated in this case, unlike "if () {...}".
I'm not sure whether this is an unintended side-effect of the syntax, or if
it is needed in some other case?
I don't recall seeing an issue for it, I'm not sure what keywords to search
for. I've probably stumbled across this a few times myself without
realising.
On 6 August 2015 at 22:15, MichaelAtOz oz.at.michael@gmail.com wrote:
Sorry, yes you are right! I was responding to Michael's comment, he
confused me talking about round braces.
For the OP, I believe that
if (1) cube ();
if (1) { cube (); }
if (1) group () { cube(); }
if (1) union () { cube(); }
are all identical in function.
The reason I said to avoid plain { } is the code below (cut down example),
with the commented out union() does not produce the same geometry as with
the uncommented union(). Both for F5 & F6. I came across this yesterday
morning, so it was fresh in my mind.
intersection() {
cube();
//union()
{
sphere();
cylinder(r=0.5,h=5,true);
}
}
Unless specifically shown otherwise above, my contribution is in the
Public Domain; To the extent possible under law, I have waived all
copyright and related or neighbouring rights to this work. This work is
published globally via the internet. :) Inclusion of works of previous
authors is not included in the above.
View this message in context:
http://forum.openscad.org/Syntax-Query-tp13457p13465.html
Sent from the OpenSCAD mailing list archive at Nabble.com.
OpenSCAD mailing list
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Yes, that seems like a bug, if not an unexpected feature. the "{..}" gets
flattened in the CSG tree:
group() {
intersection() {
cube(size = [1, 1, 1], center = false);
sphere($fn = 0, $fa = 12, $fs = 2, r = 1);
cylinder($fn = 0, $fa = 12, $fs = 2, h = 1, r1 = 0.5, r2 = 0.5, center
= false);
}
}
There is no implicit union generated in this case, unlike "if () {...}".
I'm not sure whether this is an unintended side-effect of the syntax, or if
it is needed in some other case?
I don't recall seeing an issue for it, I'm not sure what keywords to search
for. I've probably stumbled across this a few times myself without
realising.
On 6 August 2015 at 22:15, MichaelAtOz <oz.at.michael@gmail.com> wrote:
> bobc wrote
> > Sorry, yes you are right! I was responding to Michael's comment, he
> > confused me talking about round braces.
> >
> > For the OP, I believe that
> >
> > if (1) cube ();
> > if (1) { cube (); }
> > if (1) group () { cube(); }
> > if (1) union () { cube(); }
> >
> > are all identical in function.
>
> The reason I said to avoid plain { } is the code below (cut down example),
> with the commented out union() does not produce the same geometry as with
> the uncommented union(). Both for F5 & F6. I came across this yesterday
> morning, so it was fresh in my mind.
>
> intersection() {
> cube();
> //union()
> {
> sphere();
> cylinder(r=0.5,h=5,true);
> }
> }
>
>
>
> -----
> Unless specifically shown otherwise above, my contribution is in the
> Public Domain; To the extent possible under law, I have waived all
> copyright and related or neighbouring rights to this work. This work is
> published globally via the internet. :) Inclusion of works of previous
> authors is not included in the above.
>
> The TPP is no simple “trade agreement.” Fight it!
> http://www.ourfairdeal.org/
> --
> View this message in context:
> http://forum.openscad.org/Syntax-Query-tp13457p13465.html
> Sent from the OpenSCAD mailing list archive at Nabble.com.
>
> _______________________________________________
> OpenSCAD mailing list
> Discuss@lists.openscad.org
> http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
>
M
MichaelAtOz
Thu, Aug 6, 2015 10:00 PM
Given group() and the use of plain {} is undocumented, I just steer clear
most of the time.
I just use {} to group related variables so they can be collapsed in the
editor.
Unless specifically shown otherwise above, my contribution is in the Public Domain; To the extent possible under law, I have waived all copyright and related or neighbouring rights to this work. This work is published globally via the internet. :) Inclusion of works of previous authors is not included in the above.
View this message in context: http://forum.openscad.org/Syntax-Query-tp13457p13467.html
Sent from the OpenSCAD mailing list archive at Nabble.com.
Given group() and the use of plain {} is undocumented, I just steer clear
most of the time.
I just use {} to group related variables so they can be collapsed in the
editor.
-----
Unless specifically shown otherwise above, my contribution is in the Public Domain; To the extent possible under law, I have waived all copyright and related or neighbouring rights to this work. This work is published globally via the internet. :) Inclusion of works of previous authors is not included in the above.
The TPP is no simple “trade agreement.” Fight it! http://www.ourfairdeal.org/
--
View this message in context: http://forum.openscad.org/Syntax-Query-tp13457p13467.html
Sent from the OpenSCAD mailing list archive at Nabble.com.