My understanding is that an existing matrix array like:
pathArray = [[49.8324, 57.0574],[49.8324, 57.0574],[50.3134,
58.2726],[50.7438, 59.3865]];
cannot be modified without the results being a new variable.
For example, I cannot append to the existing array nor can I change any of
the values inside it without creating a new array.
Am I correct?
Yes, that is correct. But be aware that the new variable can have the
same name as the old one if it's in a different scope.
For example:
let(foo = 3) // creates foo equal to 3
let(foo=foo+1) // creates a new foo in a sub-scope. RHS refers to
old foo, LHS refers to new one
This doesn't mean that foo has been redefined, though----a new foo in
a different scope has been created. If you're worried about
efficiency...this doesn't help anything. So yes, changing one entry
in a list requires creating a new list. Like if you wanted to set
entry k to [0,0,0] you might do
new_array = [for(i=[0:len(array)-1]) i==k ? [0,0,0] : array[i]];
which rewrites the array with the desired substitution at k. Most of
the time these kind of efficiencies aren't very important because
actually creating geometry is much slower and dominates the time.
But for complicated algorithms it can matter, so you may want to think
about getting your list right the first time instead of rewriting it a
bunch of times. Also note that it's not always obvious what is the
fastest method for doing a task in OpenSCAD.
On Sun, May 8, 2022 at 12:52 PM Joe Weinpert joe.weinpert@gmail.com wrote:
My understanding is that an existing matrix array like:
pathArray = [[49.8324, 57.0574],[49.8324, 57.0574],[50.3134, 58.2726],[50.7438, 59.3865]];
cannot be modified without the results being a new variable.
For example, I cannot append to the existing array nor can I change any of the values inside it without creating a new array.
Am I correct?
OpenSCAD mailing list
To unsubscribe send an email to discuss-leave@lists.openscad.org