I'm sure that this has been discussed here before, but a quick search of
the forum did not discover anything.
Q: What is the general opinion of libraries that silently override OpenSCAD
primitives?
I just wasted the better part of an hour chasing down a weird anomaly in my
code, only to find that it was caused by the BOSL2 library overriding the
square() primitive, with a default of with center=true!
From this experience, I personally think that this is a bad coding
practice. But, I'm open to hearing reasons as to why this practice is
beneficial.
Any ideas?
Respectfully, Len
On 3/28/2023 6:51 PM, Leonard Martin Struttmann wrote:
Q: What is the general opinion of libraries that silently override
OpenSCAD primitives?
I personally think it's a bad idea. There's just too much opportunity
for confusion. But it is allowed.
I just wasted the better part of an hour chasing down a weird anomaly
in my code, only to find that it was caused by the BOSL2 library
overriding the square() primitive, with a default of with center=true!
I don't duplicate that. With what I believe is a current BOSL2, a
simple square(10) yields a square in +XY, just like stock OpenSCAD.
(And I confirm that I'm getting the BOSL2 variant: it accepts
"anchor=CENTER" as a valid argument.)
From this experience, I personally think that this is a bad coding
practice. But, I'm open to hearing reasons as to why this practice is
beneficial.
It arguably keeps the picture simpler - rather than having two
differently-named functions (one built-in, one from the library) that
behave almost the same, there's just one.
The problem is that it has to be done perfectly - it's no good if the
library's version isn't a perfect superset of the built-in version.
Even then there's an opportunity for confusion if you don't remember
which features come from the library; you might move a snippet from a
file that uses the library to a file that doesn't, and be surprised when
it fails. There's also a possibility for compatibility problems, when a
new release of OpenSCAD adds a feature that conflicts with the features
that the library has added.
If square() in BOSL2 doesn't produce identical results to square() without
BOSL2 then you should file a bug report against BOSL2 with examples.
The only thing that is supposed to be different is that anchoring works.
On Tue, Mar 28, 2023 at 9:52 PM Leonard Martin Struttmann <
lenstruttmann@gmail.com> wrote:
I'm sure that this has been discussed here before, but a quick search of
the forum did not discover anything.
Q: What is the general opinion of libraries that silently override
OpenSCAD primitives?
I just wasted the better part of an hour chasing down a weird anomaly in
my code, only to find that it was caused by the BOSL2 library overriding
the square() primitive, with a default of with center=true!
From this experience, I personally think that this is a bad coding
practice. But, I'm open to hearing reasons as to why this practice is
beneficial.
Any ideas?
Respectfully, Len
OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org
Digging deeper, there ARE cases where the BOSL2 square() produces different
results from the OpenSCAD primitive square(), BUT IT DOES NOT APPEAR TO BE
A BOSL2 ISSUE.
I apologize for falsely accusing BOSL2.
It appears that the OpenSCAD 2021.01 primitive square() does not interpret
boolean values the same way as if(). Per the documentation:
Boolean values[edit
https://en.wikibooks.org/w/index.php?title=OpenSCAD_User_Manual/General&veaction=edit§ion=4
| edit source
https://en.wikibooks.org/w/index.php?title=OpenSCAD_User_Manual/General&action=edit§ion=4
]
Booleans are variables with two states, typically denoted in OpenSCAD as
true and false. Boolean variables are typically generated by conditional
tests and are employed by conditional statement 'if()'. conditional
operator '? :', and generated by logical operators ! (not), && (and),
and || (or).
Statements such as if() actually accept non-boolean variables, but most
values are converted to true in a boolean context. The values that count as
false are:
Note that "false" (the string), [0] (a numeric vector), [ [] ] (a vector
containing an empty vector), [false] (a vector containing the Boolean value
false) and 0/0 (not a number) all count as true.
This says that if() converts "A" and 1 both to true. But, square() does not
do this. This code illustrates the difference:
if ("A")
{
echo("A==true");
}
translate( [ 30, 0, 0 ] )
square( 5, center="A");
if (0)
{
echo("0==true");
}
translate( [ 20, 0, 0 ] )
square( 5, center=0 );
if (1)
{
echo("1==true");
}
translate( [ 10, 0, 0 ] )
square( 5, center=1);
square( 5, true );
The results:
Compiling design (CSG Tree generation)...
ECHO: "A==true"
ECHO: "1==true"
Compiling design (CSG Products generation)...
[image: image.png]
On Tue, Mar 28, 2023 at 9:31 PM Adrian Mariano avm4@cornell.edu wrote:
If square() in BOSL2 doesn't produce identical results to square() without
BOSL2 then you should file a bug report against BOSL2 with examples.
The only thing that is supposed to be different is that anchoring works.
On Tue, Mar 28, 2023 at 9:52 PM Leonard Martin Struttmann <
lenstruttmann@gmail.com> wrote:
I'm sure that this has been discussed here before, but a quick search of
the forum did not discover anything.
Q: What is the general opinion of libraries that silently override
OpenSCAD primitives?
I just wasted the better part of an hour chasing down a weird anomaly in
my code, only to find that it was caused by the BOSL2 library overriding
the square() primitive, with a default of with center=true!
From this experience, I personally think that this is a bad coding
practice. But, I'm open to hearing reasons as to why this practice is
beneficial.
Any ideas?
Respectfully, Len
OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org
OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org
On 3/29/2023 7:47 AM, Leonard Martin Struttmann wrote:
It appears that the OpenSCAD 2021.01 primitive square() does
not interpret boolean values the same way as if().
Indeed, for better or worse, square() ignores non-boolean values for
"center".
https://github.com/openscad/openscad/blob/f334a14c882a4d0015db6e110211435d9439b246/src/core/primitives.cc#L719
if (parameters["center"].type() == Value::Type::BOOL) {
node->center = parameters["center"].toBool();
}
Square, cube, cylinder, linear extrude, and surface are all the same.
(Though, sigh, they each do it individually rather than having a common
function.)
I think that behavior is wrong. I have mixed feelings on whether it
should behave the same as "if" (and the various logical operators) or
should treat this case as an error.