Discussion:
[OpenSCAD] Scalar product is not distributive
Ronaldo Persiano
2018-12-05 16:30:38 UTC
Permalink
echo([1]+[1,2] );
echo([2]*([1]+[1,2]));
echo([2]*[1] + [2]*[1,2]);

// ECHO: [2] ???

// ECHO: 4

// ECHO: undef


Is this intentional or a bug?
Parkinbot
2018-12-05 17:06:47 UTC
Permalink
Would you expect a 1D or a 2D value as sum of a 1D vector and a 2D vector?
OpenSCAD silently returns a value procrusted to the lowest dimension. Matlab
returns a 2D value and doesn't differentiate between [1] and 1. Is it, what
you are opting for?

echo([1]+[1,2] ); // [2]
echo([1, 2, 3]+[1, 2]); //[1, 4]
echo(1+[1,2] ); // undef




--
Sent from: http://forum.openscad.org/
Ronaldo Persiano
2018-12-05 17:33:54 UTC
Permalink
I would expect undef as the sum. So, [2]*([1]+[1,2]) == [2]*[1]+[2]*[1,2])
== undef
Post by Parkinbot
Would you expect a 1D or a 2D value as sum of a 1D vector and a 2D vector?
OpenSCAD silently returns a value procrusted to the lowest dimension. Matlab
returns a 2D value and doesn't differentiate between [1] and 1. Is it, what
you are opting for?
echo([1]+[1,2] ); // [2]
echo([1, 2, 3]+[1, 2]); //[1, 4]
echo(1+[1,2] ); // undef
--
Sent from: http://forum.openscad.org/
_______________________________________________
OpenSCAD mailing list
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
nop head
2018-12-05 18:31:30 UTC
Permalink
I would not expect the truncation, so:

echo([1]+[1,2] ); // [2, 2]
echo([1, 2, 3]+[1, 2]); //[2, 4, 3]
echo(1+[1,2] ); // undef
Post by Ronaldo Persiano
I would expect undef as the sum. So, [2]*([1]+[1,2]) == [2]*[1]+[2]*[1,2])
== undef
Post by Parkinbot
Would you expect a 1D or a 2D value as sum of a 1D vector and a 2D vector?
OpenSCAD silently returns a value procrusted to the lowest dimension. Matlab
returns a 2D value and doesn't differentiate between [1] and 1. Is it, what
you are opting for?
echo([1]+[1,2] ); // [2]
echo([1, 2, 3]+[1, 2]); //[1, 4]
echo(1+[1,2] ); // undef
--
Sent from: http://forum.openscad.org/
_______________________________________________
OpenSCAD mailing list
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
_______________________________________________
OpenSCAD mailing list
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Parkinbot
2018-12-06 01:38:33 UTC
Permalink
I would expect

echo([1]+[2,3]) // undef
echo(1+[2,3]) // [3,4]
echo(1+[1,2,3]) // [2,3,4]

following the pattern

echo(5*[1,2]); // [5,10]
echo([5]*[1,2]); // undef



--
Sent from: http://forum.openscad.org/

Loading...